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

cmt_install_area.cxx

Go to the documentation of this file.
00001 //-----------------------------------------------------------
00002 // Copyright Christian Arnault LAL-Orsay CNRS
00003 // 
00004 // See the complete license in cmt_license.txt "http://www.cecill.info". 
00005 //-----------------------------------------------------------
00006 
00007 #include "cmt_system.h"
00008 #include "cmt.h"
00009 #include "cmt_install_area.h"
00010 #include "cmt_syntax.h"
00011 #include "cmt_use.h"
00012 #include "cmt_symbol.h"
00013 #include "cmt_cmtpath_pattern.h"
00014 #include "cmt_project.h"
00015 
00016 CmtInstallAreaMgr& CmtInstallAreaMgr::instance ()
00017 {
00018   static CmtInstallAreaMgr me;
00019 
00020   return (me);
00021 }
00022 
00023 void CmtInstallAreaMgr::setup_current_installarea ()
00024 {
00025   m_installarea = build_current_installarea ();
00026 
00027   if (m_installarea == "") return;
00028 
00029   cmt_string macro_name;
00030 
00031   Project* project = Project::find_by_cmtpath (m_installarea);
00032 
00033   if (project != 0)
00034     {
00035       macro_name = project->get_name ();
00036     }
00037   else
00038     {
00039       macro_name = "cmt";
00040     }
00041 
00042   macro_name += "_installarea_prefix";
00043 
00044   Symbol* macro = Symbol::find (macro_name);
00045 
00046   cmt_string installarea_prefix;
00047 
00048   if (macro != 0)
00049     {
00050       installarea_prefix = macro->build_macro_value ();
00051     }
00052 
00053   if (installarea_prefix != "")
00054     {
00055       m_installarea += CmtSystem::file_separator ();
00056       m_installarea += installarea_prefix;
00057     }
00058 
00059   Use& current_use = Use::current ();
00060   cmt_string buffer;
00061 
00062   if (!Symbol::is_selected ("CMTINSTALLAREA"))
00063     {
00064       buffer = "macro CMTINSTALLAREA \"";
00065       buffer += m_installarea;
00066       buffer += "\"";
00067       
00068       SyntaxParser::parse_requirements_line (buffer, ¤t_use);
00069       buffer = "";
00070     }
00071 }
00072 
00073 void CmtInstallAreaMgr::setup ()
00074 {
00075   m_installarea = build_current_installarea ();
00076 
00077   setup_current_installarea ();
00078 }
00079 
00080 void CmtInstallAreaMgr::config () const
00081 {
00082   cmt_string installarea = build_current_installarea ();
00083 
00084   CmtPathPattern::apply_all ();
00085 
00086   if (installarea == "") return;
00087 
00088   // cout << "InstallArea installed in " << installarea << endl;
00089 
00090   if (!Cmt::get_quiet ())
00091     {
00092       cerr << "#CMT> Warning: Doing cleanup in the installation area " << installarea << endl;
00093     }
00094 
00095   Symbol* macro = Symbol::find ("cmt_installarea_paths");
00096   if (macro == 0) return;
00097   cmt_string installarea_paths = macro->build_macro_value ();
00098 
00099   CmtSystem::cmt_string_vector areapaths;
00100   CmtSystem::split (installarea_paths, " \t", areapaths);
00101 
00102     // Try a cleanup only in this selected install area
00103 
00104   for (int i = 0; i < areapaths.size (); i++)
00105     {
00106       const cmt_string& p = areapaths[i];
00107       
00108       cmt_string path = installarea;
00109       path += CmtSystem::file_separator ();
00110       path += p;
00111       
00112       Symbol::expand (path);
00113 
00114       path.replace_all ("/", CmtSystem::file_separator ());
00115       path.replace_all ("\\", CmtSystem::file_separator ());
00116       
00117       CmtSystem::cmt_string_vector refs;
00118       cmt_regexp expression (".*[.]cmtref$");
00119 
00120         // Look for all cmtref files in this PATH pattern
00121 
00122       CmtSystem::scan_dir (path, expression, refs);
00123       
00124       for (int j = 0; j < refs.size (); j++)
00125         {
00126           const cmt_string& ref_file = refs[j];
00127 
00128             // We get the absolute location of the installed file
00129 
00130           cmt_string ref;
00131           ref.read (ref_file);
00132           int pos;
00133 
00134           ref.replace_all ("\"", "");
00135 
00136           if (Cmt::get_debug ())
00137             {
00138               cout << "CmtInstallAreaMgr::config> " << ref_file << " " << ref << endl;
00139             }
00140 
00141           pos = ref.find ("\r\n");
00142           if (pos != cmt_string::npos) ref.erase (pos);
00143           pos = ref.find ('\n');
00144           if (pos != cmt_string::npos) ref.erase (pos);
00145           pos = ref.find ('\r');
00146           if (pos != cmt_string::npos) ref.erase (pos);
00147           pos = ref.find (' ');
00148           if (pos != cmt_string::npos) ref.erase (pos);
00149 
00150             //  If the referenced file cannot be reached we remove the 
00151             // corresponding installation
00152             //  (this happens if the referenced file has be removed, or 
00153             //   moved away)
00154           
00155           if (!CmtSystem::test_file (ref))
00156             {
00157               cmt_string ref_name;
00158 
00159                 // Get the name of the referenced file
00160               CmtSystem::basename (ref, ref_name);
00161 
00162                 // Get the installation directory
00163               CmtSystem::dirname (ref_file, ref);
00164 
00165               ref += CmtSystem::file_separator ();
00166               ref += ref_name;
00167               
00168                 // Remove both the installed file
00169                 // and the reference file
00170 
00171               if (!Cmt::get_quiet ())
00172                 {
00173                   cout << "# Removing obsolete installed file ["  << ref << "]";
00174                   cout << "  (and " << ref_file << ")" << endl;
00175                 }
00176 
00177               CmtSystem::remove_file (ref);
00178               CmtSystem::remove_file (ref_file);
00179             }
00180         }
00181     }
00182 }
00183 
00184 const cmt_string& CmtInstallAreaMgr::get_installarea () const
00185 {
00186   return (m_installarea);
00187 }
00188 
00189 cmt_string CmtInstallAreaMgr::build_current_installarea () const
00190 {
00191   cmt_string installarea;
00192 
00193   const cmt_string pwd = CmtSystem::pwd ();
00194 
00195   installarea = Project::find_in_cmt_paths (pwd);
00196 
00197   return (installarea);
00198 }
00199 
00200 
00201 

Generated on Mon May 2 10:25:05 2005 for CMT by 1.3.5