Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

DependencyGenerator Class Reference

#include <cmt_generators.h>

Inheritance diagram for DependencyGenerator:

Inheritance graph
[legend]
Collaboration diagram for DependencyGenerator:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void build (const CmtSystem::cmt_string_vector &arguments)

Private Member Functions

void add_line_to_text (const cmt_string &line, cmt_string &text)
cmt_string build (const cmt_string &file_name)

Private Attributes

bool m_stamps

Member Function Documentation

void DependencyGenerator::add_line_to_text const cmt_string line,
cmt_string text
[private]
 

Definition at line 2856 of file cmt_generators.cxx.

References cmt_string::erase(), cmt_string::find(), cmt_string::replace(), and cmt_string::substr().

Referenced by build().

02857 {
02858   static const cmt_string empty;
02859 
02860   int pos = line.find (" = ");
02861   if (pos != cmt_string::npos)
02862     {
02863       static cmt_string key;
02864       line.substr (0, pos + 3, key);
02865       pos = text.find (key);
02866       if (pos != cmt_string::npos)
02867         {
02868           // The key in line exists in text.
02869           // Now check if the key is exactly the same.
02870 
02871           if ((pos == 0) || (text[pos -1] == '\n'))
02872             {
02873               // The key is either in the first line or
02874               // exactly matches '^key = ...'
02875 
02876               int nl = text.find (pos, "\n");
02877               if (nl != cmt_string::npos)
02878                 {
02879                   static cmt_string old;
02880                   text.substr (pos, nl - pos + 1, old);
02881                   text.replace (old, empty);
02882                 }
02883               else
02884                 {
02885                   text.erase (pos);
02886                 }
02887             }
02888         }
02889     }
02890   if (line != "")
02891     {
02892       text += line;
02893       text += "\n";
02894     }
02895 }

cmt_string DependencyGenerator::build const cmt_string file_name  )  [private]
 

Definition at line 2897 of file cmt_generators.cxx.

References CmtSystem::absolute_path(), CmtSystem::basename(), CmtSystem::cmt_string_vector, Symbol::expand(), CmtSystem::file_separator(), CmtGenerator::filter_path(), CmtSystem::get_dot_suffix(), CmtSystem::get_suffix(), log, Log, log_endl, m_stamps, CmtSystem::mkdir(), Constituent::name, cmt_string::read(), DepsBuilder::run(), cmt_vector< T >::size(), CmtSystem::test_file(), and cmt_string::write().

02898 {
02899   Log;
02900 
02901   const Constituent& constituent = *m_constituent;
02902 
02903   static cmt_string full_name;
02904   static cmt_string suffix;
02905   static cmt_string name;
02906   static cmt_string line;
02907 
02908   full_name = "";
02909   line = "";
02910 
02911   if (!CmtSystem::absolute_path (file_name))
02912     {
02913       full_name = srcdir;
02914     }
02915 
02916   full_name += file_name;
02917 
02918   CmtSystem::get_dot_suffix (full_name, suffix);
02919   CmtSystem::basename (full_name, suffix, name);
02920   CmtSystem::get_suffix (full_name, suffix);
02921 
02922   if (name == "requirements") return (line);
02923 
02924   const CmtSystem::cmt_string_vector& deps = m_deps_builder.run (full_name);
02925 
02926   line  = name;
02927   line += "_";
02928   line += suffix;
02929   line += "_dependencies = ";
02930 
02931   filter_path (full_name);
02932 
02933 #ifdef WIN32
02934   static const char quote = '\"';
02935 #else
02936   static const char quote = ' ';
02937 #endif
02938 
02939   line += quote;
02940   line += full_name;
02941   line += quote;
02942 
02943   for (int j = 0; j < deps.size (); j++)
02944     {
02945       cmt_string d = deps[j];
02946 
02947       log << "dep line = " << d << log_endl;
02948 
02949       filter_path (d);
02950 
02951       log << "filtered dep line = " << d << log_endl;
02952 
02953       line += " ";
02954       line += quote;
02955       line += d;
02956       line += quote;
02957     }
02958 
02959   Symbol::expand (line);
02960 
02961   if (m_stamps)
02962     {
02963       cmt_string stamp_output_base = constituent.name;
02964       stamp_output_base += "_deps";
02965 
02966       cmt_string stamp_output = m_bin;
02967       stamp_output += stamp_output_base;
02968 
02969       if (!CmtSystem::mkdir (stamp_output))
02970         {
02971           cerr << "Cannot create the binary output directory for this constituent" << endl;
02972         }
02973 
02974       stamp_output_base += CmtSystem::file_separator ();
02975       stamp_output_base += name;
02976       stamp_output_base += "_";
02977       stamp_output_base += suffix;
02978       stamp_output_base += ".stamp";
02979 
02980       stamp_output = m_bin;
02981       stamp_output += stamp_output_base;
02982       
02983       line += " $(bin)";
02984       line += stamp_output_base;
02985       
02986       cmt_string old_stamp;
02987       
02988       if (CmtSystem::test_file (stamp_output))
02989         {
02990           old_stamp.read (stamp_output);
02991         }
02992 
02993       if (line != old_stamp)
02994         {
02995           line.write (stamp_output);
02996         }
02997     }
02998 
02999   return (line);
03000 }

void DependencyGenerator::build const CmtSystem::cmt_string_vector arguments  ) 
 

Definition at line 2614 of file cmt_generators.cxx.

References add_line_to_text(), DependencyFilter::add_source(), Cmt::build_nmake(), cmt_string::c_str(), CmtSystem::cmt_string_vector, CmtSystem::compress_path(), Use::current(), CmtSystem::current_branch(), Constituent::exclude_exprs, Symbol::expand(), CmtSystem::file_separator(), cmt_string::find(), Constituent::find(), CmtGenerator::get_all_files(), Use::get_package(), CmtSystem::getenv(), DependencyFilter::has_source(), Package::is_cmt(), m_stamps, Constituent::modules, CmtGenerator::prepare_use_context(), cmt_string::read(), CmtGenerator::reset(), Awk::run(), Constituent::select_exprs, CmtGenerator::set_full_name(), cmt_vector< T >::size(), cmt_string::size(), and cmt_string::write().

Referenced by Generator::build_dependencies().

02615 {
02616   reset ();
02617   prepare_use_context ();
02618 
02619   m_stamps = true;
02620 
02621   const cmt_string& name = arguments[0];
02622 
02623   //cerr << "name=" << name << endl;
02624 
02625   m_constituent = Constituent::find (name);
02626   if (m_constituent == 0)
02627     {
02628       // Error : wrong constituent name...
02629       
02630       return;
02631     }
02632 
02633   const Constituent& constituent = *m_constituent;
02634 
02635   cmt_string file_name;
02636   cmt_string full_name;
02637   cmt_string compressed_name;
02638   cmt_string suffix;
02639   cmt_string dependencies;
02640 
02641   //
02642   // Now prepare the output file names
02643   //
02644   cmt_string branch = CmtSystem::current_branch ();
02645 
02646   if ((branch == "mgr") || (branch == "cmt"))
02647     {
02648       Use& current_use = Use::current ();
02649 
02650       Package* p = current_use.get_package ();
02651 
02652       if (p->is_cmt ())
02653         {
02654           m_bin = "../";
02655           m_bin += CmtSystem::getenv ("CMTBIN");
02656           m_bin += CmtSystem::file_separator ();
02657         }
02658       else
02659         {
02660           m_bin = "${bin}";
02661         }
02662 
02663       Symbol::expand (m_bin);
02664 
02665       //cerr << "m_output_file_name=" << m_output_file_name << endl;
02666       //cerr << "current_tag=" << Cmt::current_tag << endl;
02667     }
02668   else
02669     {
02670       m_bin = ".";
02671       m_bin += CmtSystem::file_separator ();
02672     }
02673 
02674   m_output_file_name = m_bin;
02675   m_output_file_name += name;
02676   m_output_file_name += "_";
02677   m_output_file_name += "dependencies.";
02678   if (Cmt::build_nmake ())
02679     {
02680       m_output_file_name += "nmake";
02681     }
02682   else
02683     {
02684       m_output_file_name += "make";
02685     }
02686 
02687   //
02688   // New read the existing dependency file if any and filter it to
02689   // extract the source names
02690   //
02691   static DependencyFilter filter;
02692 
02693   dependencies.read (m_output_file_name);
02694 
02695   filter.run (dependencies);
02696 
02697   //
02698   // Scan the sources.
02699   //
02700 
02701   //
02702   //  We have to rebuild the dependencies for :
02703   //
02704   //   o all sources if the parameter -all_sources has been received
02705   //   o otherwise,
02706   //      + all source names provided in the argument list (if any)
02707   //      + all source names missing from the existing dependency file (if any)
02708   //
02709 
02710   const CmtSystem::cmt_string_vector& sources = constituent.modules;
02711   const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs;
02712   const cmt_vector<cmt_regexp>& selects = constituent.select_exprs;
02713 
02714   bool all_sources = false;
02715 
02716   int source_number = arguments.size ();
02717   int i;
02718 
02719   //cerr << "source_number=" << source_number << endl;
02720 
02721   for (i = source_number-1; i >= 0; i--)
02722     {
02723       file_name = arguments[i];
02724 
02725       //cerr << "file_name=" << file_name << endl;
02726 
02727         // Get rid of files that may come from the makefile fragment
02728       if (file_name.find ("requirements") != cmt_string::npos) source_number--;
02729       else if (file_name.find (".make") != cmt_string::npos) source_number--;
02730       else if (file_name == "-all_sources") 
02731         {
02732           source_number = sources.size ();
02733           all_sources = true;
02734         }
02735       else if (file_name == "-no_stamps") 
02736         {
02737           source_number--;
02738           m_stamps = false;
02739         }
02740     }
02741 
02742 
02743   if (all_sources)
02744     {
02745       for (i = 0; i < sources.size (); i++)
02746         {
02747           file_name = sources[i];
02748           
02749           set_full_name (full_name, file_name);
02750           if (full_name == "") continue;
02751 
02752           CmtSystem::compress_path (full_name, compressed_name);
02753           full_name = compressed_name;
02754           
02755           static CmtSystem::cmt_string_vector files;
02756 
02757           get_all_files (full_name, excludes, selects, files);
02758 
02759           for (int j = 0; j < files.size (); j++)
02760             {
02761               const cmt_string& name = files[j];
02762               
02763               if (name != "") 
02764                 {
02765                   const cmt_string& line = build (name);
02766                   
02767                   //cout << ">>> line=[" << line << "]" << endl;
02768                   
02769                   add_line_to_text (line, dependencies);
02770                 }
02771             }
02772         }
02773     }
02774   else
02775     {
02776       for (i = 1; i < source_number; i++)
02777         {
02778           file_name = arguments[i];
02779 
02780           set_full_name (full_name, file_name);
02781           if (full_name == "") continue;
02782 
02783           CmtSystem::compress_path (full_name, compressed_name);
02784           full_name = compressed_name;
02785           
02786           const cmt_string& line = build (full_name);
02787                   
02788             //cout << ">>> name2=" << full_name << endl;
02789                   
02790           add_line_to_text (line, dependencies);
02791 
02792             //cout << ">>from deps : " << filter.get_sources () << endl;
02793           filter.add_source (full_name);
02794 
02795         }
02796 
02797         //cout << ">>from deps : " << filter.get_sources () << endl;
02798 
02799         // Now : are there still any missing source file in dependencies??
02800 
02801       for (i = 0; i < sources.size (); i++)
02802         {
02803           file_name = sources[i];
02804           
02805           set_full_name (full_name, file_name);
02806           if (full_name == "") continue;
02807           
02808           CmtSystem::compress_path (full_name, compressed_name);
02809           full_name = compressed_name;
02810           
02811           static CmtSystem::cmt_string_vector files;
02812           
02813           get_all_files (full_name, excludes, selects, files);
02814 
02815           for (int j = 0; j < files.size (); j++)
02816             {
02817               const cmt_string& name = files[j];
02818               
02819               if (name != "") 
02820                 {
02821                   if (!filter.has_source (name))
02822                     {
02823                       const cmt_string& line = build (name);
02824                   
02825                         //cout << ">>> name3=" << name << endl;
02826                   
02827                       add_line_to_text (line, dependencies);
02828                     }
02829                 }
02830             }
02831         }
02832     }
02833 
02834   FILE* f = fopen (m_output_file_name.c_str (), "wb");
02835 
02836   if (f == 0)
02837     {
02838       cerr << "Cannot open " << m_output_file_name << " for write" << endl;
02839     }
02840   else
02841     {
02842       dependencies.write (f);
02843       fclose (f);
02844     }
02845 }


Member Data Documentation

bool DependencyGenerator::m_stamps [private]
 

Definition at line 218 of file cmt_generators.h.

Referenced by build().


The documentation for this class was generated from the following files:
Generated on Mon May 2 10:25:37 2005 for CMT by doxygen 1.3.5