source: CMT/v1r25-branch/source/cmt_install_area.cxx

Last change on this file was 664, checked in by rybkin, 10 years ago

merge -r 646:663 HEAD

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// Modified by Grigory Rybkin
5// See the complete license in cmt_license.txt "http://www.cecill.info".
6//-----------------------------------------------------------
7
8#include "cmt_system.h"
9#include "cmt.h"
10#include "cmt_install_area.h"
11#include "cmt_syntax.h"
12#include "cmt_use.h"
13#include "cmt_symbol.h"
14#include "cmt_cmtpath_pattern.h"
15#include "cmt_project.h"
16#include "cmt_log.h"
17
18CmtInstallAreaMgr& CmtInstallAreaMgr::instance ()
19{
20  static CmtInstallAreaMgr me;
21
22  return (me);
23}
24
25void CmtInstallAreaMgr::setup_current_installarea ()
26{
27  m_installarea = build_current_installarea ();
28
29  if (m_installarea == "") return;
30
31  cmt_string macro_name;
32
33  Project* project = Project::find_by_cmtpath (m_installarea);
34
35  if (project != 0)
36    {
37      macro_name = project->get_name ();
38    }
39  else
40    {
41      macro_name = "cmt";
42    }
43
44  macro_name += "_installarea_prefix";
45
46  Symbol* macro = Symbol::find (macro_name);
47
48  cmt_string installarea_prefix;
49
50  if (macro != 0)
51    {
52      installarea_prefix = macro->build_macro_value ();
53    }
54
55  if (installarea_prefix != "")
56    {
57      m_installarea += CmtSystem::file_separator ();
58      m_installarea += installarea_prefix;
59    }
60
61  Use& current_use = Use::current ();
62  cmt_string buffer;
63
64  if (!Symbol::is_selected ("CMTINSTALLAREA"))
65    {
66      buffer = "macro CMTINSTALLAREA \"";
67      buffer += m_installarea;
68      buffer += "\"";
69     
70      SyntaxParser::parse_requirements_line (buffer, &current_use);
71      buffer = "";
72    }
73}
74
75void CmtInstallAreaMgr::setup ()
76{
77  m_installarea = build_current_installarea ();
78
79  setup_current_installarea ();
80}
81
82void CmtInstallAreaMgr::config () const
83{
84  cmt_string installarea = build_current_installarea ();
85
86  CmtPathPattern::apply_all ();
87
88  if (installarea == "") return;
89
90  CmtMessage::warning ("Doing cleanup in the installation area " + installarea);
91  /*
92  if (!Cmt::get_quiet ())
93    {
94      cerr << "#CMT> Warning: Doing cleanup in the installation area " << installarea << endl;
95    }
96  */
97
98  Symbol* macro = Symbol::find ("cmt_installarea_paths");
99  if (macro == 0) return;
100  cmt_string installarea_paths = macro->build_macro_value ();
101
102  CmtSystem::cmt_string_vector areapaths;
103  CmtSystem::split (installarea_paths, " \t", areapaths);
104
105  // Try a cleanup only in this selected install area
106
107  for (int i = 0; i < areapaths.size (); i++)
108    {
109      const cmt_string& p = areapaths[i];
110     
111      cmt_string path = installarea;
112      path += CmtSystem::file_separator ();
113      path += p;
114     
115      Symbol::expand (path);
116
117      path.replace_all ("/", CmtSystem::file_separator ());
118      path.replace_all ("\\", CmtSystem::file_separator ());
119     
120      CmtSystem::cmt_string_vector refs;
121      cmt_regexp expression (".*[.]cmtref$");
122
123      // Look for all cmtref files in this PATH pattern
124
125      CmtSystem::scan_dir (path, expression, refs);
126     
127      for (int j = 0; j < refs.size (); j++)
128        {
129          const cmt_string& ref_file = refs[j];
130
131          // We get the absolute location of the installed file
132
133          cmt_string ref;
134          ref.read (ref_file);
135          int pos;
136
137          ref.replace_all ("\"", "");
138
139          if (Cmt::get_debug ())
140            {
141              cout << "CmtInstallAreaMgr::config> " << ref_file << " " << ref << endl;
142            }
143
144          pos = ref.find ("\r\n");
145          if (pos != cmt_string::npos) ref.erase (pos);
146          pos = ref.find ('\n');
147          if (pos != cmt_string::npos) ref.erase (pos);
148          pos = ref.find ('\r');
149          if (pos != cmt_string::npos) ref.erase (pos);
150          pos = ref.find (' ');
151          if (pos != cmt_string::npos) ref.erase (pos);
152
153          //  If the referenced file cannot be reached we remove the
154          // corresponding installation
155          //  (this happens if the referenced file has be removed, or
156          //   moved away)
157         
158          if (!CmtSystem::test_file (ref))
159            {
160              cmt_string ref_name;
161
162              // Get the name of the referenced file
163              CmtSystem::basename (ref, ref_name);
164
165              // Get the installation directory
166              CmtSystem::dirname (ref_file, ref);
167
168              ref += CmtSystem::file_separator ();
169              ref += ref_name;
170             
171              // Remove both the installed file
172              // and the reference file
173
174              CmtMessage::info ("Removing obsolete installed file [" + ref + "]"
175                                "  (and " + ref_file + ")");
176              /*
177              if (!Cmt::get_quiet ())
178                {
179                  cerr << "# Removing obsolete installed file ["  << ref << "]";
180                  cerr << "  (and " << ref_file << ")" << endl;
181                }
182              */
183
184              CmtSystem::remove_file (ref);
185              CmtSystem::remove_file (ref_file);
186            }
187        }
188    }
189}
190
191const cmt_string& CmtInstallAreaMgr::get_installarea () const
192{
193  return (m_installarea);
194}
195
196cmt_string CmtInstallAreaMgr::build_current_installarea () const
197{
198  cmt_string installarea;
199
200  const Use& use = Use::current ();
201  cmt_string current_path (use.real_path);
202  if (!use.located ())
203    {
204      CmtMessage::verbose ("build_current_installarea: Current use not located");
205      current_path = CmtSystem::pwd ();
206    }
207  //const cmt_string pwd = CmtSystem::pwd ();
208
209  installarea = Project::find_in_cmt_paths (current_path);
210  //installarea = Project::find_in_cmt_paths (pwd);
211
212  return (installarea);
213}
214
215
216
Note: See TracBrowser for help on using the repository browser.