Changeset 535


Ignore:
Timestamp:
Mar 26, 2010, 11:56:50 AM (14 years ago)
Author:
rybkin
Message:

See C.L. 422

Location:
CMT/HEAD
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/ChangeLog

    r534 r535  
     12010-03-26    <rybkin@lal.in2p3.fr> 422
     2
     3        * source/cmt_system.cxx: In function CMTPathManager::do_add_cmt_path,
     4        ensure that projects created from CMTPATH environment variable entries do
     5        not become each others children-parents automatically (that will be
     6        based on use statements in project.cmt files). Ensure that command exit
     7        status is returned by CmtSystem::execute (const cmt_string&, cmt_string&)
     8        * source/cmt_database.h: Introduce member m_ordered_projects to keep vector
     9        of pointers to the ordered projects and function ordered_projects to return
     10        that
     11        * source/cmt_database.cxx: Implement function ordered_projects
     12        * source/cmt_project.h: Introduce functions order_all, set_is_current,
     13        is_current, erase_child, and member m_is_current
     14        * source/cmt_project.cxx: Implement introduced functions. In function
     15        ProjectFactory::create_project, call Project::order_all () if projects
     16        dependencies are updated or new project is created, call
     17        Cmt::get_current_dir_real to determine (and set the project member
     18        accordingly) whether project is current or not, do NOT make project that
     19        has no parent the top project. In function get_current, make use of
     20        is_current rather than pwd. Function Project::ordered_projects now only
     21        returns ordered projects pointers vector, projects ordering is done in
     22        Project::order_all. Ordering starts with current project, if exists, and
     23        projects without parents, if current project does not exist or has no
     24        parents and no children (the case for projects created from CMTPATH
     25        environment variable entries), and aims to put parents before children
     26        in projects order. If current project exists, only ordered projects are
     27        present in ordered projects vector. For projects without parents and
     28        without children, strategies are updated from the project next after
     29        them in the ordered projects vector. In function Project::show_all, always
     30        show all projects (rather than children of current or first project only),
     31        first show ordered projects, then show the rest. In function Project::visit,
     32        do not reorder current project if exists. Implement functions is_current,
     33        set_is_current, erase_child. In function container_action, start search
     34        from project m_cmtpath_pwd, if container is found, ensure its real_path is
     35        absolute path
     36        * source/cmt_use.h: Add helper function get_info to return use info as
     37        string
     38        * source/cmt_use.cxx: In function show_all, for home_package and
     39        user_context_package use version assigned when they are created rather
     40        than hard-wire version here, set error package_not_found if there are uses
     41        that are not located. In function reach_package, consider case of empty
     42        version. Implement get_info and make use of it in function Use::add
     43        * source/cmt_pattern.cxx: In function ApplyPattern::action, always print
     44        warning pattern_not_found, if appropriate, but do not set error (for now)
     45        * source/cmt_syntax.cxx: In functions do_parse_requirements, do_parse_words,
     46        clear syntax_error only, and print error messages in case of syntax_error
     47        only
     48        * source/cmt_log.h: Add CmtMessage::verbose function
     49        * source/cmt.h: Introduce functions get_current_dir_real, get_current_path,
     50        set_recursive
     51        * source/cmt_parser.cxx: Implement introduced functions, in function
     52        use_special_requirements, set use m_located member value to true, if
     53        requirements file exists
     54        * source/cmt_vcs.h: In class Vcs, introduce functions checkout_context,
     55        parse_arguments, resolve_uses, introduce class IUseVisitor
     56        * source/cmt_vcs.cxx: Introduce and implement class GlobalProjectAction,
     57        class Packages, in order to generate uses available via current context
     58        and search for specific packages among them. Rewrite class Walkthru to
     59        accept an implementation of IUseVisitor interface, replace parse_checkout
     60        with parse_arguments with new options -C, -i, and implement new
     61        parse_checkout, in particular, in order to implement new options -C, -i.
     62        Introduce helper classes VisitorForInfo, VisitorForCheckout implementing
     63        IUseVisitor interface, enhance Vcs::checkout_module to allow for HEAD,
     64        head, TRUNK, trunk to be used as arguments of option -r. Implement
     65        functions visit, Vcs::checkout_context, Vcs::resolve_uses in order to
     66        implement option -C, enhance Vcs::checkout_from_requirements in order to
     67        implement option -i
     68        * src/Makefile.header: Improve a diagnostic message
     69        * src/Makefile.core: Do not ignore errors in command lines beginning with
     70        macro echo
     71        * mgr/cmt_dependencies.make: Update
     72       
    1732010-02-25    <rybkin@lal.in2p3.fr> 421
    274
  • CMT/HEAD/mgr/cmt_dependencies.make

    r528 r535  
    1717cmt_pattern_cxx_dependencies =  ../source/cmt_pattern.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h   ../source/cmt_error.h   ../source/cmt_syntax.h   ../source/cmt_log.h
    1818cmt_language_cxx_dependencies =  ../source/cmt_language.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_language.h   ../source/cmt_branch.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h   ../source/cmt_error.h
    19 cmt_vcs_cxx_dependencies =  ../source/cmt_vcs.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_cvs.h   ../source/cmt_vcs.h   ../source/cmt_awk.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_project.h   ../source/cmt_log.h   ../source/cmt_error.h
     19cmt_vcs_cxx_dependencies =  ../source/cmt_vcs.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_cvs.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_vcs.h   ../source/cmt_awk.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_project.h   ../source/cmt_log.h   ../source/cmt_error.h   ../source/cmt_syntax.h
    2020cmt_group_cxx_dependencies =  ../source/cmt_group.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_group.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h
    2121cmt_database_cxx_dependencies =  ../source/cmt_database.cxx   ../source/cmt_vector.h   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h
  • CMT/HEAD/source/cmt.h

    r525 r535  
    210210  static const cmt_string& get_cmt_version ();
    211211  static const cmt_string& get_current_dir ();
     212  static const cmt_string get_current_dir_real ();
    212213  static const cmt_string& get_current_package ();
     214  static const cmt_string& get_current_path ();
    213215  static const cmt_string& get_current_cmtpath ();
    214216  static const cmt_string& get_current_offset ();
     
    258260  static void restore_all_tags (Use* use);
    259261  static void set_current_access (AccessMode mode);
     262  static void set_recursive (bool mode);
    260263  static void set_scope_filtering_mode (CmtScopeFilteringMode mode);
    261264  static void set_standard_macros ();
  • CMT/HEAD/source/cmt_database.cxx

    r11 r535  
    158158}
    159159
     160Project::ProjectPtrVector& Database::ordered_projects ()
     161{
     162  static Database& db = instance ();
     163
     164  return (db.m_ordered_projects);
     165}
     166
    160167CmtPathPattern::CmtPathPatternVector& Database::cmtpath_patterns ()
    161168{
  • CMT/HEAD/source/cmt_database.h

    r11 r535  
    5454
    5555  static Project::ProjectVector& projects ();
     56  static Project::ProjectPtrVector& ordered_projects ();
    5657
    5758  static CmtPathPattern::CmtPathPatternVector& cmtpath_patterns ();
     
    8384  Tag::TagMap m_tag_map;
    8485  Project::ProjectVector m_projects;
     86  Project::ProjectPtrVector m_ordered_projects;
    8587
    8688  CmtPathPattern::CmtPathPatternVector m_cmtpath_patterns;
  • CMT/HEAD/source/cmt_log.h

    r467 r535  
    6464  static void set_level (const CmtMsgLevel& level);
    6565  static bool active (const CmtMsgLevel& level);
     66  static void verbose (const cmt_string& message);
    6667  static void info (const cmt_string& message);
    6768  static void warning (const cmt_string& message);
     
    118119}
    119120
     121inline void CmtMessage::verbose (const cmt_string& message)
     122{
     123  if (active (Verbose))
     124    cerr << prefix () << " Verbose: " << message << endl;
     125}
     126
    120127inline void CmtMessage::info (const cmt_string& message)
    121128{
  • CMT/HEAD/source/cmt_parser.cxx

    r532 r535  
    532532  log << "configure_site_tag" << log_endl;
    533533  configure_site_tag (0);
     534  log << "configure_current_dir" << log_endl;
     535  configure_current_dir ();
    534536  log << "configure_home" << log_endl;
    535537  // CMTHOME, CMTUSERCONTEXT and CMTPATH
    536538  configure_home (0);
    537   log << "configure_current_dir" << log_endl;
     539  //  log << "configure_current_dir" << log_endl;
    538540
    539541
     
    547549  Me.m_quiet = save_quiet;
    548550
    549   configure_current_dir ();
     551  //  configure_current_dir ();
    550552
    551553  guess_current_project ();
     
    42894291  cout << "----------> uses" << endl;
    42904292  do_show_uses (ap);
     4293  // This is temporary to ensure that Make - which runs "cmt show setup" -
     4294  // does not fail for packages with unresolved uses
     4295  if (CmtError::get_last_error_code () == CmtError::package_not_found)
     4296    CmtError::clear ();
    42914297
    42924298  cout << "----------> tags" << endl;
     
    45714577}
    45724578
     4579const cmt_string Cmt::get_current_dir_real ()
     4580{
     4581  cmt_string current_dir_real;
     4582  if (CmtSystem::realpath_ (Me.m_current_dir, current_dir_real))
     4583    return current_dir_real;
     4584  return (Me.m_current_dir);
     4585}
     4586
    45734587const cmt_string& Cmt::get_current_package ()
    45744588{
    45754589  return (Me.m_current_package);
     4590}
     4591
     4592const cmt_string& Cmt::get_current_path ()
     4593{
     4594  return (Me.m_current_path);
    45764595}
    45774596
     
    85628581
    85638582//----------------------------------------------------------
     8583void Cmt::set_recursive (bool mode)
     8584{
     8585  Me.m_recursive = mode;
     8586}
     8587
     8588//----------------------------------------------------------
    85648589void Cmt::set_scope_filtering_mode (CmtScopeFilteringMode mode)
    85658590{
     
    87788803  f += CmtSystem::file_separator ();
    87798804  f += file_name;
     8805  if (CmtSystem::test_file (f))
     8806    {
     8807      use->m_located = true;
     8808    }
    87808809  SyntaxParser::parse_requirements (f, use);
    87818810
  • CMT/HEAD/source/cmt_pattern.cxx

    r504 r535  
    844844  if (p == 0)
    845845    {
    846       CmtError::set (CmtError::pattern_not_found, name);
     846      if (use->get_current_scope () != ScopeUnspecified &&
     847          use->get_current_scope () != ScopePublic)
     848        return;
     849      /*
     850      cmt_string use_info (use->get_package_name () +
     851                           " " + use->version +
     852                           (use->path != "" ? " " + use->path : "") +
     853                           " " + use->real_path
     854                           );
     855      */
     856      CmtMessage::warning (CmtError::get_error_name (CmtError::pattern_not_found) +
     857                           ": " + name +
     858                           " (applied by " + use->get_package_name () + ")"
     859                           );
     860      /*
     861        CmtError::set (CmtError::pattern_not_found, name +
     862        " (applied by " + use->get_package_name () + ")"
     863        );
     864      */
     865      /*
    847866      if (CmtMessage::active (Verbose))
    848867        {
    849           cmt_string cmtpath, offset;
    850           use->get_cmtpath_and_offset (cmtpath, offset);
    851           CmtMessage::warning ((offset != "" ? offset + "/" : "")
    852                                + use->get_package_name ()
    853                                + ": " + CmtError::get_last_error ());
    854           //CmtMessage::warning (CmtError::get_last_error ());
     868          CmtMessage::warning (CmtError::get_last_error ());
    855869        }
     870      */
    856871      return;
    857872    }
  • CMT/HEAD/source/cmt_project.cxx

    r528 r535  
    247247            }
    248248 
     249          bool updated (false);
    249250          if (parent != 0)
    250251            {
     252              if (!p.has_parent (parent) || !parent->has_child (&p))
     253                {
    251254              p.add_parent (parent);
    252255              parent->add_child (&p);
     
    255258
    256259              parent->update_strategies_from_children ();
     260              updated = true;
     261                }
     262
    257263            }
    258264
    259265          CmtSystem::cd (here);
     266          if (updated) Project::order_all ();
    260267          return (&p);
    261268        }
     
    278285
    279286  // In case there are symlinks
    280   cmt_string here_real, pwd_real;
     287
     288  //  cmt_string here_real, pwd_real;
    281289  //cerr << "realpath_: create_project" << endl;
     290  /*
    282291  if (CmtSystem::realpath_ (here, here_real) && CmtSystem::realpath_ (pwd, pwd_real))
    283292    {
    284293      if (here_real.find (pwd_real) == 0) is_current = true;
     294    }
     295  */
     296  cmt_string pwd_real;
     297  if (CmtSystem::realpath_ (pwd, pwd_real))
     298    {
     299      if (Cmt::get_current_dir_real ().find (pwd_real) == 0) is_current = true;
    285300    }
    286301
     
    544559      parent->update_strategies_from_children ();
    545560    }
     561  /*
    546562  else if ((name != "CMTUSERCONTEXT") && (name != "CMTHOME"))
    547563    //  else
     
    569585      project->update_strategies_from_children ();
    570586    }
    571 
     587  */
    572588  if (source == "default path")
    573589    {
     
    581597  project->set_cmtpath_source (source);
    582598
     599  project->set_is_current (is_current);
     600
    583601  if (is_current)
    584602    {
     603      //      cerr << "current: " << project->get_name () << endl;
    585604      //
    586605      // The current project defines a tag with its name
     
    594613
    595614
     615  //  Project::order_all ();
    596616
    597617  if (text != "")
     
    649669
    650670  CmtSystem::cd (here);
     671  Project::order_all ();
    651672
    652673  return (project);
     
    820841Project* Project::get_current ()
    821842{
     843  /*
    822844  cmt_string here = CmtSystem::pwd ();
    823845
     
    825847  cmt_string here_real;
    826848  CmtSystem::realpath_ (here, here_real);
    827 
     849  */
    828850  static ProjectVector& Projects = projects ();
    829851
     
    840862
    841863//      if (here.find (p.m_cmtpath) == 0)
    842       if (here_real.find (p.m_cmtpath_real) == 0)
     864      if (p.is_current ())
     865        //      if (here_real.find (p.m_cmtpath_real) == 0)
    843866        {
    844867          result = &p;
     
    907930
    908931//----------------------------------------------------------
    909 Project::ProjectPtrVector Project::ordered_projects ()
    910 {
    911   static ProjectPtrVector OrderedProjects;
     932Project::ProjectPtrVector& Project::ordered_projects ()
     933{
     934  static Database& db = Database::instance ();
     935  static ProjectPtrVector& Projects = db.ordered_projects ();
     936
     937  return (Projects);
     938}
     939
     940//----------------------------------------------------------
     941void Project::order_all ()
     942//Project::ProjectPtrVector Project::ordered_projects ()
     943{
     944  ProjectPtrVector OrderedProjects;
     945  //  static ProjectPtrVector OrderedProjects;
     946  static Project::ProjectPtrVector& orderedProjects = Project::ordered_projects ();
    912947
    913948  static Project::ProjectVector& Projects = Project::projects ();
     
    956991          OrderedProjects[i] = p;
    957992        }
     993      /*
    958994      if (2 == offset)
    959995        {
     
    962998          OrderedProjects[0]->update_strategies_from_children ();
    963999        }
    964       return OrderedProjects;
     1000      */
     1001      for (int i = OrderedProjects.size () - 2; i >= 0; i--)
     1002        {
     1003          if (!OrderedProjects[i]->has_parents () &&
     1004              OrderedProjects[i]->get_children_size () == 0)
     1005            {
     1006              OrderedProjects[i]->add_child (OrderedProjects[i + 1]);
     1007              OrderedProjects[i]->update_strategies_from_children ();
     1008              OrderedProjects[i]->erase_child (OrderedProjects[i + 1]);
     1009            }
     1010        }
     1011
     1012      orderedProjects = OrderedProjects;
     1013      //      return OrderedProjects;
     1014      return;
    9651015    }
    9661016
     
    9681018
    9691019  //  cerr << "get_current: " << p << " offset: " << offset << endl;
     1020  /*
    9701021  if (p == 0)
    9711022    {
     
    9731024      //      p = &(Projects[0]);
    9741025    }
     1026  */
    9751027  //  cerr << "p: " << p << " offset: " << offset << " name: " << p->get_name () << endl;
    9761028
    9771029  int order (-1);
    978 
     1030  /*
    9791031  if ((p->get_name () != "CMTUSERCONTEXT") && (p->get_name () != "CMTHOME"))
    9801032    {
     
    9891041  //  cerr << "order: " << order << endl;
    9901042  //  int unordered = size - offset - (order + 1);
     1043  */
     1044  ProjectPtrVector projs;
     1045
     1046  if (p != 0 && (p->get_name () != "CMTUSERCONTEXT") && (p->get_name () != "CMTHOME"))
     1047    {
     1048      p->m_order = ++order;
     1049      projs.push_back (p);
     1050    }
     1051
     1052  if (p == 0 ||
     1053      (!p->has_parents () && p->get_children_size () == 0)
     1054      // comes from CMTPATH entry
     1055      )
     1056    {
     1057      for (int i = offset; i < size; i++)
     1058        {
     1059          Project* q = &(Projects[i]);
     1060          if (q != p && !q->has_parents ())
     1061            {
     1062              q->m_order = ++order;
     1063              projs.push_back (q);
     1064            }
     1065        }
     1066    }
     1067
     1068  visit (offset, order, projs);
    9911069
    9921070  int beg (0);
     
    10171095          */
    10181096        }
     1097      else if (-2 != j)
     1098        {
     1099          OrderedProjects[beg + j] = p;
     1100        }
     1101      /*
    10191102      else if  (-2 == j)
    10201103        {
     
    10261109          //      cerr << "OrderedProjects[" << beg + j << "]: " << (OrderedProjects[beg + j])->get_name () << endl;
    10271110        }
    1028     }
    1029 
     1111      */
     1112    }
     1113
     1114  if (p != 0)
     1115    {
     1116      for (int i = 0; i < noorder; i++)
     1117        OrderedProjects.pop_back ();
     1118    }
    10301119  if  (-1 != ihome)
    10311120    {
    1032       OrderedProjects[size - 1] = &(Projects[ihome]);
    1033     }
    1034 
     1121      OrderedProjects[OrderedProjects.size () - 1] = &(Projects[ihome]);
     1122    }
     1123  /*
     1124  if (p)
     1125    {
     1126      if  (-1 != ihome)
     1127        {
     1128          OrderedProjects[beg + order + 1] = &(Projects[ihome]);
     1129        }
     1130      for (int i = 0; i < noorder; i++)
     1131        OrderedProjects.pop_back ();
     1132    }
     1133  else
     1134    {
     1135      if  (-1 != ihome)
     1136        {
     1137          OrderedProjects[size - 1] = &(Projects[ihome]);
     1138        }
     1139    }
     1140  */
     1141      /*
    10351142  if  (-1 != iuser)
    10361143    {
     
    10391146      OrderedProjects[0]->update_strategies_from_children ();
    10401147    }
    1041 
    1042   if  (-1 != ihome)
    1043     {
     1148      */
     1149
     1150//   if  (-1 != ihome)
     1151//     {
    10441152      /*
    10451153      cerr << "beg: " << beg << " order: " << order << endl;
    10461154      cerr << "noorder: " << noorder << " size - offset: " << size - offset << endl;
    10471155      */
     1156      /*
    10481157      if (noorder != size - offset)
    10491158        {  // the last ordered project
     
    10581167          OrderedProjects[size - 2]->update_strategies_from_children ();
    10591168        }
    1060     }
    1061 
    1062   return OrderedProjects;
     1169      */
     1170//     }
     1171
     1172  for (int i = OrderedProjects.size () - 2; i >= 0; i--)
     1173    {
     1174      if (!OrderedProjects[i]->has_parents () &&
     1175          OrderedProjects[i]->get_children_size () == 0)
     1176        {
     1177          OrderedProjects[i]->add_child (OrderedProjects[i + 1]);
     1178          OrderedProjects[i]->update_strategies_from_children ();
     1179          OrderedProjects[i]->erase_child (OrderedProjects[i + 1]);
     1180        }
     1181    }
     1182
     1183  orderedProjects = OrderedProjects;
     1184  //  return OrderedProjects;
     1185  return;
    10631186}
    10641187
     
    10801203void Project::show_all ()
    10811204{
    1082   const Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
    1083   //  static const Project::ProjectPtrVector Ordered = Project::ordered_projects ();
    1084  
    1085   for (int i = 0; i < Ordered.size (); i++)
    1086     {
    1087       Project* p = Ordered[i];
    1088       p->m_visited = false;
    1089     }
    1090 
    1091   Project* p = get_current ();
    1092 
    1093   if (p == 0)
    1094     {
    1095       if (Ordered.size () == 0) return;
    1096 
    1097       p = Ordered[0];
    1098     }
    1099   /*
     1205  static const Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
    11001206  static Project::ProjectVector& Projects = Project::projects ();
    11011207 
     
    11061212    }
    11071213
     1214  for (int i = 0; i < Ordered.size (); i++)
     1215    Ordered[i]->show ();
     1216
     1217  for (int i = 0; i < Projects.size (); i++)
     1218    Projects[i].show ();
     1219
     1220  /*
    11081221  Project* p = get_current ();
    11091222
    11101223  if (p == 0)
    11111224    {
    1112       if (Projects.size () == 0) return;
    1113 
    1114       p = &(Projects[0]);
     1225      if (Ordered.size () == 0) return;
     1226
     1227      p = Ordered[0];
    11151228    }
    11161229  */
    1117 
    1118   p->show ();
     1230  //  p->show ();
    11191231}
    11201232
     
    13031415void Project::fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections)
    13041416{
    1305   static ProjectPtrVector Ordered = Project::ordered_projects ();
     1417  static ProjectPtrVector& Ordered = Project::ordered_projects ();
    13061418  for (int i = 0; i < Ordered.size (); i++)
    13071419    {
     
    13521464void Project::broadcast (IProjectAction& action)
    13531465{
    1354   static ProjectPtrVector Projects = Project::ordered_projects ();
     1466  //  const ProjectPtrVector Projects = Project::ordered_projects ();
     1467  static ProjectPtrVector& Projects = Project::ordered_projects ();
    13551468
    13561469  for (int i = 0; i < Projects.size (); i++)
     
    13751488void Project::reverse_broadcast (IProjectAction& action)
    13761489{
    1377   static ProjectPtrVector Projects = Project::ordered_projects ();
     1490  //  const ProjectPtrVector Projects = Project::ordered_projects ();
     1491  static ProjectPtrVector& Projects = Project::ordered_projects ();
    13781492
    13791493  for (int i = (Projects.size () - 1); i >= 0; i--)
     
    15561670{
    15571671  int size = projs.size ();
     1672  //  cerr << "visit: " << offset << " " << order << " " << size << endl;
    15581673  if (0 == size) return;
    15591674  static ProjectVector& all = Project::projects ();
     
    15911706              child->m_order = ++order;
    15921707            }
    1593           else if (0 == chorder)
     1708          else if (child->is_current ())
     1709            //    else if (0 == chorder)
    15941710            { // the project we started with, i. e. the current project:
    15951711              //     o circular dependency
     
    16011717                                     + " " + child->get_cmtpath ());
    16021718            }
    1603           else if ((0 < chorder) && (chorder < porder))
     1719          else if ((0 <= chorder) && (chorder < porder))
     1720            //    else if ((0 < chorder) && (chorder < porder))
    16041721            { // ordered already, want to put it after the parent in the order
    16051722              for (int k = offset; k < all.size (); k++)
     
    16091726                    {// the child we are putting after the parent in the order
    16101727                      q.m_order = porder;
    1611                       //     cerr << "Moved back: " << q.get_name () << " order: " << q.m_order << endl;
     1728                      //              cerr << "Moved back: " << q.get_name () << " order: " << q.m_order << endl;
    16121729                    }
    16131730                  else if ((chorder < q.m_order) && (q.m_order <= porder))
     
    16151732                }
    16161733            }
    1617           //      cerr << child->get_name () << " out: " << child->m_order << endl;
     1734          //  cerr << child->get_name () << " out: " << child->m_order << endl;
    16181735          //      child->m_visits++;
    16191736          bool unknown (true);
     
    17481865  start_visit (visitor);
    17491866  */
    1750   const ProjectPtrVector Ordered = Project::ordered_projects ();
     1867  const ProjectPtrVector& Ordered = Project::ordered_projects ();
    17511868
    17521869  buffer = "path CMTPATH \"\" \n";
     
    19092026
    19102027//----------------------------------------------------------
     2028void Project::set_is_current (bool is_current)
     2029{
     2030  m_is_current = is_current;
     2031}
     2032
     2033//----------------------------------------------------------
     2034bool Project::is_current () const
     2035{
     2036  return m_is_current;
     2037}
     2038
     2039//----------------------------------------------------------
    19112040void Project::clear ()
    19122041{
     
    19252054
    19262055  m_strategies.clear ();
     2056  m_is_current = false;
    19272057}
    19282058
     
    20192149
    20202150  m_children.push_back (p);
     2151}
     2152
     2153//----------------------------------------------------------
     2154void Project::erase_child (Project* p)
     2155{
     2156  if (p == 0) return;
     2157  if (p == this) return;
     2158
     2159  if (!has_child (p)) return;
     2160
     2161  const cmt_string& name = p->get_name ();
     2162
     2163  for (int i = 0; i < m_children.size (); i++)
     2164    {
     2165      const Project* child = m_children[i];
     2166      if (child == 0) continue;
     2167
     2168      if (child->get_name () == name)
     2169        {
     2170          // registered as a child
     2171          m_children.erase (i);
     2172          break;
     2173        }
     2174    }
    20212175}
    20222176
     
    20882242      use->set (name, version, path);
    20892243      use->get_package ()->remove_use (use);
     2244      CmtSystem::cd (m_cmtpath_pwd);
    20902245      if (use->move_to ())
    20912246        {
     
    21032258            {
    21042259              use->~Use ();
     2260            }
     2261          else if (!CmtSystem::absolute_path (use->real_path))
     2262            {
     2263              use->change_path (m_cmtpath_pwd);
    21052264            }
    21062265        }
     
    23822541  static int level = 0;
    23832542
    2384   bool is_current = false;
     2543  //  bool is_current = false;
    23852544
    23862545  //  cmt_string here = CmtSystem::pwd ();
    23872546  // In case there are symlinks
     2547  /*
    23882548  cmt_string here_real;
    23892549  CmtSystem::realpath_ (CmtSystem::pwd (), here_real);
     
    23972557        }
    23982558    }
    2399 
     2559  */
    24002560  for (int tab = 0; tab < level; tab++) cout << "  ";
    24012561  cout << m_name << " " << (m_name != "CMTUSERCONTEXT" && m_name != "CMTHOME" ? m_release : "v0") << " (in " << m_cmtpath << ")";
    24022562  //  cout << m_name << " " << m_release << " (in " << m_cmtpath << ")";
    24032563
    2404   if (is_current) cout << " (current)";
     2564  if (m_is_current) cout << " (current)";
     2565  //  if (is_current) cout << " (current)";
    24052566
    24062567  int i;
  • CMT/HEAD/source/cmt_project.h

    r526 r535  
    109109
    110110  static ProjectVector& projects ();
    111   static ProjectPtrVector ordered_projects ();
     111  static ProjectPtrVector& ordered_projects ();
     112  static void order_all ();
    112113  static void clear_all ();
    113114  static void show_all ();
     
    163164  void set_cmtpath_pwd (const cmt_string& path);
    164165  void set_cmtpath_source (const cmt_string& source);
     166  void set_is_current (bool is_current);
     167  bool is_current () const;
    165168  void clear ();
    166169  void configure ();
     
    170173  void add_parent (Project* p);
    171174  void add_child (Project* p);
     175  void erase_child (Project* p);
    172176
    173177  void container_action (const CmtSystem::cmt_string_vector& words);
     
    225229  int m_visits;
    226230  int m_order;
     231  bool m_is_current;
    227232
    228233  cmt_string m_cmtpath;
  • CMT/HEAD/source/cmt_syntax.cxx

    r526 r535  
    16561656  cmt_string text;
    16571657
    1658   CmtError::clear ();
     1658  if (CmtError::get_last_error_code () == CmtError::syntax_error)
     1659    CmtError::clear ();
    16591660
    16601661  if (!CmtSystem::test_file (actual_file_name))
     
    18881889                                   Use* use)
    18891890{
    1890   CmtError::clear ();
     1891  if (CmtError::get_last_error_code () == CmtError::syntax_error)
     1892        CmtError::clear ();
    18911893
    18921894  if (words.size () == 0) return;
     
    19211923    }
    19221924
    1923   if (CmtError::has_pending_error ())
     1925  if (CmtError::get_last_error_code () == CmtError::syntax_error)
     1926    //  if (CmtError::has_pending_error ())
    19241927    {
     1928      CmtError::print ();
     1929
    19251930      char num[32]; sprintf (num, "%d", line_number);
    19261931      CmtMessage::error ("bad syntax in requirements of " + use->get_package_name ()
     
    19551960                                   Project* project)
    19561961{
    1957   CmtError::clear ();
     1962  if (CmtError::get_last_error_code () == CmtError::syntax_error)
     1963    CmtError::clear ();
    19581964
    19591965  if (words.size () == 0) return;
     
    19731979    }
    19741980
    1975   if (CmtError::has_pending_error ())
     1981  if (CmtError::get_last_error_code () == CmtError::syntax_error)
     1982    //  if (CmtError::has_pending_error ())
    19761983    {
     1984      CmtError::print ();
     1985
    19771986      char num[32]; sprintf (num, "%d", line_number);
    19781987      CmtMessage::error ("bad syntax in project file of " + project->get_name ()
  • CMT/HEAD/source/cmt_system.cxx

    r533 r535  
    14131413          }
    14141414
    1415         m_project = factory.create_project (project_name, npath, path_source, m_project);
     1415        m_project = factory.create_project (project_name, npath, path_source, 0);
     1416        //      m_project = factory.create_project (project_name, npath, path_source, m_project);
     1417        /*
    14161418        if ((path_source == "CMTUSERCONTEXT") ||
    14171419            (path_source == "CMTHOME"))
     
    14191421            m_project = 0;
    14201422          }
     1423        */
    14211424      }
    14221425  }
     
    16461649  output = "";
    16471650
    1648   //cerr << "CmtSystem::execute2> [" << command << "]" << endl;
     1651  //  cerr << "CmtSystem::execute2> [" << command << "]" << endl;
    16491652
    16501653  FILE* f = popen (command.c_str (), "r");
     
    16611664        }
    16621665
    1663       if (pclose (f) == -1)
     1666      int status = pclose (f);
     1667      if (status == -1) // error reported by pclose ()
    16641668        {
     1669          perror ("pclose");
    16651670          if (errno == ECHILD)
    16661671            {
    16671672              return (0);
    16681673            }
    1669           return (1);
     1674          return (-1);
    16701675        }
    1671 
    1672       return (0);
    1673     }
    1674 
    1675   return (1);
     1676      else
     1677        {
     1678          return WEXITSTATUS(status); // return status of the command
     1679          //return (0);
     1680        }
     1681    }
     1682
     1683  return (-2);
    16761684}
    16771685
  • CMT/HEAD/source/cmt_use.cxx

    r531 r535  
    574574        }
    575575
     576      Use* suse = Use::find (CmtSystem::get_home_package ());
     577      if (suse != 0 && !suse->discarded && !suse->m_hidden && suse->located ())
     578        {
     579          cout << prefix << suse->get_package_name ()
     580               << " " << suse->version;
     581          if (!Cmt::get_quiet ())
     582            {
     583              cout << " (" << suse->path << ")";
     584            }
     585          cout << endl;
     586        }
     587      suse = Use::find (CmtSystem::get_user_context_package ());
     588      if (suse != 0 && !suse->discarded && !suse->m_hidden && suse->located ())
     589        {
     590          cout << prefix << suse->get_package_name ()
     591               << " " << suse->version;
     592          if (!Cmt::get_quiet ())
     593            {
     594              cout << " (" << suse->path << ")";
     595            }
     596          cout << endl;
     597        }
     598      /*
    576599      if (Cmt::get_cmt_home () != "")
    577600        {
     
    593616          cout << endl;
    594617        }
     618      */
     619    }
     620 
     621  const UseVector& instances = get_instances ();
     622  for (int use_index = 0; use_index < instances.size (); use_index++)
     623    {
     624      Use* use = &(instances[use_index]);
     625      //Use* use = uses[j];
     626     
     627      if (use->discarded) continue;
     628      if (use->m_hidden) continue;
     629     
     630      if (!use->located ())
     631        {
     632          CmtError::set (CmtError::package_not_found, use->get_info ());
     633        }
     634      else
     635        {
     636          /*
     637            CmtMessage::info ("package " +
     638            use->get_package_name () +
     639            " " + use->version +
     640            (use->path != "" ? " " + use->path : "") +
     641            " found");
     642          */
     643        }
    595644    }
    596645}
     
    854903              }
    855904          }
     905        /*
     906        else // new_use == 0
     907          {
     908            cerr << "action: " << action << " new_use: " <<  new_use
     909                 << " package: " <<  package << endl;
     910
     911            CmtError::set (CmtError::package_not_found, package);
     912          }
     913        */
    856914
    857915        return (new_use);
     
    16041662      return (1);
    16051663    }
    1606   else if (!CmtSystem::cd (version))
     1664  else if (!CmtSystem::cd (version) || (version == ""))
     1665    //  else if (!CmtSystem::cd (version))
    16071666    {
    16081667      //
     
    16101669      // There are alternate possibilities when it contains wild cards
    16111670      //
     1671      if ((version.find ("*") != cmt_string::npos) || (version == ""))
    16121672      //      if ((version == "") || (version.find ("*") != cmt_string::npos))
    1613       if (version.find ("*") != cmt_string::npos)
     1673      //      if (version.find ("*") != cmt_string::npos)
    16141674        {
    16151675          static CmtSystem::cmt_string_vector versions;
     
    16181678          name = ".";
    16191679          name += CmtSystem::file_separator ();
    1620           name += version;
     1680          if (version != "") name += version;
     1681          else name += "*";
    16211682          /*
    16221683          if (version == "") name += "*";
    16231684          else name += version;
    16241685          */
    1625 
     1686          //          name += version;
    16261687          CmtSystem::scan_dir (name, versions);
    16271688          if (n_version != "")
     
    25062567  if (!found)
    25072568    {
     2569      CmtMessage::warning (CmtError::get_error_name (CmtError::package_not_found)
     2570                           + ": " + use->get_info ()
     2571                           + ( (context_use != 0) ?
     2572                               " (requested by " + context_use->get_package_name () + ")" :
     2573                               "" )
     2574                           );
     2575      /*
    25082576      CmtMessage::warning ("package " + use->get_package_name ()
    25092577                           + " " + use->version + " " + use->path
     
    25132581                               "" )
    25142582                           );
     2583      */
    25152584      /*
    25162585      if (!Cmt::get_quiet ())
     
    25302599
    25312600      //CmtError::set (CmtError::package_not_found, use->get_package_name ());
     2601      //use->m_located = false;
    25322602      use = 0;
    25332603    }
     
    46704740  return p;   
    46714741}
     4742
     4743//----------------------------------------------------------
     4744cmt_string Use::get_info () const
     4745{   
     4746  return get_package_name () + " " + (version != "" ? version : "*") +
     4747    (path != "" ? " " + path : "") ;
     4748  //  return get_package_name () + " " + version + (path != "" ? " " + path : "") ;
     4749}
  • CMT/HEAD/source/cmt_use.h

    r531 r535  
    134134
    135135  Project* get_project ();
     136  cmt_string get_info () const;
    136137// Public attributes
    137138public:
  • CMT/HEAD/source/cmt_vcs.cxx

    r534 r535  
    1818#include "cmt_error.h"
    1919
     20#include "cmt_syntax.h"
     21
    2022/**
    2123
     
    9294};
    9395
     96//--------------------------------------------------------------------
     97static void show_packages ()
     98{
     99  Package::PackageVector& vector = Package::packages ();
     100
     101  int i;
     102  int j;
     103
     104  cout << "### Packages: ";
     105  for (i = 0; i < vector.size (); i++)
     106    {
     107      Package& p = vector[i];
     108      cout << p.get_name () << "[";
     109      Use::UsePtrVector& uses = p.get_uses ();
     110      for (j = 0; j < uses.size (); j++)
     111        {
     112          Use* u = uses[j];
     113          cout << u << ",";
     114        }
     115
     116      cout << "] ";
     117    }
     118  cout << endl;
     119
     120  {
     121    Use::UsePtrVector& uses = Use::get_ordered_uses ();
     122    //    static Use::UsePtrVector& uses = Use::get_ordered_uses ();
     123
     124    cout << "### Uses: ";
     125    for (i = 0; i < uses.size (); i++)
     126      {
     127        Use* u = uses[i];
     128        cout << "[" << u << "]" << u->get_package_name () << " ";
     129      }
     130  }
     131
     132  cout << endl;
     133}
     134
     135//--------------------------------------------------------------------
     136
     137class GlobalProjectAction : public IProjectAction
     138{
     139public:
     140  GlobalProjectAction (const cmt_string& package,
     141                       const cmt_string& version = "",
     142                        const cmt_string& path = "")
     143    : m_package (package), m_version (version), m_path (path)
     144  {
     145    m_home_dir = CmtSystem::pwd ();
     146    m_current = Use::current();
     147    m_current_name = m_current.get_package_name ();
     148    m_current.set_package_name ("m_current");
     149  }
     150
     151  bool run (const Project& project)
     152  {
     153    if (project.is_current ()) return true;
     154    CmtMessage::verbose ("run: " + project.get_cmtpath ());
     155    const Use* use = &(project.get_container ());
     156    if (use->get_package_name () != "" && use->located ())
     157      {
     158        CmtMessage::verbose ("container " + use->get_info () +
     159                             " (" + use->real_path + ")");
     160        Use* cuse = Use::add (use->real_path,
     161                              use->get_package_name (),
     162                              use->version,
     163                              "", "", "", 0); // 0 == NOT used by current
     164        if (cuse)
     165          {
     166            cmt_string cmt (use->get_full_path ());
     167            cmt += CmtSystem::file_separator ();
     168            cmt += "cmt";
     169            if (!CmtSystem::cd (cmt))
     170              {
     171                CmtMessage::error ("Cannot move to directory " + cmt);
     172                CmtError::set (CmtError::file_access_error, cmt);
     173                if (!CmtSystem::cd (m_home_dir))
     174                  {
     175                    CmtMessage::error ("Cannot move to directory " + m_home_dir);
     176                    CmtError::set (CmtError::file_access_error, m_home_dir);
     177                  }
     178                return true;
     179              }
     180            //cerr << "parsing: " << "requirements" << endl;
     181            SyntaxParser::parse_requirements ("requirements", cuse);
     182            //cerr << "parsed: " << "requirements" << endl;
     183            //show_packages ();
     184          }
     185        else
     186          {
     187            CmtMessage::error ("Cannot add container " + use->get_package_name () +
     188                               " " + use->version + " " + use->real_path);
     189          }
     190        if (!CmtSystem::cd (m_home_dir))
     191          {
     192            CmtMessage::error ("Cannot move to directory " + m_home_dir);
     193            CmtError::set (CmtError::file_access_error, m_home_dir);
     194          }
     195      }
     196    return true;
     197  }
     198
     199private:
     200  cmt_string m_home_dir;
     201  cmt_string m_package;
     202  cmt_string m_version;
     203  cmt_string m_path;
     204  cmt_string m_cmtpath;
     205  Use m_current;
     206  cmt_string m_current_name;
     207};
     208
     209//--------------------------------------------------------------------
     210/**
     211 *
     212 *   Packages: keep info on all packages that can be found
     213 *   in current context - CMTPATHs.
     214 *
     215 */
     216
     217class Packages
     218{
     219public:
     220  static Packages& instance ();
     221  //  void clear ();
     222  //  void install (const cmt_string& line);
     223  //  bool is_installed (const cmt_string& line);
     224
     225  Use* find (const cmt_string& name,
     226             const cmt_string& version = "",
     227             const cmt_string& path = "");
     228
     229private:
     230  Packages ();
     231  void exclude_current_project ();
     232  void restore_current_project ();
     233
     234  int m_i;
     235  Project* m_cur;
     236  Project m_null;
     237  bool m_initialized;
     238};
     239
     240//--------------------------------------------------------------------
     241Packages::Packages ()
     242  : m_i (-1), m_cur (0), m_initialized (false)
     243{
     244  m_null.set_cmtpath (CmtSystem::get_temporary_name ());
     245}
     246
     247//--------------------------------------------------------------------
     248Packages& Packages::instance ()
     249{
     250  static Packages pkgs;
     251  return (pkgs);
     252}
     253
     254//--------------------------------------------------------------------
     255Use* Packages::find (const cmt_string& name,
     256                     const cmt_string& version,
     257                     const cmt_string& path)
     258{
     259  if (name == "") return 0;
     260  //  cerr << "find: " << name << " " << version << " " << path << endl;
     261  exclude_current_project ();
     262  if (path != "")
     263    {
     264      //cerr << "find: No need to find path: " << name << " " << path << endl;
     265      //      Use use_obj (name, "", path);
     266      Use use_obj (name, version, path);
     267      Use* use = &use_obj;
     268      //use->set (name, version, path);
     269      use->get_package ()->remove_use (use);
     270      if (use->move_to ())
     271        {
     272          CmtSystem::cd (Cmt::get_current_dir ());
     273          /*
     274          cerr << "real_path: " << use->real_path
     275               << " style: " << use->style
     276               << " structuring_style: " << use->structuring_style
     277               << " full_path: " << use->get_full_path () << endl;
     278          */
     279          Use::UseVector& instances = Use::get_instances ();
     280          Use& use_object = instances.add ();
     281          use_object = *use;
     282          /*
     283          use_object.set (use->get_package_name (), use->version, use->path,
     284                          use->version_alias, use->path_alias);
     285          use_object.get_package ()->remove_use (&use_object);
     286          */
     287          restore_current_project ();
     288          return (&use_object);
     289        }
     290      else
     291        {
     292          CmtSystem::cd (Cmt::get_current_dir ());
     293          CmtMessage::warning (CmtError::get_error_name (CmtError::package_not_found)
     294                               + ": " + use->get_info ());
     295        }
     296    }
     297  //
     298  // Second try is among the CMTPATHs
     299  //
     300  if (!m_initialized)
     301    {
     302      m_initialized = true;
     303
     304      GlobalProjectAction pa (name, version, path);
     305     
     306      Project::reverse_broadcast (pa);
     307  //  Project::broadcast (pa);
     308    }
     309  //  cerr << "find: " << name << " " << version << " " << path << " Done." << endl;
     310  //show_packages ();
     311
     312  Package* p = Package::find (name);
     313  if (p == 0)
     314    {
     315      restore_current_project ();
     316      return 0;
     317    }
     318    //return PackageInfo (name, version, path, "");
     319  Use::UsePtrVector& uses = p->get_uses ();
     320  Use* p_use (0);
     321  //  cerr << "find for: " << name << endl;
     322  for (int use_index = 0; use_index < uses.size (); use_index++)
     323    {
     324      Use* use = uses[use_index];
     325      char index[8];
     326      sprintf (index, "%d", use->m_index);
     327      CmtMessage::verbose ("find: " + use->get_info () +
     328                           " (" + use->real_path + ")" +
     329                           " m_index: " + index +
     330                           " located: " + (use->located () ? "1" : "0"));
     331      if (use->located ()) p_use = use;
     332      //      if (use->m_index >= 0) return use;
     333      if (use->m_index >= 0) break;
     334    }
     335  if (p_use)
     336    {
     337//       cerr << "find: Try to validate: " << p_use->get_info ()
     338//         << ": " << p_use->real_path << endl;
     339      //      Use use_obj (name, "", path);
     340      Use use_obj (name, version, p_use->path);
     341      Use* use = &use_obj;
     342      use->get_package ()->remove_use (use);
     343      if (use->move_to ())
     344        {
     345          CmtSystem::cd (Cmt::get_current_dir ());
     346          if (use->version == p_use->version)
     347            {
     348              CmtMessage::verbose ("Validated: " + p_use->get_info () +
     349                                   " (" + p_use->real_path + ")");
     350              restore_current_project ();
     351              return p_use;
     352            }
     353          Use* n_use = Use::add (use->real_path,
     354                                 use->get_package_name (),
     355                                 use->version,
     356                                 use->version_alias,
     357                                 use->path_alias,
     358                                 use->native_version,
     359                                 0); // 0 == NOT used by current
     360          CmtSystem::cd (Cmt::get_current_dir ());
     361          restore_current_project ();
     362          return n_use;
     363        }
     364      else
     365        {
     366          CmtSystem::cd (Cmt::get_current_dir ());
     367          CmtMessage::verbose (CmtError::get_error_name (CmtError::package_not_found)
     368                               + ": " + use->get_info ());
     369          restore_current_project ();
     370          return 0;
     371        }
     372    }
     373
     374  restore_current_project ();
     375  return p_use;
     376  //  return PackageInfo (name, version, path, "");
     377  //  return pa.info ();
     378}
     379
     380//--------------------------------------------------------------------
     381void Packages::exclude_current_project ()
     382{
     383  if (m_i != -1 || m_cur != 0) return;
     384  //  cerr << "exclude_current_project: " << m_i << ": " << m_cur << endl;
     385  Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
     386  int i = -1;
     387  //  m_cur = 0;
     388  //  Project null;
     389  for (i = 0; i < Ordered.size (); i++)
     390    if (Ordered[i]->is_current ()) break;
     391  if (i >= 0 && i < Ordered.size ())
     392    {
     393      m_i = i;
     394      m_cur = Ordered[i];
     395      Ordered[i] = &m_null;
     396    }
     397}
     398
     399//--------------------------------------------------------------------
     400void Packages::restore_current_project ()
     401{
     402  Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
     403  if (m_i >= 0 && m_i < Ordered.size ())
     404    {
     405      Ordered[m_i] = m_cur;
     406      m_i = -1;
     407      m_cur = 0;
     408    }
     409}
     410
     411//--------------------------------------------------------------------
     412/*
     413void Packages::clear ()
     414{
     415  m_installed = "";
     416}
     417
     418void Packages::install (const cmt_string& line)
     419{
     420  m_installed += "|";
     421  m_installed += line;
     422  m_installed += "|";
     423}
     424
     425bool Packages::is_installed (const cmt_string& line)
     426{
     427  if (m_installed.find (line) != cmt_string::npos)
     428    {
     429      return (true);
     430    }
     431 
     432  return (false);
     433}
     434*/
     435
     436//--------------------------------------------------------------------
    94437/**
    95438
     
    129472};
    130473
    131 class Walkthru : public Awk
     474//--------------------------------------------------------------------
     475/**
     476 *
     477 * Helper classes
     478 *
     479 */
     480
     481/*
     482class SelectSubUses : public Awk
    132483{
    133484public:
    134   Walkthru (const Vcs::Checkout& checkout,
    135             bool config, bool with_version_directory,
    136             Vcs::VcsType type);
    137   //  RecursivePass2 (CvsImplementation& cvs);
     485
    138486  void begin ();
    139487  void filter (const cmt_string& line);
     488  //  const cmt_string& result () const;
     489  bool has (const cmt_string& package) const;
    140490
    141491private:
    142   const Vcs::Checkout& m_checkout;
    143   bool m_config;
    144   bool m_with_version_directory;
    145   Vcs::VcsType m_type;
    146   //  CvsImplementation& m_cvs;
     492  void append (const cmt_string& package);
     493  cmt_string m_result;
     494  bool m_first;
    147495};
    148496
    149 Walkthru::Walkthru (const Vcs::Checkout& checkout,
    150                     bool config, bool with_version_directory,
    151                     Vcs::VcsType type)
    152   : m_checkout (checkout),
    153     m_config (config), m_with_version_directory (with_version_directory),
    154     m_type (type)
    155 {
    156 }
    157 
    158 void Walkthru::begin ()
    159 {
    160 }
    161 
    162 void Walkthru::filter (const cmt_string& line)
    163 {
    164 //   History& h = History::instance ();
    165  
    166 //   if (h.is_installed (line)) return;
    167  
    168 //   h.install (line);
    169  
     497void SelectSubUses::begin ()
     498{
     499  m_first = true;
     500  m_result = "";
     501}
     502
     503void SelectSubUses::filter (const cmt_string& line)
     504{
    170505  CmtSystem::cmt_string_vector words;
    171506 
     
    183518  cmt_string version;
    184519  cmt_string path;
    185 
    186   for (int i = 1; i < words.size (); i++)
     520  cerr << line;
     521  for (int i = 2; i < words.size (); i++)
    187522    {
    188523      const cmt_string& s = words[i];
    189 
     524      cerr << " `" + s + "'";
    190525      if (s[0] == '-') continue;
    191526
     
    201536          break;
    202537        case need_path:
    203           path = s;
     538          if (s.find ("(") != 0)
     539            path = s;
    204540          state = no_need;
    205541          break;
    206542        }
    207543    }
    208 
     544  cerr << endl;
     545
     546  if (package == "" ||
     547      package == "CMT" ||
     548      package == "cmt")
     549    return;
     550  append (package);
     551}
     552
     553void SelectSubUses::append (const cmt_string& package)
     554{
     555  if (m_first)
     556    {
     557      m_first = false;
     558      m_result = "|" + package + "|";
     559    }
     560  else
     561    {
     562      if (!has (package))
     563        m_result += package + "|";
     564    }
     565  cerr << "m_result: " << m_result << endl;
     566}
     567
     568bool SelectSubUses::has (const cmt_string& package) const
     569{
     570  return (m_result.find ("|" + package + "|") != cmt_string::npos);
     571}
     572*/
     573
     574//--------------------------------------------------------------------
     575class Walkthru : public Awk
     576{
     577public:
     578  Walkthru (IUseVisitor& visitor);
     579  //  RecursivePass2 (CvsImplementation& cvs);
     580  void begin ();
     581  void filter (const cmt_string& line);
     582
     583private:
     584  //  CvsImplementation& m_cvs;
     585  IUseVisitor& m_visitor;
     586};
     587
     588//--------------------------------------------------------------------
     589Walkthru::Walkthru (IUseVisitor& visitor)
     590  : m_visitor (visitor)
     591{
     592}
     593
     594//--------------------------------------------------------------------
     595void Walkthru::begin ()
     596{
     597}
     598
     599//--------------------------------------------------------------------
     600void Walkthru::filter (const cmt_string& line)
     601{
     602  CmtSystem::cmt_string_vector words;
     603 
     604  CmtSystem::split (line, " \t", words);
     605
     606  enum
     607    {
     608      need_package,
     609      need_version,
     610      need_path,
     611      no_need
     612    } state = need_package;
     613
     614  cmt_string package;
     615  cmt_string version;
     616  cmt_string path;
     617  //  cerr << line;
     618  for (int i = 1; i < words.size (); i++)
     619    {
     620      const cmt_string& s = words[i];
     621      //      cerr << " `" + s + "'";
     622      if (s[0] == '-') continue;
     623
     624      switch (state)
     625        {
     626        case need_package:
     627          package = s;
     628          state = need_version;
     629          break;
     630        case need_version:
     631          version = s;
     632          state = need_path;
     633          break;
     634        case need_path:
     635          if (s.find ("(") != 0 && s.find ("#") != 0)
     636            path = s;
     637          state = no_need;
     638          break;
     639        }
     640    }
     641  //  cerr << endl;
     642 
     643  if (package == "" ||
     644      package == "CMT" ||
     645      package == "cmt" ||
     646      package == CmtSystem::get_home_package () ||
     647      package == CmtSystem::get_user_context_package ()
     648      )
     649    return;
     650  /*
    209651  if (version == "")
    210     {
    211       version = "*";
    212     }
    213 
    214   if (version.find ("*") != cmt_string::npos &&
    215       !m_checkout.m_context)
    216     {
    217       /*
    218         cerr << "# ================= Package " << package
    219         << " version " << version << " " << path
    220         << " has wild cards and will not be considered." << endl;
    221       */
     652    version = "*";
     653  */
     654
     655  if (version.find ("*") != cmt_string::npos)
     656    {
     657//      cerr << "# ================= Package " << package
     658//      << " version " << version << " " << path
     659//      << " has wild cards and will not be considered." << endl;
    222660      CmtMessage::warning (package + " " + version +
    223661                           (path != "" ? " " + path : "") +
    224                            " has wildcards in version and will not be considered.");
     662                           ": Skipped due to wildcards in version."
     663                           " Consider using -C option.");
    225664    }
    226665  else
    227666    {
     667      Use use_obj (package, version, path);
     668      Use* use = &use_obj;
     669      //use->set (name, version, path);
     670      use->get_package ()->remove_use (use);
     671      m_visitor.in (use);
    228672      //      static const cmt_string empty;
    229673      //      m_cvs.do_checkout_phase2 (path, package, version, empty);
    230       cmt_string module ((path != "") ? path + "/" + package : package);
    231       Vcs::checkout_module (m_checkout,
    232                             m_config, m_with_version_directory,
    233                             module, version,
    234                             m_type);
    235     }
    236 }
     674//       cmt_string module ((path != "") ? path + "/" + package : package);
     675//       Vcs::checkout_module (m_checkout,
     676//                          m_config, m_with_version_directory,
     677//                          module, version,
     678//                          m_type);
     679    }
     680
     681}
     682
     683//--------------------------------------------------------------------
    237684
    238685/**
     
    11801627  void add_cmtpath (const cmt_string& dir)
    11811628  {
     1629    return;
    11821630    static cmt_string CMTPATH;
    11831631
     
    32283676}
    32293677
     3678//--------------------------------------------------------------------
    32303679void Vcs::help ()
    32313680{
     
    32383687  cerr << "   -R          Process used products recursively." << endl;
    32393688  cerr << "   -r rev      Check out version tag. (is sticky)" << endl;
     3689  cerr << "   -C          Determine version tag and/or package container from context." << endl;
     3690  cerr << "   -i          Do not check out, show package(s) information only." << endl;
    32403691  cerr << "   -vd dir     Use this version directory instead of version tag." << endl;
    32413692  cerr << "   -d dir      Check out into dir instead of module name." << endl;
     
    32573708}
    32583709
     3710//--------------------------------------------------------------------
    32593711/**
    32603712 * When running cmt cvs commands, we stand by definition outside of any existing
     
    32623714 * This function manually prepends CMTPATH entries to the environment variable.
    32633715 */
     3716//--------------------------------------------------------------------
    32643717void Vcs::add_cmtpath (const cmt_string& dir)
    32653718{
     
    32933746}
    32943747
     3748//--------------------------------------------------------------------
    32953749bool Vcs::need_version_directory ()
    32963750{
     
    33123766}
    33133767
    3314 int Vcs::parse_checkout (const CmtSystem::cmt_string_vector& arguments,
    3315                          Checkout& checkout, bool& config)
     3768//--------------------------------------------------------------------
     3769int Vcs::parse_arguments (const CmtSystem::cmt_string_vector& arguments,
     3770                          Checkout& checkout, bool& config)
    33163771{
    33173772  if (arguments.size () < 1)
     
    34203875              //m_head = false;
    34213876            }
     3877          else if (option == "-C")
     3878            {
     3879              checkout.m_context = true;
     3880            }
     3881          else if (option == "-i")
     3882            {
     3883              checkout.m_info = true;
     3884            }
    34223885          else if (option == "-d")
    34233886            {
     
    34703933          else
    34713934            {
     3935              if (option.size () == 0)
     3936                {
     3937                  CmtMessage::warning ("Skipping bad module `" +
     3938                                       option + "'");
     3939                  continue;
     3940                }
    34723941              checkout.m_modules.push_back (option);
    34733942            }
     
    34973966}
    34983967
     3968//--------------------------------------------------------------------
     3969class Modules
     3970{
     3971public:
     3972  //  Use::UsePtrVector m_packages;
     3973  //  cmt_vector<PackageInfo> m_packages;
     3974  Use::UseVector m_packages;
     3975  cmt_string m_uses;
     3976};
     3977
     3978//--------------------------------------------------------------------
     3979int Vcs::parse_checkout (Checkout& checkout,
     3980                         Modules& modules)
     3981  //                     cmt_string& uses)
     3982{
     3983  int retval (0);
     3984
     3985  if (checkout.m_requirements != "")
     3986    {
     3987      if (!CmtSystem::test_file (checkout.m_requirements))
     3988        {
     3989          CmtError::set (CmtError::path_not_found, checkout.m_requirements);
     3990          ++retval;
     3991        }
     3992      else
     3993        {
     3994          cmt_string text;
     3995          if (!text.read (checkout.m_requirements))
     3996            {
     3997              CmtError::set (CmtError::file_access_error, checkout.m_requirements);
     3998              ++retval;
     3999            }
     4000          else
     4001            {
     4002              modules.m_uses = text;
     4003            }
     4004        }
     4005    }
     4006
     4007  const cmt_string& version_tag = checkout.m_version_tag;
     4008  if (version_tag == "HEAD" || version_tag == "head" ||
     4009      version_tag == "TRUNK" || version_tag == "trunk")
     4010    checkout.m_head = true;
     4011 
     4012  cmt_string uses;
     4013  for (int arg = 0; arg < checkout.m_modules.size (); arg++)
     4014    {
     4015      cmt_string use ("use");
     4016      cmt_string name = checkout.m_modules[arg];
     4017      cmt_string package;
     4018      cmt_string version;
     4019      cmt_string path;
     4020      /*
     4021        if (checkout.m_context)
     4022        {
     4023        name.replace_all ("//", "/");
     4024        }
     4025      */
     4026      while (name.size () > 0 && name[name.size () - 1] == '/')
     4027        name.erase (name.size () - 1);
     4028      if (name.size () == 0)
     4029        {
     4030          CmtError::set (CmtError::syntax_error, "Bad module name `" +
     4031                         checkout.m_modules[arg] + "'");
     4032          CmtError::print ();
     4033          continue;
     4034        }
     4035     
     4036      int pos = name.find_last_of ('/');
     4037      if (pos != cmt_string::npos)
     4038        {
     4039          package = name.substr (pos + 1);
     4040          path = name.substr (0, pos);
     4041        }
     4042      else
     4043        {
     4044          package = name;
     4045        }
     4046      if (checkout.m_context)
     4047        {
     4048          if (version_tag == "" || path == "")
     4049            {
     4050              Packages& pkgs = Packages::instance ();
     4051              //if (version_tag == "") - want to find 1) version
     4052              //                                      2) path, if (path == "")
     4053              // args: package, version_tag, path
     4054              //if (path == "") - want to find 1) path
     4055              //                               2) version, if (version_tag == "")
     4056              // args: package, "", path
     4057              // package, "", path
     4058              Use* p_use = pkgs.find (package, "", path);
     4059              if (p_use == 0)
     4060                {
     4061                  CmtError::set (CmtError::package_not_found, package +
     4062                                 ": Context");
     4063                  CmtError::print ();
     4064                  ++retval;
     4065                  continue;
     4066                }
     4067//            cerr << "Obtained: " << p_use->get_info ()
     4068//                 << " " << p_use->real_path << endl;
     4069              if (version_tag == "" )
     4070                version = p_use->version;
     4071              else
     4072                version = version_tag;
     4073
     4074              path = p_use->path;
     4075            }
     4076          if (!checkout.m_head)
     4077            {
     4078              use += " " + package + " " + version + " " + path + "\n";
     4079              CmtMessage::verbose (use);
     4080              uses += use;
     4081            }
     4082        } // end of checkout.m_context
     4083      else
     4084        {
     4085          version = version_tag;
     4086        }
     4087      {
     4088        Use use_obj (package, version, path);
     4089        Use* use = &use_obj;
     4090        use->get_package ()->remove_use (use);
     4091        modules.m_packages.push_back (use_obj);
     4092      }
     4093    } // end of for-loop over checkout.m_modules
     4094  if (checkout.m_context)
     4095    {
     4096      resolve_uses (checkout, uses + modules.m_uses);
     4097    }
     4098
     4099  return retval;
     4100}
     4101
     4102//--------------------------------------------------------------------
    34994103void Vcs::checkout (const CmtSystem::cmt_string_vector& arguments)
    35004104{
     
    35244128  bool config (true);
    35254129  Checkout checkout;
    3526   parse_checkout (arguments, checkout, config);
     4130  parse_arguments (arguments, checkout, config);
    35274131
    35284132  if (CmtError::has_pending_error ()) return;
    35294133
    3530   add_cmtpath (CmtSystem::pwd ());
     4134  //  cmt_string uses;
     4135  //  parse_checkout (checkout, uses);
     4136  Modules modules;
     4137  parse_checkout (checkout, modules);
     4138  //  add_cmtpath (CmtSystem::pwd ());
    35314139  bool with_version_directory (need_version_directory ());
    35324140      /*
     
    35374145  if (svnroot != "")
    35384146    {
    3539       Svn::checkout (checkout, config, with_version_directory);
     4147      Svn::checkout (checkout, modules, config, with_version_directory);
    35404148      return;
    35414149    }
    35424150}
    35434151
    3544 void Svn::checkout (Vcs::Checkout checkout,
     4152//--------------------------------------------------------------------
     4153class VisitorForInfo : public IUseVisitor
     4154{
     4155public:
     4156  VisitorForInfo ()
     4157  {
     4158  }
     4159
     4160  void in (Use* use)
     4161  {
     4162    cmt_string p = use->real_path;
     4163    if (use->path != "")
     4164      {
     4165        int pos = p.find_last_of (use->path);
     4166        if (pos != cmt_string::npos)
     4167          {
     4168            p.erase (pos);
     4169          }
     4170      }
     4171
     4172    cout << use->get_package_name ()
     4173         << " " << use->version;
     4174   
     4175    if (CmtSystem::absolute_path (use->path))
     4176      {
     4177        if (!Cmt::get_quiet ())
     4178          {
     4179            cout << " (" << use->path << ")";
     4180          }
     4181      }
     4182    else
     4183      {
     4184        if (use->path != "") cout << " " << use->path;
     4185      }
     4186   
     4187    if (!Cmt::get_quiet ())
     4188      {
     4189        if (p != "") cout << " (" << p << ")";
     4190      }
     4191   
     4192    cout << endl;
     4193  }
     4194};
     4195
     4196//--------------------------------------------------------------------
     4197class VisitorForCheckout : public IUseVisitor
     4198{
     4199public:
     4200  VisitorForCheckout (const Vcs::Checkout& checkout,
     4201                      bool config, bool with_version_directory,
     4202                      Vcs::VcsType type)
     4203    : m_checkout (checkout),
     4204      m_config (config), m_with_version_directory (with_version_directory),
     4205      m_type (type)
     4206  {
     4207  }
     4208 
     4209  void in (Use* use)
     4210  {
     4211    cmt_string module ((use->path != "") ? use->path + "/" + use->get_package_name () :
     4212                       use->get_package_name ());
     4213    Vcs::checkout_module (m_checkout,
     4214                          m_config, m_with_version_directory,
     4215                          //                      module, version,
     4216                          module,
     4217                          use->version,
     4218                          m_type);
     4219  }
     4220
     4221private:
     4222  const Vcs::Checkout& m_checkout;
     4223  bool m_config;
     4224  bool m_with_version_directory;
     4225  Vcs::VcsType m_type;
     4226};
     4227
     4228//--------------------------------------------------------------------
     4229void Svn::checkout (Vcs::Checkout checkout, Modules modules,
    35454230                   bool config, bool with_version_directory)
    35464231{
     
    35604245
    35614246  /**
     4247   * Checkout packages found in context
     4248   */
     4249  if (checkout.m_context)
     4250    {
     4251      Vcs::checkout_context (checkout, modules,
     4252                             config, with_version_directory,
     4253                             Vcs::Svn);
     4254      if (!checkout.m_head) return;
     4255    }
     4256
     4257  /**
    35624258   * Call checkout for each command line argument
    35634259   */
     4260  VisitorForInfo visitor_i;
     4261  VisitorForCheckout visitor_co (checkout,
     4262                                 config, with_version_directory,
     4263                                 Vcs::Svn);
     4264  for (int i = 0; i < modules.m_packages.size (); i++)
     4265    {
     4266      Use* use = &(modules.m_packages[i]);
     4267      if (checkout.m_info)
     4268        visitor_i.in (use);
     4269      else
     4270        visitor_co.in (use);
     4271    }
     4272  /*
    35644273  for (int arg = 0; arg < checkout.m_modules.size (); arg++)
    35654274    {
     
    35724281      //      do_checkout_phase1 (modules[arg], m_version_dir, version_tag);
    35734282    }
     4283  */
     4284
     4285  if (checkout.m_context) return;
    35744286
    35754287  /**
    35764288   * Call checkout for used package in requirements file
    35774289   */
    3578   if (checkout.m_requirements != "")
     4290  if (checkout.m_requirements != "" &&
     4291      modules.m_uses != "")
    35794292    Vcs::checkout_from_requirements (checkout,
    35804293                                     config, with_version_directory,
     
    35834296}
    35844297
     4298//--------------------------------------------------------------------
    35854299void Vcs::checkout_module (const Vcs::Checkout& checkout,
    35864300                           bool config, bool with_version_directory,
    3587                            const cmt_string& module, cmt_string version_tag,
     4301                           cmt_string module, cmt_string version_tag,
    35884302                           Vcs::VcsType type)
    35894303{
    3590 //   cmt_string checkout_command;
    3591 //   Symbol* checkout_command_macro = Symbol::find ("svn_checkout_command");
    3592 //   if (checkout_command_macro != 0)
    3593 //     {
    3594 //       checkout_command = checkout_command_macro->resolve_macro_value ();
    3595 //     }
    3596 //   if (checkout_command == "")
    3597 //     {
    3598 //       CmtError::set (CmtError::symbol_not_found,
    3599 //                   "Macro svn_checkout_command not defined");
    3600 //       return;
    3601 //     }
    3602   if (checkout.m_context)
    3603     {
    3604       int i;
    3605       if (version_tag == "")
    3606         // version tag not specified on the command line
    3607         {
    3608         }
    3609       else if ((i = version_tag.find ("*")) != cmt_string::npos)
    3610         // version has wildcards (or not specified) in requirements
    3611         {
    3612         }
    3613     }
    3614 
    36154304  History& h = History::instance ();
    36164305  cmt_string line (module + " " + version_tag);
     
    36314320    cmd += " --without_version_directory";
    36324321
    3633   if (version_tag != "")
     4322  if (version_tag == "" ||
     4323      version_tag == "HEAD" || version_tag == "head" ||
     4324      version_tag == "TRUNK" || version_tag == "trunk"
     4325      )
     4326    {
     4327      msg += (version_tag == "" ? " (HEAD)" : " (" + version_tag + ")");
     4328      version_tag = "";
     4329    }
     4330  else
    36344331    {
    36354332      cmd += " -r " + version_tag;
    36364333      msg += " (" + version_tag + ")";
    3637     }
    3638   else
    3639     {
    3640       msg += " (HEAD)";
    36414334    }
    36424335  if (checkout.m_offset != "")
     
    36564349   * Then call checkout for the module
    36574350   */
    3658   //   for (int arg = 0; arg < checkout.m_modules.size (); arg++)
    3659   //     {
    3660   //       const cmt_string& module = checkout.m_modules[arg];
    36614351  CmtMessage::info ("Working on " + module + msg);
    36624352  //      cerr << cmd + " " + module << endl;
     
    36654355    {
    36664356      CmtMessage::info (module + " done.");
    3667       if (checkout.m_recursive)
     4357      if (checkout.m_recursive && !checkout.m_context)
     4358        //      if (checkout.m_recursive)
    36684359        {
    36694360          cmt_string requirements;
     
    36944385                    { // checkout of trunk
    36954386                      //
    3696                       static CmtSystem::cmt_string_vector versions;
    3697                       static cmt_string name;
     4387                      CmtSystem::cmt_string_vector versions;
     4388                      cmt_string name;
    36984389                     
    36994390                      name = requirements;
     
    37504441                      if (n < 1)
    37514442                        {
    3752                           CmtMessage::error ("Cannot find package in " +
    3753                                              requirements +
    3754                                              " for recursion");
     4443                          CmtMessage::error ("Cannot find package for recursion"
     4444                                             " in " + requirements);
    37554445                          CmtError::set (CmtError::package_not_found,
    37564446                                         "in " + requirements);
     
    37604450                }
    37614451            } // end of with_version_directory
    3762           cmt_string cmt_req = requirements +
     4452          cmt_string
     4453            cmt_req = requirements +
    37634454            CmtSystem::file_separator () +
    37644455            "cmt" +
    37654456            CmtSystem::file_separator () +
    37664457            "requirements";
    3767           cmt_string mgr_req = requirements +
     4458          cmt_string
     4459            mgr_req = requirements +
    37684460            CmtSystem::file_separator () +
    37694461            "mgr" +
     
    37974489}
    37984490
     4491//--------------------------------------------------------------------
     4492static void visit (const Use::UsePtrVector& uses, IUseVisitor& visitor)
     4493{
     4494  for (int i = 0; i < uses.size (); i++)
     4495    {
     4496      Use* use = uses[i];
     4497      if (use == 0) continue;
     4498      if (use->selected) continue;
     4499      use->selected = true;
     4500      if (use->discarded) continue;
     4501      if (use->m_hidden) continue;
     4502      if (!use->located ()) continue;
     4503      if (use->get_package_name () == "CMT") continue;
     4504      if (use->get_package_name () == "cmt_standalone") continue;
     4505      if (use->get_package_name () == CmtSystem::get_home_package ()) continue;
     4506      if (use->get_package_name () == CmtSystem::get_user_context_package ()) continue;
     4507
     4508      //      visitor.in (use);
     4509      visit (use->sub_uses, visitor);
     4510      visitor.in (use);
     4511    }
     4512}
     4513
     4514//--------------------------------------------------------------------
     4515void Vcs::checkout_context (const Vcs::Checkout& checkout, Modules modules,
     4516                            bool config, bool with_version_directory,
     4517                            Vcs::VcsType type)
     4518{
     4519  VisitorForInfo visitor_i;
     4520  VisitorForCheckout visitor_co (checkout,
     4521                                 config, with_version_directory,
     4522                                 type);
     4523 
     4524  Use* current = &(Use::current ());
     4525  if (checkout.m_info)
     4526    visit (current->sub_uses, visitor_i);
     4527  else
     4528    visit (current->sub_uses, visitor_co);
     4529
     4530}
     4531
     4532//--------------------------------------------------------------------
     4533int Vcs::resolve_uses (const cmt_string& text, cmt_string& uses)
     4534{
     4535  cerr << "Vcs::resolve_uses" << endl;
     4536  cmt_string home_dir = CmtSystem::pwd ();
     4537  //
     4538  // Resolve uses by creating a package in a temporary directory
     4539  //
     4540  cmt_string tmp_dir = CmtSystem::getenv ("TMPDIR");
     4541  if (tmp_dir == "")
     4542    {
     4543      tmp_dir = CmtSystem::file_separator ();
     4544      tmp_dir += "tmp";
     4545    }
     4546 
     4547  if (!CmtSystem::test_directory (tmp_dir))
     4548    //if (!CmtSystem::cd (tmp_dir))
     4549    {
     4550      tmp_dir = home_dir;
     4551    }
     4552 
     4553  tmp_dir += CmtSystem::file_separator ();
     4554  tmp_dir += "cmtvcs";
     4555  cmt_string temp = CmtSystem::get_temporary_name ();
     4556  CmtSystem::basename (temp, temp);
     4557  // Suppress dots for Windows
     4558  temp.replace_all (".", "");
     4559  tmp_dir += temp;
     4560
     4561  cerr << "tmp_dir: " << tmp_dir << endl;
     4562  //  tmp_dir = "/tmp/cmtvcsfileEvmagO";
     4563
     4564  if (CmtSystem::test_directory (tmp_dir))
     4565    {
     4566      if (!CmtSystem::remove_directory (tmp_dir))
     4567        {
     4568          // CmtMessage::error ("Cannot remove temporary directory " + tmp_dir);
     4569          // error message printed by CmtSystem::remove_directory
     4570          return 1;
     4571        }
     4572    }
     4573  if (!CmtSystem::mkdir (tmp_dir))
     4574    {
     4575      CmtMessage::error ("Cannot create temporary directory " + tmp_dir);
     4576      return 1;
     4577    }
     4578
     4579  cmt_string pkgspec (temp + " v1 " + tmp_dir);
     4580  if (0 != CmtSystem::execute ("cmt -without_version_directory create " + pkgspec))
     4581    //  if (0 != CmtSystem::execute ("cmt -with_version_directory create " + pkg))
     4582    {
     4583      CmtMessage::error ("Cannot create package " + pkgspec);
     4584      CmtSystem::remove_directory (tmp_dir);
     4585      return 1;
     4586    }
     4587
     4588  cmt_string cmt_dir (tmp_dir +
     4589                      CmtSystem::file_separator () + temp +
     4590                      //                      CmtSystem::file_separator () + "v1" +
     4591                      CmtSystem::file_separator () + "cmt");
     4592 
     4593  cmt_string reqtext;
     4594  cmt_string requirements (cmt_dir +
     4595                           CmtSystem::file_separator () + "requirements");
     4596  if (!reqtext.read (requirements))
     4597    {
     4598      CmtError::set (CmtError::file_access_error, requirements);
     4599      CmtSystem::remove_directory (tmp_dir);
     4600      return 1;
     4601    }
     4602
     4603  FILE* file = fopen (requirements, "wb");
     4604  if (file != NULL)
     4605    {
     4606      (reqtext + text).write (file);
     4607      CmtSystem::close_ostream (file, requirements);
     4608      //      fclose (file);
     4609    }
     4610  else
     4611    {
     4612      CmtError::set (CmtError::file_access_error, requirements);
     4613      CmtSystem::remove_directory (tmp_dir);
     4614      return 1;
     4615    }
     4616
     4617  if (!CmtSystem::cd (cmt_dir))
     4618    {
     4619      CmtMessage::error ("Cannot move to temporary package directory " + cmt_dir);
     4620      CmtSystem::remove_directory (tmp_dir);
     4621      return 1;
     4622    }
     4623
     4624  int status = CmtSystem::execute ("cmt show uses", uses);
     4625  //  cerr << "status: " << status << endl;
     4626  if (status != 0)
     4627    {
     4628      CmtMessage::error ("Cannot show uses for package " + pkgspec);
     4629    }
     4630  //  cerr << "uses:\n" + uses << endl;
     4631  CmtSystem::cd (home_dir);
     4632  CmtSystem::remove_directory (tmp_dir);
     4633  return  status == 0 ? 0 : -1;
     4634}
     4635
     4636//--------------------------------------------------------------------
     4637int Vcs::resolve_uses (const cmt_string& text, Use::UsePtrVector& uses)
     4638{
     4639  cerr << "Vcs::resolve_uses NEW" << endl;
     4640  cmt_string home_dir = CmtSystem::pwd ();
     4641
     4642  Use* current = &(Use::current());
     4643
     4644  SyntaxParser::parse_requirements_text (text, "", current);
     4645
     4646  cerr <<  "recursive: " <<  Cmt::get_recursive () << endl;
     4647
     4648  Use::show_all ();
     4649
     4650  if (CmtError::get_last_error_code () == CmtError::package_not_found)
     4651    CmtError::print ();
     4652
     4653  return -1;
     4654}
     4655
     4656//--------------------------------------------------------------------
     4657int Vcs::resolve_uses (const Checkout& checkout, const cmt_string& uses)
     4658  //int Vcs::resolve_uses (const Checkout& checkout, const Modules& modules)
     4659{
     4660  if (!checkout.m_context) return 0;
     4661
     4662  //  cerr << "Vcs::resolve_uses NEW+" << endl;
     4663  cmt_string home_dir = CmtSystem::pwd ();
     4664  //
     4665  // Resolve uses by creating a package in a temporary directory
     4666  //
     4667  cmt_string tmp_dir = CmtSystem::getenv ("TMPDIR");
     4668  if (tmp_dir == "")
     4669    {
     4670      tmp_dir = CmtSystem::file_separator ();
     4671      tmp_dir += "tmp";
     4672    }
     4673 
     4674  if (!CmtSystem::test_directory (tmp_dir))
     4675    //if (!CmtSystem::cd (tmp_dir))
     4676    {
     4677      tmp_dir = home_dir;
     4678    }
     4679 
     4680  tmp_dir += CmtSystem::file_separator ();
     4681  tmp_dir += "cmtvcs";
     4682  cmt_string temp = CmtSystem::get_temporary_name ();
     4683  CmtSystem::basename (temp, temp);
     4684  // Suppress dots for Windows
     4685  temp.replace_all (".", "");
     4686  tmp_dir += temp;
     4687
     4688  if (CmtSystem::test_directory (tmp_dir))
     4689    {
     4690      if (!CmtSystem::remove_directory (tmp_dir))
     4691        {
     4692          CmtError::set (CmtError::file_access_error, tmp_dir);
     4693          // CmtMessage::error ("Cannot remove temporary directory " + tmp_dir);
     4694          // error message printed by CmtSystem::remove_directory
     4695          return 1;
     4696        }
     4697    }
     4698  if (!CmtSystem::mkdir (tmp_dir))
     4699    {
     4700      CmtError::set (CmtError::file_access_error,
     4701                     "Cannot create temporary directory " + tmp_dir);
     4702      CmtError::print ();
     4703      //CmtMessage::error ("Cannot create temporary directory " + tmp_dir);
     4704      return 1;
     4705    }
     4706
     4707    if (!CmtSystem::cd (tmp_dir))
     4708    {
     4709      CmtError::set (CmtError::file_access_error,
     4710                     "Cannot move to temporary package directory " + tmp_dir);
     4711      CmtError::print ();
     4712     //CmtMessage::error ("Cannot move to temporary package directory " + tmp_dir);
     4713      CmtSystem::remove_directory (tmp_dir);
     4714      return 1;
     4715    }
     4716
     4717  Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
     4718  int i (-1);
     4719  Project* cur (0);
     4720  Project null;
     4721  for (i = 0; i < Ordered.size (); i++)
     4722    if (Ordered[i]->is_current ()) break;
     4723  if (i >= 0 && i < Ordered.size ())
     4724    {
     4725      cur = Ordered[i];
     4726      Ordered[i] = &null;
     4727    }
     4728
     4729  bool cur_recursive (Cmt::get_recursive ());
     4730  CmtScopeFilteringMode
     4731    cur_scope_filtering_mode (Cmt::get_scope_filtering_mode ());
     4732  if (checkout.m_recursive)
     4733    {
     4734      Cmt::set_recursive (true);
     4735      Cmt::set_scope_filtering_mode (reach_private_uses);
     4736    }
     4737
     4738  SyntaxParser::parse_requirements_text (uses, "", &(Use::current()));
     4739
     4740  if (checkout.m_recursive)
     4741    {
     4742      Cmt::set_recursive (cur_recursive);
     4743      Cmt::set_scope_filtering_mode (cur_scope_filtering_mode);
     4744    }
     4745
     4746  if (i >= 0 && i < Ordered.size ())
     4747    {
     4748      Ordered[i] = cur;
     4749    }
     4750
     4751  CmtSystem::cd (home_dir);
     4752  CmtSystem::remove_directory (tmp_dir);
     4753
     4754  if (CmtError::get_last_error_code () == CmtError::package_not_found)
     4755    {
     4756      CmtError::print ();
     4757      return -1;
     4758    }
     4759
     4760  return 0;
     4761}
     4762
     4763//--------------------------------------------------------------------
    37994764void Vcs::checkout_from_requirements (const Vcs::Checkout& checkout,
    38004765                                      bool config,
     
    38084773  if (!text.read (requirements))
    38094774    {
    3810       CmtError::set (CmtError::path_not_found, requirements);
     4775      CmtError::set (CmtError::file_access_error, requirements);
    38114776      return;
    38124777    }
     4778
    38134779  static cmt_regexp expression ("^[ \t]*use[ \t]");
    3814 
    3815 //   RecursivePass1 p1;
    3816 //   p1.run (text, expression);
    3817 //   bool result = (p1.result () != "");
    3818 //   if (result)
    3819 //     cerr << p1.result () << endl;
    3820   Walkthru wth (checkout,
    3821                 config,
    3822                 with_version_directory,
    3823                 type);
    3824   wth.run (text, expression);
    3825 }
     4780  if (checkout.m_info)
     4781    {
     4782      VisitorForInfo visitor_i;
     4783      Walkthru wth (visitor_i);
     4784      wth.run (text, expression);
     4785    }
     4786  else
     4787    {
     4788      VisitorForCheckout visitor_co (checkout,
     4789                                     config, with_version_directory,
     4790                                     type);
     4791      Walkthru wth (visitor_co);
     4792      wth.run (text, expression);
     4793    }
     4794}
     4795//--------------------------------------------------------------------
  • CMT/HEAD/source/cmt_vcs.h

    r534 r535  
    99
    1010#include "cmt_system.h"
     11#include "cmt_use.h"
    1112
     13class Modules;
    1214class Vcs
    1315{
     
    3234  public:
    3335    Checkout ()
    34       : m_recursive (false), m_context (false)
     36      : m_head (false), m_recursive (false), m_context (false), m_info (false)
    3537      { }
    3638    cmt_string m_version_tag;
     39    bool m_head;
    3740    cmt_string m_checkout_dir;
    3841    cmt_string m_version_dir;
     
    4346    bool m_recursive;
    4447    bool m_context;
     48    bool m_info;
    4549    void print ()
    4650      {
    4751        cerr << "m_version_tag: " << m_version_tag << endl;
     52        cerr << "m_head: " << m_head << endl;
    4853        cerr << "m_checkout_dir: " << m_checkout_dir << endl;
    4954        cerr << "m_version_dir: " << m_version_dir << endl;
     
    6267  static void checkout_module (const Checkout& checkout,
    6368                               bool config, bool with_version_directory,
    64                                const cmt_string& module, cmt_string version_tag,
     69                               cmt_string module, cmt_string version_tag,
    6570                               VcsType type);
    6671  static void checkout_from_requirements (const Checkout& checkout,
     
    6873                                          const cmt_string& requirements,
    6974                                          VcsType type);
     75  static void checkout_context (const Checkout& checkout, Modules modules,
     76                                bool config, bool with_version_directory,
     77                                VcsType type);
    7078
    7179 private:
     
    7482  static void add_cmtpath (const cmt_string& dir);
    7583  static bool need_version_directory ();
    76   static int parse_checkout (const CmtSystem::cmt_string_vector& arguments,
    77                              Checkout& checkout, bool& config);
     84  static int parse_arguments (const CmtSystem::cmt_string_vector& arguments,
     85                              Checkout& checkout, bool& config);
     86  static int parse_checkout (Checkout& checkout, Modules& modules);
     87  //  static int parse_checkout (const Checkout& checkout, cmt_string& uses);
     88  static int resolve_uses (const cmt_string& text, cmt_string& uses);
     89  static int resolve_uses (const cmt_string& text, Use::UsePtrVector& uses);
     90  static int resolve_uses (const Checkout& checkout, const cmt_string& uses);
     91  //  static int resolve_uses (const Checkout& checkout, const Modules& modules);
     92  //  static void start_visit (IUseVisitor& visitor);
    7893};
    7994
     
    8297 public:
    8398 
    84   static void checkout (Vcs::Checkout checkout,
     99  static void checkout (Vcs::Checkout checkout, Modules modules,
    85100                       bool config, bool with_version_directory);
    86101};
    87102
     103class IUseVisitor
     104{
     105 public:
     106  //virtual void pre (Project* p) = 0;
     107  virtual void in (Use* use) = 0;
     108  //virtual void in_again (Project* p) = 0;
     109  //virtual void post (Project* p) = 0;
     110};
     111
    88112#endif
  • CMT/HEAD/src/Makefile.core

    r483 r535  
    7676ifdef cmtmsg
    7777export cmtmsg
    78 echo = @- echo "$(CMTMSGPREFIX)"
     78echo = @echo "$(CMTMSGPREFIX)"
    7979else
    8080echo = @:
  • CMT/HEAD/src/Makefile.header

    r527 r535  
    4242          $(MAKE) --no-print-directory target="all" common_target; \
    4343        else \
    44           echo "#CMT> There are configuration errors. Please correct them before running gmake"; \
     44          test -z "$(cmtmsg)" || \
     45          echo "$(CMTMSGPREFIX)" "(Makefile.header) Configuration error(s). Please correct" >&2; \
    4546        fi
    4647
     
    5354            test -z "$(cmtmsg)" || \
    5455            echo "$(CMTMSGPREFIX)" "(Makefile.header) Removing binary directory $(bin)"; \
    55             /bin/rm -rf $(bin) ; \
     56            \rm -rf $(bin) ; \
    5657          fi ; \
    5758        fi
Note: See TracChangeset for help on using the changeset viewer.