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

See C.L. 422

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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//--------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.