source: CMT/v1r19/source/cmt_install_area.cxx @ 1

Last change on this file since 1 was 1, checked in by arnault, 19 years ago

Import all tags

File size: 5.1 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  // cout << "InstallArea installed in " << installarea << endl;
89
90  if (!Cmt::get_quiet ())
91    {
92      cerr << "#CMT> Warning: Doing cleanup in the installation area " << installarea << endl;
93    }
94
95  Symbol* macro = Symbol::find ("cmt_installarea_paths");
96  if (macro == 0) return;
97  cmt_string installarea_paths = macro->build_macro_value ();
98
99  CmtSystem::cmt_string_vector areapaths;
100  CmtSystem::split (installarea_paths, " \t", areapaths);
101
102    // Try a cleanup only in this selected install area
103
104  for (int i = 0; i < areapaths.size (); i++)
105    {
106      const cmt_string& p = areapaths[i];
107     
108      cmt_string path = installarea;
109      path += CmtSystem::file_separator ();
110      path += p;
111     
112      Symbol::expand (path);
113
114      path.replace_all ("/", CmtSystem::file_separator ());
115      path.replace_all ("\\", CmtSystem::file_separator ());
116     
117      CmtSystem::cmt_string_vector refs;
118      cmt_regexp expression (".*[.]cmtref$");
119
120        // Look for all cmtref files in this PATH pattern
121
122      CmtSystem::scan_dir (path, expression, refs);
123     
124      for (int j = 0; j < refs.size (); j++)
125        {
126          const cmt_string& ref_file = refs[j];
127
128            // We get the absolute location of the installed file
129
130          cmt_string ref;
131          ref.read (ref_file);
132          int pos;
133
134          ref.replace_all ("\"", "");
135
136          if (Cmt::get_debug ())
137            {
138              cout << "CmtInstallAreaMgr::config> " << ref_file << " " << ref << endl;
139            }
140
141          pos = ref.find ("\r\n");
142          if (pos != cmt_string::npos) ref.erase (pos);
143          pos = ref.find ('\n');
144          if (pos != cmt_string::npos) ref.erase (pos);
145          pos = ref.find ('\r');
146          if (pos != cmt_string::npos) ref.erase (pos);
147          pos = ref.find (' ');
148          if (pos != cmt_string::npos) ref.erase (pos);
149
150            //  If the referenced file cannot be reached we remove the
151            // corresponding installation
152            //  (this happens if the referenced file has be removed, or
153            //   moved away)
154         
155          if (!CmtSystem::test_file (ref))
156            {
157              cmt_string ref_name;
158
159                // Get the name of the referenced file
160              CmtSystem::basename (ref, ref_name);
161
162                // Get the installation directory
163              CmtSystem::dirname (ref_file, ref);
164
165              ref += CmtSystem::file_separator ();
166              ref += ref_name;
167             
168                // Remove both the installed file
169                // and the reference file
170
171              if (!Cmt::get_quiet ())
172                {
173                  cout << "# Removing obsolete installed file ["  << ref << "]";
174                  cout << "  (and " << ref_file << ")" << endl;
175                }
176
177              CmtSystem::remove_file (ref);
178              CmtSystem::remove_file (ref_file);
179            }
180        }
181    }
182}
183
184const cmt_string& CmtInstallAreaMgr::get_installarea () const
185{
186  return (m_installarea);
187}
188
189cmt_string CmtInstallAreaMgr::build_current_installarea () const
190{
191  cmt_string installarea;
192
193  const cmt_string pwd = CmtSystem::pwd ();
194
195  installarea = Project::find_in_cmt_paths (pwd);
196
197  return (installarea);
198}
199
200
201
Note: See TracBrowser for help on using the repository browser.