Main Page ? Class Hierarchy ? Compound List ? File List ? Compound Members ? File Members ?

DependencyGenerator Class Reference

#include <cmt_generators.h>

Inheritance diagram for DependencyGenerator:

[legend]
Collaboration diagram for DependencyGenerator:

[legend]
List of all members.

Public Methods

void? build (const cmt_string &name, int argc, char *argv[])

Private Methods

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

Member Function Documentation

void DependencyGenerator::add_line_to_text (? const cmt_string &? ? line,
cmt_string &? ? text
)? [private]
?

Definition at line 2787 of file cmt_generators.cxx.

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

Referenced by build().

02788 {
02789   static const cmt_string empty;
02790 
02791   int pos = line.find (" = ");
02792   if (pos != cmt_string::npos)
02793     {
02794       static cmt_string key;
02795       line.substr (0, pos + 3, key);
02796       pos = text.find (key);
02797       if (pos != cmt_string::npos)
02798         {
02799           // The key in line exists in text.
02800           // Now check if the key is exactly the same.
02801 
02802           if ((pos == 0) || (text[pos -1] == '\n'))
02803             {
02804               // The key is either in the first line or
02805               // exactly matches '^key = ...'
02806 
02807               int nl = text.find (pos, "\n");
02808               if (nl != cmt_string::npos)
02809                 {
02810                   static cmt_string old;
02811                   text.substr (pos, nl - pos + 1, old);
02812                   text.replace (old, empty);
02813                 }
02814               else
02815                 {
02816                   text.erase (pos);
02817                 }
02818             }
02819         }
02820     }
02821   if (line != "")
02822     {
02823       text += line;
02824       text += "\n";
02825     }
02826 }

cmt_string DependencyGenerator::build (? const cmt_string &? ? file_name )? [private]
?

Definition at line 2828 of file cmt_generators.cxx.

References CmtSystem::absolute_path(), CmtSystem::basename(), CmtGenerator::filter_path(), CmtSystem::get_dot_suffix(), CmtSystem::get_suffix(), CmtGenerator::m_deps_builder, DepsBuilder::run(), cmt_vector< cmt_string >::size(), and CmtGenerator::srcdir.

02829 {
02830   static cmt_string full_name;
02831   static cmt_string suffix;
02832   static cmt_string name;
02833   static cmt_string line;
02834 
02835   full_name = "";
02836   line = "";
02837 
02838   if (!CmtSystem::absolute_path (file_name))
02839     {
02840       full_name = srcdir;
02841     }
02842 
02843   full_name += file_name;
02844 
02845   CmtSystem::get_dot_suffix (full_name, suffix);
02846   CmtSystem::basename (full_name, suffix, name);
02847   CmtSystem::get_suffix (full_name, suffix);
02848 
02849   if (name == "requirements") return (line);
02850 
02851   const CmtSystem::cmt_string_vector& deps = m_deps_builder.run (full_name);
02852 
02853   line  = name;
02854   line += "_";
02855   line += suffix;
02856   line += "_dependencies = ";
02857 
02858   filter_path (full_name);
02859 
02860 #ifdef WIN32
02861   static const char quote = '\"';
02862 #else
02863   static const char quote = ' ';
02864 #endif
02865 
02866   line += quote;
02867   line += full_name;
02868   line += quote;
02869 
02870   for (int j = 0; j < deps.size (); j++)
02871     {
02872       cmt_string d = deps[j];
02873       filter_path (d);
02874 
02875       line += " ";
02876       line += quote;
02877       line += d;
02878       line += quote;
02879     }
02880 
02881   return (line);
02882 }

void DependencyGenerator::build (? const cmt_string &? ? name,
int? ? argc,
char *? ? argv[]
)?
?

Definition at line 2574 of file cmt_generators.cxx.

References add_line_to_text(), DependencyFilter::add_source(), Cmt::build_nmake(), cmt_string::c_str(), 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(), Constituent::modules, cmt_string::npos, CmtGenerator::prepare_use_context(), cmt_string::read(), CmtGenerator::reset(), Awk::run(), Constituent::select_exprs, CmtGenerator::set_full_name(), cmt_vector< cmt_string >::size(), and cmt_string::write().

Referenced by Generator::build_dependencies().

02575 {
02576   reset ();
02577   prepare_use_context ();
02578 
02579   const Constituent* constituent_ptr = Constituent::find (name);
02580   if (constituent_ptr == 0)
02581     {
02582       // Error : wrong constituent name...
02583       return;
02584     }
02585 
02586   const Constituent& constituent = *constituent_ptr;
02587 
02588   cmt_string file_name;
02589   cmt_string full_name;
02590   cmt_string compressed_name;
02591   cmt_string suffix;
02592   cmt_string dependencies;
02593 
02594   cmt_string branch = CmtSystem::current_branch ();
02595 
02596   if ((branch == "mgr") || (branch == "cmt"))
02597     {
02598       Use& current_use = Use::current ();
02599 
02600       Package* p = current_use.get_package ();
02601 
02602       if (p->is_cmt ())
02603         {
02604           m_output_file_name = "../";
02605           m_output_file_name += CmtSystem::getenv ("CMTBIN");
02606           m_output_file_name += CmtSystem::file_separator ();
02607         }
02608       else
02609         {
02610           m_output_file_name = "${bin}";
02611         }
02612 
02613       Symbol::expand (m_output_file_name);
02614 
02615       //cerr << "m_output_file_name=" << m_output_file_name << endl;
02616       //cerr << "current_tag=" << Cmt::current_tag << endl;
02617     }
02618 
02619   m_output_file_name += name;
02620   m_output_file_name += "_";
02621   m_output_file_name += "dependencies.";
02622   if (Cmt::build_nmake ())
02623     {
02624       m_output_file_name += "nmake";
02625     }
02626   else
02627     {
02628       m_output_file_name += "make";
02629     }
02630 
02631   static DependencyFilter filter;
02632 
02633   dependencies.read (m_output_file_name);
02634 
02635   filter.run (dependencies);
02636 
02637   //
02638   // Scan the sources.
02639   //
02640 
02641     //
02642     //  We have to rebuild the dependencies for :
02643     //
02644     //   o all sources if the parameter -all_sources has been received
02645     //   o otherwise,
02646     //      + all source names provided in the argument list (if any)
02647     //      + all source names missing from the existing dependency file (if any)
02648     //
02649 
02650   const CmtSystem::cmt_string_vector& sources = constituent.modules;
02651   const cmt_vector& excludes = constituent.exclude_exprs;
02652   const cmt_vector& selects = constituent.select_exprs;
02653 
02654   bool all_sources = false;
02655 
02656   int source_number = argc;
02657   int i;
02658 
02659   for (i = argc-1; i >= 0; i--)
02660     {
02661       file_name = argv[i];
02662 
02663         // Get rid of files that may come from the makefile fragment
02664       if (file_name.find ("requirements") != cmt_string::npos) source_number--;
02665       else if (file_name.find (".make") != cmt_string::npos) source_number--;
02666       else if (file_name == "-all_sources") 
02667         {
02668           source_number = sources.size ();
02669           all_sources = true;
02670         }
02671     }
02672 
02673 
02674   if (all_sources)
02675     {
02676       for (i = 0; i < sources.size (); i++)
02677         {
02678           file_name = sources[i];
02679           
02680           set_full_name (full_name, file_name);
02681           if (full_name == "") continue;
02682 
02683           CmtSystem::compress_path (full_name, compressed_name);
02684           full_name = compressed_name;
02685           
02686           static CmtSystem::cmt_string_vector files;
02687 
02688           get_all_files (full_name, excludes, selects, files);
02689 
02690           for (int j = 0; j < files.size (); j++)
02691             {
02692               const cmt_string& name = files[j];
02693               
02694               if (name != "") 
02695                 {
02696                   const cmt_string& line = build (name);
02697                   
02698                   //cout << ">>> line=[" << line << "]" << endl;
02699                   
02700                   add_line_to_text (line, dependencies);
02701                 }
02702             }
02703         }
02704     }
02705   else
02706     {
02707       for (i = 0; i < source_number; i++)
02708         {
02709           file_name = argv[i];
02710           
02711           set_full_name (full_name, file_name);
02712           if (full_name == "") continue;
02713 
02714           CmtSystem::compress_path (full_name, compressed_name);
02715           full_name = compressed_name;
02716           
02717           const cmt_string& line = build (full_name);
02718                   
02719             //cout << ">>> name2=" << full_name << endl;
02720                   
02721           add_line_to_text (line, dependencies);
02722 
02723             //cout << ">>from deps : " << filter.get_sources () << endl;
02724           filter.add_source (full_name);
02725 
02726         }
02727 
02728         //cout << ">>from deps : " << filter.get_sources () << endl;
02729 
02730         // Now : are there still any missing source file in dependencies??
02731 
02732       for (i = 0; i < sources.size (); i++)
02733         {
02734           file_name = sources[i];
02735           
02736           set_full_name (full_name, file_name);
02737           if (full_name == "") continue;
02738           
02739           CmtSystem::compress_path (full_name, compressed_name);
02740           full_name = compressed_name;
02741           
02742           static CmtSystem::cmt_string_vector files;
02743           
02744           get_all_files (full_name, excludes, selects, files);
02745 
02746           for (int j = 0; j < files.size (); j++)
02747             {
02748               const cmt_string& name = files[j];
02749               
02750               if (name != "") 
02751                 {
02752                   if (!filter.has_source (name))
02753                     {
02754                       const cmt_string& line = build (name);
02755                   
02756                         //cout << ">>> name3=" << name << endl;
02757                   
02758                       add_line_to_text (line, dependencies);
02759                     }
02760                 }
02761             }
02762         }
02763     }
02764 
02765   FILE* f = fopen (m_output_file_name.c_str (), "wb");
02766 
02767   if (f == 0)
02768     {
02769       cerr << "Cannot open " << m_output_file_name << " for write" << endl;
02770     }
02771   else
02772     {
02773       dependencies.write (f);
02774       fclose (f);
02775     }
02776 }

The documentation for this class was generated from the following files:
Generated on Thu Jul 1 15:26:50 2004 for CMT by 1.2.18