Changeset 15 for CMT/v1r19/source


Ignore:
Timestamp:
Mar 14, 2005, 8:42:34 AM (19 years ago)
Author:
arnault
Message:

Steps for strategy management

Location:
CMT/v1r19/source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • CMT/v1r19/source/cmt.h

    r11 r15  
    3232  cmt_string m_cmt_site;
    3333  cmt_string m_cmt_version;
    34  
    35   int m_current_build_strategy;
    36   int m_current_setup_strategy;
    3734 
    3835  cmt_string m_current_dir;
     
    204201  static const cmt_string& get_current_offset ();
    205202  static AccessMode get_current_access ();
    206   static int get_current_build_strategy ();
    207   static int get_current_setup_strategy ();
    208203  static CmtStructuringStyle get_current_structuring_style ();
    209204  static CmtDirStyle get_current_style ();
     
    240235  static void restore_all_tags (Use* use);
    241236  static void set_current_access (AccessMode mode);
    242   static void set_current_build_strategy (int strategy);
    243   static void set_current_setup_strategy (int strategy);
    244237  static void set_scope_filtering_mode (CmtScopeFilteringMode mode);
    245238  static void set_standard_macros ();
  • CMT/v1r19/source/cmt_commands.cxx

    r11 r15  
    18971897void ArgParser::option_no_cleanup ()
    18981898{
    1899   cmt.m_current_setup_strategy |= SetupNoCleanup;
     1899  //cmt.m_current_setup_strategy |= SetupNoCleanup;
    19001900}
    19011901
  • CMT/v1r19/source/cmt_parser.cxx

    r11 r15  
    6262  m_cmt_root       = "";
    6363  m_cmt_version    = "";
    64   m_current_build_strategy = DefaultBuildStrategy;
    65   m_current_setup_strategy = DefaultSetupStrategy;
    6664  m_current_dir     = "";
    6765  m_current_package = "";
     
    155153
    156154//----------------------------------------------------------
    157 static int get_build_strategy (Use& use = Use::current())
     155static bool get_strategy (const cmt_string& name, Use& use = Use::current())
    158156{
    159157  static cmt_string cmtpath;
     
    164162  Project* p = Project::find_by_cmtpath (cmtpath);
    165163
    166   int strategy = 0;
    167 
    168   if (p == 0) strategy = Cmt::get_current_build_strategy ();
    169   else strategy = p->get_build_strategy ();
    170 
    171   return (strategy);
    172 }
    173 
    174 //----------------------------------------------------------
    175 static int get_setup_strategy (Use& use = Use::current())
    176 {
    177   static cmt_string cmtpath;
    178   static cmt_string offset;
    179 
    180   use.get_cmtpath_and_offset (cmtpath, offset);
    181 
    182   Project* p = Project::find_by_cmtpath (cmtpath);
    183 
    184   int strategy = 0;
    185 
    186   if (p == 0) strategy = Cmt::get_current_setup_strategy ();
    187   else strategy = p->get_setup_strategy ();
     164  bool strategy;
     165
     166  if (p == 0) strategy = StrategyMgr::get_default_strategy (name);
     167  else strategy = p->get_strategy (name);
    188168
    189169  return (strategy);
     
    17371717  }
    17381718
    1739   if ((get_build_strategy () & InstallAreaMask) == WithInstallArea)
     1719  if (get_strategy ("InstallArea"))
    17401720    {
    17411721      const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
     
    21592139    //  Try a cleanup of the installation area
    21602140    //
    2161   if ((get_build_strategy () & InstallAreaMask) == WithInstallArea)
     2141  if (get_strategy ("InstallArea"))
    21622142    {
    21632143      CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
     
    21652145      //cout << "#IA3>" << endl;
    21662146
    2167       if ((get_setup_strategy () & SetupCleanupMask) == SetupCleanup)
     2147      if (get_strategy ("SetupCleanup"))
    21682148        {
    21692149          ia_mgr.config ();
     
    28332813              Symbol::expand (libname);
    28342814
    2835               if ((get_build_strategy () & InstallAreaMask) == WithInstallArea)
     2815              if (get_strategy ("InstallArea"))
    28362816                {
    28372817                  const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
     
    30323012    //  Try a cleanup of the installation area
    30333013    //
    3034   if ((get_build_strategy () & InstallAreaMask) == WithInstallArea)
     3014  if (get_strategy ("InstallArea"))
    30353015    {
    30363016      CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
     
    30413021
    30423022      /*
    3043       if ((get_setup_strategy () & SetupCleanupMask) == SetupCleanup)
     3023      if (get_strategy ("SetupCleanup"))
    30443024        {
    30453025          const cmt_string& installarea = ia_mgr.get_installarea ();
     
    35813561  Project* p = Project::get_current ();
    35823562
    3583   if (p != 0) p->show ();
    3584   else cout << "No current project" << endl;
     3563  /*
     3564    if (p != 0) p->show ();
     3565    else cout << "No current project" << endl;
     3566  */
    35853567
    35863568  cout << "Structuring style : ";
    3587 
    3588   int strategy = 0;
    35893569
    35903570  switch (Me.m_current_structuring_style)
     
    36023582  cout << "Build strategy    : ";
    36033583
    3604   if (p == 0) strategy = Me.m_current_build_strategy;
    3605   else strategy = p->get_build_strategy ();
     3584  if (get_strategy ("BuildPrototypes"))
     3585    {
     3586      cout << "prototypes";
     3587    }
     3588  else
     3589    {
     3590      cout << "no_prototypes";
     3591    }
    36063592 
    3607   if ((strategy & PrototypesMask) == Prototypes)
    3608     {
    3609       cout << "prototypes";
    3610     }
    3611   else
    3612     {
    3613       cout << "no_prototypes";
    3614     }
    3615  
    3616   if ((strategy & InstallAreaMask) == WithInstallArea)
     3593  if (get_strategy ("InstallArea"))
    36173594    {
    36183595      cout << " with_installarea";
     
    36273604  cout << "Setup strategy    : ";
    36283605 
    3629   strategy = get_setup_strategy ();
    3630 
    3631   if ((strategy & SetupConfigMask) == SetupConfig)
     3606  if (get_strategy ("SetupConfig"))
    36323607    {
    36333608      cout << "config";
     
    36383613    }
    36393614 
    3640   if ((strategy & SetupRootMask) == SetupRoot)
     3615  if (get_strategy ("SetupRoot"))
    36413616    {
    36423617      cout << " root";
     
    36473622    }
    36483623 
    3649   if ((strategy & SetupCleanupMask) == SetupCleanup)
     3624  if (get_strategy ("SetupCleanup"))
    36503625    {
    36513626      cout << " cleanup";
     
    38023777{
    38033778  return (Me.m_current_access);
    3804 }
    3805 
    3806 int Cmt::get_current_build_strategy ()
    3807 {
    3808   return (Me.m_current_build_strategy);
    3809 }
    3810 
    3811 int Cmt::get_current_setup_strategy ()
    3812 {
    3813   return (Me.m_current_setup_strategy);
    38143779}
    38153780
     
    41154080  cmt_string no_cleanup_opt;
    41164081
    4117   if ((get_setup_strategy () & SetupCleanupMask) != SetupCleanup)
     4082  if (get_strategy ("SetupCleanup"))
    41184083    {
    41194084      no_cleanup_opt = " -no_cleanup";
     
    43074272  cmt_string no_cleanup_opt;
    43084273
    4309   if ((get_setup_strategy () & SetupCleanupMask) != SetupCleanup)
     4274  if (get_strategy ("SetupCleanup"))
    43104275    {
    43114276      no_cleanup_opt = " -no_cleanup";
     
    46454610bool Cmt::need_prototypes ()
    46464611{
    4647   if ((get_build_strategy () & PrototypesMask) == Prototypes) return (true);
     4612  if (get_strategy ("BuildPrototypes")) return (true);
    46484613  else return (false);
    46494614}
     
    56805645  cmt_string system = CmtSystem::get_cmt_config ();
    56815646
    5682   int strategy = 0;
    5683 
    5684   strategy = get_setup_strategy (use);
    5685 
    5686   bool do_config = ((strategy & SetupConfigMask) == SetupConfig);
    5687   bool do_root = ((strategy & SetupRootMask) == SetupRoot);
     5647  bool do_config = get_strategy ("SetupConfig");
     5648  bool do_root = get_strategy ("SetupRoot");
    56885649
    56895650  switch (mode)
     
    72267187    CmtPathPattern::apply_all ();
    72277188
    7228     if ((get_build_strategy () & InstallAreaMask) == WithInstallArea)
     7189    if (get_strategy ("InstallArea"))
    72297190      {
    72307191        CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
     
    72667227
    72677228//----------------------------------------------------------
    7268 void Cmt::set_current_build_strategy (int strategy)
    7269 {
    7270   Me.m_current_build_strategy = strategy;
    7271 }
    7272 
    7273 //----------------------------------------------------------
    7274 void Cmt::set_current_setup_strategy (int strategy)
    7275 {
    7276   Me.m_current_setup_strategy = strategy;
    7277 }
    7278 
    7279 //----------------------------------------------------------
    72807229void Cmt::set_scope_filtering_mode (CmtScopeFilteringMode mode)
    72817230{
     
    73727321    //
    73737322  /*
    7374   if ((get_build_strategy () & InstallAreaMask) == WithInstallArea)
     7323  if (get_strategy ("InstallArea"))
    73757324    {
    73767325      CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
  • CMT/v1r19/source/cmt_project.cxx

    r11 r15  
    153153    Now Figure out the project name from the project file
    154154    Or construct an automatic project name when project file does no exist
    155     or does not specify the project name
     155       or does not specify the project name
    156156   */
    157157  if (CmtSystem::cd ("cmt") && CmtSystem::test_file (Project::get_project_file_name ()))
     
    841841  m_children.clear ();
    842842
    843   m_build_strategy_mask = 0;
    844   m_build_strategy = DefaultBuildStrategy;
    845   m_setup_strategy_mask = 0;
    846   m_setup_strategy = DefaultSetupStrategy;
    847 
    848843  m_configured = false;
    849844
    850   m_prototypes_tag = 0;
    851   m_no_prototypes_tag = 0;
    852   m_with_installarea_tag = 0;
    853   m_without_installarea_tag = 0;
    854  
    855   m_setup_config_tag = 0;
    856   m_setup_no_config_tag = 0;
    857   m_setup_root_tag = 0;
    858   m_setup_no_root_tag = 0;
    859   m_setup_cleanup_tag = 0;
    860   m_setup_no_cleanup_tag = 0;
     845  m_strategies.clear ();
    861846}
    862847
     
    887872      if (parent->get_name () == p->get_name ())
    888873        {
    889           // Already registered
     874          // Already registered as a parent
    890875          return;
    891876        }
     
    896881  // Since p is a new parent, we should propagate the settings UP.
    897882
    898   if (m_setup_strategy_mask != 0)
    899     {
    900       p->set_setup_strategy (m_setup_strategy_mask, m_setup_strategy & PrototypesMask);
    901       p->set_setup_strategy (m_setup_strategy_mask, m_setup_strategy & InstallAreaMask);
    902     }
    903 
    904   if (m_build_strategy_mask != 0)
    905     {
    906       p->set_build_strategy (m_build_strategy_mask, m_build_strategy & SetupConfigMask);
    907       p->set_build_strategy (m_build_strategy_mask, m_build_strategy & SetupRootMask);
    908       p->set_build_strategy (m_build_strategy_mask, m_build_strategy & SetupCleanupMask);
    909     }
     883  p->update_strategies_from_children ();
    910884}
    911885
     
    936910      if (child->get_name () == p->get_name ())
    937911        {
    938           // Already registered
     912          // Already registered as a child
    939913          return;
    940914        }
     
    947921void Project::configure ()
    948922{
    949   /*
    950 
    951   <project>_prototypes
    952   <project>_no_prototypes
    953   <project>_rebuild_makefile
    954   <project>_keep_makefile
    955   <project>_with_installarea
    956   <project>_without_installarea
    957 
    958   <project>_setup_config
    959   <project>_setup_no_config
    960   <project>_setup_root
    961   <project>_setup_no_root
    962   <project>_setup_cleanup
    963   <project>_setup_no_cleanup
    964 
    965   */
    966 
    967923  if (m_configured) return;
    968924  m_configured = true;
    969925
    970   cmt_string tag_name;
    971 
    972   tag_name = m_name;
    973   tag_name += "_prototypes";
    974   m_prototypes_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    975  
    976   tag_name = m_name;
    977   tag_name += "_no_prototypes";
    978   m_no_prototypes_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    979  
    980   m_prototypes_tag->add_tag_exclude (m_no_prototypes_tag);
    981   m_no_prototypes_tag->add_tag_exclude (m_prototypes_tag);
    982   m_prototypes_tag->mark ();
    983  
    984   tag_name = m_name;
    985   tag_name += "_with_installarea";
    986   m_with_installarea_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    987  
    988   tag_name = m_name;
    989   tag_name += "_without_installarea";
    990   m_without_installarea_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    991  
    992   m_with_installarea_tag->add_tag_exclude (m_without_installarea_tag);
    993   m_without_installarea_tag->add_tag_exclude (m_with_installarea_tag);
    994   m_without_installarea_tag->mark ();
    995 
    996 
    997 
    998   tag_name = m_name;
    999   tag_name += "_setup_config";
    1000   m_setup_config_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    1001  
    1002   tag_name = m_name;
    1003   tag_name += "_setup_no_config";
    1004   m_setup_no_config_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    1005  
    1006   m_setup_config_tag->add_tag_exclude (m_setup_no_config_tag);
    1007   m_setup_no_config_tag->add_tag_exclude (m_setup_config_tag);
    1008   m_setup_config_tag->mark ();
    1009 
    1010   tag_name = m_name;
    1011   tag_name += "_setup_root";
    1012   m_setup_root_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    1013  
    1014   tag_name = m_name;
    1015   tag_name += "_setup_no_root";
    1016   m_setup_no_root_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    1017  
    1018   m_setup_root_tag->add_tag_exclude (m_setup_no_root_tag);
    1019   m_setup_no_root_tag->add_tag_exclude (m_setup_root_tag);
    1020   m_setup_root_tag->mark ();
    1021 
    1022   tag_name = m_name;
    1023   tag_name += "_setup_cleanup";
    1024   m_setup_cleanup_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    1025  
    1026   tag_name = m_name;
    1027   tag_name += "_setup_no_cleanup";
    1028   m_setup_no_cleanup_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0);
    1029  
    1030   m_setup_cleanup_tag->add_tag_exclude (m_setup_no_cleanup_tag);
    1031   m_setup_no_cleanup_tag->add_tag_exclude (m_setup_cleanup_tag);
    1032   m_setup_cleanup_tag->mark ();
    1033 
    1034   if (Cmt::get_debug ())
    1035     {
    1036       cout << "Project::configure> " << m_name
    1037            << " " << m_prototypes_tag
    1038            << " " << m_no_prototypes_tag
    1039            << " " << m_with_installarea_tag
    1040            << " " << m_without_installarea_tag
    1041            << " " << m_setup_config_tag
    1042            << " " << m_setup_no_config_tag
    1043            << " " << m_setup_root_tag
    1044            << " " << m_setup_no_root_tag
    1045            << " " << m_setup_cleanup_tag
    1046            << " " << m_setup_no_cleanup_tag
    1047            << endl;
    1048     }
    1049 }
    1050 
    1051 //----------------------------------------------------------
     926  set_default_strategy ("SetupConfig");
     927  set_default_strategy ("SetupRoot");
     928  set_default_strategy ("SetupCleanup");
     929  set_default_strategy ("BuildPrototypes");
     930  set_default_strategy ("InstallArea");
     931}
     932
     933/**---------------------------------------------------------
     934 A use statement is met in the project file
     935*/
    1052936void Project::use_action (const cmt_string& name, const cmt_string& release)
    1053937{
     
    1059943  // If not: look for it
    1060944  //   + get CMTPROJECTPATH
    1061   //   + search from all entries of CMTPROJECTPATH : pi/<name>/<release>
     945  //   + search from all entries of CMTPROJECTPATH : p(i)/<name>/<release>
    1062946  //   + when found, this should become a new CMTPATH entry
    1063947  //   +             the new project is then parsed ... etc...
     
    1065949  cmt_string cmtprojectpath = CmtSystem::getenv ("CMTPROJECTPATH");
    1066950  cmt_string sep;
    1067   sep += CmtSystem::path_separator ();
     951  sep = CmtSystem::path_separator ();
    1068952
    1069953  //cerr << "cmtprojectpath = " << cmtprojectpath << endl;
     
    1081965      if (CmtSystem::test_directory (p))
    1082966        {
    1083           //cerr << "Project directry " << p << " exists " << endl;
     967          //cerr << "Project directory " << p << " exists " << endl;
    1084968
    1085969          IProjectFactory& factory = ProjectFactory::instance ();
     
    11771061
    11781062//----------------------------------------------------------
    1179 int Project::get_build_strategy () const
    1180 {
    1181   int result = 0;
    1182 
    1183   result = Cmt::get_current_build_strategy ();
    1184 
     1063bool Project::has_strategy (const StrategyDef* definition) const
     1064{
    11851065  int i;
    11861066
    1187   bool request_non_default_prototypes = false;
    1188   bool request_non_default_installarea = false;
    1189 
    1190   int m_prototypes = 0;
    1191   int m_installarea = 0;
     1067  for (i = 0; i < m_strategies.size (); i++)
     1068    {
     1069      const Strategy& s = m_strategies[i];
     1070      if (s.m_definition == definition)
     1071        {
     1072          return (true);
     1073        }
     1074    }
     1075
     1076  return (false);
     1077}
     1078
     1079//----------------------------------------------------------
     1080bool Project::get_strategy (const cmt_string& name) const
     1081{
     1082  static StrategyMgr& mgr = StrategyMgr::instance ();
     1083
     1084  StrategyDef* def = mgr.find_strategy (name);
     1085  if (def == 0)
     1086    {
     1087      cerr << "#CMT> strategy " << name << " undefined" << endl;
     1088      return (false);
     1089    }
     1090
     1091  return (get_strategy (def));
     1092}
     1093
     1094//----------------------------------------------------------
     1095bool Project::is_specified (const StrategyDef* definition) const
     1096{
     1097  int i;
     1098
     1099  for (i = 0; i < m_strategies.size (); i++)
     1100    {
     1101      Strategy& s = m_strategies[i];
     1102      if (s.m_definition == definition)
     1103        {
     1104          // This strategy is applied in this project
     1105          return (s.m_specified);
     1106        }
     1107    }
     1108
     1109  // This strategy is not applied in this project
     1110  return (false);
     1111}
     1112
     1113//----------------------------------------------------------
     1114bool Project::get_strategy (const StrategyDef* def) const
     1115{
     1116  int i;
     1117
     1118  for (i = 0; i < m_strategies.size (); i++)
     1119    {
     1120      Strategy& s = m_strategies[i];
     1121      if (s.m_definition == def)
     1122        {
     1123          // This strategy is applied in this project
     1124          if (s.m_specified)
     1125            {
     1126              return (s.m_specified_value);
     1127            }
     1128          return (s.m_value);
     1129        }
     1130    }
     1131
     1132  // This strategy is not applied in this project
     1133  return (def->m_default_value);
     1134}
     1135
     1136//----------------------------------------------------------
     1137void Project::set_default_strategy (const cmt_string& name)
     1138{
     1139  static StrategyMgr& mgr = StrategyMgr::instance ();
     1140
     1141  StrategyDef* def = mgr.find_strategy (name);
     1142  if (def == 0)
     1143    {
     1144      cerr << "#CMT> strategy " << name << " undefined" << endl;
     1145      return;
     1146    }
     1147
     1148  update_strategy (def, def->m_default_value);
     1149}
     1150
     1151
     1152//----------------------------------------------------------
     1153void Project::set_strategy (const cmt_string& name, const cmt_string& value)
     1154{
     1155  static StrategyMgr& mgr = StrategyMgr::instance ();
     1156
     1157  StrategyDef* def = mgr.find_strategy (name);
     1158  if (def == 0)
     1159    {
     1160      cerr << "#CMT> strategy " << name << " undefined" << endl;
     1161      return;
     1162    }
     1163
     1164  bool b_value = false;
     1165
     1166  if (value == def->m_on_value)
     1167    {
     1168      b_value = true;
     1169    }
     1170  else if (value == def->m_off_value)
     1171    {
     1172      b_value = false;
     1173    }
     1174  else
     1175    {
     1176      cerr << "#CMT> requested strategy value " << value << " undefined in strategy " << name << endl;
     1177      return;
     1178    }
     1179
     1180  set_strategy (def, b_value);
     1181}
     1182
     1183//----------------------------------------------------------
     1184void Project::set_strategy (StrategyDef* definition, bool b_value)
     1185{
     1186  bool need_strategy = true;
     1187
     1188  int i;
     1189
     1190  for (i = 0; i < m_strategies.size (); i++)
     1191    {
     1192      Strategy& s = m_strategies[i];
     1193      if (s.m_definition == definition)
     1194        {
     1195          // This strategy is already applied in this project. Let's change it's value
     1196          s.set (definition, b_value, get_name ());
     1197          need_strategy = false;
     1198          break;
     1199        }
     1200    }
     1201
     1202  if (need_strategy)
     1203    {
     1204      // This strategy is not yet applied in this project.
     1205
     1206      Strategy& s = m_strategies.add ();
     1207      s.set (definition, b_value, get_name ());
     1208    }
     1209 
     1210  for (i = 0; i < m_parents.size (); i++)
     1211    {
     1212      Project* project = m_parents[i];
     1213
     1214      project->update_strategy (definition, b_value);
     1215    }
     1216}
     1217
     1218/**----------------------------------------------------------
     1219   The strategy value is changed because of indirect influences
     1220   - default strategy at initialization time
     1221   - change in the children
     1222   - change in the children list
     1223
     1224   (This is not a specification : see the set_strategy method)
     1225 */
     1226void Project::update_strategy (StrategyDef* definition, bool b_value)
     1227{
     1228  bool need_strategy = true;
     1229
     1230  int i;
     1231
     1232  for (i = 0; i < m_strategies.size (); i++)
     1233    {
     1234      Strategy& s = m_strategies[i];
     1235      if (s.m_definition == definition)
     1236        {
     1237          // This strategy is already applied in this project. Let's change it's value
     1238          s.update (definition, b_value, get_name ());
     1239          need_strategy = false;
     1240          break;
     1241        }
     1242    }
     1243
     1244  if (need_strategy)
     1245    {
     1246      // This strategy is not yet applied in this project.
     1247
     1248      Strategy& s = m_strategies.add ();
     1249      s.update (definition, b_value, get_name ());
     1250    }
     1251 
     1252  for (i = 0; i < m_parents.size (); i++)
     1253    {
     1254      Project* project = m_parents[i];
     1255
     1256      if (project->has_strategy (definition))
     1257        {
     1258          project->update_strategy (definition, b_value);
     1259        }
     1260    }
     1261}
     1262
     1263/**----------------------------------------------------------
     1264   At least one of the children has changed this strategy
     1265   Or the list of children has changed.
     1266   We need to update the strategy value accordingly
     1267   This will not change the specified value for this strategy
     1268 */
     1269void Project::update_strategy_from_children (StrategyDef* definition)
     1270{
     1271  // If this strategy is specified we don't care what happens from the children
     1272
     1273  cerr << "Updating strategy " << definition->m_name << " from children for project " << m_name << endl;
     1274
     1275  int i;
     1276
     1277  for (i = 0; i < m_strategies.size (); i++)
     1278    {
     1279      Strategy& s = m_strategies[i];
     1280      if (s.m_definition == definition)
     1281        {
     1282          // This strategy is applied in this project.
     1283
     1284          if (s.m_specified)
     1285            {
     1286              // There will be no impact since the strategy is specified
     1287
     1288              cerr << "This strategy is specified in this project" << endl;
     1289              return;
     1290            }
     1291
     1292          break;
     1293        }
     1294    }
     1295
     1296  // The strategy is not specified locally so we will now figure out
     1297  // which strategy has to be considered from the mixture of specifications
     1298  // from all children.
     1299
     1300  // Algorithm:
     1301  // - We consider children by pairs
     1302  // - a child that specifies its strategy wins over a child that does not
     1303  // - when the two children have the same level of priority we consider the priority value
     1304
     1305  Project* selected = 0;
     1306  bool selected_is_specified = false;
     1307  bool selected_value = false;
    11921308
    11931309  for (i = 0; i < m_children.size (); i++)
    11941310    {
    1195       const Project* p = m_children[i];
    1196       int s = p->get_build_strategy ();
    1197 
    1198       int s_prototypes = s & ~PrototypesMask;
    1199 
    1200       if (s_prototypes != DefaultPrototypesStrategy)
    1201         {
    1202           // keep it. At least one of the children has specified a non-default strategy
    1203           request_non_default_prototypes = true;
    1204           m_prototypes = s_prototypes;
    1205         }
    1206 
    1207       int s_installarea = s & ~InstallAreaMask;
    1208 
    1209       if (s_installarea != DefaultInstallAreaStrategy)
    1210         {
    1211           // keep it. At least one of the children has specified a non-default strategy
    1212           request_non_default_installarea = true;
    1213           m_installarea = s_installarea;
    1214         }
    1215     }
    1216 
    1217   if (m_build_strategy_mask != 0)
    1218     {
    1219       result &= ~m_build_strategy_mask;
    1220       result |= m_build_strategy;
     1311      Project* p = m_children[i];
     1312
     1313      cerr << "Checking strategy for child " << p->get_name () << endl;
     1314
     1315      bool is_specified = p->is_specified (definition);
     1316      bool value = p->get_strategy (definition);
     1317
     1318      if (selected == 0)
     1319        {
     1320          selected = p;
     1321          selected_is_specified = is_specified;
     1322          selected_value = value;
     1323          continue;
     1324        }
     1325
     1326      if (is_specified == selected_is_specified)
     1327        {
     1328          if (selected_value != value)
     1329            {
     1330              // same level of priority but different values -> we must decide
     1331              bool priority_value = definition->m_priority_value;
     1332              if (value == priority_value)
     1333                {
     1334                  selected = p;
     1335                  selected_is_specified = is_specified;
     1336                  selected_value = value;
     1337                }
     1338            }
     1339        }
     1340      else
     1341        {
     1342          if (is_specified)
     1343            {
     1344              selected = p;
     1345              selected_is_specified = is_specified;
     1346              selected_value = value;
     1347            }
     1348        }
     1349    }
     1350
     1351  update_strategy (definition, selected_value); 
     1352}
     1353
     1354/**----------------------------------------------------------
     1355   At least one of the children has changed its strategies
     1356   Or the list of children has changed.
     1357   We need to update the strategy values accordingly
     1358   This will not change the specified values
     1359 */
     1360void Project::update_strategies_from_children ()
     1361{
     1362  StrategyDef::StrategyDefs& defs = StrategyMgr::get_definitions ();
     1363
     1364  cerr << "Updating strategies from children for project " << m_name << endl;
     1365
     1366  int i;
     1367
     1368  for (i = 0; i < defs.size (); i++)
     1369    {
     1370      StrategyDef* def = defs[i];
     1371
     1372      update_strategy_from_children (def);
     1373    }
     1374}
     1375
     1376/**----------------------------------------------------------
     1377   The StrategyMgr singleton
     1378 */
     1379StrategyMgr& StrategyMgr::instance ()
     1380{
     1381  static StrategyMgr me;
     1382  return (me);
     1383}
     1384
     1385/**----------------------------------------------------------
     1386   The StrategyMgr constructor
     1387   Here are primarily constructed all strategy definitions
     1388 */
     1389StrategyMgr::StrategyMgr ()
     1390{
     1391  m_defs.clear ();
     1392
     1393  StrategyDef* s;
     1394
     1395  s = new StrategyDef;
     1396  s->m_name = "BuildPrototypes";
     1397  s->m_on_value = "prototypes";
     1398  s->m_off_value = "no_prototypes";
     1399  s->m_default_value = true;
     1400  s->m_priority_value = false;
     1401
     1402  m_defs.push_back (s);
     1403
     1404  s = new StrategyDef;
     1405  s->m_name = "InstallArea";
     1406  s->m_on_value = "with_installarea";
     1407  s->m_off_value = "without_installarea";
     1408  s->m_default_value = false;
     1409  s->m_priority_value = true;
     1410
     1411  m_defs.push_back (s);
     1412
     1413  s = new StrategyDef;
     1414  s->m_name = "SetupConfig";
     1415  s->m_on_value = "config";
     1416  s->m_off_value = "no_config";
     1417  s->m_default_value = true;
     1418  s->m_priority_value = false;
     1419
     1420  m_defs.push_back (s);
     1421
     1422  s = new StrategyDef;
     1423  s->m_name = "SetupRoot";
     1424  s->m_on_value = "root";
     1425  s->m_off_value = "no_root";
     1426  s->m_default_value = true;
     1427  s->m_priority_value = false;
     1428
     1429  m_defs.push_back (s);
     1430
     1431  s = new StrategyDef;
     1432  s->m_name = "SetupCleanup";
     1433  s->m_on_value = "cleanup";
     1434  s->m_off_value = "no_cleanup";
     1435  s->m_default_value = true;
     1436  s->m_priority_value = false;
     1437
     1438  m_defs.push_back (s);
     1439}
     1440
     1441/**----------------------------------------------------------
     1442   Find a strategy definition by its name
     1443 */
     1444StrategyDef* StrategyMgr::find_strategy (const cmt_string& name)
     1445{
     1446  static StrategyMgr& me = instance ();
     1447
     1448  int i;
     1449
     1450  for (i = 0; i < me.m_defs.size (); i++)
     1451    {
     1452      StrategyDef* def = me.m_defs[i];
     1453      if (def->m_name == name)
     1454        {
     1455          return (def);
     1456        }
     1457    }
     1458
     1459  return (0);
     1460}
     1461
     1462/**----------------------------------------------------------
     1463   Retreive the default value defined for a given strategy
     1464 */
     1465bool StrategyMgr::get_default_strategy (const cmt_string& name)
     1466{
     1467  StrategyDef* def = find_strategy (name);
     1468  if (def == 0) return (false);
     1469  return (def->m_default_value);
     1470}
     1471
     1472/**----------------------------------------------------------
     1473   Retreive the priority value defined for a given strategy
     1474   This value is used when two children of a project request two conflicting strategy values
     1475 */
     1476bool StrategyMgr::get_priority_strategy (const cmt_string& name)
     1477{
     1478  StrategyDef* def = find_strategy (name);
     1479  if (def == 0) return (false);
     1480  return (def->m_priority_value);
     1481}
     1482
     1483/**----------------------------------------------------------
     1484   Return the vector of all existing strategy definitions
     1485 */
     1486StrategyDef::StrategyDefs& StrategyMgr::get_definitions ()
     1487{
     1488  static StrategyMgr& me = instance ();
     1489
     1490  return (me.m_defs);
     1491}
     1492
     1493/**----------------------------------------------------------
     1494   Specify a new value for this strategy.
     1495   This only happens when a strategy statement is met in a project file or in a requirements file.
     1496 */
     1497void Strategy::set (StrategyDef* definition, bool value, const cmt_string& project_name)
     1498{
     1499  m_definition = definition;
     1500  m_specified = true;
     1501  m_specified_value = value;
     1502
     1503  update (definition, value, project_name);
     1504}
     1505
     1506/**----------------------------------------------------------
     1507   Change the effective value for this strategy.
     1508   This has no impact on to the specified value.
     1509   This will adapt the tag settings
     1510 */
     1511void Strategy::update (StrategyDef* definition, bool value, const cmt_string& project_name)
     1512{
     1513  m_value = value;
     1514
     1515  cmt_string to_tag_name = project_name;
     1516  cmt_string to_untag_name = project_name;
     1517
     1518  to_tag_name += "_";
     1519  to_untag_name += "_";
     1520
     1521  if (m_value)
     1522    {
     1523      to_tag_name += m_definition->m_on_value;
     1524      to_untag_name += m_definition->m_off_value;
    12211525    }
    12221526  else
    12231527    {
    1224       if (request_non_default_prototypes)
    1225         {
    1226           result |= m_prototypes;
    1227         }
    1228 
    1229       if (request_non_default_installarea)
    1230         {
    1231           result |= m_installarea;
    1232         }
    1233     }
    1234 
    1235   return (result);
    1236 }
    1237 
    1238 //----------------------------------------------------------
    1239 int Project::get_setup_strategy () const
    1240 {
    1241   int result = 0;
    1242 
    1243   /*
    1244   if (m_reference != 0) result = m_reference->get_setup_strategy ();
    1245   else if (m_predecessor != 0) result = m_predecessor->get_setup_strategy ();
    1246   else result = Cmt::get_current_setup_strategy ();
    1247   */
    1248 
    1249   result = Cmt::get_current_setup_strategy ();
    1250 
    1251   if (m_setup_strategy_mask != 0)
    1252     {
    1253       result &= ~m_setup_strategy_mask;
    1254       result |= m_setup_strategy;
    1255     }
    1256 
    1257   return (result);
    1258 }
    1259 
    1260 //----------------------------------------------------------
    1261 void Project::set_build_strategy (int mask, int strategy)
    1262 {
    1263   m_build_strategy_mask |= mask;
    1264   m_build_strategy &= ~mask;
    1265   m_build_strategy |= strategy;
    1266 
    1267   cmt_string to_tag_name = m_name;
    1268   cmt_string to_untag_name = m_name;
    1269 
    1270   Tag* to_tag = 0;
    1271   Tag* to_untag = 0;
    1272 
    1273   switch (strategy)
    1274     {
    1275     case Prototypes:
    1276       to_tag_name += "_prototypes";
    1277       to_untag_name += "_no_prototypes";
    1278       break;
    1279     case NoPrototypes:
    1280       to_tag_name += "_no_prototypes";
    1281       to_untag_name += "_prototypes";
    1282       break;
    1283     case WithInstallArea:
    1284       to_tag_name += "_with_installarea";
    1285       to_untag_name += "_without_installarea";
    1286       break;
    1287     case WithoutInstallArea:
    1288       to_tag_name += "_without_installarea";
    1289       to_untag_name += "_with_installarea";
    1290       break;
    1291     }
    1292 
    1293   to_tag = Tag::find (to_tag_name);
    1294   to_untag = Tag::find (to_untag_name);
    1295 
    1296   if (to_untag != 0)
    1297     {
    1298       to_untag->unmark ();
    1299     }
    1300 
    1301   if (to_tag != 0)
    1302     {
    1303       to_tag->mark ();
    1304     }
    1305  
    1306   for (int i = 0; i < m_parents.size (); i++)
    1307     {
    1308       Project* project = m_parents[i];
    1309 
    1310       if ((project->m_build_strategy_mask & mask) == 0)
    1311         {
    1312           project->set_build_strategy (mask, strategy);
    1313         }
    1314     }
    1315 }
    1316 
    1317 //----------------------------------------------------------
    1318 void Project::set_setup_strategy (int mask, int strategy)
    1319 {
    1320   m_setup_strategy_mask |= mask;
    1321   m_setup_strategy &= ~mask;
    1322   m_setup_strategy |= strategy;
    1323 
    1324   cmt_string to_tag_name = m_name;
    1325   cmt_string to_untag_name = m_name;
    1326 
    1327   Tag* to_tag = 0;
    1328   Tag* to_untag = 0;
    1329 
    1330   switch (strategy)
    1331     {
    1332     case SetupConfig:
    1333       to_tag_name += "_setup_config";
    1334       to_untag_name += "_setup_no_config";
    1335       break;
    1336     case SetupNoConfig:
    1337       to_tag_name += "_setup_no_config";
    1338       to_untag_name += "_setup_config";
    1339       break;
    1340     case SetupRoot:
    1341       to_tag_name += "_setup_root";
    1342       to_untag_name += "_setup_no_root";
    1343       break;
    1344     case SetupNoRoot:
    1345       to_tag_name += "_setup_no_root";
    1346       to_untag_name += "_setup_root";
    1347       break;
    1348     case SetupCleanup:
    1349       to_tag_name += "_setup_cleanup";
    1350       to_untag_name += "_setup_no_cleanup";
    1351       break;
    1352     case SetupNoCleanup:
    1353       to_tag_name += "_setup_no_cleanup";
    1354       to_untag_name += "_setup_cleanup";
    1355       break;
    1356     }
    1357 
    1358   to_tag = Tag::find (to_tag_name);
    1359   to_untag = Tag::find (to_untag_name);
    1360 
    1361   if (to_untag != 0)
    1362     {
    1363       to_untag->unmark ();
    1364     }
    1365 
    1366   if (to_tag != 0)
    1367     {
    1368       to_tag->mark ();
    1369     }
    1370  
    1371   for (int i = 0; i < m_parents.size (); i++)
    1372     {
    1373       Project* project = m_parents[i];
    1374 
    1375       if ((project->m_setup_strategy_mask & mask) == 0)
    1376         {
    1377           project->set_setup_strategy (mask, strategy);
    1378         }
    1379     }
    1380 }
    1381 
     1528      to_tag_name += m_definition->m_off_value;
     1529      to_untag_name += m_definition->m_on_value;
     1530    }
     1531
     1532  m_on_tag = Tag::find (to_tag_name);
     1533  m_off_tag = Tag::find (to_untag_name);
     1534
     1535  if (m_on_tag == 0)
     1536    {
     1537      m_on_tag = Tag::add (to_tag_name, PriorityConfig, "PROJECT", 0);
     1538      m_off_tag = Tag::add (to_untag_name, PriorityConfig, "PROJECT", 0);
     1539
     1540      m_on_tag->add_tag_exclude (m_off_tag);
     1541      m_off_tag->add_tag_exclude (m_on_tag);
     1542    }
     1543
     1544  m_off_tag->unmark ();
     1545  m_on_tag->mark ();
     1546}
     1547
     1548const cmt_string& StrategyDef::get_default_value () const
     1549{
     1550  if (m_default_value)
     1551    {
     1552      return (m_on_value);
     1553    }
     1554  else
     1555    {
     1556      return (m_off_value);
     1557    }
     1558}
     1559
  • CMT/v1r19/source/cmt_project.h

    r11 r15  
    1313
    1414class Project;
     15
     16class StrategyDef
     17{
     18public:
     19  typedef cmt_vector <StrategyDef*> StrategyDefs;
     20
     21  cmt_string m_name;
     22  cmt_string m_on_value;
     23  cmt_string m_off_value;
     24  bool m_default_value;
     25  bool m_priority_value;
     26
     27  const cmt_string& get_default_value () const;
     28};
     29
     30class Strategy
     31{
     32public:
     33  StrategyDef* m_definition;
     34  bool m_specified;
     35  bool m_specified_value;
     36  bool m_value;
     37  Tag* m_on_tag;
     38  Tag* m_off_tag;
     39
     40  void set (StrategyDef* definition, bool value, const cmt_string& project_name);
     41  void update (StrategyDef* definition, bool value, const cmt_string& project_name);
     42};
     43
     44class StrategyMgr
     45{
     46public:
     47  static StrategyMgr& instance ();
     48  static StrategyDef* find_strategy (const cmt_string& name);
     49  static bool get_default_strategy (const cmt_string& name);
     50  static bool get_priority_strategy (const cmt_string& name);
     51  static StrategyDef::StrategyDefs& get_definitions ();
     52
     53private:
     54  StrategyMgr ();
     55  StrategyDef::StrategyDefs m_defs;
     56};
    1557
    1658class ProjectFactory : public IProjectFactory
     
    110152  void show ();
    111153  void show_strategies () const;
    112   int get_build_strategy () const;
    113   int get_setup_strategy () const;
    114   void set_build_strategy (int mask, int strategy);
    115   void set_setup_strategy (int mask, int strategy);
     154
     155  bool has_strategy (const StrategyDef* definition) const;
     156  bool is_specified (const StrategyDef* definition) const;
     157  bool get_strategy (const StrategyDef* definition) const;
     158  bool get_strategy (const cmt_string& name) const;
     159  void set_default_strategy (const cmt_string& name);
     160  void set_strategy (const cmt_string& name, const cmt_string& value);
     161  void set_strategy (StrategyDef* definition, bool b_value);
     162  void update_strategy (StrategyDef* definition, bool b_value);
     163  void update_strategy_from_children (StrategyDef* definition);
     164  void update_strategies_from_children ();
    116165
    117166  void visit (IProjectVisitor& visitor);
     
    133182  cmt_string m_cmtpath_source;
    134183
    135   int m_build_strategy_mask;
    136   int m_build_strategy;
    137   int m_setup_strategy_mask;
    138   int m_setup_strategy;
    139 
    140184  bool m_configured;
    141185
    142   Tag* m_prototypes_tag;
    143   Tag* m_no_prototypes_tag;
    144   Tag* m_with_installarea_tag;
    145   Tag* m_without_installarea_tag;
    146 
    147   Tag* m_setup_config_tag;
    148   Tag* m_setup_no_config_tag;
    149   Tag* m_setup_root_tag;
    150   Tag* m_setup_no_root_tag;
    151   Tag* m_setup_cleanup_tag;
    152   Tag* m_setup_no_cleanup_tag;
    153 
     186  cmt_vector <Strategy> m_strategies;
    154187};
    155188
  • CMT/v1r19/source/cmt_syntax.cxx

    r11 r15  
    118118{
    119119public:
    120   bool decode (const cmt_string& w,
    121                int& mask,
    122                int& strategy)
     120  bool decode (const cmt_string& w, cmt_string& strategy, cmt_string& value)
    123121  {
    124122    bool result = true;
    125123
     124    value = w;
     125
    126126    if (w == "prototypes")
    127127      {
    128         mask = PrototypesMask;
    129         strategy = Prototypes;
     128        strategy = "BuildPrototypes";
    130129      }
    131130    else if (w == "no_prototypes")
    132131      {
    133         mask = PrototypesMask;
    134         strategy = NoPrototypes;
     132        strategy = "BuildPrototypes";
    135133      }
    136134    else if ((w == "with_installarea") || (w == "with_install_area"))
    137135      {
    138         mask = InstallAreaMask;
    139         strategy = WithInstallArea;
     136        value = "with_installarea";
     137        strategy = "InstallArea";
    140138      }
    141139    else if ((w == "without_installarea") || (w == "without_install_area"))
    142140      {
    143         mask = InstallAreaMask;
    144         strategy = WithoutInstallArea;
     141        value = "without_installarea";
     142        strategy = "InstallArea";
    145143      }
    146144    else
     
    168166        const cmt_string& w = words[i];
    169167
    170         int mask = 0;
    171         int strategy = 0;
     168        cmt_string strategy;
     169        cmt_string value;
    172170
    173171        bool in_error = false;
    174172
    175         if (!decode (w, mask, strategy))
     173        if (decode (w, strategy, value))
     174          {
     175            if (p != 0) p->set_strategy (strategy, value);
     176          }
     177        else
    176178          {
    177179            in_error = true;
    178180
    179181            CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
    180           }
    181 
    182         if (mask != 0)
    183           {
    184             if (p == 0) Cmt::set_current_build_strategy (strategy);
    185             else p->set_build_strategy (mask, strategy);
    186182          }
    187183
     
    211207        const cmt_string& w = words[i];
    212208
    213         int mask = 0;
    214         int strategy = 0;
     209        cmt_string strategy;
     210        cmt_string value;
    215211
    216212        bool in_error = false;
    217213
    218         if (!decode (w, mask, strategy))
     214        if (decode (w, strategy, value))
     215          {
     216            if (project != 0) project->set_strategy (strategy, value);
     217          }
     218        else
    219219          {
    220220            in_error = true;
    221221
    222222            CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
    223           }
    224 
    225         if (mask != 0)
    226           {
    227             if (project == 0) Cmt::set_current_build_strategy (strategy);
    228             else project->set_build_strategy (mask, strategy);
    229223          }
    230224
     
    729723{
    730724public:
    731   bool decode (const cmt_string& w, int& mask, int& strategy)
     725  bool decode (const cmt_string& w, cmt_string& strategy, cmt_string& value)
    732726  {
    733727    bool result = true;
    734728
     729    value = w;
     730
    735731    if (w == "config")
    736732      {
    737         mask = SetupConfigMask;
    738         strategy = SetupConfig;
     733        strategy = "SetupConfig";
    739734      }
    740735    else if (w == "no_config")
    741736      {
    742         mask = SetupConfigMask;
    743         strategy = SetupNoConfig;
     737        strategy = "SetupConfig";
    744738      }
    745739    else if (w == "root")
    746740      {
    747         mask = SetupRootMask;
    748         strategy = SetupRoot;
     741        strategy = "SetupRoot";
    749742      }
    750743    else if (w == "no_root")
    751744      {
    752         mask = SetupRootMask;
    753         strategy = SetupNoRoot;
     745        strategy = "SetupRoot";
    754746      }
    755747    else if (w == "cleanup")
    756748      {
    757         mask = SetupCleanupMask;
    758         strategy = SetupCleanup;
     749        strategy = "SetupCleanup";
    759750      }
    760751    else if (w == "no_cleanup")
    761752      {
    762         mask = SetupCleanupMask;
    763         strategy = SetupNoCleanup;
     753        strategy = "SetupCleanup";
    764754      }
    765755    else
     
    787777        const cmt_string& w = words[i];
    788778
    789         int mask = 0;
    790         int strategy = 0;
     779        cmt_string strategy;
     780        cmt_string value;
    791781
    792782        bool in_error = false;
    793783
    794         if (!decode (w, mask, strategy))
     784        if (decode (w, strategy, value))
     785          {
     786            if (p != 0) p->set_strategy (strategy, value);
     787          }
     788        else
    795789          {
    796790            in_error = true;
    797791
    798792            CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
    799           }
    800        
    801         if (mask != 0)
    802           {
    803             if (p == 0) Cmt::set_current_setup_strategy (strategy);
    804             else p->set_setup_strategy (mask, strategy);
    805793          }
    806794
     
    830818        const cmt_string& w = words[i];
    831819
    832         int mask = 0;
    833         int strategy = 0;
     820        cmt_string strategy;
     821        cmt_string value;
    834822
    835823        bool in_error = false;
    836824
    837         if (!decode (w, mask, strategy))
     825        if (decode (w, strategy, value))
     826          {
     827            if (project != 0) project->set_strategy (strategy, value);
     828          }
     829        else
    838830          {
    839831            in_error = true;
    840832
    841833            CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
    842           }
    843        
    844         if (mask != 0)
    845           {
    846             if (project == 0) Cmt::set_current_setup_strategy (strategy);
    847             else project->set_setup_strategy (mask, strategy);
    848834          }
    849835
Note: See TracChangeset for help on using the changeset viewer.