Changeset 534


Ignore:
Timestamp:
Feb 25, 2010, 10:05:31 AM (14 years ago)
Author:
rybkin
Message:

See C.L. 421

Location:
CMT/HEAD
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/ChangeLog

    r533 r534  
     12010-02-25    <rybkin@lal.in2p3.fr> 421
     2
     3        * source/cmt_vcs.h: In class Vcs, introduce functions checkout_module,
     4        checkout_from_requirements. In class Vcs::Checkout, introduce members
     5        m_requirements, m_command, m_recursive, m_context
     6        * source/cmt_vcs.cxx: Implement introduced functions so that options
     7        -R (recursive checkout) and -requirements (checkout from requirements file)
     8        be functional with Subversion
     9       
    1102010-02-03    <rybkin@lal.in2p3.fr> 420
    211
  • CMT/HEAD/source/cmt_vcs.cxx

    r497 r534  
    128128  CvsImplementation& m_cvs;
    129129};
     130
     131class Walkthru : public Awk
     132{
     133public:
     134  Walkthru (const Vcs::Checkout& checkout,
     135            bool config, bool with_version_directory,
     136            Vcs::VcsType type);
     137  //  RecursivePass2 (CvsImplementation& cvs);
     138  void begin ();
     139  void filter (const cmt_string& line);
     140
     141private:
     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;
     147};
     148
     149Walkthru::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
     158void Walkthru::begin ()
     159{
     160}
     161
     162void 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 
     170  CmtSystem::cmt_string_vector words;
     171 
     172  CmtSystem::split (line, " \t", words);
     173
     174  enum
     175    {
     176      need_package,
     177      need_version,
     178      need_path,
     179      no_need
     180    } state = need_package;
     181
     182  cmt_string package;
     183  cmt_string version;
     184  cmt_string path;
     185
     186  for (int i = 1; i < words.size (); i++)
     187    {
     188      const cmt_string& s = words[i];
     189
     190      if (s[0] == '-') continue;
     191
     192      switch (state)
     193        {
     194        case need_package:
     195          package = s;
     196          state = need_version;
     197          break;
     198        case need_version:
     199          version = s;
     200          state = need_path;
     201          break;
     202        case need_path:
     203          path = s;
     204          state = no_need;
     205          break;
     206        }
     207    }
     208
     209  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      */
     222      CmtMessage::warning (package + " " + version +
     223                           (path != "" ? " " + path : "") +
     224                           " has wildcards in version and will not be considered.");
     225    }
     226  else
     227    {
     228      //      static const cmt_string empty;
     229      //      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}
    130237
    131238/**
     
    31283235  cerr << "" << endl;
    31293236  cerr << "   modifier :" << endl;
    3130   cerr << "   -l        Do not process used packages (default)." << endl;
    3131   //cerr << "   -R        Process used products recursively." << endl;
    3132   cerr << "   -r rev    Check out version tag. (is sticky)" << endl;
    3133   cerr << "   -vd dir   Use this version directory instead of version tag." << endl;
    3134   cerr << "   -d dir    Check out into dir instead of module name." << endl;
    3135   cerr << "   -o offset Offset in the repository" << endl;
    3136   //cerr << "   -requirements <requirements file path>  Check out packages referenced in this requirements file" << endl;
     3237  cerr << "   -l          Do not process used packages (default)." << endl;
     3238  cerr << "   -R          Process used products recursively." << endl;
     3239  cerr << "   -r rev      Check out version tag. (is sticky)" << endl;
     3240  cerr << "   -vd dir     Use this version directory instead of version tag." << endl;
     3241  cerr << "   -d dir      Check out into dir instead of module name." << endl;
     3242  cerr << "   -o offset   Offset in the repository" << endl;
     3243  cerr << "   -requirements <requirements file path>  Check out packages referenced in this requirements file" << endl;
    31373244  //cerr << "   -t        Change file timestamps to the date of checkout" << endl;
    31383245  //cerr << "   -n        simulation mode on" << endl;
     
    31403247  //cerr << "   -v        verbose mode on" << endl;
    31413248  cerr << "   -rs suffix  Same as -r <packagename|projectname>suffix" << endl;
    3142   cerr << "   --help    print this help" << endl;
     3249  cerr << "   --help      Print this help" << endl;
    31433250  cerr << "" << endl;
    31443251  cerr << "(Modifiers are recognised anywhere on the command line.)" << endl;
     
    32823389          //m_head = false;
    32833390          //checkout_from_requirements (option);
     3391          checkout.m_requirements = option;
    32843392        }
    32853393      else if (need_version_tag_suffix)
     
    32923400          if (option == "-R")
    32933401            {
    3294               CmtMessage::warning ("Option " + option + " not implemented");
     3402              //CmtMessage::warning ("Option " + option + " not implemented");
     3403              //CmtMessage::warning ("Option " + option + " under testing");
    32953404              //m_recursive = true;
     3405              checkout.m_recursive = true;
    32963406            }
    32973407          else if (option == "-t")
     
    33023412          else if (option == "-l")
    33033413            {
     3414              checkout.m_recursive = false;
    33043415              //m_recursive = false;
    33053416            }
     
    33373448          else if (option == "-requirements")
    33383449            {
    3339               CmtMessage::warning ("Option " + option + " not implemented");
     3450              //CmtMessage::warning ("Option " + option + " under testing");
    33403451              need_requirements_file = true;
    33413452            }
     
    33743485    }
    33753486
    3376   if (checkout.m_modules.size () < 1)
     3487  if (checkout.m_modules.size () < 1 &&
     3488      checkout.m_requirements == "")
    33773489    {
    33783490      CmtError::set (CmtError::syntax_error, "No module to checkout specified");
     
    33813493      return 2;
    33823494    }
    3383   //  checkout.print ();
     3495  //checkout.print ();
    33843496  return 0;
    33853497}
     
    34303542}
    34313543
    3432 void Svn::checkout (const Vcs::Checkout& checkout,
     3544void Svn::checkout (Vcs::Checkout checkout,
    34333545                   bool config, bool with_version_directory)
    34343546{
     
    34453557      return;
    34463558    }
    3447 
    3448   cmt_string cmd (checkout_command);
     3559  checkout.m_command = checkout_command;
     3560
     3561  /**
     3562   * Call checkout for each command line argument
     3563   */
     3564  for (int arg = 0; arg < checkout.m_modules.size (); arg++)
     3565    {
     3566      const cmt_string& module = checkout.m_modules[arg];
     3567      const cmt_string& version_tag = checkout.m_version_tag;
     3568      Vcs::checkout_module (checkout,
     3569                            config, with_version_directory,
     3570                            module, version_tag,
     3571                            Vcs::Svn);
     3572      //      do_checkout_phase1 (modules[arg], m_version_dir, version_tag);
     3573    }
     3574
     3575  /**
     3576   * Call checkout for used package in requirements file
     3577   */
     3578  if (checkout.m_requirements != "")
     3579    Vcs::checkout_from_requirements (checkout,
     3580                                     config, with_version_directory,
     3581                                     checkout.m_requirements,
     3582                                     Vcs::Svn);
     3583}
     3584
     3585void Vcs::checkout_module (const Vcs::Checkout& checkout,
     3586                           bool config, bool with_version_directory,
     3587                           const cmt_string& module, cmt_string version_tag,
     3588                           Vcs::VcsType type)
     3589{
     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
     3615  History& h = History::instance ();
     3616  cmt_string line (module + " " + version_tag);
     3617  //cerr << "get: " << line << endl; 
     3618  if (h.is_installed (line)) return;
     3619  h.install (line);
     3620  //cerr << "install: " << line << endl; 
     3621
     3622  cmt_string cmd (checkout.m_command);
    34493623  cmt_string msg;
    34503624
     
    34573631    cmd += " --without_version_directory";
    34583632
    3459   if (checkout.m_version_tag != "")
    3460     {
    3461       cmd += " -r " + checkout.m_version_tag;
    3462       msg += " (" + checkout.m_version_tag + ")";
     3633  if (version_tag != "")
     3634    {
     3635      cmd += " -r " + version_tag;
     3636      msg += " (" + version_tag + ")";
    34633637    }
    34643638  else
     
    34803654
    34813655  /**
    3482    * Then call checkout for each argument
     3656   * Then call checkout for the module
    34833657   */
    3484   for (int arg = 0; arg < checkout.m_modules.size (); arg++)
    3485     {
    3486       const cmt_string& module = checkout.m_modules[arg];
    3487       CmtMessage::info ("Working on " + module + msg);
    3488       //      cerr << cmd + " " + module << endl;
    3489       int status = CmtSystem::execute (cmd + " " + module);
    3490       if (0 == status)
     3658  //   for (int arg = 0; arg < checkout.m_modules.size (); arg++)
     3659  //     {
     3660  //       const cmt_string& module = checkout.m_modules[arg];
     3661  CmtMessage::info ("Working on " + module + msg);
     3662  //      cerr << cmd + " " + module << endl;
     3663  int status = CmtSystem::execute (cmd + " " + module);
     3664  if (0 == status)
     3665    {
     3666      CmtMessage::info (module + " done.");
     3667      if (checkout.m_recursive)
    34913668        {
    3492           CmtMessage::info (module + " done.");
    3493         }
    3494       else
    3495         {
    3496           CmtError::set (CmtError::execution_failed, cmd + " " + module, status);
    3497         }
    3498       //      do_checkout_phase1 (modules[arg], m_version_dir, version_tag);
    3499     }
    3500 }
     3669          cmt_string requirements;
     3670          if (checkout.m_checkout_dir != "")
     3671            {
     3672              requirements = checkout.m_checkout_dir;
     3673            }
     3674          else
     3675            {
     3676              requirements = module;
     3677              requirements.replace_all ("/", CmtSystem::file_separator ());
     3678            }
     3679          if (with_version_directory)
     3680            {
     3681              if (checkout.m_version_dir != "")
     3682                {
     3683                  requirements += CmtSystem::file_separator ();
     3684                  requirements += checkout.m_version_dir;
     3685                }
     3686              else
     3687                {
     3688                  if (version_tag != "")
     3689                    {
     3690                      requirements += CmtSystem::file_separator ();
     3691                      requirements += version_tag;
     3692                    }
     3693                  else
     3694                    { // checkout of trunk
     3695                      //
     3696                      static CmtSystem::cmt_string_vector versions;
     3697                      static cmt_string name;
     3698                     
     3699                      name = requirements;
     3700                      name += CmtSystem::file_separator ();
     3701                      name += "*";
     3702                      CmtSystem::scan_dir (name, versions);
     3703
     3704                      int n (0);
     3705                      for (int i = 0; i < versions.size (); i++)
     3706                        {
     3707                          const cmt_string& vers = versions[i];
     3708                         
     3709                          if (Cmt::get_debug ())
     3710                            {
     3711                              cout << "     ... version " << vers << " exists" << endl;
     3712                            }
     3713                          /*
     3714                            This check is not sufficient !! We need to check in addition
     3715                            that the selected directory is really the start of a true CMT
     3716                            package (ie with either /mgr/requirements or /cmt/requirements below)
     3717                          */
     3718                         
     3719                          cmt_string req;
     3720                          req = vers;
     3721                          //req = name;
     3722                          req += CmtSystem::file_separator ();
     3723                          req += "mgr";
     3724                          req += CmtSystem::file_separator ();
     3725                          req += "requirements";
     3726                         
     3727                          if (!CmtSystem::test_file (req))
     3728                            {
     3729                              req = vers;
     3730                              //req = name;
     3731                              req += CmtSystem::file_separator ();
     3732                              req += "cmt";
     3733                              req += CmtSystem::file_separator ();
     3734                              req += "requirements";
     3735                             
     3736                              if (!CmtSystem::test_file (req)) continue;
     3737                            }
     3738                          n += 1;
     3739                          if (n > 1)
     3740                            {
     3741                              CmtMessage::warning (requirements +
     3742                                                   ": Ambiguous choice"
     3743                                                   " for recursion");
     3744                              break;
     3745                            }
     3746                          CmtSystem::basename (vers, name);
     3747                          requirements += CmtSystem::file_separator ();
     3748                          requirements += name;
     3749                        } // end of for versions loop
     3750                      if (n < 1)
     3751                        {
     3752                          CmtMessage::error ("Cannot find package in " +
     3753                                             requirements +
     3754                                             " for recursion");
     3755                          CmtError::set (CmtError::package_not_found,
     3756                                         "in " + requirements);
     3757                          return;
     3758                        }
     3759                    } // end of checkout of trunk
     3760                }
     3761            } // end of with_version_directory
     3762          cmt_string cmt_req = requirements +
     3763            CmtSystem::file_separator () +
     3764            "cmt" +
     3765            CmtSystem::file_separator () +
     3766            "requirements";
     3767          cmt_string mgr_req = requirements +
     3768            CmtSystem::file_separator () +
     3769            "mgr" +
     3770            CmtSystem::file_separator () +
     3771            "requirements";
     3772          if (CmtSystem::test_file (cmt_req))
     3773            {
     3774              requirements = cmt_req;
     3775            }
     3776          else if (CmtSystem::test_file (mgr_req))
     3777            {
     3778              requirements = mgr_req;
     3779            }
     3780          else
     3781            {
     3782              CmtError::set (CmtError::path_not_found,
     3783                             cmt_req + " or " + mgr_req);
     3784              return;
     3785            }
     3786          Vcs::checkout_from_requirements (checkout,
     3787                                           config, with_version_directory,
     3788                                           requirements,
     3789                                           type);
     3790        } // end of checkout.m_recursive
     3791    }
     3792  else
     3793    {
     3794      CmtError::set (CmtError::execution_failed, cmd + " " + module, status);
     3795    }
     3796  //      do_checkout_phase1 (modules[arg], m_version_dir, version_tag);
     3797}
     3798
     3799void Vcs::checkout_from_requirements (const Vcs::Checkout& checkout,
     3800                                      bool config,
     3801                                      bool with_version_directory,
     3802                                      const cmt_string& requirements,
     3803                                      Vcs::VcsType type)
     3804{
     3805  CmtMessage::info ("Processing " + requirements);
     3806
     3807  cmt_string text;
     3808  if (!text.read (requirements))
     3809    {
     3810      CmtError::set (CmtError::path_not_found, requirements);
     3811      return;
     3812    }
     3813  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}
  • CMT/HEAD/source/cmt_vcs.h

    r496 r534  
    1313{
    1414 public:
     15
     16  typedef enum
     17    {
     18      Cvs,
     19      Svn
     20    } VcsType;
     21
     22 public:
    1523 
    1624/*   static void tags (const CmtSystem::cmt_string_vector& arguments); */
     
    2331  {
    2432  public:
     33    Checkout ()
     34      : m_recursive (false), m_context (false)
     35      { }
    2536    cmt_string m_version_tag;
    2637    cmt_string m_checkout_dir;
     
    2839    cmt_string m_offset;
    2940    CmtSystem::cmt_string_vector m_modules;
     41    cmt_string m_requirements;
     42    cmt_string m_command;
     43    bool m_recursive;
     44    bool m_context;
    3045    void print ()
    3146      {
     
    3853            cerr << "m_modules[" << arg << "]: " << m_modules[arg] << endl;
    3954          }
     55        cerr << "m_requirements: " << m_requirements << endl;
     56        cerr << "m_command: " << m_command << endl;
     57        cerr << "m_recursive: " << m_recursive << endl;
     58        cerr << "m_context: " << m_context << endl;
    4059      }
    4160  };
     61
     62  static void checkout_module (const Checkout& checkout,
     63                               bool config, bool with_version_directory,
     64                               const cmt_string& module, cmt_string version_tag,
     65                               VcsType type);
     66  static void checkout_from_requirements (const Checkout& checkout,
     67                                          bool config, bool with_version_directory,
     68                                          const cmt_string& requirements,
     69                                          VcsType type);
    4270
    4371 private:
     
    5482 public:
    5583 
    56   static void checkout (const Vcs::Checkout& checkout,
     84  static void checkout (Vcs::Checkout checkout,
    5785                       bool config, bool with_version_directory);
    5886};
Note: See TracChangeset for help on using the changeset viewer.