[2] | 1 | //----------------------------------------------------------- |
---|
| 2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
| 3 | // arnault@lal.in2p3.fr |
---|
[272] | 4 | // Modified by garonne@lal.in2p3.fr |
---|
[2] | 5 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
| 6 | //----------------------------------------------------------- |
---|
| 7 | |
---|
| 8 | #ifndef __cmt_use_h__ |
---|
| 9 | #define __cmt_use_h__ |
---|
| 10 | |
---|
| 11 | #include "cmt_map.h" |
---|
| 12 | #include "cmt_include.h" |
---|
| 13 | #include "cmt_script.h" |
---|
| 14 | #include "cmt_pattern.h" |
---|
| 15 | #include "cmt_scope_section.h" |
---|
| 16 | |
---|
| 17 | class Package; |
---|
| 18 | class UseProjectAction; |
---|
| 19 | |
---|
| 20 | class Use |
---|
| 21 | { |
---|
| 22 | // Public class methods |
---|
| 23 | public: |
---|
| 24 | typedef cmt_vector<Use> UseVector; |
---|
| 25 | typedef cmt_vector<Use*> UsePtrVector; |
---|
| 26 | |
---|
| 27 | static Use* action (const CmtSystem::cmt_string_vector& words, Use* use); |
---|
| 28 | static Use* find (const cmt_string& package, |
---|
| 29 | const cmt_string& version = "", |
---|
| 30 | const cmt_string& path = ""); |
---|
| 31 | static int find_index (const cmt_string& package, |
---|
| 32 | const cmt_string& version, |
---|
| 33 | const cmt_string& path); |
---|
[566] | 34 | static Use* find_valid (const cmt_string& package); |
---|
[563] | 35 | //static void set_auto_imports_state (int use_index, |
---|
| 36 | //cmt_vector<bool>& auto_imports_states); |
---|
| 37 | static void set_auto_imports_state (const Use::UsePtrVector& uses, |
---|
[575] | 38 | cmt_vector<bool>& auto_imports_states); |
---|
| 39 | static void set_auto_imports_state (const Use::UsePtrVector& uses, |
---|
[563] | 40 | cmt_vector<bool>& auto_imports_states, |
---|
| 41 | cmt_map <Use*, bool>& visited); |
---|
[2] | 42 | static Use* add (const cmt_string& path, |
---|
| 43 | const cmt_string& package, |
---|
| 44 | const cmt_string& version, |
---|
| 45 | const cmt_string& version_alias, |
---|
| 46 | const cmt_string& path_alias, |
---|
[280] | 47 | const cmt_string& native_version, |
---|
[2] | 48 | Use* context_use, |
---|
[563] | 49 | const State specified_auto_imports = Unspecified); |
---|
[2] | 50 | static void move (Use* use1); |
---|
| 51 | static void reorder (Use* use1, Use* use2); |
---|
| 52 | static void select_clients (const cmt_string& package, |
---|
| 53 | const cmt_string& version); |
---|
[550] | 54 | static void show_all (bool skip_discarded = false, ostream& out = cout, PrintMode mode = Csh); // Csh is default for ArgParser::mode |
---|
| 55 | // static void show_all (bool skip_discarded = false, ostream& out = cout ); |
---|
[547] | 56 | // static void show_all (bool skip_discarded = false); |
---|
| 57 | static void show_all (const cmt_string& prefix, bool skip_discarded = false, |
---|
[550] | 58 | ostream& out = cout, PrintMode mode = Csh); // Csh is default for ArgParser::mode |
---|
[547] | 59 | // static void show_all (const cmt_string& prefix, bool skip_discarded = false); |
---|
[2] | 60 | |
---|
| 61 | static Use& current (); |
---|
| 62 | static const Use& const_current (); |
---|
| 63 | |
---|
| 64 | static UseVector& get_instances (); |
---|
| 65 | static UsePtrVector& get_ordered_uses (); |
---|
| 66 | |
---|
| 67 | static void clear_all (); |
---|
| 68 | static void unselect_all (); |
---|
| 69 | static void undiscard_all (); |
---|
| 70 | static void fill_macro_all (cmt_string& buffer, const cmt_string& suffix); |
---|
| 71 | |
---|
| 72 | static Use* create (const cmt_string& path, |
---|
| 73 | const cmt_string& package, |
---|
| 74 | const cmt_string& version, |
---|
| 75 | const cmt_string& version_alias, |
---|
[334] | 76 | const cmt_string& path_alias, |
---|
| 77 | const cmt_string& n_version=""); |
---|
[2] | 78 | |
---|
[295] | 79 | void add_sub_use(Use* use) |
---|
| 80 | { |
---|
| 81 | this->sub_uses.push_back (use); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | // Private class methods |
---|
| 85 | private: |
---|
| 86 | |
---|
[2] | 87 | // Public instance methods |
---|
| 88 | public: |
---|
| 89 | Use (); |
---|
| 90 | Use (const cmt_string& new_package, |
---|
| 91 | const cmt_string& new_version, |
---|
| 92 | const cmt_string& new_path); |
---|
| 93 | ~Use (); |
---|
| 94 | void set (const cmt_string& new_package, |
---|
| 95 | const cmt_string& new_version, |
---|
| 96 | const cmt_string& new_path, |
---|
| 97 | const cmt_string& new_version_alias = "", |
---|
| 98 | const cmt_string& new_path_alias = ""); |
---|
| 99 | void author_action (const CmtSystem::cmt_string_vector& words); |
---|
| 100 | void manager_action (const CmtSystem::cmt_string_vector& words); |
---|
[536] | 101 | bool move_to (const cmt_string& native_version="", bool curdir = false); |
---|
| 102 | // bool move_to (const cmt_string& native_version=""); |
---|
[2] | 103 | void discard (); |
---|
| 104 | void undiscard (); |
---|
| 105 | void apply_global_patterns (); |
---|
| 106 | void set_include_path (const cmt_string& new_path); |
---|
| 107 | void get_full_path (cmt_string& s) const; |
---|
| 108 | cmt_string get_full_path () const; |
---|
| 109 | void reduce_path (cmt_string& s) const; |
---|
| 110 | void get_cmtpath_and_offset (cmt_string& cmtpath, cmt_string& offset) const; |
---|
[81] | 111 | bool get_strategy (const cmt_string& name) const; |
---|
[608] | 112 | inline const cmt_string& get_realpath () const { return m_realpath; } |
---|
[2] | 113 | |
---|
| 114 | void fill_includes_macro (cmt_string& buffer) const; |
---|
| 115 | void fill_macro (cmt_string& buffer, const cmt_string& suffix) const; |
---|
| 116 | void fill_standard_macros (cmt_string& buffer) const; |
---|
| 117 | void build_library_links (const cmt_string& cmtinstallarea, |
---|
| 118 | const cmt_string& tag, |
---|
| 119 | const cmt_string& shlibsuffix, |
---|
| 120 | const cmt_string& symlinkcmd) const; |
---|
[588] | 121 | void remove_library_links (const cmt_string& cmtinstallarea, |
---|
| 122 | const cmt_string& tag, |
---|
| 123 | const cmt_string& shlibsuffix, |
---|
| 124 | const cmt_string& symunlinkcmd) const; |
---|
| 125 | |
---|
[2] | 126 | bool get_all_clients (const cmt_string& to_name); |
---|
| 127 | |
---|
| 128 | bool get_paths (Use* to, UsePtrVector& list); |
---|
| 129 | |
---|
| 130 | bool located () const; |
---|
| 131 | |
---|
| 132 | void change_path (const cmt_string& path); |
---|
[563] | 133 | void set_auto_imports (State context_state, State specified_state, |
---|
| 134 | cmt_map <Use*, bool>& visited); |
---|
| 135 | // void set_auto_imports (State new_state); |
---|
| 136 | //void set_auto_imports_state (cmt_vector<bool>& auto_imports_states, |
---|
| 137 | //cmt_map <Use*, bool>& visited); |
---|
[2] | 138 | void set_native_version (bool state); |
---|
| 139 | bool has_native_version () const; |
---|
| 140 | |
---|
| 141 | Package* get_package () const; |
---|
| 142 | const cmt_string& get_package_name () const; |
---|
| 143 | void set_package_name (const cmt_string& name); |
---|
| 144 | |
---|
| 145 | int get_index () const; |
---|
| 146 | |
---|
| 147 | void show_cycles (); |
---|
| 148 | |
---|
| 149 | void push_scope_section (ScopeType type); |
---|
| 150 | void pop_scope_section (); |
---|
| 151 | void close_scope_sections (); |
---|
| 152 | |
---|
| 153 | ScopeType get_current_scope () const; |
---|
| 154 | |
---|
[295] | 155 | Project* get_project (); |
---|
[535] | 156 | cmt_string get_info () const; |
---|
[566] | 157 | bool is_head_version (const cmt_string& version); |
---|
[582] | 158 | void clear (); |
---|
[588] | 159 | void absolute_library_path (const cmt_string& libname, |
---|
| 160 | const cmt_string& shlibsuffix, |
---|
| 161 | CmtSystem::cmt_string_vector& paths) const; |
---|
[2] | 162 | // Public attributes |
---|
| 163 | public: |
---|
| 164 | |
---|
| 165 | cmt_string specified_version; /* idem */ |
---|
| 166 | cmt_string specified_path; /* idem */ |
---|
| 167 | cmt_string version_alias; |
---|
| 168 | cmt_string path_alias; |
---|
| 169 | cmt_string author; /* idem */ |
---|
| 170 | cmt_string manager; /* idem */ |
---|
| 171 | |
---|
| 172 | cmt_string path; /* expanded path */ |
---|
| 173 | cmt_string version; /* idem */ |
---|
| 174 | cmt_string real_path; |
---|
[280] | 175 | cmt_string native_version; /* idem */ |
---|
[531] | 176 | CmtDirStyle style; /* May be cmt, or mgr, or none_style */ |
---|
| 177 | CmtStructuringStyle structuring_style; /* with or without version directory */ |
---|
[2] | 178 | |
---|
| 179 | cmt_string prefix; /* upper case copy of package */ |
---|
| 180 | bool done; /* true when requirements file has |
---|
| 181 | already been read */ |
---|
| 182 | bool discarded; /* discarded by version strategy */ |
---|
| 183 | bool selected; /* used for recursive access */ |
---|
[328] | 184 | bool m_located; |
---|
[331] | 185 | bool m_hidden; |
---|
[328] | 186 | ScopeType initial_scope; |
---|
[2] | 187 | |
---|
[328] | 188 | UsePtrVector sub_uses; |
---|
| 189 | cmt_vector<ScopeType> sub_use_scopes; |
---|
| 190 | cmt_vector<State> sub_use_auto_imports; |
---|
| 191 | |
---|
| 192 | int m_index; // Position within the ordered list of uses |
---|
| 193 | |
---|
[2] | 194 | State auto_imports; |
---|
| 195 | |
---|
| 196 | Include::IncludeVector includes; |
---|
| 197 | cmt_string include_path; |
---|
| 198 | Script::ScriptVector scripts; |
---|
| 199 | ApplyPattern::ApplyPatternVector apply_patterns; |
---|
| 200 | IgnorePattern::IgnorePatternVector ignore_patterns; |
---|
| 201 | |
---|
| 202 | // Private methods |
---|
| 203 | private: |
---|
[582] | 204 | // void clear (); |
---|
[331] | 205 | int reach_package (const cmt_string& current_path, const cmt_string& n_version=""); |
---|
[2] | 206 | void select (); |
---|
| 207 | void unselect (); |
---|
| 208 | bool is_selected (); |
---|
| 209 | bool is_client (const cmt_string& package, |
---|
| 210 | const cmt_string& version); |
---|
[572] | 211 | void show_sub_uses (cmt_map <Use*, bool>& visited, |
---|
| 212 | const cmt_string& request, State specified_state, |
---|
| 213 | bool skip_discarded = false, ostream& out = cout); |
---|
[547] | 214 | // void show_sub_uses (const cmt_string& request, bool skip_discarded = false); |
---|
[2] | 215 | bool select_alternate (); |
---|
| 216 | Use* get_selected_version (); |
---|
| 217 | Use* set_selected_version (Use* selected_use); |
---|
| 218 | |
---|
| 219 | static bool need_new (const cmt_string& path, |
---|
| 220 | const cmt_string& package, |
---|
| 221 | const cmt_string& version, |
---|
[334] | 222 | const cmt_string& n_version, |
---|
[2] | 223 | Use** old_use, |
---|
[280] | 224 | Use* context_use); |
---|
[2] | 225 | |
---|
| 226 | bool get_all_clients (Use* to, |
---|
| 227 | const cmt_string& result, |
---|
| 228 | cmt_map <cmt_string, Use*>& all_clients, |
---|
| 229 | cmt_map <cmt_string, Use*>& all_clients_ok); |
---|
| 230 | |
---|
| 231 | // Private attributes |
---|
| 232 | private: |
---|
| 233 | |
---|
| 234 | Package* m_package; |
---|
| 235 | //cmt_string m_package_name; /* directly read from requirements */ |
---|
| 236 | |
---|
| 237 | bool m_has_native_version; |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | cmt_vector<ScopeSection> scope_sections; |
---|
| 241 | |
---|
| 242 | CmtSystem::cmt_string_vector alternate_versions; |
---|
| 243 | CmtSystem::cmt_string_vector alternate_paths; |
---|
[566] | 244 | cmt_vector<bool> alternate_is_head_versions; |
---|
[2] | 245 | |
---|
| 246 | CmtSystem::cmt_string_vector requests; |
---|
| 247 | |
---|
[566] | 248 | cmt_regexp m_head_version; |
---|
[608] | 249 | cmt_string m_realpath; /* canonicalized absolute real_path */ |
---|
[2] | 250 | |
---|
| 251 | friend class UseProjectAction; |
---|
| 252 | }; |
---|
| 253 | |
---|
| 254 | class Package |
---|
| 255 | { |
---|
| 256 | public: |
---|
| 257 | |
---|
| 258 | typedef cmt_map<cmt_string, Package> PackageMap; |
---|
| 259 | typedef cmt_vector<Package> PackageVector; |
---|
| 260 | |
---|
| 261 | static Package* find (const cmt_string& name); |
---|
| 262 | static Package* add (const cmt_string& name); |
---|
| 263 | |
---|
| 264 | static PackageVector& packages (); |
---|
| 265 | static PackageMap& package_map (); |
---|
| 266 | |
---|
| 267 | static void clear_all (); |
---|
| 268 | |
---|
[461] | 269 | static bool get_version (cmt_string& version, const cmt_string& path = "."); |
---|
| 270 | static const cmt_string& get_version_file_name (); |
---|
[531] | 271 | static bool get_name (cmt_string& name, const cmt_string& path = "."); |
---|
[461] | 272 | |
---|
[2] | 273 | public: |
---|
| 274 | |
---|
| 275 | Package (); |
---|
| 276 | ~Package (); |
---|
| 277 | |
---|
| 278 | const cmt_string& get_name () const; |
---|
| 279 | void add_use (Use* use); |
---|
| 280 | void remove_use (Use* use); |
---|
| 281 | Use::UsePtrVector& get_uses (); |
---|
| 282 | |
---|
| 283 | bool is_cmt (); |
---|
| 284 | |
---|
| 285 | private: |
---|
| 286 | bool m_is_cmt; |
---|
| 287 | |
---|
| 288 | cmt_string m_name; |
---|
| 289 | Use::UsePtrVector m_uses; |
---|
| 290 | }; |
---|
| 291 | |
---|
[283] | 292 | #endif |
---|