source: CMT/v1r20p20070524/source/cmt_install_area.cxx

Last change on this file was 400, checked in by arnault, 17 years ago

Text formatting
Sending warnings & errors to stderr
Using internally PWD for every cd/pwd
CL 327

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