[515] | 1 | |
---|
[2] | 2 | //----------------------------------------------------------- |
---|
| 3 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
| 4 | // arnault@lal.in2p3.fr |
---|
[272] | 5 | // Modified by garonne@lal.in2p3.fr |
---|
[2] | 6 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
| 7 | //----------------------------------------------------------- |
---|
| 8 | |
---|
| 9 | #include <stdio.h> |
---|
| 10 | #include <stdlib.h> |
---|
| 11 | #include <string.h> |
---|
| 12 | #include <ctype.h> |
---|
| 13 | |
---|
| 14 | #include "cmt_project.h" |
---|
| 15 | #include "cmt_database.h" |
---|
| 16 | #include "cmt_system.h" |
---|
| 17 | #include "cmt_awk.h" |
---|
| 18 | #include "cmt_syntax.h" |
---|
| 19 | #include "cmt_tag.h" |
---|
[8] | 20 | #include "cmt_error.h" |
---|
[459] | 21 | #include "cmt_log.h" |
---|
[2] | 22 | |
---|
| 23 | class ProjectReader : public Awk |
---|
| 24 | { |
---|
| 25 | public: |
---|
| 26 | |
---|
| 27 | ProjectReader () |
---|
| 28 | { |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | const cmt_string& get_project_name () const |
---|
| 32 | { |
---|
| 33 | return (m_project); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | void filter (const cmt_string& line) |
---|
| 37 | { |
---|
| 38 | CmtSystem::cmt_string_vector words; |
---|
| 39 | CmtSystem::split (line, " \t", words); |
---|
| 40 | if (words[0] == "project") |
---|
| 41 | { |
---|
| 42 | m_project = words[1]; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | private: |
---|
| 47 | cmt_string m_project; |
---|
| 48 | }; |
---|
| 49 | |
---|
| 50 | class ProjectPatcher : public Awk |
---|
| 51 | { |
---|
| 52 | public: |
---|
| 53 | |
---|
| 54 | ProjectPatcher (const cmt_string& p) : m_project (p) |
---|
| 55 | { |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | void commit () |
---|
| 59 | { |
---|
| 60 | m_output.write (Project::get_project_file_name ()); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | void filter (const cmt_string& line) |
---|
| 64 | { |
---|
| 65 | CmtSystem::cmt_string_vector words; |
---|
| 66 | CmtSystem::split (line, " \t", words); |
---|
| 67 | if (words[0] == "project") |
---|
| 68 | { |
---|
| 69 | m_output += "project "; |
---|
| 70 | m_output += m_project; |
---|
| 71 | } |
---|
| 72 | else |
---|
| 73 | { |
---|
| 74 | m_output += line; |
---|
| 75 | } |
---|
[79] | 76 | |
---|
| 77 | m_output += "\n"; |
---|
[2] | 78 | } |
---|
| 79 | |
---|
| 80 | private: |
---|
| 81 | cmt_string m_output; |
---|
| 82 | const cmt_string& m_project; |
---|
| 83 | }; |
---|
| 84 | |
---|
| 85 | IProjectFactory& ProjectFactory::instance () |
---|
| 86 | { |
---|
| 87 | static ProjectFactory me; |
---|
| 88 | |
---|
| 89 | return (me); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | void ProjectFactory::reset () |
---|
| 93 | { |
---|
| 94 | Project::clear_all (); |
---|
| 95 | } |
---|
| 96 | |
---|
[36] | 97 | static bool get_release_from_path (const CmtSystem::cmt_string_vector& items, |
---|
| 98 | const cmt_string& path, |
---|
| 99 | const cmt_string& name, |
---|
| 100 | cmt_string& real_name, |
---|
| 101 | cmt_string& release) |
---|
[18] | 102 | { |
---|
| 103 | bool result = false; |
---|
| 104 | |
---|
| 105 | release = ""; |
---|
[36] | 106 | real_name = ""; |
---|
[18] | 107 | |
---|
| 108 | cmt_string p = path; |
---|
| 109 | |
---|
[36] | 110 | if ((items.size () == 0) && (name == "")) |
---|
| 111 | { |
---|
| 112 | // There is no CMTPROJECTPATH and no expected project name. |
---|
| 113 | // We have no way to find a project structure |
---|
| 114 | // So we only expect a 2-level structure. |
---|
| 115 | |
---|
| 116 | CmtSystem::basename (p, release); |
---|
| 117 | CmtSystem::dirname (p, p); |
---|
| 118 | CmtSystem::basename (p, real_name); |
---|
| 119 | |
---|
| 120 | return (false); |
---|
| 121 | } |
---|
| 122 | |
---|
[18] | 123 | for (;;) |
---|
| 124 | { |
---|
[36] | 125 | if (p == "") |
---|
| 126 | { |
---|
| 127 | // Protection: we found no matching project name |
---|
| 128 | // and path was outside any CMTPROJECTPATH |
---|
| 129 | |
---|
| 130 | p = path; |
---|
| 131 | |
---|
| 132 | CmtSystem::basename (p, release); |
---|
| 133 | CmtSystem::dirname (p, p); |
---|
| 134 | CmtSystem::basename (p, real_name); |
---|
| 135 | |
---|
| 136 | return (false); |
---|
| 137 | } |
---|
| 138 | |
---|
[18] | 139 | cmt_string n; |
---|
| 140 | |
---|
| 141 | CmtSystem::basename (p, n); |
---|
| 142 | CmtSystem::dirname (p, p); |
---|
| 143 | |
---|
| 144 | if (n == name) |
---|
| 145 | { |
---|
[36] | 146 | real_name = name; |
---|
[18] | 147 | result = true; |
---|
| 148 | break; |
---|
| 149 | } |
---|
| 150 | |
---|
[36] | 151 | CmtSystem::basename (p, real_name); |
---|
| 152 | |
---|
| 153 | for (int i = 0; i < items.size (); i++) |
---|
| 154 | { |
---|
| 155 | const cmt_string& item = items[i]; |
---|
| 156 | if (p == item) |
---|
| 157 | { |
---|
| 158 | // We have reached an item of CMTPROJECTPATH, no need to continue |
---|
| 159 | return (false); |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
[18] | 163 | if (release == "") |
---|
| 164 | { |
---|
| 165 | release = n; |
---|
| 166 | } |
---|
| 167 | else |
---|
| 168 | { |
---|
| 169 | cmt_string r; |
---|
| 170 | |
---|
| 171 | r = n; |
---|
| 172 | r += CmtSystem::file_separator (); |
---|
| 173 | r += release; |
---|
| 174 | release = r; |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | //cerr << "$CMT> GRFP> path=" << path << " name=" << name << " rel=" << release << endl; |
---|
| 179 | |
---|
| 180 | return (result); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | |
---|
[3] | 184 | /* |
---|
| 185 | Every new CMTPATH entry becomes associated with a dedicated PROJECT |
---|
| 186 | This function will understand this new entry to CMTPATH and understand it: |
---|
| 187 | - it can correspond to an existing project (ie already declared) |
---|
| 188 | - it's a new project |
---|
[400] | 189 | - then it tries to read and parse its project file |
---|
| 190 | */ |
---|
[18] | 191 | Project* ProjectFactory::create_project (const cmt_string& specified_name, |
---|
| 192 | const cmt_string& path, |
---|
[9] | 193 | const cmt_string& source, |
---|
| 194 | Project* parent) |
---|
[2] | 195 | { |
---|
| 196 | cmt_string compressed_path = path; |
---|
| 197 | CmtSystem::compress_path (compressed_path); |
---|
[18] | 198 | bool specify_name = (specified_name != ""); |
---|
[2] | 199 | |
---|
[36] | 200 | if (Cmt::get_debug ()) |
---|
| 201 | { |
---|
| 202 | cout << "Creating project " << path << " with parent " << ((parent==0)? "0" : parent->get_name ()) << endl; |
---|
| 203 | Project::show_all (); |
---|
| 204 | } |
---|
[16] | 205 | |
---|
[36] | 206 | cmt_string sep; |
---|
| 207 | sep = CmtSystem::path_separator (); |
---|
| 208 | |
---|
[138] | 209 | cmt_string cmtprojectpath = Symbol::get_env_value ("CMTPROJECTPATH"); |
---|
[36] | 210 | CmtSystem::cmt_string_vector items; |
---|
| 211 | CmtSystem::split (cmtprojectpath, sep, items); |
---|
| 212 | |
---|
[39] | 213 | cmt_string here = CmtSystem::pwd (); |
---|
| 214 | if (!CmtSystem::cd (compressed_path)) return (0); |
---|
| 215 | cmt_string pwd = CmtSystem::pwd (); |
---|
| 216 | |
---|
[2] | 217 | static Project::ProjectVector& Projects = Project::projects (); |
---|
[79] | 218 | |
---|
| 219 | int i; |
---|
[2] | 220 | |
---|
[79] | 221 | for (i = 0; i < Projects.size (); i++) |
---|
[2] | 222 | { |
---|
| 223 | Project& p = Projects[i]; |
---|
| 224 | |
---|
[9] | 225 | if ((p.get_cmtpath () == compressed_path) || |
---|
[39] | 226 | (p.get_cmtpath_pwd () == pwd) || |
---|
[18] | 227 | (specify_name && (p.get_name () == specified_name))) |
---|
[9] | 228 | { |
---|
[18] | 229 | cmt_string r; |
---|
[36] | 230 | cmt_string n; |
---|
[18] | 231 | |
---|
[36] | 232 | get_release_from_path (items, compressed_path, p.get_name (), n, r); |
---|
[18] | 233 | |
---|
| 234 | if (r != p.get_release ()) |
---|
| 235 | { |
---|
[459] | 236 | CmtMessage::error ("Project " + p.get_name () |
---|
| 237 | + " requested with conflicting releases " |
---|
| 238 | + p.get_release () + " and " + r); |
---|
| 239 | /* |
---|
[411] | 240 | if (!Cmt::get_quiet ()) |
---|
| 241 | { |
---|
| 242 | cerr << "#CMT> Project " << p.get_name () |
---|
| 243 | << " requested with conflicting releases " << p.get_release () << " and " << r << endl; |
---|
| 244 | } |
---|
[459] | 245 | */ |
---|
[18] | 246 | CmtError::set (CmtError::project_release_conflict, p.get_name ()); |
---|
| 247 | } |
---|
| 248 | |
---|
[535] | 249 | bool updated (false); |
---|
[9] | 250 | if (parent != 0) |
---|
| 251 | { |
---|
[535] | 252 | if (!p.has_parent (parent) || !parent->has_child (&p)) |
---|
| 253 | { |
---|
[9] | 254 | p.add_parent (parent); |
---|
| 255 | parent->add_child (&p); |
---|
[16] | 256 | |
---|
| 257 | // Since p is a new parent, we should propagate the settings UP. |
---|
| 258 | |
---|
| 259 | parent->update_strategies_from_children (); |
---|
[535] | 260 | updated = true; |
---|
| 261 | } |
---|
| 262 | |
---|
[9] | 263 | } |
---|
[16] | 264 | |
---|
[39] | 265 | CmtSystem::cd (here); |
---|
[535] | 266 | if (updated) Project::order_all (); |
---|
[9] | 267 | return (&p); |
---|
| 268 | } |
---|
[2] | 269 | } |
---|
[18] | 270 | |
---|
| 271 | |
---|
[2] | 272 | Project* project = 0; |
---|
| 273 | Project* cmt = 0; |
---|
| 274 | |
---|
| 275 | bool is_current = false; |
---|
| 276 | |
---|
[24] | 277 | cmt_string name = specified_name; |
---|
[36] | 278 | cmt_string project_name; |
---|
[8] | 279 | cmt_string release; |
---|
| 280 | |
---|
[3] | 281 | // |
---|
| 282 | // Figure out if this is the current project |
---|
| 283 | // |
---|
[435] | 284 | // if (here.find (pwd) == 0) is_current = true; |
---|
[2] | 285 | |
---|
[435] | 286 | // In case there are symlinks |
---|
[535] | 287 | |
---|
| 288 | // cmt_string here_real, pwd_real; |
---|
[437] | 289 | //cerr << "realpath_: create_project" << endl; |
---|
[535] | 290 | /* |
---|
[435] | 291 | if (CmtSystem::realpath_ (here, here_real) && CmtSystem::realpath_ (pwd, pwd_real)) |
---|
| 292 | { |
---|
| 293 | if (here_real.find (pwd_real) == 0) is_current = true; |
---|
| 294 | } |
---|
[535] | 295 | */ |
---|
| 296 | cmt_string pwd_real; |
---|
[537] | 297 | if (!CmtSystem::realpath_ (pwd, pwd_real)) |
---|
[535] | 298 | { |
---|
[537] | 299 | CmtError::set (CmtError::file_access_error, "Cannot compute real path `" + |
---|
| 300 | pwd + "'"); |
---|
| 301 | CmtError::print (); |
---|
| 302 | return 0; |
---|
| 303 | // if (Cmt::get_current_dir_real ().find (pwd_real) == 0) is_current = true; |
---|
[535] | 304 | } |
---|
[435] | 305 | |
---|
[2] | 306 | cmt_string text; |
---|
| 307 | |
---|
[3] | 308 | /* |
---|
| 309 | Now Figure out the project name from the project file |
---|
[400] | 310 | or does not specify the project name |
---|
| 311 | */ |
---|
[36] | 312 | bool has_project_file = false; |
---|
| 313 | |
---|
[2] | 314 | if (CmtSystem::cd ("cmt") && CmtSystem::test_file (Project::get_project_file_name ())) |
---|
| 315 | { |
---|
[36] | 316 | has_project_file = true; |
---|
[2] | 317 | text.read (Project::get_project_file_name ()); |
---|
| 318 | |
---|
| 319 | ProjectReader reader; |
---|
| 320 | |
---|
| 321 | reader.run (text); |
---|
| 322 | |
---|
[36] | 323 | project_name = reader.get_project_name (); |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | enum |
---|
| 327 | { |
---|
| 328 | without_project_file = 0x01, |
---|
| 329 | with_project_file = 0x02, |
---|
| 330 | without_project_name = 0x04, |
---|
| 331 | with_project_name = 0x08, |
---|
| 332 | without_specified_name = 0x10, |
---|
| 333 | with_specified_name = 0x20, |
---|
| 334 | names_mismatch = 0x40, |
---|
| 335 | names_match = 0x80 |
---|
| 336 | }; |
---|
| 337 | |
---|
| 338 | int status = ((has_project_file) ? with_project_file : without_project_file) | |
---|
| 339 | ((has_project_file && (project_name != "")) ? with_project_name : without_project_name) | |
---|
| 340 | ((specify_name) ? with_specified_name : without_specified_name) | |
---|
| 341 | ((specify_name && has_project_file && (project_name == specified_name)) ? names_match : names_mismatch); |
---|
| 342 | |
---|
| 343 | if (source == "default path") |
---|
| 344 | { |
---|
| 345 | name = "CMT"; |
---|
| 346 | } |
---|
| 347 | else |
---|
| 348 | { |
---|
| 349 | cmt_string n; |
---|
| 350 | |
---|
| 351 | switch (status) |
---|
[2] | 352 | { |
---|
[36] | 353 | case with_project_file | without_project_name | without_specified_name | names_mismatch: |
---|
| 354 | |
---|
| 355 | // The project is neither specified from the caller nor from the project file |
---|
| 356 | |
---|
| 357 | /* |
---|
| 358 | if (!Cmt::get_quiet ()) |
---|
[18] | 359 | { |
---|
[36] | 360 | cerr << "#CMT> Warning: project name unspecified in project file." << endl; |
---|
| 361 | } |
---|
| 362 | */ |
---|
| 363 | |
---|
| 364 | get_release_from_path (items, compressed_path, "", name, release); |
---|
[18] | 365 | |
---|
[36] | 366 | break; |
---|
| 367 | |
---|
| 368 | case with_project_file | without_project_name | with_specified_name | names_mismatch: |
---|
| 369 | |
---|
| 370 | // The name is only specified from the caller |
---|
| 371 | // find this specified name in the path |
---|
| 372 | |
---|
| 373 | if (get_release_from_path (items, compressed_path, specified_name, name, release)) |
---|
| 374 | { |
---|
| 375 | // The specified name has been found from the path. |
---|
| 376 | // We believe in the release spec. |
---|
| 377 | } |
---|
| 378 | else |
---|
| 379 | { |
---|
| 380 | // The specified name is not in the path. |
---|
[38] | 381 | /* |
---|
[400] | 382 | if (!Cmt::get_quiet ()) |
---|
[23] | 383 | { |
---|
[400] | 384 | cerr << "#CMT> Warning: specified project name " |
---|
| 385 | << specified_name |
---|
| 386 | << " from the caller does not match path." << endl; |
---|
[23] | 387 | } |
---|
[38] | 388 | */ |
---|
| 389 | name = specified_name; |
---|
[18] | 390 | } |
---|
[36] | 391 | |
---|
| 392 | break; |
---|
| 393 | |
---|
| 394 | case with_project_file | with_project_name | with_specified_name | names_match: |
---|
| 395 | |
---|
| 396 | // We have a double specification: from the caller and from the project file. |
---|
| 397 | // And both specifications are consistent. |
---|
| 398 | |
---|
| 399 | if (get_release_from_path (items, compressed_path, specified_name, name, release)) |
---|
| 400 | { |
---|
| 401 | // The specified name has been found from the path. |
---|
| 402 | // We believe in the release spec. |
---|
| 403 | } |
---|
[18] | 404 | else |
---|
| 405 | { |
---|
[36] | 406 | // The specified name is not in the path. |
---|
[38] | 407 | /* |
---|
[400] | 408 | if (!Cmt::get_quiet ()) |
---|
[18] | 409 | { |
---|
[400] | 410 | cerr << "#CMT> Warning: specified project name " |
---|
| 411 | << specified_name |
---|
| 412 | << " from project file and from caller does not match path." << endl; |
---|
[18] | 413 | } |
---|
[38] | 414 | */ |
---|
| 415 | name = specified_name; |
---|
[18] | 416 | } |
---|
[36] | 417 | |
---|
| 418 | break; |
---|
| 419 | |
---|
| 420 | case with_project_file | with_project_name | with_specified_name | names_mismatch: |
---|
| 421 | |
---|
| 422 | // We have a double specification: from the caller and from the project file. |
---|
| 423 | // Specifications are inconsistent!! |
---|
| 424 | |
---|
[151] | 425 | /* |
---|
[400] | 426 | if (!Cmt::get_quiet ()) |
---|
[18] | 427 | { |
---|
[400] | 428 | cerr << "#CMT> Warning: specified project name " |
---|
| 429 | << specified_name |
---|
| 430 | << " inconsistent with name " |
---|
| 431 | << project_name |
---|
| 432 | << " from project file." << endl; |
---|
[36] | 433 | } |
---|
[151] | 434 | */ |
---|
[36] | 435 | |
---|
| 436 | if (get_release_from_path (items, compressed_path, specified_name, n, release)) |
---|
| 437 | { |
---|
| 438 | // name from caller wins. |
---|
| 439 | } |
---|
| 440 | else if (get_release_from_path (items, compressed_path, project_name, name, release)) |
---|
| 441 | { |
---|
| 442 | // name from project file wins. |
---|
| 443 | } |
---|
| 444 | else |
---|
| 445 | { |
---|
| 446 | // The specified name is not in the path. |
---|
| 447 | |
---|
[459] | 448 | CmtMessage::warning ("none of specified project names " |
---|
| 449 | + specified_name + " from graph and " |
---|
| 450 | + project_name + " from project file match path."); |
---|
| 451 | /* |
---|
[36] | 452 | if (!Cmt::get_quiet ()) |
---|
[18] | 453 | { |
---|
[36] | 454 | cerr << "#CMT> Warning: none of specified project names " |
---|
| 455 | << specified_name |
---|
| 456 | << " from graph and " |
---|
| 457 | << project_name |
---|
| 458 | << " from project file match path." << endl; |
---|
[18] | 459 | } |
---|
[459] | 460 | */ |
---|
[38] | 461 | |
---|
| 462 | name = specified_name; |
---|
[18] | 463 | } |
---|
[36] | 464 | |
---|
| 465 | break; |
---|
| 466 | |
---|
| 467 | case with_project_file | with_project_name | without_specified_name | names_mismatch: |
---|
| 468 | |
---|
| 469 | // Project name is specified in the project file but not from the caller. |
---|
| 470 | |
---|
| 471 | if (get_release_from_path (items, compressed_path, project_name, name, release)) |
---|
[18] | 472 | { |
---|
[36] | 473 | // The specified name has been found from the path. |
---|
| 474 | // We believe in the release spec. |
---|
[38] | 475 | |
---|
[36] | 476 | } |
---|
| 477 | else |
---|
| 478 | { |
---|
| 479 | // The specified name is not in the path. |
---|
[18] | 480 | |
---|
[23] | 481 | /* |
---|
[400] | 482 | if (!Cmt::get_quiet ()) |
---|
[23] | 483 | { |
---|
[400] | 484 | cerr << "#CMT> Warning: specified project name " |
---|
| 485 | << project_name |
---|
| 486 | << " from project file does not match path." << endl; |
---|
[23] | 487 | } |
---|
| 488 | */ |
---|
[38] | 489 | |
---|
| 490 | name = project_name; |
---|
[18] | 491 | } |
---|
[36] | 492 | |
---|
| 493 | break; |
---|
| 494 | |
---|
| 495 | case without_project_file | without_project_name | without_specified_name | names_mismatch: |
---|
| 496 | |
---|
| 497 | // The project is not specified from the caller and there is no project file |
---|
| 498 | // This corresponds to the backward compatibility |
---|
| 499 | // For the moment, assume /name/release/ structure where release is one level only |
---|
| 500 | |
---|
| 501 | /* |
---|
| 502 | if (!Cmt::get_quiet ()) |
---|
| 503 | { |
---|
| 504 | cerr << "#CMT> Warning: project name is not specified " |
---|
| 505 | << " (no project file)." << endl; |
---|
| 506 | } |
---|
| 507 | */ |
---|
| 508 | |
---|
| 509 | CmtSystem::basename (compressed_path, release); |
---|
| 510 | CmtSystem::dirname (compressed_path, name); |
---|
| 511 | CmtSystem::basename (name, name); |
---|
[97] | 512 | |
---|
| 513 | if (name == "") |
---|
| 514 | { |
---|
| 515 | name = release; |
---|
| 516 | release = ""; |
---|
| 517 | } |
---|
[36] | 518 | |
---|
| 519 | break; |
---|
| 520 | |
---|
| 521 | case without_project_file | without_project_name | with_specified_name | names_mismatch: |
---|
| 522 | |
---|
| 523 | // The name is only specified from the caller |
---|
| 524 | // find this specified name in the path |
---|
| 525 | |
---|
| 526 | if (get_release_from_path (items, compressed_path, specified_name, name, release)) |
---|
| 527 | { |
---|
| 528 | // The specified name has been found from the path. |
---|
| 529 | // We believe in the release spec. |
---|
| 530 | } |
---|
[18] | 531 | else |
---|
| 532 | { |
---|
[36] | 533 | // The specified name is not in the path. |
---|
[38] | 534 | /* |
---|
[400] | 535 | if (!Cmt::get_quiet ()) |
---|
[18] | 536 | { |
---|
[400] | 537 | cerr << "#CMT> Warning: specified project name " |
---|
| 538 | << specified_name |
---|
| 539 | << " from project graph does not match path." << endl; |
---|
[18] | 540 | } |
---|
[38] | 541 | */ |
---|
| 542 | name = specified_name; |
---|
[18] | 543 | } |
---|
[36] | 544 | |
---|
| 545 | break; |
---|
[2] | 546 | } |
---|
| 547 | } |
---|
| 548 | |
---|
[97] | 549 | if (name == "") |
---|
| 550 | { |
---|
| 551 | name = "Project"; |
---|
| 552 | } |
---|
| 553 | |
---|
[8] | 554 | project = Project::add (name, release); |
---|
[36] | 555 | |
---|
[9] | 556 | if (parent != 0) |
---|
| 557 | { |
---|
| 558 | project->add_parent (parent); |
---|
| 559 | parent->add_child (project); |
---|
[16] | 560 | |
---|
[79] | 561 | // Since project is a new child, we should propagate the settings UP. |
---|
[16] | 562 | |
---|
| 563 | parent->update_strategies_from_children (); |
---|
[9] | 564 | } |
---|
[535] | 565 | /* |
---|
[515] | 566 | else if ((name != "CMTUSERCONTEXT") && (name != "CMTHOME")) |
---|
| 567 | // else |
---|
[79] | 568 | { |
---|
| 569 | // this project has no parent thus it should become the top project. |
---|
| 570 | // Let's look for all projects without parent. |
---|
| 571 | // they will become children of this project. |
---|
[9] | 572 | |
---|
[79] | 573 | for (i = 0; i < Projects.size (); i++) |
---|
| 574 | { |
---|
| 575 | Project* p = &(Projects[i]); |
---|
[515] | 576 | const cmt_string& n = p->get_name (); |
---|
| 577 | if (n == name) continue; |
---|
| 578 | // if (p->get_name () == name) continue; |
---|
| 579 | if ((n == "CMTUSERCONTEXT") || (n == "CMTHOME")) continue; |
---|
[79] | 580 | if (!p->has_parents ()) |
---|
| 581 | { |
---|
| 582 | project->add_child (p); |
---|
| 583 | p->add_parent (project); |
---|
| 584 | } |
---|
| 585 | } |
---|
| 586 | |
---|
| 587 | // Since project is a new parent, we should upgrade its settings |
---|
| 588 | |
---|
| 589 | project->update_strategies_from_children (); |
---|
| 590 | } |
---|
[535] | 591 | */ |
---|
[2] | 592 | if (source == "default path") |
---|
| 593 | { |
---|
| 594 | cmt = project; |
---|
| 595 | is_current = false; |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | project->set_cmtpath (compressed_path); |
---|
[437] | 599 | project->set_cmtpath_real (pwd_real); |
---|
[2] | 600 | project->set_cmtpath_pwd (pwd); |
---|
| 601 | project->set_cmtpath_source (source); |
---|
| 602 | |
---|
[537] | 603 | // project->set_is_current (is_current); |
---|
| 604 | /* |
---|
[2] | 605 | if (is_current) |
---|
| 606 | { |
---|
[535] | 607 | // cerr << "current: " << project->get_name () << endl; |
---|
[3] | 608 | // |
---|
| 609 | // The current project defines a tag with its name |
---|
| 610 | // |
---|
| 611 | |
---|
[2] | 612 | Tag* tag; |
---|
| 613 | |
---|
| 614 | tag = Tag::add (project->get_name (), PriorityConfig, "PROJECT", 0); |
---|
| 615 | tag->mark (); |
---|
| 616 | } |
---|
[537] | 617 | */ |
---|
[2] | 618 | |
---|
[535] | 619 | // Project::order_all (); |
---|
[295] | 620 | |
---|
[2] | 621 | if (text != "") |
---|
| 622 | { |
---|
[3] | 623 | // Last step is to parse the project file |
---|
| 624 | |
---|
[100] | 625 | if (Cmt::get_debug ()) |
---|
| 626 | { |
---|
| 627 | cout << "About to parse project file [" << text << "]" << endl; |
---|
| 628 | } |
---|
| 629 | |
---|
[295] | 630 | // First create the Project.m_use for the policy |
---|
[400] | 631 | |
---|
[295] | 632 | Use* project_use = Use::create (project->get_cmtpath(), |
---|
[400] | 633 | "package_policy_for_project_" + project->get_name(), |
---|
[328] | 634 | project->get_release (), "", ""); |
---|
[400] | 635 | |
---|
| 636 | project_use->done = true; |
---|
| 637 | project_use->discarded = false; |
---|
[331] | 638 | project_use->m_hidden = true; |
---|
[328] | 639 | project_use->selected = true; |
---|
| 640 | project_use->m_located = true; |
---|
[334] | 641 | project_use->set_auto_imports(Off); |
---|
[328] | 642 | project_use->initial_scope = ScopePublic; |
---|
[295] | 643 | project->set_use(project_use); |
---|
[328] | 644 | |
---|
| 645 | |
---|
[400] | 646 | // add at the uses level ????? |
---|
| 647 | /*static Use::UsePtrVector& uses = Use::get_ordered_uses (); |
---|
| 648 | bool found = false; |
---|
| 649 | int size = uses.size (); |
---|
| 650 | cerr << "\n size:"<<size<< ":" << endl; |
---|
| 651 | for (int n = 0; n < size; n++) |
---|
| 652 | { |
---|
| 653 | Use* tuse = uses[n]; |
---|
| 654 | cerr << "\tpackage file [" << tuse->get_package_name() << "]" <<project_use->get_package_name()<< endl; |
---|
| 655 | if (tuse->get_package_name()==project_use->get_package_name()) |
---|
| 656 | found=true; |
---|
[295] | 657 | |
---|
[400] | 658 | } |
---|
[328] | 659 | |
---|
[400] | 660 | if (not found) |
---|
| 661 | { |
---|
[328] | 662 | uses.push_back (project_use); |
---|
| 663 | project_use->m_index = uses.size () - 1; |
---|
[400] | 664 | } |
---|
[328] | 665 | */ |
---|
| 666 | |
---|
[2] | 667 | SyntaxParser::parse_project_file_text (text, |
---|
| 668 | Project::get_project_file_name (), |
---|
| 669 | project); |
---|
| 670 | } |
---|
| 671 | |
---|
[295] | 672 | |
---|
| 673 | |
---|
[2] | 674 | CmtSystem::cd (here); |
---|
[535] | 675 | Project::order_all (); |
---|
[9] | 676 | |
---|
| 677 | return (project); |
---|
[2] | 678 | } |
---|
| 679 | |
---|
| 680 | /*----------------------------------------------------------*/ |
---|
| 681 | /* */ |
---|
| 682 | /* Operations on Projects */ |
---|
| 683 | /* */ |
---|
| 684 | /*----------------------------------------------------------*/ |
---|
| 685 | |
---|
| 686 | //---------------------------------------------------------- |
---|
[79] | 687 | bool Project::create (const cmt_string& name, |
---|
[22] | 688 | const cmt_string& release, |
---|
| 689 | const cmt_string& path) |
---|
[2] | 690 | { |
---|
[400] | 691 | cmt_string pwd = CmtSystem::pwd (); |
---|
[22] | 692 | |
---|
[459] | 693 | if (CmtMessage::active (Error)) |
---|
| 694 | { |
---|
[400] | 695 | cerr << "------------------------------------------" << endl; |
---|
| 696 | cerr << "Configuring environment for project " << name << " " << release << " (from " << pwd << ") "; |
---|
| 697 | |
---|
[22] | 698 | if (path != "") |
---|
| 699 | { |
---|
| 700 | cout << " in " << path; |
---|
| 701 | } |
---|
| 702 | |
---|
[400] | 703 | cerr << endl; |
---|
| 704 | cerr << "CMT version " << Cmt::get_cmt_version () << "." << endl; |
---|
| 705 | cerr << "------------------------------------------" << endl; |
---|
[459] | 706 | } |
---|
[2] | 707 | |
---|
[22] | 708 | if (path != "") |
---|
| 709 | { |
---|
| 710 | if (!CmtSystem::mkdir (path)) |
---|
| 711 | { |
---|
[459] | 712 | CmtMessage::error ("Cannot create the " + path + " directory"); |
---|
| 713 | // cerr << "Cannot create the " << path << " directory" << endl; |
---|
[79] | 714 | return (false); |
---|
[22] | 715 | } |
---|
| 716 | |
---|
| 717 | if (!CmtSystem::cd (path)) |
---|
| 718 | { |
---|
[459] | 719 | CmtMessage::error ("Cannot access the " + path + " directory"); |
---|
| 720 | // cerr << "Cannot access the " << path << " directory" << endl; |
---|
[79] | 721 | return (false); |
---|
[22] | 722 | } |
---|
| 723 | } |
---|
| 724 | |
---|
| 725 | if (!CmtSystem::mkdir (name)) |
---|
| 726 | { |
---|
[459] | 727 | CmtMessage::error ("Cannot create the " + name + " directory"); |
---|
| 728 | // cerr << "Cannot create the " << name << " directory" << endl; |
---|
[79] | 729 | return (false); |
---|
[22] | 730 | } |
---|
| 731 | |
---|
| 732 | if (!CmtSystem::cd (name)) |
---|
| 733 | { |
---|
[459] | 734 | CmtMessage::error ("Cannot access the " + name + " directory"); |
---|
| 735 | // cerr << "Cannot access the " << name << " directory" << endl; |
---|
[79] | 736 | return (false); |
---|
[22] | 737 | } |
---|
| 738 | |
---|
| 739 | if (release != "") |
---|
| 740 | { |
---|
| 741 | if (!CmtSystem::mkdir (release)) |
---|
| 742 | { |
---|
[459] | 743 | CmtMessage::error ("Cannot create the " + release + " directory"); |
---|
| 744 | // cerr << "Cannot create the " << release << " directory" << endl; |
---|
[79] | 745 | return (false); |
---|
[22] | 746 | } |
---|
| 747 | |
---|
| 748 | if (!CmtSystem::cd (release)) |
---|
| 749 | { |
---|
[459] | 750 | CmtMessage::error ("Cannot access the " + release + " directory"); |
---|
| 751 | // cerr << "Cannot access the " << release << " directory" << endl; |
---|
[79] | 752 | return (false); |
---|
[22] | 753 | } |
---|
| 754 | } |
---|
| 755 | |
---|
[2] | 756 | if (!CmtSystem::test_directory ("cmt")) |
---|
| 757 | { |
---|
| 758 | if (!CmtSystem::mkdir ("cmt")) |
---|
| 759 | { |
---|
[459] | 760 | CmtMessage::error ("Cannot create the cmt directory"); |
---|
| 761 | // cerr << "Cannot create the cmt directory" << endl; |
---|
[79] | 762 | return (false); |
---|
[2] | 763 | } |
---|
| 764 | else |
---|
| 765 | { |
---|
[459] | 766 | if (CmtMessage::active (Info)) |
---|
| 767 | cerr << "Installing the cmt directory" << endl; |
---|
[2] | 768 | } |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | CmtSystem::cd ("cmt"); |
---|
| 772 | |
---|
| 773 | if (!CmtSystem::test_file (get_project_file_name ())) |
---|
| 774 | { |
---|
[459] | 775 | if (CmtMessage::active (Info)) |
---|
| 776 | cerr << "Creating a new project file" << endl; |
---|
[2] | 777 | |
---|
| 778 | ofstream f (get_project_file_name ()); |
---|
| 779 | if (f) |
---|
| 780 | { |
---|
| 781 | f << "project " << name << endl; |
---|
| 782 | f << endl; |
---|
| 783 | f.close (); |
---|
| 784 | } |
---|
[79] | 785 | else |
---|
| 786 | { |
---|
[459] | 787 | CmtMessage::error ("Cannot create the project file"); |
---|
| 788 | // cerr << "Cannot create the project file" << endl; |
---|
[79] | 789 | return (false); |
---|
| 790 | } |
---|
[2] | 791 | } |
---|
| 792 | else |
---|
| 793 | { |
---|
| 794 | cmt_string text; |
---|
| 795 | text.read (get_project_file_name ()); |
---|
| 796 | |
---|
| 797 | ProjectPatcher p (name); |
---|
| 798 | |
---|
| 799 | p.run (text); |
---|
| 800 | p.commit (); |
---|
| 801 | |
---|
[459] | 802 | if (CmtMessage::active (Info)) |
---|
| 803 | cerr << "project file already there" << endl; |
---|
[2] | 804 | } |
---|
[79] | 805 | |
---|
| 806 | return (true); |
---|
[2] | 807 | } |
---|
| 808 | |
---|
| 809 | //---------------------------------------------------------- |
---|
| 810 | Project* Project::find_by_name (const cmt_string& name) |
---|
| 811 | { |
---|
| 812 | static ProjectVector& Projects = projects (); |
---|
| 813 | |
---|
| 814 | for (int i = 0; i < Projects.size (); i++) |
---|
| 815 | { |
---|
| 816 | Project& p = Projects[i]; |
---|
| 817 | if (p.m_name == name) return (&p); |
---|
[273] | 818 | |
---|
[2] | 819 | } |
---|
| 820 | |
---|
| 821 | return (0); |
---|
| 822 | } |
---|
| 823 | |
---|
| 824 | //---------------------------------------------------------- |
---|
| 825 | Project* Project::find_by_cmtpath (const cmt_string& cmtpath) |
---|
| 826 | { |
---|
| 827 | cmt_string compressed_path = cmtpath; |
---|
| 828 | CmtSystem::compress_path (compressed_path); |
---|
| 829 | |
---|
| 830 | static ProjectVector& Projects = projects (); |
---|
| 831 | |
---|
| 832 | for (int i = 0; i < Projects.size (); i++) |
---|
| 833 | { |
---|
| 834 | Project& p = Projects[i]; |
---|
| 835 | |
---|
| 836 | if (p.m_cmtpath == compressed_path) return (&p); |
---|
[437] | 837 | if (p.m_cmtpath_real == compressed_path) return (&p); |
---|
[2] | 838 | if (p.m_cmtpath_pwd == compressed_path) return (&p); |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | return (0); |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | //---------------------------------------------------------- |
---|
| 845 | Project* Project::get_current () |
---|
| 846 | { |
---|
[535] | 847 | /* |
---|
[2] | 848 | cmt_string here = CmtSystem::pwd (); |
---|
| 849 | |
---|
[435] | 850 | // In case there are symlinks |
---|
| 851 | cmt_string here_real; |
---|
| 852 | CmtSystem::realpath_ (here, here_real); |
---|
[535] | 853 | */ |
---|
[2] | 854 | static ProjectVector& Projects = projects (); |
---|
| 855 | |
---|
| 856 | Project* result = 0; |
---|
| 857 | |
---|
| 858 | for (int i = (Projects.size () - 1); i >= 0; i--) |
---|
| 859 | { |
---|
| 860 | Project& p = Projects[i]; |
---|
| 861 | |
---|
[437] | 862 | // if (here.find (p.m_cmtpath_pwd) == 0) |
---|
| 863 | // { |
---|
| 864 | // result = &p; |
---|
| 865 | // } |
---|
[2] | 866 | |
---|
[437] | 867 | // if (here.find (p.m_cmtpath) == 0) |
---|
[535] | 868 | if (p.is_current ()) |
---|
| 869 | // if (here_real.find (p.m_cmtpath_real) == 0) |
---|
[2] | 870 | { |
---|
| 871 | result = &p; |
---|
| 872 | } |
---|
| 873 | } |
---|
| 874 | |
---|
| 875 | return (result); |
---|
| 876 | } |
---|
| 877 | |
---|
| 878 | //---------------------------------------------------------- |
---|
[8] | 879 | Project* Project::add (const cmt_string& name, |
---|
| 880 | const cmt_string& release) |
---|
[2] | 881 | { |
---|
| 882 | static ProjectVector& Projects = projects (); |
---|
| 883 | |
---|
| 884 | { |
---|
| 885 | Project* project; |
---|
| 886 | |
---|
| 887 | project = find_by_name (name); |
---|
| 888 | if (project != 0) |
---|
| 889 | { |
---|
[459] | 890 | // if (!Cmt::get_quiet ()) |
---|
| 891 | // { |
---|
[8] | 892 | if (release != project->get_release ()) |
---|
| 893 | { |
---|
[501] | 894 | if (CmtMessage::active (Verbose)) |
---|
| 895 | CmtMessage::error ("Project " + name |
---|
| 896 | + " requested with conflicting releases " |
---|
| 897 | + project->get_release () + " and " + release); |
---|
[459] | 898 | // cerr << "#CMT> Project " << name << " requested with conflicting releases " << project->get_release () << " and " << release << endl; |
---|
[8] | 899 | CmtError::set (CmtError::project_release_conflict, name); |
---|
| 900 | } |
---|
[459] | 901 | // } |
---|
[8] | 902 | |
---|
| 903 | // Project objects are recreated here to follow the hierarchy |
---|
| 904 | // This duplication is needed for properly applying the strategies |
---|
[2] | 905 | Project& p = Projects.add (); |
---|
| 906 | |
---|
| 907 | p.set_name (name); |
---|
[8] | 908 | p.set_release (release); |
---|
[10] | 909 | p.configure (); |
---|
[2] | 910 | |
---|
| 911 | return (&p); |
---|
[8] | 912 | |
---|
| 913 | //return (project); |
---|
[2] | 914 | } |
---|
| 915 | } |
---|
| 916 | |
---|
| 917 | Project& project = Projects.add (); |
---|
[16] | 918 | project.clear (); |
---|
[2] | 919 | project.set_name (name); |
---|
[8] | 920 | project.set_release (release); |
---|
[10] | 921 | project.configure (); |
---|
[2] | 922 | |
---|
| 923 | return (&project); |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | //---------------------------------------------------------- |
---|
| 927 | Project::ProjectVector& Project::projects () |
---|
| 928 | { |
---|
| 929 | static Database& db = Database::instance (); |
---|
| 930 | static ProjectVector& Projects = db.projects (); |
---|
| 931 | |
---|
| 932 | return (Projects); |
---|
| 933 | } |
---|
| 934 | |
---|
[470] | 935 | //---------------------------------------------------------- |
---|
[535] | 936 | Project::ProjectPtrVector& Project::ordered_projects () |
---|
[470] | 937 | { |
---|
[535] | 938 | static Database& db = Database::instance (); |
---|
| 939 | static ProjectPtrVector& Projects = db.ordered_projects (); |
---|
[470] | 940 | |
---|
[535] | 941 | return (Projects); |
---|
| 942 | } |
---|
| 943 | |
---|
| 944 | //---------------------------------------------------------- |
---|
| 945 | void Project::order_all () |
---|
| 946 | //Project::ProjectPtrVector Project::ordered_projects () |
---|
| 947 | { |
---|
| 948 | ProjectPtrVector OrderedProjects; |
---|
| 949 | // static ProjectPtrVector OrderedProjects; |
---|
| 950 | static Project::ProjectPtrVector& orderedProjects = Project::ordered_projects (); |
---|
| 951 | |
---|
[519] | 952 | static Project::ProjectVector& Projects = Project::projects (); |
---|
[515] | 953 | const int size = Projects.size (); |
---|
[471] | 954 | |
---|
[515] | 955 | int offset (0); |
---|
| 956 | int iuser (-1); |
---|
| 957 | int ihome (-1); |
---|
| 958 | for (int i = 0; i < 2; i++) |
---|
| 959 | { |
---|
| 960 | if (offset < size) |
---|
| 961 | { |
---|
| 962 | const cmt_string& name = Projects[offset].get_name (); |
---|
| 963 | if (name == "CMTUSERCONTEXT") |
---|
| 964 | { |
---|
| 965 | iuser = offset; |
---|
| 966 | ++offset; |
---|
| 967 | } |
---|
| 968 | else if (name == "CMTHOME") |
---|
| 969 | { |
---|
| 970 | ihome = offset; |
---|
| 971 | ++offset; |
---|
| 972 | } |
---|
| 973 | else |
---|
| 974 | break; |
---|
| 975 | } |
---|
| 976 | } |
---|
| 977 | |
---|
| 978 | OrderedProjects.resize (size); |
---|
| 979 | |
---|
[537] | 980 | Use& use = Use::current(); |
---|
| 981 | cmt_string current_path (Cmt::get_current_dir ()); |
---|
| 982 | if (use.located ()) |
---|
| 983 | { |
---|
| 984 | current_path = use.real_path; |
---|
| 985 | CmtMessage::verbose ("Using current use real_path `" + current_path + "'"); |
---|
| 986 | } |
---|
| 987 | |
---|
| 988 | cmt_string current_path_real; |
---|
| 989 | if (!CmtSystem::realpath_ (current_path, current_path_real)) |
---|
| 990 | { |
---|
| 991 | CmtError::set (CmtError::file_access_error, "Cannot compute real path `" + |
---|
| 992 | current_path + "'"); |
---|
| 993 | CmtError::print (); |
---|
| 994 | return; |
---|
| 995 | //CmtMessage::error ("Cannot compute real path `" + Use::current().real_path + "'"); |
---|
| 996 | } |
---|
| 997 | |
---|
| 998 | Project* p_cur (0); |
---|
[471] | 999 | for (int i = 0; i < size; i++) |
---|
| 1000 | { |
---|
| 1001 | Project& p = Projects[i]; |
---|
[515] | 1002 | if (i >= offset) |
---|
| 1003 | p.m_order = -1; |
---|
| 1004 | else |
---|
| 1005 | p.m_order = -2; |
---|
[471] | 1006 | p.m_visits = 0; |
---|
[537] | 1007 | // |
---|
| 1008 | // The current project specification |
---|
| 1009 | // |
---|
| 1010 | if (current_path_real.find (p.get_cmtpath_real ()) == 0) |
---|
| 1011 | { |
---|
[540] | 1012 | p_cur = &p; |
---|
[537] | 1013 | if (p.is_current ()) continue; |
---|
[540] | 1014 | |
---|
[537] | 1015 | p.set_is_current (true); |
---|
| 1016 | // |
---|
| 1017 | // The current project defines a tag with its name |
---|
| 1018 | // |
---|
| 1019 | |
---|
| 1020 | Tag* tag; |
---|
| 1021 | |
---|
| 1022 | tag = Tag::add (p.get_name (), PriorityConfig, "PROJECT", 0); |
---|
| 1023 | tag->mark (); |
---|
| 1024 | } |
---|
| 1025 | else if (p.is_current ()) |
---|
| 1026 | { |
---|
| 1027 | // |
---|
| 1028 | // Unset the tag with its name - TODO |
---|
| 1029 | // |
---|
| 1030 | p.set_is_current (false); |
---|
| 1031 | } |
---|
[471] | 1032 | } |
---|
[470] | 1033 | |
---|
[515] | 1034 | if (size == offset) |
---|
| 1035 | { |
---|
| 1036 | for (int i = 0; i < offset; i++) |
---|
| 1037 | { |
---|
| 1038 | Project* p = &(Projects[i]); |
---|
| 1039 | OrderedProjects[i] = p; |
---|
| 1040 | } |
---|
[535] | 1041 | /* |
---|
[515] | 1042 | if (2 == offset) |
---|
| 1043 | { |
---|
| 1044 | OrderedProjects[0]->add_child (OrderedProjects[1]); |
---|
| 1045 | OrderedProjects[1]->add_parent (OrderedProjects[0]); |
---|
| 1046 | OrderedProjects[0]->update_strategies_from_children (); |
---|
| 1047 | } |
---|
[535] | 1048 | */ |
---|
| 1049 | for (int i = OrderedProjects.size () - 2; i >= 0; i--) |
---|
| 1050 | { |
---|
| 1051 | if (!OrderedProjects[i]->has_parents () && |
---|
| 1052 | OrderedProjects[i]->get_children_size () == 0) |
---|
| 1053 | { |
---|
| 1054 | OrderedProjects[i]->add_child (OrderedProjects[i + 1]); |
---|
| 1055 | OrderedProjects[i]->update_strategies_from_children (); |
---|
| 1056 | OrderedProjects[i]->erase_child (OrderedProjects[i + 1]); |
---|
| 1057 | } |
---|
| 1058 | } |
---|
| 1059 | |
---|
| 1060 | orderedProjects = OrderedProjects; |
---|
| 1061 | // return OrderedProjects; |
---|
| 1062 | return; |
---|
[515] | 1063 | } |
---|
| 1064 | |
---|
[537] | 1065 | Project* p (p_cur); |
---|
| 1066 | // Project* p = get_current (); |
---|
[471] | 1067 | |
---|
[515] | 1068 | // cerr << "get_current: " << p << " offset: " << offset << endl; |
---|
[535] | 1069 | /* |
---|
[471] | 1070 | if (p == 0) |
---|
[470] | 1071 | { |
---|
[515] | 1072 | p = &(Projects[offset]); |
---|
| 1073 | // p = &(Projects[0]); |
---|
[471] | 1074 | } |
---|
[535] | 1075 | */ |
---|
[515] | 1076 | // cerr << "p: " << p << " offset: " << offset << " name: " << p->get_name () << endl; |
---|
[471] | 1077 | |
---|
| 1078 | int order (-1); |
---|
[535] | 1079 | /* |
---|
[515] | 1080 | if ((p->get_name () != "CMTUSERCONTEXT") && (p->get_name () != "CMTHOME")) |
---|
| 1081 | { |
---|
| 1082 | ProjectPtrVector projs; |
---|
| 1083 | p->m_order = ++order; |
---|
| 1084 | // p->m_visits++; |
---|
| 1085 | projs.push_back (p); |
---|
| 1086 | |
---|
| 1087 | visit (offset, order, projs); |
---|
| 1088 | // visit (order, projs); |
---|
| 1089 | } |
---|
| 1090 | // cerr << "order: " << order << endl; |
---|
| 1091 | // int unordered = size - offset - (order + 1); |
---|
[535] | 1092 | */ |
---|
| 1093 | ProjectPtrVector projs; |
---|
[471] | 1094 | |
---|
[535] | 1095 | if (p != 0 && (p->get_name () != "CMTUSERCONTEXT") && (p->get_name () != "CMTHOME")) |
---|
| 1096 | { |
---|
| 1097 | p->m_order = ++order; |
---|
| 1098 | projs.push_back (p); |
---|
| 1099 | } |
---|
| 1100 | |
---|
| 1101 | if (p == 0 || |
---|
| 1102 | (!p->has_parents () && p->get_children_size () == 0) |
---|
| 1103 | // comes from CMTPATH entry |
---|
| 1104 | ) |
---|
| 1105 | { |
---|
| 1106 | for (int i = offset; i < size; i++) |
---|
| 1107 | { |
---|
| 1108 | Project* q = &(Projects[i]); |
---|
| 1109 | if (q != p && !q->has_parents ()) |
---|
| 1110 | { |
---|
| 1111 | q->m_order = ++order; |
---|
| 1112 | projs.push_back (q); |
---|
| 1113 | } |
---|
| 1114 | } |
---|
| 1115 | } |
---|
| 1116 | |
---|
| 1117 | visit (offset, order, projs); |
---|
| 1118 | |
---|
[515] | 1119 | int beg (0); |
---|
| 1120 | if (-1 != iuser) |
---|
[471] | 1121 | { |
---|
[515] | 1122 | OrderedProjects[0] = &(Projects[iuser]); |
---|
| 1123 | // cerr << "OrderedProjects[0]: " << (OrderedProjects[0])->get_name () << endl; |
---|
| 1124 | ++beg; |
---|
| 1125 | } |
---|
| 1126 | |
---|
| 1127 | int noorder (0); |
---|
| 1128 | for (int i = offset; i < size; i++) |
---|
| 1129 | // for (int i = 0; i < size; i++) |
---|
| 1130 | { |
---|
[471] | 1131 | Project* p = &(Projects[i]); |
---|
| 1132 | int j = p->m_order; |
---|
| 1133 | if (-1 == j) |
---|
[470] | 1134 | { |
---|
[515] | 1135 | OrderedProjects[beg + order + 1 + noorder++] = p; |
---|
| 1136 | // cerr << "no: OrderedProjects[" << beg + order + noorder << "]: " << (OrderedProjects[beg + order + noorder])->get_name () << endl; |
---|
| 1137 | // OrderedProjects[order + 1 + noorder++] = p; |
---|
| 1138 | /* |
---|
[470] | 1139 | if (CmtMessage::active (Verbose)) |
---|
[471] | 1140 | CmtMessage::warning ("Not ordered project " + p->get_name () + |
---|
| 1141 | " in path " + p->get_cmtpath_pwd () + |
---|
| 1142 | " from " + p->get_cmtpath_source ()); |
---|
| 1143 | continue; |
---|
[515] | 1144 | */ |
---|
[470] | 1145 | } |
---|
[535] | 1146 | else if (-2 != j) |
---|
| 1147 | { |
---|
| 1148 | OrderedProjects[beg + j] = p; |
---|
| 1149 | } |
---|
| 1150 | /* |
---|
[515] | 1151 | else if (-2 == j) |
---|
| 1152 | { |
---|
| 1153 | } |
---|
| 1154 | else |
---|
| 1155 | { |
---|
| 1156 | OrderedProjects[beg + j] = p; |
---|
| 1157 | // OrderedProjects[j] = p; |
---|
| 1158 | // cerr << "OrderedProjects[" << beg + j << "]: " << (OrderedProjects[beg + j])->get_name () << endl; |
---|
| 1159 | } |
---|
[535] | 1160 | */ |
---|
[470] | 1161 | } |
---|
| 1162 | |
---|
[535] | 1163 | if (p != 0) |
---|
| 1164 | { |
---|
| 1165 | for (int i = 0; i < noorder; i++) |
---|
| 1166 | OrderedProjects.pop_back (); |
---|
| 1167 | } |
---|
[515] | 1168 | if (-1 != ihome) |
---|
| 1169 | { |
---|
[535] | 1170 | OrderedProjects[OrderedProjects.size () - 1] = &(Projects[ihome]); |
---|
[515] | 1171 | } |
---|
[535] | 1172 | /* |
---|
| 1173 | if (p) |
---|
| 1174 | { |
---|
| 1175 | if (-1 != ihome) |
---|
| 1176 | { |
---|
| 1177 | OrderedProjects[beg + order + 1] = &(Projects[ihome]); |
---|
| 1178 | } |
---|
| 1179 | for (int i = 0; i < noorder; i++) |
---|
| 1180 | OrderedProjects.pop_back (); |
---|
| 1181 | } |
---|
| 1182 | else |
---|
| 1183 | { |
---|
| 1184 | if (-1 != ihome) |
---|
| 1185 | { |
---|
| 1186 | OrderedProjects[size - 1] = &(Projects[ihome]); |
---|
| 1187 | } |
---|
| 1188 | } |
---|
| 1189 | */ |
---|
| 1190 | /* |
---|
[515] | 1191 | if (-1 != iuser) |
---|
| 1192 | { |
---|
| 1193 | OrderedProjects[0]->add_child (OrderedProjects[1]); |
---|
| 1194 | OrderedProjects[1]->add_parent (OrderedProjects[0]); |
---|
| 1195 | OrderedProjects[0]->update_strategies_from_children (); |
---|
| 1196 | } |
---|
[535] | 1197 | */ |
---|
[515] | 1198 | |
---|
[535] | 1199 | // if (-1 != ihome) |
---|
| 1200 | // { |
---|
[515] | 1201 | /* |
---|
| 1202 | cerr << "beg: " << beg << " order: " << order << endl; |
---|
| 1203 | cerr << "noorder: " << noorder << " size - offset: " << size - offset << endl; |
---|
| 1204 | */ |
---|
[535] | 1205 | /* |
---|
[515] | 1206 | if (noorder != size - offset) |
---|
| 1207 | { // the last ordered project |
---|
| 1208 | OrderedProjects[beg + order]->add_child (OrderedProjects[size - 1]); |
---|
| 1209 | OrderedProjects[size - 1]->add_parent (OrderedProjects[beg + order]); |
---|
| 1210 | OrderedProjects[beg + order]->update_strategies_from_children (); |
---|
| 1211 | } |
---|
| 1212 | else |
---|
| 1213 | { |
---|
| 1214 | OrderedProjects[size - 2]->add_child (OrderedProjects[size - 1]); |
---|
| 1215 | OrderedProjects[size - 1]->add_parent (OrderedProjects[size - 2]); |
---|
| 1216 | OrderedProjects[size - 2]->update_strategies_from_children (); |
---|
| 1217 | } |
---|
[535] | 1218 | */ |
---|
| 1219 | // } |
---|
| 1220 | |
---|
| 1221 | for (int i = OrderedProjects.size () - 2; i >= 0; i--) |
---|
| 1222 | { |
---|
| 1223 | if (!OrderedProjects[i]->has_parents () && |
---|
| 1224 | OrderedProjects[i]->get_children_size () == 0) |
---|
| 1225 | { |
---|
| 1226 | OrderedProjects[i]->add_child (OrderedProjects[i + 1]); |
---|
| 1227 | OrderedProjects[i]->update_strategies_from_children (); |
---|
| 1228 | OrderedProjects[i]->erase_child (OrderedProjects[i + 1]); |
---|
| 1229 | } |
---|
[515] | 1230 | } |
---|
| 1231 | |
---|
[535] | 1232 | orderedProjects = OrderedProjects; |
---|
| 1233 | // return OrderedProjects; |
---|
| 1234 | return; |
---|
[470] | 1235 | } |
---|
| 1236 | |
---|
[2] | 1237 | /*----------------------------------------------------------*/ |
---|
| 1238 | void Project::clear_all () |
---|
| 1239 | { |
---|
| 1240 | static ProjectVector& Projects = projects (); |
---|
| 1241 | |
---|
| 1242 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1243 | { |
---|
| 1244 | Project& project = Projects[i]; |
---|
| 1245 | project.clear (); |
---|
| 1246 | } |
---|
| 1247 | |
---|
| 1248 | Projects.clear (); |
---|
| 1249 | } |
---|
| 1250 | |
---|
| 1251 | /*----------------------------------------------------------*/ |
---|
| 1252 | void Project::show_all () |
---|
| 1253 | { |
---|
[535] | 1254 | static const Project::ProjectPtrVector& Ordered = Project::ordered_projects (); |
---|
[9] | 1255 | static Project::ProjectVector& Projects = Project::projects (); |
---|
| 1256 | |
---|
| 1257 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1258 | { |
---|
| 1259 | Project& p = Projects[i]; |
---|
| 1260 | p.m_visited = false; |
---|
| 1261 | } |
---|
| 1262 | |
---|
[535] | 1263 | for (int i = 0; i < Ordered.size (); i++) |
---|
| 1264 | Ordered[i]->show (); |
---|
| 1265 | |
---|
| 1266 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1267 | Projects[i].show (); |
---|
| 1268 | |
---|
| 1269 | /* |
---|
[78] | 1270 | Project* p = get_current (); |
---|
[9] | 1271 | |
---|
[78] | 1272 | if (p == 0) |
---|
| 1273 | { |
---|
[535] | 1274 | if (Ordered.size () == 0) return; |
---|
[78] | 1275 | |
---|
[535] | 1276 | p = Ordered[0]; |
---|
[78] | 1277 | } |
---|
[515] | 1278 | */ |
---|
[535] | 1279 | // p->show (); |
---|
[2] | 1280 | } |
---|
| 1281 | |
---|
[16] | 1282 | /*----------------------------------------------------------*/ |
---|
[525] | 1283 | void Project::show_container () |
---|
| 1284 | { |
---|
| 1285 | Project* p = get_current (); |
---|
| 1286 | |
---|
| 1287 | if (p == 0) return; |
---|
| 1288 | Use* use = &(p->m_container); |
---|
| 1289 | if (use->get_package_name () == "") return; |
---|
| 1290 | |
---|
| 1291 | if (!use->located ()) |
---|
| 1292 | { |
---|
| 1293 | CmtMessage::warning ("container " + use->get_package_name () |
---|
| 1294 | + " " + use->version + " " + use->path |
---|
| 1295 | + " not found"); |
---|
| 1296 | /* |
---|
| 1297 | if (!Cmt::get_quiet ()) |
---|
| 1298 | { |
---|
| 1299 | cout << "# package " << use->get_package_name () << |
---|
| 1300 | " " << use->version << " " << use->path << |
---|
| 1301 | " not found" << |
---|
| 1302 | endl; |
---|
| 1303 | } |
---|
| 1304 | */ |
---|
| 1305 | CmtError::set (CmtError::package_not_found, use->get_package_name ()); |
---|
| 1306 | } |
---|
| 1307 | else |
---|
| 1308 | { |
---|
| 1309 | static const cmt_string empty; |
---|
| 1310 | cmt_string p = use->real_path; |
---|
| 1311 | if (use->path != "") |
---|
| 1312 | { |
---|
| 1313 | int pos = p.find_last_of (use->path); |
---|
| 1314 | if (pos != cmt_string::npos) |
---|
| 1315 | { |
---|
| 1316 | p.erase (pos); |
---|
| 1317 | } |
---|
| 1318 | } |
---|
| 1319 | |
---|
| 1320 | cout << "container " << use->get_package_name () |
---|
| 1321 | << " " << use->version; |
---|
| 1322 | |
---|
| 1323 | if (CmtSystem::absolute_path (use->path)) |
---|
| 1324 | { |
---|
| 1325 | if (!Cmt::get_quiet ()) |
---|
| 1326 | { |
---|
| 1327 | cout << " (" << use->path << ")"; |
---|
| 1328 | } |
---|
| 1329 | } |
---|
| 1330 | else |
---|
| 1331 | { |
---|
| 1332 | cout << " " << use->path; |
---|
| 1333 | } |
---|
| 1334 | |
---|
| 1335 | if (!Cmt::get_quiet ()) |
---|
| 1336 | { |
---|
| 1337 | if (p != "") cout << " (" << p << ")"; |
---|
| 1338 | if (use->auto_imports == Off) cout << " (no_auto_imports)"; |
---|
| 1339 | } |
---|
| 1340 | |
---|
| 1341 | cout << endl; |
---|
| 1342 | } |
---|
| 1343 | } |
---|
| 1344 | /*----------------------------------------------------------*/ |
---|
[16] | 1345 | void Project::show_specified_strategies_for_all () |
---|
| 1346 | { |
---|
| 1347 | static ProjectVector& Projects = projects (); |
---|
| 1348 | |
---|
| 1349 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1350 | { |
---|
| 1351 | const Project& project = Projects[i]; |
---|
| 1352 | project.show_specified_strategies (); |
---|
| 1353 | } |
---|
| 1354 | } |
---|
| 1355 | |
---|
| 1356 | /*----------------------------------------------------------*/ |
---|
[9] | 1357 | class VisitorForShowPaths : public IProjectVisitor |
---|
[2] | 1358 | { |
---|
[9] | 1359 | public: |
---|
| 1360 | VisitorForShowPaths () |
---|
| 1361 | { |
---|
| 1362 | } |
---|
[2] | 1363 | |
---|
[9] | 1364 | void pre (Project* p) |
---|
| 1365 | { |
---|
| 1366 | const cmt_string& w = p->get_cmtpath_pwd (); |
---|
| 1367 | const cmt_string& s = p->get_cmtpath_source (); |
---|
[2] | 1368 | |
---|
[9] | 1369 | if (s == "default path") return; |
---|
[2] | 1370 | |
---|
[9] | 1371 | if (CmtSystem::test_directory (w)) |
---|
| 1372 | { |
---|
| 1373 | cout << "# Add path " << w << " from " << s << endl; |
---|
| 1374 | } |
---|
| 1375 | } |
---|
[2] | 1376 | |
---|
[9] | 1377 | void in (Project* p) |
---|
| 1378 | { |
---|
| 1379 | const cmt_string& w = p->get_cmtpath_pwd (); |
---|
| 1380 | const cmt_string& s = p->get_cmtpath_source (); |
---|
[2] | 1381 | |
---|
[9] | 1382 | if (s == "default path") return; |
---|
[2] | 1383 | |
---|
[9] | 1384 | if (CmtSystem::test_directory (w)) |
---|
| 1385 | { |
---|
| 1386 | cout << "# Add path " << w << " from " << s << endl; |
---|
| 1387 | } |
---|
| 1388 | } |
---|
| 1389 | |
---|
[470] | 1390 | void in_again (Project* p) |
---|
| 1391 | { |
---|
| 1392 | const cmt_string& w = p->get_cmtpath_pwd (); |
---|
| 1393 | const cmt_string& s = p->get_cmtpath_source (); |
---|
| 1394 | |
---|
| 1395 | if (s == "default path") return; |
---|
| 1396 | |
---|
| 1397 | if (CmtSystem::test_directory (w)) |
---|
| 1398 | { |
---|
| 1399 | cout << "# Remove path " << w << " from " << s << endl; |
---|
| 1400 | cout << "# Add path " << w << " from " << s << endl; |
---|
| 1401 | } |
---|
| 1402 | } |
---|
| 1403 | |
---|
[9] | 1404 | void post (Project* p) |
---|
| 1405 | { |
---|
| 1406 | } |
---|
| 1407 | }; |
---|
| 1408 | |
---|
| 1409 | /*----------------------------------------------------------*/ |
---|
[482] | 1410 | void Project::show_paths (const CmtSystem::cmt_string_vector& arguments) |
---|
| 1411 | //void Project::show_paths () |
---|
[9] | 1412 | { |
---|
[482] | 1413 | if (arguments.size () == 0) |
---|
| 1414 | { |
---|
[519] | 1415 | const ProjectPtrVector& Ordered = Project::ordered_projects (); |
---|
[482] | 1416 | for (int i = 0; i < Ordered.size (); i++) |
---|
| 1417 | { |
---|
| 1418 | const Project* p = Ordered[i]; |
---|
| 1419 | const cmt_string& w = p->get_cmtpath_pwd (); |
---|
| 1420 | const cmt_string& s = p->get_cmtpath_source (); |
---|
| 1421 | |
---|
| 1422 | if (s == "default path") continue; |
---|
| 1423 | |
---|
| 1424 | if (CmtSystem::test_directory (w)) |
---|
| 1425 | { |
---|
| 1426 | cout << "# Add path " << w << " from " << s << endl; |
---|
| 1427 | } |
---|
| 1428 | } |
---|
| 1429 | } |
---|
| 1430 | else if (arguments.size () == 1 && cmt_string (arguments[0]) == "-d") |
---|
| 1431 | { |
---|
[515] | 1432 | const ProjectVector& Projects = projects (); |
---|
| 1433 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1434 | { |
---|
| 1435 | Project& p = Projects[i]; |
---|
| 1436 | const cmt_string& w = p.get_cmtpath_pwd (); |
---|
| 1437 | const cmt_string& s = p.get_cmtpath_source (); |
---|
| 1438 | |
---|
| 1439 | if (s == "default path") continue; |
---|
| 1440 | |
---|
| 1441 | if (CmtSystem::test_directory (w)) |
---|
| 1442 | { |
---|
| 1443 | cout << "# Create path " << w << " from " << s << endl; |
---|
| 1444 | } |
---|
| 1445 | } |
---|
| 1446 | /* |
---|
[482] | 1447 | VisitorForShowPaths visitor; |
---|
| 1448 | start_visit (visitor); |
---|
[515] | 1449 | */ |
---|
[482] | 1450 | } |
---|
| 1451 | else |
---|
| 1452 | CmtMessage::error ("show_paths: unexpected argument(s)"); |
---|
[2] | 1453 | } |
---|
| 1454 | |
---|
| 1455 | //---------------------------------------------------------- |
---|
| 1456 | const cmt_string& Project::get_project_file_name () |
---|
| 1457 | { |
---|
| 1458 | static const cmt_string name = "project.cmt"; |
---|
| 1459 | |
---|
| 1460 | return (name); |
---|
| 1461 | } |
---|
| 1462 | |
---|
| 1463 | //---------------------------------------------------------- |
---|
| 1464 | void Project::fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections) |
---|
| 1465 | { |
---|
[535] | 1466 | static ProjectPtrVector& Ordered = Project::ordered_projects (); |
---|
[515] | 1467 | for (int i = 0; i < Ordered.size (); i++) |
---|
| 1468 | { |
---|
| 1469 | const Project* project = Ordered[i]; |
---|
| 1470 | |
---|
| 1471 | const cmt_string& p = project->get_cmtpath (); |
---|
| 1472 | const cmt_string& pwd = project->get_cmtpath_pwd (); |
---|
| 1473 | const cmt_string& p_real = project->get_cmtpath_real (); |
---|
| 1474 | const cmt_string& src = project->get_cmtpath_source (); |
---|
| 1475 | /* |
---|
[2] | 1476 | static ProjectVector& Projects = projects (); |
---|
| 1477 | |
---|
| 1478 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1479 | { |
---|
| 1480 | Project& project = Projects[i]; |
---|
| 1481 | |
---|
| 1482 | const cmt_string& p = project.get_cmtpath (); |
---|
| 1483 | const cmt_string& pwd = project.get_cmtpath_pwd (); |
---|
[457] | 1484 | const cmt_string& p_real = project.get_cmtpath_real (); |
---|
[2] | 1485 | const cmt_string& src = project.get_cmtpath_source (); |
---|
[515] | 1486 | */ |
---|
[2] | 1487 | if (src != "default path") |
---|
| 1488 | { |
---|
| 1489 | if (depth > 0) |
---|
| 1490 | { |
---|
| 1491 | cmt_string& s1 = path_selections.add (); |
---|
| 1492 | s1 = p; |
---|
[457] | 1493 | if (pwd != p) |
---|
| 1494 | { |
---|
| 1495 | cmt_string& s2 = path_selections.add (); |
---|
| 1496 | s2 = pwd; |
---|
| 1497 | } |
---|
| 1498 | if (p_real != p && p_real != pwd) |
---|
| 1499 | { |
---|
| 1500 | cmt_string& s3 = path_selections.add (); |
---|
| 1501 | s3 = p_real; |
---|
| 1502 | } |
---|
[460] | 1503 | if (src != "CMTHOME" && src != "CMTUSERCONTEXT") |
---|
| 1504 | depth--; |
---|
[2] | 1505 | |
---|
| 1506 | if (depth == 0) break; |
---|
| 1507 | } |
---|
| 1508 | } |
---|
| 1509 | } |
---|
| 1510 | } |
---|
| 1511 | |
---|
| 1512 | //---------------------------------------------------------- |
---|
| 1513 | void Project::broadcast (IProjectAction& action) |
---|
| 1514 | { |
---|
[535] | 1515 | // const ProjectPtrVector Projects = Project::ordered_projects (); |
---|
| 1516 | static ProjectPtrVector& Projects = Project::ordered_projects (); |
---|
[2] | 1517 | |
---|
| 1518 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1519 | { |
---|
[471] | 1520 | const Project* project = Projects[i]; |
---|
| 1521 | |
---|
| 1522 | if (!action.run (*project)) break; |
---|
| 1523 | } |
---|
| 1524 | /* |
---|
| 1525 | static ProjectVector& Projects = projects (); |
---|
| 1526 | |
---|
| 1527 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1528 | { |
---|
[2] | 1529 | const Project& project = Projects[i]; |
---|
| 1530 | |
---|
| 1531 | if (!action.run (project)) break; |
---|
| 1532 | } |
---|
[471] | 1533 | */ |
---|
[2] | 1534 | } |
---|
| 1535 | |
---|
| 1536 | //---------------------------------------------------------- |
---|
| 1537 | void Project::reverse_broadcast (IProjectAction& action) |
---|
| 1538 | { |
---|
[535] | 1539 | // const ProjectPtrVector Projects = Project::ordered_projects (); |
---|
| 1540 | static ProjectPtrVector& Projects = Project::ordered_projects (); |
---|
[2] | 1541 | |
---|
| 1542 | for (int i = (Projects.size () - 1); i >= 0; i--) |
---|
| 1543 | { |
---|
[471] | 1544 | const Project* project = Projects[i]; |
---|
| 1545 | |
---|
| 1546 | if (!action.run (*project)) break; |
---|
| 1547 | } |
---|
| 1548 | /* |
---|
| 1549 | static ProjectVector& Projects = projects (); |
---|
| 1550 | |
---|
| 1551 | for (int i = (Projects.size () - 1); i >= 0; i--) |
---|
| 1552 | { |
---|
[2] | 1553 | const Project& project = Projects[i]; |
---|
| 1554 | |
---|
| 1555 | if (!action.run (project)) break; |
---|
| 1556 | } |
---|
[471] | 1557 | */ |
---|
[2] | 1558 | } |
---|
| 1559 | |
---|
| 1560 | //---------------------------------------------------------- |
---|
| 1561 | void Project::scan_paths (PathScanner& scanner, PathScanner::actor& a) |
---|
| 1562 | { |
---|
| 1563 | static ProjectVector& Projects = projects (); |
---|
| 1564 | |
---|
[79] | 1565 | int i; |
---|
| 1566 | |
---|
| 1567 | for (i = 0; i < Projects.size (); i++) |
---|
[2] | 1568 | { |
---|
[138] | 1569 | Project& p = Projects[i]; |
---|
[79] | 1570 | p.m_visited = false; |
---|
| 1571 | } |
---|
| 1572 | |
---|
| 1573 | for (i = 0; i < Projects.size (); i++) |
---|
| 1574 | { |
---|
[2] | 1575 | const Project& project = Projects[i]; |
---|
[138] | 1576 | |
---|
[2] | 1577 | const cmt_string& p = project.m_cmtpath; |
---|
| 1578 | scanner.scan_path (p, a); |
---|
| 1579 | } |
---|
| 1580 | } |
---|
| 1581 | |
---|
| 1582 | //---------------------------------------------------------- |
---|
| 1583 | void Project::scan_paths_for_package (PathScanner& scanner, const cmt_string& name) |
---|
| 1584 | { |
---|
| 1585 | static ProjectVector& Projects = projects (); |
---|
| 1586 | |
---|
[528] | 1587 | bool found (false); |
---|
[2] | 1588 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1589 | { |
---|
| 1590 | const Project& project = Projects[i]; |
---|
| 1591 | |
---|
| 1592 | const cmt_string& p = project.m_cmtpath; |
---|
[528] | 1593 | if (scanner.scan_package (p, name)) |
---|
| 1594 | found = true; |
---|
[2] | 1595 | } |
---|
[528] | 1596 | |
---|
| 1597 | if (!found) |
---|
| 1598 | CmtError::set (CmtError::package_not_found, name); |
---|
[2] | 1599 | } |
---|
| 1600 | |
---|
| 1601 | //---------------------------------------------------------- |
---|
| 1602 | cmt_string Project::find_in_cmt_paths (const cmt_string& path) |
---|
| 1603 | { |
---|
| 1604 | const cmt_string pwd = CmtSystem::pwd (); |
---|
| 1605 | |
---|
[437] | 1606 | // In case there are symlinks |
---|
| 1607 | cmt_string path_real; |
---|
| 1608 | //cerr << "realpath_: find_in_cmt_paths" << endl; |
---|
| 1609 | CmtSystem::realpath_ (path, path_real); |
---|
| 1610 | |
---|
[2] | 1611 | static ProjectVector& Projects = projects (); |
---|
| 1612 | |
---|
| 1613 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1614 | { |
---|
| 1615 | const Project& project = Projects[i]; |
---|
| 1616 | |
---|
| 1617 | const cmt_string& p = project.m_cmtpath; |
---|
[437] | 1618 | const cmt_string& p_real = project.m_cmtpath_real; |
---|
[2] | 1619 | const cmt_string& w = project.m_cmtpath_pwd; |
---|
| 1620 | const cmt_string& s = project.m_cmtpath_source; |
---|
| 1621 | |
---|
| 1622 | if (s == "default path") continue; |
---|
| 1623 | |
---|
| 1624 | if (CmtSystem::test_directory (p)) |
---|
| 1625 | { |
---|
[435] | 1626 | // if (path.find (p) != cmt_string::npos) |
---|
| 1627 | // { |
---|
| 1628 | // return (p); |
---|
| 1629 | // } |
---|
| 1630 | |
---|
[437] | 1631 | if (path_real.find (p_real) != cmt_string::npos) |
---|
[2] | 1632 | { |
---|
[437] | 1633 | return (p); |
---|
[2] | 1634 | } |
---|
| 1635 | |
---|
| 1636 | // To become the current area, a path must correspond to the current package |
---|
| 1637 | if (path.find (w) != cmt_string::npos) |
---|
| 1638 | { |
---|
| 1639 | return (p); |
---|
| 1640 | } |
---|
| 1641 | } |
---|
| 1642 | |
---|
| 1643 | if (p == w) continue; |
---|
| 1644 | |
---|
| 1645 | if (CmtSystem::test_directory (w)) |
---|
| 1646 | { |
---|
| 1647 | if (path.find (w) != cmt_string::npos) |
---|
| 1648 | { |
---|
| 1649 | return (w); |
---|
| 1650 | } |
---|
| 1651 | } |
---|
| 1652 | } |
---|
| 1653 | |
---|
| 1654 | return (""); |
---|
| 1655 | } |
---|
| 1656 | |
---|
| 1657 | //---------------------------------------------------------- |
---|
[9] | 1658 | void Project::visit (IProjectVisitor& visitor) |
---|
[3] | 1659 | { |
---|
[9] | 1660 | if (m_visited) return; |
---|
| 1661 | m_visited = true; |
---|
[3] | 1662 | |
---|
[9] | 1663 | int i; |
---|
[3] | 1664 | |
---|
[9] | 1665 | for (i = 0; i < get_children_size (); i++) |
---|
[3] | 1666 | { |
---|
[9] | 1667 | Project* child = get_child (i); |
---|
[3] | 1668 | |
---|
[9] | 1669 | if (child->visited ()) continue; |
---|
[3] | 1670 | |
---|
[9] | 1671 | visitor.in (child); |
---|
| 1672 | } |
---|
[3] | 1673 | |
---|
[9] | 1674 | for (i = 0; i < m_children.size (); i++) |
---|
| 1675 | { |
---|
| 1676 | Project* child = m_children[i]; |
---|
| 1677 | child->visit (visitor); |
---|
[3] | 1678 | } |
---|
| 1679 | } |
---|
| 1680 | |
---|
| 1681 | //---------------------------------------------------------- |
---|
[470] | 1682 | void Project::visit (IProjectVisitor& visitor, ProjectPtrVector& projects) |
---|
| 1683 | { |
---|
| 1684 | int size = projects.size (); |
---|
| 1685 | if (0 == size) return; |
---|
| 1686 | |
---|
| 1687 | ProjectPtrVector children; |
---|
| 1688 | for (int j = 0; j < size; j++) |
---|
| 1689 | { |
---|
| 1690 | Project* p = projects[j]; |
---|
| 1691 | if (20 == p->m_visits) |
---|
| 1692 | continue; |
---|
| 1693 | for (int i = 0; i < p->get_children_size (); i++) |
---|
| 1694 | { |
---|
| 1695 | Project* child = p->get_child (i); |
---|
| 1696 | if (0 == child->m_visits) |
---|
| 1697 | visitor.in (child); |
---|
| 1698 | else |
---|
| 1699 | visitor.in_again (child); |
---|
| 1700 | child->m_visits++; |
---|
| 1701 | children.push_back (child); |
---|
| 1702 | } |
---|
| 1703 | } |
---|
| 1704 | |
---|
| 1705 | visit (visitor, children); |
---|
| 1706 | } |
---|
| 1707 | |
---|
| 1708 | //---------------------------------------------------------- |
---|
[471] | 1709 | /** |
---|
| 1710 | * Visit the projects tree and order the projects. |
---|
| 1711 | * Order is the projects upon which the project depends directly, |
---|
| 1712 | * then the direct dependencies of the of the first dependency, of the second |
---|
| 1713 | * dependency and so on. That is first left to right, then downwards. |
---|
[515] | 1714 | * @param offset the offset from which to use all the projects |
---|
[471] | 1715 | * @param order the order of the last project visited |
---|
| 1716 | * @param projs vector of projects to visit and order |
---|
| 1717 | */ |
---|
[515] | 1718 | void Project::visit (const int offset, int& order, ProjectPtrVector& projs) |
---|
[471] | 1719 | { |
---|
| 1720 | int size = projs.size (); |
---|
[535] | 1721 | // cerr << "visit: " << offset << " " << order << " " << size << endl; |
---|
[471] | 1722 | if (0 == size) return; |
---|
| 1723 | static ProjectVector& all = Project::projects (); |
---|
[515] | 1724 | /* |
---|
| 1725 | cerr << "@ visit: " << order; |
---|
| 1726 | for (int j = 0; j < size; j++) |
---|
| 1727 | { |
---|
| 1728 | Project* p = projs[j]; |
---|
| 1729 | cerr << " " << p->get_name (); |
---|
| 1730 | } |
---|
| 1731 | cerr << " @" << endl; |
---|
| 1732 | */ |
---|
[471] | 1733 | ProjectPtrVector children; |
---|
| 1734 | for (int j = 0; j < size; j++) |
---|
| 1735 | { |
---|
| 1736 | Project* p = projs[j]; |
---|
[515] | 1737 | p->m_visits++; |
---|
[471] | 1738 | // Avoid looping in case of circular project dependencies |
---|
[515] | 1739 | if (500 <= p->m_visits) |
---|
| 1740 | // if (100 <= p->m_visits) |
---|
[471] | 1741 | continue; |
---|
| 1742 | for (int i = 0; i < p->get_children_size (); i++) |
---|
| 1743 | { |
---|
| 1744 | Project* child = p->get_child (i); |
---|
| 1745 | const int chorder = child->m_order; |
---|
[515] | 1746 | const int porder = p->m_order; |
---|
| 1747 | /* |
---|
| 1748 | cerr << ">>> " << p->get_name () << " child: " << i << endl; |
---|
| 1749 | cerr << child->get_name () << " in: " << chorder << endl; |
---|
| 1750 | */ |
---|
| 1751 | if (-2 == chorder) |
---|
| 1752 | continue; |
---|
| 1753 | else if (-1 == chorder) |
---|
| 1754 | { // not ordered yet, i.e. visited for the first time |
---|
| 1755 | child->m_order = ++order; |
---|
| 1756 | } |
---|
[535] | 1757 | else if (child->is_current ()) |
---|
| 1758 | // else if (0 == chorder) |
---|
[515] | 1759 | { // the project we started with, i. e. the current project: |
---|
| 1760 | // o circular dependency |
---|
| 1761 | // o do want to keep it first no matter what |
---|
| 1762 | if (CmtMessage::active (Verbose)) |
---|
| 1763 | CmtMessage::warning ("Circular dependency on project: " |
---|
| 1764 | + child->get_name () |
---|
| 1765 | + " " + child->get_release () |
---|
| 1766 | + " " + child->get_cmtpath ()); |
---|
| 1767 | } |
---|
[535] | 1768 | else if ((0 <= chorder) && (chorder < porder)) |
---|
| 1769 | // else if ((0 < chorder) && (chorder < porder)) |
---|
[515] | 1770 | { // ordered already, want to put it after the parent in the order |
---|
| 1771 | for (int k = offset; k < all.size (); k++) |
---|
[471] | 1772 | { |
---|
| 1773 | Project& q = all[k]; |
---|
[515] | 1774 | if (&q == child) |
---|
| 1775 | {// the child we are putting after the parent in the order |
---|
| 1776 | q.m_order = porder; |
---|
[535] | 1777 | // cerr << "Moved back: " << q.get_name () << " order: " << q.m_order << endl; |
---|
[515] | 1778 | } |
---|
| 1779 | else if ((chorder < q.m_order) && (q.m_order <= porder)) |
---|
[471] | 1780 | q.m_order--; |
---|
| 1781 | } |
---|
| 1782 | } |
---|
[535] | 1783 | // cerr << child->get_name () << " out: " << child->m_order << endl; |
---|
[515] | 1784 | // child->m_visits++; |
---|
| 1785 | bool unknown (true); |
---|
| 1786 | for (int j = 0; j < children.size (); j++) |
---|
| 1787 | { |
---|
| 1788 | if (children[j] == child) |
---|
| 1789 | { |
---|
| 1790 | unknown = false; |
---|
| 1791 | break; |
---|
| 1792 | } |
---|
| 1793 | } |
---|
| 1794 | if (unknown) |
---|
| 1795 | { |
---|
| 1796 | children.push_back (child); |
---|
| 1797 | } |
---|
[471] | 1798 | } |
---|
| 1799 | } |
---|
| 1800 | |
---|
[515] | 1801 | visit (offset, order, children); |
---|
[471] | 1802 | } |
---|
| 1803 | |
---|
| 1804 | //---------------------------------------------------------- |
---|
[9] | 1805 | void Project::start_visit (IProjectVisitor& visitor) |
---|
[2] | 1806 | { |
---|
[9] | 1807 | static Project::ProjectVector& Projects = Project::projects (); |
---|
| 1808 | |
---|
| 1809 | for (int i = 0; i < Projects.size (); i++) |
---|
| 1810 | { |
---|
| 1811 | Project& p = Projects[i]; |
---|
| 1812 | p.m_visited = false; |
---|
[470] | 1813 | p.m_visits = 0; |
---|
[9] | 1814 | } |
---|
| 1815 | |
---|
| 1816 | Project* p = get_current (); |
---|
| 1817 | |
---|
[78] | 1818 | if (p == 0) |
---|
| 1819 | { |
---|
| 1820 | if (Projects.size () == 0) return; |
---|
[9] | 1821 | |
---|
[78] | 1822 | p = &(Projects[0]); |
---|
| 1823 | } |
---|
| 1824 | |
---|
[470] | 1825 | // visitor.pre (p); |
---|
| 1826 | //p->visit (visitor); |
---|
| 1827 | // visitor.post (p); |
---|
| 1828 | visitor.in (p); |
---|
| 1829 | p->m_visits++; |
---|
[471] | 1830 | ProjectPtrVector projs; |
---|
| 1831 | projs.push_back (p); |
---|
| 1832 | visit (visitor, projs); |
---|
[9] | 1833 | } |
---|
| 1834 | |
---|
| 1835 | //---------------------------------------------------------- |
---|
| 1836 | class VisitorForFillCMTPATH : public IProjectVisitor |
---|
| 1837 | { |
---|
| 1838 | public: |
---|
| 1839 | VisitorForFillCMTPATH (cmt_string& buffer) : m_buffer (buffer) |
---|
| 1840 | { |
---|
[78] | 1841 | buffer = "path CMTPATH \"\" \n"; |
---|
[9] | 1842 | } |
---|
| 1843 | |
---|
| 1844 | void pre (Project* p) |
---|
| 1845 | { |
---|
| 1846 | const cmt_string& w = p->get_cmtpath_pwd (); |
---|
| 1847 | const cmt_string& s = p->get_cmtpath_source (); |
---|
| 1848 | |
---|
| 1849 | if (s == "default path") return; |
---|
| 1850 | |
---|
| 1851 | if (CmtSystem::test_directory (w)) |
---|
| 1852 | { |
---|
| 1853 | m_buffer += "path_append CMTPATH \""; |
---|
| 1854 | m_buffer += w; |
---|
[79] | 1855 | m_buffer += "\" \n"; |
---|
[9] | 1856 | } |
---|
| 1857 | } |
---|
| 1858 | |
---|
| 1859 | void in (Project* p) |
---|
| 1860 | { |
---|
| 1861 | const cmt_string& w = p->get_cmtpath_pwd (); |
---|
| 1862 | const cmt_string& s = p->get_cmtpath_source (); |
---|
| 1863 | |
---|
| 1864 | if (s == "default path") return; |
---|
| 1865 | |
---|
| 1866 | if (CmtSystem::test_directory (w)) |
---|
| 1867 | { |
---|
| 1868 | m_buffer += "path_append CMTPATH \""; |
---|
| 1869 | m_buffer += w; |
---|
[79] | 1870 | m_buffer += "\" \n"; |
---|
[9] | 1871 | } |
---|
| 1872 | } |
---|
| 1873 | |
---|
[470] | 1874 | void in_again (Project* p) |
---|
| 1875 | { |
---|
| 1876 | const cmt_string& w = p->get_cmtpath_pwd (); |
---|
| 1877 | const cmt_string& s = p->get_cmtpath_source (); |
---|
| 1878 | |
---|
| 1879 | if (s == "default path") return; |
---|
| 1880 | |
---|
| 1881 | if (CmtSystem::test_directory (w)) |
---|
| 1882 | { |
---|
| 1883 | m_buffer += "path_remove CMTPATH \""; |
---|
| 1884 | m_buffer += w; |
---|
| 1885 | m_buffer += "\" \n"; |
---|
| 1886 | m_buffer += "path_append CMTPATH \""; |
---|
| 1887 | m_buffer += w; |
---|
| 1888 | m_buffer += "\" \n"; |
---|
| 1889 | } |
---|
| 1890 | } |
---|
| 1891 | |
---|
[9] | 1892 | void post (Project* p) |
---|
| 1893 | { |
---|
| 1894 | //cerr << "Buffer = " << m_buffer << endl; |
---|
| 1895 | } |
---|
| 1896 | |
---|
| 1897 | private: |
---|
| 1898 | cmt_string& m_buffer; |
---|
| 1899 | |
---|
| 1900 | }; |
---|
| 1901 | |
---|
| 1902 | //---------------------------------------------------------- |
---|
| 1903 | void Project::fill_cmtpaths (cmt_string& buffer) |
---|
| 1904 | { |
---|
| 1905 | /* |
---|
| 1906 | Try to re-create all CMTPATH items from project definitions. |
---|
| 1907 | The goal is to generate CMTPATH even if this EV was not pre-set |
---|
| 1908 | which is the case when CMTPROJECTPATH is only used |
---|
[400] | 1909 | */ |
---|
[9] | 1910 | |
---|
[471] | 1911 | /* |
---|
[9] | 1912 | VisitorForFillCMTPATH visitor (buffer); |
---|
| 1913 | |
---|
| 1914 | start_visit (visitor); |
---|
[471] | 1915 | */ |
---|
[535] | 1916 | const ProjectPtrVector& Ordered = Project::ordered_projects (); |
---|
[471] | 1917 | |
---|
| 1918 | buffer = "path CMTPATH \"\" \n"; |
---|
| 1919 | for (int i = 0; i < Ordered.size (); i++) |
---|
| 1920 | { |
---|
| 1921 | const Project* p = Ordered[i]; |
---|
| 1922 | const cmt_string& w = p->get_cmtpath_pwd (); |
---|
| 1923 | const cmt_string& s = p->get_cmtpath_source (); |
---|
| 1924 | |
---|
| 1925 | if (s == "default path") continue; |
---|
| 1926 | |
---|
| 1927 | if (CmtSystem::test_directory (w)) |
---|
| 1928 | { |
---|
| 1929 | buffer += "path_append CMTPATH \""; |
---|
| 1930 | buffer += w; |
---|
| 1931 | buffer += "\" \n"; |
---|
| 1932 | } |
---|
| 1933 | } |
---|
[9] | 1934 | } |
---|
| 1935 | |
---|
| 1936 | //---------------------------------------------------------- |
---|
[272] | 1937 | Project::Project () : m_name (""), m_author("") |
---|
[9] | 1938 | { |
---|
[2] | 1939 | clear (); |
---|
| 1940 | } |
---|
| 1941 | |
---|
| 1942 | //---------------------------------------------------------- |
---|
| 1943 | const cmt_string& Project::get_name () const |
---|
| 1944 | { |
---|
| 1945 | return (m_name); |
---|
| 1946 | } |
---|
| 1947 | |
---|
| 1948 | //---------------------------------------------------------- |
---|
[8] | 1949 | const cmt_string& Project::get_release () const |
---|
| 1950 | { |
---|
| 1951 | return (m_release); |
---|
| 1952 | } |
---|
| 1953 | |
---|
| 1954 | //---------------------------------------------------------- |
---|
[525] | 1955 | const cmt_string& Project::get_container_name () const |
---|
[41] | 1956 | { |
---|
[525] | 1957 | return (m_container_name); |
---|
[41] | 1958 | } |
---|
| 1959 | |
---|
| 1960 | //---------------------------------------------------------- |
---|
| 1961 | const cmt_string& Project::get_container_version () const |
---|
| 1962 | { |
---|
| 1963 | return (m_container_version); |
---|
| 1964 | } |
---|
| 1965 | |
---|
| 1966 | //---------------------------------------------------------- |
---|
[525] | 1967 | const cmt_string& Project::get_container_path () const |
---|
| 1968 | { |
---|
| 1969 | return (m_container_path); |
---|
| 1970 | } |
---|
| 1971 | |
---|
| 1972 | //---------------------------------------------------------- |
---|
[526] | 1973 | const Use& Project::get_container () const |
---|
| 1974 | { |
---|
| 1975 | return (m_container); |
---|
| 1976 | } |
---|
| 1977 | |
---|
| 1978 | //---------------------------------------------------------- |
---|
[2] | 1979 | const cmt_string& Project::get_cmtpath () const |
---|
| 1980 | { |
---|
| 1981 | return (m_cmtpath); |
---|
| 1982 | } |
---|
| 1983 | |
---|
| 1984 | //---------------------------------------------------------- |
---|
[437] | 1985 | const cmt_string& Project::get_cmtpath_real () const |
---|
| 1986 | { |
---|
| 1987 | return (m_cmtpath_real); |
---|
| 1988 | } |
---|
| 1989 | |
---|
| 1990 | //---------------------------------------------------------- |
---|
[2] | 1991 | const cmt_string& Project::get_cmtpath_pwd () const |
---|
| 1992 | { |
---|
| 1993 | return (m_cmtpath_pwd); |
---|
| 1994 | } |
---|
| 1995 | |
---|
| 1996 | //---------------------------------------------------------- |
---|
| 1997 | const cmt_string& Project::get_cmtpath_source () const |
---|
| 1998 | { |
---|
| 1999 | return (m_cmtpath_source); |
---|
| 2000 | } |
---|
| 2001 | |
---|
| 2002 | //---------------------------------------------------------- |
---|
[9] | 2003 | int Project::get_children_size () const |
---|
| 2004 | { |
---|
| 2005 | return (m_children.size ()); |
---|
| 2006 | } |
---|
| 2007 | |
---|
| 2008 | //---------------------------------------------------------- |
---|
| 2009 | Project* Project::get_child (int index) const |
---|
| 2010 | { |
---|
| 2011 | if (index < 0) return (0); |
---|
| 2012 | if (index >= m_children.size ()) return (0); |
---|
| 2013 | return (m_children[index]); |
---|
| 2014 | } |
---|
| 2015 | |
---|
| 2016 | //---------------------------------------------------------- |
---|
| 2017 | bool Project::visited () const |
---|
| 2018 | { |
---|
| 2019 | return (m_visited); |
---|
| 2020 | } |
---|
| 2021 | |
---|
| 2022 | //---------------------------------------------------------- |
---|
[2] | 2023 | void Project::set_name (const cmt_string& name) |
---|
| 2024 | { |
---|
| 2025 | m_name = name; |
---|
| 2026 | } |
---|
| 2027 | |
---|
| 2028 | //---------------------------------------------------------- |
---|
[8] | 2029 | void Project::set_release (const cmt_string& release) |
---|
| 2030 | { |
---|
| 2031 | m_release = release; |
---|
| 2032 | } |
---|
| 2033 | |
---|
| 2034 | //---------------------------------------------------------- |
---|
[525] | 2035 | void Project::set_container_name (const cmt_string& name) |
---|
[41] | 2036 | { |
---|
[525] | 2037 | m_container_name = name; |
---|
[41] | 2038 | } |
---|
| 2039 | |
---|
| 2040 | //---------------------------------------------------------- |
---|
| 2041 | void Project::set_container_version (const cmt_string& container_version) |
---|
| 2042 | { |
---|
| 2043 | m_container_version = container_version; |
---|
| 2044 | } |
---|
| 2045 | |
---|
| 2046 | //---------------------------------------------------------- |
---|
[525] | 2047 | void Project::set_container_path (const cmt_string& container_path) |
---|
| 2048 | { |
---|
| 2049 | m_container_path = container_path; |
---|
| 2050 | } |
---|
| 2051 | |
---|
| 2052 | //---------------------------------------------------------- |
---|
[2] | 2053 | void Project::set_cmtpath (const cmt_string& path) |
---|
| 2054 | { |
---|
| 2055 | m_cmtpath = path; |
---|
| 2056 | } |
---|
| 2057 | |
---|
| 2058 | //---------------------------------------------------------- |
---|
[437] | 2059 | void Project::set_cmtpath_real (const cmt_string& path) |
---|
| 2060 | { |
---|
| 2061 | m_cmtpath_real = path; |
---|
| 2062 | } |
---|
| 2063 | |
---|
| 2064 | //---------------------------------------------------------- |
---|
[2] | 2065 | void Project::set_cmtpath_pwd (const cmt_string& path) |
---|
| 2066 | { |
---|
| 2067 | m_cmtpath_pwd = path; |
---|
| 2068 | } |
---|
| 2069 | |
---|
| 2070 | //---------------------------------------------------------- |
---|
| 2071 | void Project::set_cmtpath_source (const cmt_string& source) |
---|
| 2072 | { |
---|
| 2073 | m_cmtpath_source = source; |
---|
| 2074 | } |
---|
| 2075 | |
---|
| 2076 | //---------------------------------------------------------- |
---|
[535] | 2077 | void Project::set_is_current (bool is_current) |
---|
| 2078 | { |
---|
| 2079 | m_is_current = is_current; |
---|
| 2080 | } |
---|
| 2081 | |
---|
| 2082 | //---------------------------------------------------------- |
---|
| 2083 | bool Project::is_current () const |
---|
| 2084 | { |
---|
| 2085 | return m_is_current; |
---|
| 2086 | } |
---|
| 2087 | |
---|
| 2088 | //---------------------------------------------------------- |
---|
[2] | 2089 | void Project::clear () |
---|
| 2090 | { |
---|
[295] | 2091 | m_name = ""; |
---|
[8] | 2092 | m_release = ""; |
---|
[2] | 2093 | m_cmtpath = ""; |
---|
[437] | 2094 | m_cmtpath_real = ""; |
---|
[295] | 2095 | m_cmtpath_pwd = ""; |
---|
[2] | 2096 | m_cmtpath_source = ""; |
---|
[295] | 2097 | m_use = 0; |
---|
[2] | 2098 | |
---|
[9] | 2099 | m_parents.clear (); |
---|
| 2100 | m_children.clear (); |
---|
| 2101 | |
---|
[2] | 2102 | m_configured = false; |
---|
| 2103 | |
---|
[15] | 2104 | m_strategies.clear (); |
---|
[535] | 2105 | m_is_current = false; |
---|
[2] | 2106 | } |
---|
| 2107 | |
---|
| 2108 | //---------------------------------------------------------- |
---|
[79] | 2109 | bool Project::has_parents () const |
---|
| 2110 | { |
---|
| 2111 | return ((m_parents.size () > 0)); |
---|
| 2112 | } |
---|
| 2113 | |
---|
| 2114 | //---------------------------------------------------------- |
---|
[36] | 2115 | bool Project::has_parent (Project* p) const |
---|
[9] | 2116 | { |
---|
[36] | 2117 | if (p == 0) return (false); |
---|
| 2118 | if (p == this) return (false); |
---|
[9] | 2119 | |
---|
[36] | 2120 | const cmt_string& name = p->get_name (); |
---|
[16] | 2121 | |
---|
[9] | 2122 | int i; |
---|
| 2123 | |
---|
[36] | 2124 | for (i = 0; i < m_parents.size (); i++) |
---|
[9] | 2125 | { |
---|
[36] | 2126 | const Project* parent = m_parents[i]; |
---|
| 2127 | if (parent == 0) continue; |
---|
[9] | 2128 | |
---|
[36] | 2129 | if (parent->get_name () == name) |
---|
[9] | 2130 | { |
---|
[36] | 2131 | // registered as a parent |
---|
| 2132 | return (true); |
---|
[9] | 2133 | } |
---|
| 2134 | |
---|
[36] | 2135 | if (parent->has_parent (p)) |
---|
[9] | 2136 | { |
---|
[36] | 2137 | // recurse |
---|
| 2138 | return (true); |
---|
[9] | 2139 | } |
---|
| 2140 | } |
---|
| 2141 | |
---|
[36] | 2142 | return (false); |
---|
[9] | 2143 | } |
---|
| 2144 | |
---|
| 2145 | //---------------------------------------------------------- |
---|
[36] | 2146 | bool Project::has_child (Project* p) const |
---|
[9] | 2147 | { |
---|
[36] | 2148 | if (p == 0) return (false); |
---|
| 2149 | if (p == this) return (false); |
---|
[9] | 2150 | |
---|
[36] | 2151 | const cmt_string& name = p->get_name (); |
---|
| 2152 | |
---|
[9] | 2153 | int i; |
---|
| 2154 | |
---|
[36] | 2155 | for (i = 0; i < m_children.size (); i++) |
---|
[9] | 2156 | { |
---|
[36] | 2157 | const Project* child = m_children[i]; |
---|
| 2158 | if (child == 0) continue; |
---|
[9] | 2159 | |
---|
[36] | 2160 | if (child->get_name () == name) |
---|
[9] | 2161 | { |
---|
[36] | 2162 | // registered as a child |
---|
| 2163 | return (true); |
---|
[9] | 2164 | } |
---|
| 2165 | |
---|
[36] | 2166 | if (child->has_child (p)) |
---|
[9] | 2167 | { |
---|
[36] | 2168 | // recurse |
---|
| 2169 | return (true); |
---|
[9] | 2170 | } |
---|
| 2171 | } |
---|
| 2172 | |
---|
[36] | 2173 | return (false); |
---|
| 2174 | } |
---|
| 2175 | |
---|
| 2176 | //---------------------------------------------------------- |
---|
| 2177 | void Project::add_parent (Project* p) |
---|
| 2178 | { |
---|
| 2179 | if (p == 0) return; |
---|
| 2180 | if (p == this) return; |
---|
| 2181 | |
---|
| 2182 | //cerr << "Adding parent " << p->get_name () << " to " << m_name << endl; |
---|
| 2183 | |
---|
| 2184 | if (has_child (p)) return; |
---|
| 2185 | if (has_parent (p)) return; |
---|
| 2186 | |
---|
| 2187 | m_parents.push_back (p); |
---|
| 2188 | } |
---|
| 2189 | |
---|
| 2190 | //---------------------------------------------------------- |
---|
| 2191 | void Project::add_child (Project* p) |
---|
| 2192 | { |
---|
| 2193 | if (p == 0) return; |
---|
| 2194 | if (p == this) return; |
---|
| 2195 | |
---|
| 2196 | if (has_child (p)) return; |
---|
| 2197 | if (has_parent (p)) return; |
---|
| 2198 | |
---|
[9] | 2199 | m_children.push_back (p); |
---|
| 2200 | } |
---|
| 2201 | |
---|
| 2202 | //---------------------------------------------------------- |
---|
[535] | 2203 | void Project::erase_child (Project* p) |
---|
| 2204 | { |
---|
| 2205 | if (p == 0) return; |
---|
| 2206 | if (p == this) return; |
---|
| 2207 | |
---|
| 2208 | if (!has_child (p)) return; |
---|
| 2209 | |
---|
| 2210 | const cmt_string& name = p->get_name (); |
---|
| 2211 | |
---|
| 2212 | for (int i = 0; i < m_children.size (); i++) |
---|
| 2213 | { |
---|
| 2214 | const Project* child = m_children[i]; |
---|
| 2215 | if (child == 0) continue; |
---|
| 2216 | |
---|
| 2217 | if (child->get_name () == name) |
---|
| 2218 | { |
---|
| 2219 | // registered as a child |
---|
| 2220 | m_children.erase (i); |
---|
| 2221 | break; |
---|
| 2222 | } |
---|
| 2223 | } |
---|
| 2224 | } |
---|
| 2225 | |
---|
| 2226 | //---------------------------------------------------------- |
---|
[2] | 2227 | void Project::configure () |
---|
| 2228 | { |
---|
| 2229 | if (m_configured) return; |
---|
| 2230 | m_configured = true; |
---|
| 2231 | |
---|
[15] | 2232 | set_default_strategy ("SetupConfig"); |
---|
| 2233 | set_default_strategy ("SetupRoot"); |
---|
| 2234 | set_default_strategy ("SetupCleanup"); |
---|
[523] | 2235 | set_default_strategy ("SetupScripts"); |
---|
[15] | 2236 | set_default_strategy ("BuildPrototypes"); |
---|
| 2237 | set_default_strategy ("InstallArea"); |
---|
[83] | 2238 | set_default_strategy ("VersionDirectory"); |
---|
[2] | 2239 | } |
---|
| 2240 | |
---|
[15] | 2241 | /**--------------------------------------------------------- |
---|
[400] | 2242 | A container statement is met in the project file |
---|
[41] | 2243 | */ |
---|
[525] | 2244 | void Project::container_action (const CmtSystem::cmt_string_vector& words) |
---|
| 2245 | //void Project::container_action (const cmt_string& name, const cmt_string& version) |
---|
[41] | 2246 | { |
---|
[525] | 2247 | // |
---|
| 2248 | // complete syntax : "container <package> <version> <path>" |
---|
| 2249 | // minimal syntax : "container <package>" |
---|
| 2250 | // |
---|
| 2251 | // o if <version> is omitted then take any version available |
---|
| 2252 | // o <version> can be specified using "v*" or "v<n>r*" or "v<n>r<m>p*" |
---|
| 2253 | // |
---|
| 2254 | // o the notation "v*" is preferred to omission (particularly since |
---|
| 2255 | // omission does not permit <path>) |
---|
| 2256 | // |
---|
| 2257 | Use* use = &m_container; |
---|
| 2258 | use->~Use (); |
---|
| 2259 | if (words.size () < 2) return; |
---|
[41] | 2260 | |
---|
[525] | 2261 | CmtSystem::cmt_string_vector ewords; |
---|
| 2262 | for (int i = 1; i < words.size (); i++) |
---|
| 2263 | { |
---|
| 2264 | const cmt_string& w = words[i]; |
---|
| 2265 | cmt_string ew = w; |
---|
| 2266 | |
---|
| 2267 | Symbol::expand (ew); |
---|
| 2268 | if (ew != w) |
---|
| 2269 | { |
---|
| 2270 | CmtSystem::cmt_string_vector ws; |
---|
| 2271 | CmtSystem::split (ew, " ", ws); |
---|
| 2272 | |
---|
| 2273 | for (int j = 0; j < ws.size (); ++j) |
---|
| 2274 | { |
---|
| 2275 | ewords.push_back (ws[j]); |
---|
| 2276 | } |
---|
| 2277 | } |
---|
| 2278 | else |
---|
| 2279 | { |
---|
| 2280 | ewords.push_back (w); |
---|
| 2281 | } |
---|
| 2282 | } |
---|
| 2283 | |
---|
| 2284 | cmt_string name, version, path; |
---|
| 2285 | if (ewords.size () > 0) name = ewords[0]; |
---|
| 2286 | if (ewords.size () > 1) version = ewords[1]; |
---|
| 2287 | if (ewords.size () > 2) path = ewords[2]; |
---|
| 2288 | |
---|
| 2289 | if (name != "") |
---|
| 2290 | { |
---|
| 2291 | use->set (name, version, path); |
---|
| 2292 | use->get_package ()->remove_use (use); |
---|
[535] | 2293 | CmtSystem::cd (m_cmtpath_pwd); |
---|
[536] | 2294 | if (use->move_to ("", true) && |
---|
| 2295 | !CmtSystem::absolute_path (use->real_path)) |
---|
[525] | 2296 | { |
---|
[536] | 2297 | use->change_path (m_cmtpath_pwd); |
---|
[525] | 2298 | } |
---|
| 2299 | CmtSystem::cd (m_cmtpath_pwd + CmtSystem::file_separator () + "cmt"); |
---|
| 2300 | } |
---|
| 2301 | |
---|
| 2302 | set_container_name (name); |
---|
[41] | 2303 | set_container_version (version); |
---|
[525] | 2304 | set_container_path (path); |
---|
[41] | 2305 | } |
---|
| 2306 | |
---|
| 2307 | /**--------------------------------------------------------- |
---|
[400] | 2308 | A use statement is met in the project file |
---|
[15] | 2309 | */ |
---|
[3] | 2310 | void Project::use_action (const cmt_string& name, const cmt_string& release) |
---|
| 2311 | { |
---|
[100] | 2312 | if (Cmt::get_debug ()) |
---|
| 2313 | { |
---|
| 2314 | cout << "Use action " << name << " " << release << endl; |
---|
| 2315 | } |
---|
[3] | 2316 | |
---|
| 2317 | // A project with its release is specified |
---|
| 2318 | // |
---|
| 2319 | // Is this project already visible? |
---|
| 2320 | // If not: look for it |
---|
| 2321 | // + get CMTPROJECTPATH |
---|
[15] | 2322 | // + search from all entries of CMTPROJECTPATH : p(i)/<name>/<release> |
---|
[3] | 2323 | // + when found, this should become a new CMTPATH entry |
---|
| 2324 | // + the new project is then parsed ... etc... |
---|
| 2325 | |
---|
[273] | 2326 | // First test it wilcard is used |
---|
| 2327 | int v = -1; |
---|
| 2328 | int r = -1; |
---|
| 2329 | int p = -1; |
---|
| 2330 | cmt_string new_release = release; |
---|
| 2331 | CmtSystem::is_version_directory (new_release, v, r, p); |
---|
| 2332 | bool use_has_wild_card = (v == -1) || (r == -1) || (p == -1); |
---|
| 2333 | if (use_has_wild_card) |
---|
[400] | 2334 | { |
---|
[273] | 2335 | cmt_string selected_release = ""; |
---|
[400] | 2336 | |
---|
[273] | 2337 | if (select_release(name, new_release,selected_release)) |
---|
[400] | 2338 | { |
---|
| 2339 | // cerr <<"selected_release: "<<selected_release<<endl; |
---|
[273] | 2340 | new_release = selected_release; |
---|
[400] | 2341 | } |
---|
| 2342 | } |
---|
[273] | 2343 | |
---|
[136] | 2344 | cmt_string cmtprojectpath = Symbol::get_env_value ("CMTPROJECTPATH"); |
---|
[3] | 2345 | cmt_string sep; |
---|
[15] | 2346 | sep = CmtSystem::path_separator (); |
---|
[3] | 2347 | |
---|
| 2348 | CmtSystem::cmt_string_vector items; |
---|
| 2349 | CmtSystem::split (cmtprojectpath, sep, items); |
---|
[16] | 2350 | |
---|
| 2351 | bool found = false; |
---|
| 2352 | |
---|
[3] | 2353 | for (int i = 0; i < items.size (); i++) |
---|
| 2354 | { |
---|
| 2355 | const cmt_string& item = items[i]; |
---|
| 2356 | cmt_string p = item; |
---|
| 2357 | p += CmtSystem::file_separator (); |
---|
| 2358 | p += name; |
---|
[273] | 2359 | if (new_release != "") |
---|
[100] | 2360 | { |
---|
| 2361 | p += CmtSystem::file_separator (); |
---|
[273] | 2362 | p += new_release; |
---|
[100] | 2363 | } |
---|
[3] | 2364 | |
---|
[400] | 2365 | if (CmtSystem::test_directory (p)) |
---|
[3] | 2366 | { |
---|
[15] | 2367 | //cerr << "Project directory " << p << " exists " << endl; |
---|
[3] | 2368 | |
---|
[16] | 2369 | found = true; |
---|
| 2370 | |
---|
[3] | 2371 | IProjectFactory& factory = ProjectFactory::instance (); |
---|
| 2372 | |
---|
[18] | 2373 | factory.create_project (name, p, "ProjectPath", this); |
---|
[3] | 2374 | |
---|
| 2375 | break; |
---|
| 2376 | } |
---|
| 2377 | } |
---|
[16] | 2378 | |
---|
| 2379 | if (!found) |
---|
| 2380 | { |
---|
| 2381 | Project* p = Project::find_by_name (name); |
---|
| 2382 | |
---|
| 2383 | if (p != 0) |
---|
[400] | 2384 | { |
---|
| 2385 | found = true; |
---|
| 2386 | p->add_parent (this); |
---|
| 2387 | add_child (p); |
---|
[16] | 2388 | |
---|
[400] | 2389 | update_strategies_from_children (); |
---|
| 2390 | } |
---|
[16] | 2391 | } |
---|
[273] | 2392 | |
---|
[16] | 2393 | if (!found && (cmtprojectpath != "")) |
---|
| 2394 | { |
---|
[459] | 2395 | CmtMessage::warning ("Project " + name + " " + release + " requested by " + m_name + " not found in CMTPROJECTPATH"); |
---|
| 2396 | // cerr << "#CMT> Project " << name << " " << release << " requested by " << m_name << " not found in CMTPROJECTPATH" << endl; |
---|
[16] | 2397 | } |
---|
[3] | 2398 | } |
---|
| 2399 | |
---|
[273] | 2400 | //--------------------------------------------------------- |
---|
| 2401 | bool Project::select_release(const cmt_string& name, const cmt_string& release, cmt_string& result) |
---|
| 2402 | { |
---|
[400] | 2403 | cmt_string selected_release = ""; |
---|
[3] | 2404 | |
---|
[400] | 2405 | int v = -1; |
---|
| 2406 | int r = -1; |
---|
| 2407 | int p = -1; |
---|
| 2408 | CmtSystem::is_version_directory (release, v, r, p); |
---|
[273] | 2409 | |
---|
[400] | 2410 | int selected_v = -1; |
---|
| 2411 | int selected_r = -1; |
---|
| 2412 | int selected_p = -1; |
---|
| 2413 | CmtSystem::cmt_string_vector releases = get_project_releases(name); |
---|
| 2414 | for (int j = 0; j < releases.size (); j++) |
---|
[273] | 2415 | { |
---|
[400] | 2416 | int new_v = -1; |
---|
| 2417 | int new_r = -1; |
---|
| 2418 | int new_p = -1; |
---|
| 2419 | CmtSystem::is_version_directory (releases[j], new_v, new_r, new_p); |
---|
| 2420 | if (v == -1) |
---|
| 2421 | { |
---|
| 2422 | if (selected_v < new_v) |
---|
| 2423 | { |
---|
| 2424 | selected_v = new_v; |
---|
| 2425 | selected_r = -1; |
---|
| 2426 | selected_p = -1; |
---|
| 2427 | selected_release = releases[j]; |
---|
| 2428 | } |
---|
| 2429 | else if (selected_v == new_v) |
---|
| 2430 | { |
---|
| 2431 | // We compare the r |
---|
| 2432 | if (selected_r < new_r) |
---|
| 2433 | { |
---|
| 2434 | selected_r = new_r; |
---|
| 2435 | selected_p = -1; |
---|
| 2436 | selected_release = releases[j]; |
---|
| 2437 | } |
---|
| 2438 | else if (selected_r == new_r) |
---|
| 2439 | { |
---|
| 2440 | // We compare the p |
---|
| 2441 | if (selected_p < new_p) |
---|
| 2442 | { |
---|
| 2443 | selected_p = new_p; |
---|
| 2444 | selected_release = releases[j]; |
---|
| 2445 | } |
---|
| 2446 | // else if ? not possible |
---|
| 2447 | } |
---|
| 2448 | } |
---|
| 2449 | } |
---|
| 2450 | else if (r == -1) |
---|
| 2451 | { |
---|
| 2452 | if (v == new_v) |
---|
| 2453 | { |
---|
| 2454 | // We compare the r |
---|
| 2455 | if (selected_r < new_r) |
---|
| 2456 | { |
---|
| 2457 | selected_r = new_r; |
---|
| 2458 | selected_p = -1; |
---|
| 2459 | selected_release = releases[j]; |
---|
| 2460 | } |
---|
| 2461 | else if (selected_r == new_r) |
---|
| 2462 | { |
---|
| 2463 | // We compare the p |
---|
| 2464 | if (selected_p < new_p) |
---|
| 2465 | { |
---|
| 2466 | selected_p = new_p; |
---|
| 2467 | selected_release = releases[j]; |
---|
| 2468 | } |
---|
| 2469 | // else if ? not possible |
---|
| 2470 | } |
---|
| 2471 | } |
---|
| 2472 | } |
---|
| 2473 | else if (p == -1) |
---|
| 2474 | { |
---|
| 2475 | if ((v == new_v) && (r == new_r)) |
---|
| 2476 | { |
---|
| 2477 | // We compare the p |
---|
| 2478 | if (selected_p < new_p) |
---|
| 2479 | { |
---|
| 2480 | selected_p = new_p; |
---|
| 2481 | selected_release = releases[j]; |
---|
| 2482 | } |
---|
| 2483 | // else if ? not possible |
---|
| 2484 | } |
---|
| 2485 | } |
---|
| 2486 | |
---|
| 2487 | //cerr << "v:" << new_v << ", r:" << new_r << ", p:" << new_p << endl; |
---|
| 2488 | //cerr << "req v:" << v << ", req r:" << r << ", req p:" << p << endl; |
---|
| 2489 | |
---|
[273] | 2490 | } |
---|
[400] | 2491 | |
---|
| 2492 | // cerr << "selected release: " << selected_release << endl; |
---|
| 2493 | |
---|
| 2494 | if (selected_release == "") return false; |
---|
| 2495 | |
---|
| 2496 | result = selected_release; |
---|
| 2497 | |
---|
| 2498 | return (true); |
---|
[273] | 2499 | } |
---|
| 2500 | |
---|
| 2501 | //--------------------------------------------------------- |
---|
[400] | 2502 | const CmtSystem::cmt_string_vector Project::get_project_releases (const cmt_string& name) const |
---|
[273] | 2503 | { |
---|
[400] | 2504 | CmtSystem::cmt_string_vector releases; |
---|
| 2505 | cmt_string cmtprojectpath = Symbol::get_env_value ("CMTPROJECTPATH"); |
---|
[273] | 2506 | |
---|
[400] | 2507 | static cmt_string sep = CmtSystem::path_separator (); |
---|
| 2508 | |
---|
| 2509 | CmtSystem::cmt_string_vector items; |
---|
| 2510 | CmtSystem::split (cmtprojectpath, sep, items); |
---|
| 2511 | |
---|
| 2512 | for (int i = 0; i < items.size (); i++) |
---|
[273] | 2513 | { |
---|
[400] | 2514 | const cmt_string& item = items[i]; |
---|
| 2515 | cmt_string p = item; |
---|
| 2516 | p += CmtSystem::file_separator (); |
---|
| 2517 | p += name; |
---|
| 2518 | |
---|
| 2519 | if (CmtSystem::test_directory (p)) |
---|
| 2520 | { |
---|
| 2521 | CmtSystem::cmt_string_vector directories; |
---|
| 2522 | CmtSystem::scan_dir (p, directories); |
---|
| 2523 | |
---|
| 2524 | for (int j = 0; j < directories.size (); j++) |
---|
| 2525 | { |
---|
| 2526 | if (CmtSystem::test_directory(directories[j])) |
---|
| 2527 | { |
---|
| 2528 | cmt_string release; |
---|
| 2529 | CmtSystem:: basename(directories[j], release); |
---|
| 2530 | |
---|
| 2531 | if (CmtSystem::is_version_directory(release)) |
---|
| 2532 | { |
---|
| 2533 | cmt_string& name_entry = releases.add (); |
---|
| 2534 | name_entry = release; |
---|
| 2535 | } |
---|
| 2536 | } |
---|
| 2537 | } |
---|
| 2538 | } |
---|
[273] | 2539 | } |
---|
[400] | 2540 | return (releases); |
---|
[273] | 2541 | } |
---|
| 2542 | |
---|
[3] | 2543 | //---------------------------------------------------------- |
---|
[2] | 2544 | Project& Project::operator = (const Project& other) |
---|
| 2545 | { |
---|
| 2546 | m_name = other.m_name; |
---|
| 2547 | m_cmtpath = other.m_cmtpath; |
---|
[437] | 2548 | m_cmtpath_real = other.m_cmtpath_real; |
---|
[2] | 2549 | m_cmtpath_pwd = other.m_cmtpath_pwd; |
---|
| 2550 | m_cmtpath_source = other.m_cmtpath_source; |
---|
| 2551 | |
---|
| 2552 | return (*this); |
---|
| 2553 | } |
---|
| 2554 | |
---|
| 2555 | //---------------------------------------------------------- |
---|
| 2556 | bool Project::operator == (const cmt_string& name) const |
---|
| 2557 | { |
---|
| 2558 | return ((m_name == name)); |
---|
| 2559 | } |
---|
| 2560 | |
---|
| 2561 | //---------------------------------------------------------- |
---|
| 2562 | bool Project::operator != (const cmt_string& name) const |
---|
| 2563 | { |
---|
| 2564 | return ((m_name != name)); |
---|
| 2565 | } |
---|
| 2566 | |
---|
| 2567 | //---------------------------------------------------------- |
---|
[9] | 2568 | void Project::show () |
---|
[2] | 2569 | { |
---|
[515] | 2570 | if (m_visited) return; |
---|
| 2571 | m_visited = true; |
---|
| 2572 | |
---|
[9] | 2573 | static int level = 0; |
---|
| 2574 | |
---|
[535] | 2575 | // bool is_current = false; |
---|
[2] | 2576 | |
---|
[437] | 2577 | // cmt_string here = CmtSystem::pwd (); |
---|
| 2578 | // In case there are symlinks |
---|
[535] | 2579 | /* |
---|
[437] | 2580 | cmt_string here_real; |
---|
| 2581 | CmtSystem::realpath_ (CmtSystem::pwd (), here_real); |
---|
[2] | 2582 | |
---|
[437] | 2583 | // if (here.find (m_cmtpath) == 0) |
---|
| 2584 | if (here_real.find (m_cmtpath_real) == 0) |
---|
[2] | 2585 | { |
---|
| 2586 | if (m_cmtpath_source != "default path") |
---|
| 2587 | { |
---|
| 2588 | is_current = true; |
---|
| 2589 | } |
---|
| 2590 | } |
---|
[535] | 2591 | */ |
---|
[9] | 2592 | for (int tab = 0; tab < level; tab++) cout << " "; |
---|
[519] | 2593 | cout << m_name << " " << (m_name != "CMTUSERCONTEXT" && m_name != "CMTHOME" ? m_release : "v0") << " (in " << m_cmtpath << ")"; |
---|
| 2594 | // cout << m_name << " " << m_release << " (in " << m_cmtpath << ")"; |
---|
[2] | 2595 | |
---|
[535] | 2596 | if (m_is_current) cout << " (current)"; |
---|
| 2597 | // if (is_current) cout << " (current)"; |
---|
[2] | 2598 | |
---|
[9] | 2599 | int i; |
---|
| 2600 | |
---|
| 2601 | for (i = 0; i < m_parents.size (); i++) |
---|
| 2602 | { |
---|
| 2603 | Project* p = m_parents[i]; |
---|
| 2604 | if (p == 0) continue; |
---|
| 2605 | cout << " P=" << p->get_name (); |
---|
| 2606 | } |
---|
| 2607 | |
---|
| 2608 | for (i = 0; i < m_children.size (); i++) |
---|
| 2609 | { |
---|
| 2610 | Project* p = m_children[i]; |
---|
| 2611 | if (p == 0) continue; |
---|
| 2612 | cout << " C=" << p->get_name (); |
---|
| 2613 | } |
---|
| 2614 | |
---|
[2] | 2615 | cout << endl; |
---|
[9] | 2616 | |
---|
[515] | 2617 | /* |
---|
[9] | 2618 | if (m_visited) return; |
---|
| 2619 | |
---|
| 2620 | m_visited = true; |
---|
[515] | 2621 | */ |
---|
[9] | 2622 | |
---|
| 2623 | for (i = 0; i < m_children.size (); i++) |
---|
| 2624 | { |
---|
| 2625 | Project* p = m_children[i]; |
---|
| 2626 | if (p == 0) continue; |
---|
| 2627 | level++; |
---|
| 2628 | p->show (); |
---|
| 2629 | level--; |
---|
| 2630 | } |
---|
[2] | 2631 | } |
---|
| 2632 | |
---|
| 2633 | |
---|
| 2634 | //---------------------------------------------------------- |
---|
[16] | 2635 | void Project::show_specified_strategies () const |
---|
[2] | 2636 | { |
---|
[16] | 2637 | int i; |
---|
| 2638 | |
---|
| 2639 | for (i = 0; i < m_strategies.size (); i++) |
---|
| 2640 | { |
---|
| 2641 | const Strategy& s = m_strategies[i]; |
---|
| 2642 | if (s.m_specified) |
---|
| 2643 | { |
---|
| 2644 | const StrategyDef* def = s.m_definition; |
---|
| 2645 | |
---|
| 2646 | cout << "# Project " << m_name |
---|
| 2647 | << " sets " << def->m_keyword |
---|
| 2648 | << " strategy to " << ((s.m_value) ? def->m_on_value : def->m_off_value); |
---|
| 2649 | |
---|
| 2650 | if (s.m_context != "") |
---|
| 2651 | { |
---|
| 2652 | cout << " (from package " << s.m_context << ")"; |
---|
| 2653 | } |
---|
| 2654 | |
---|
| 2655 | cout << endl; |
---|
| 2656 | } |
---|
| 2657 | } |
---|
[2] | 2658 | } |
---|
| 2659 | |
---|
| 2660 | //---------------------------------------------------------- |
---|
[15] | 2661 | bool Project::has_strategy (const StrategyDef* definition) const |
---|
[2] | 2662 | { |
---|
[10] | 2663 | int i; |
---|
| 2664 | |
---|
[15] | 2665 | for (i = 0; i < m_strategies.size (); i++) |
---|
[10] | 2666 | { |
---|
[15] | 2667 | const Strategy& s = m_strategies[i]; |
---|
| 2668 | if (s.m_definition == definition) |
---|
[10] | 2669 | { |
---|
[15] | 2670 | return (true); |
---|
[10] | 2671 | } |
---|
[15] | 2672 | } |
---|
[10] | 2673 | |
---|
[15] | 2674 | return (false); |
---|
| 2675 | } |
---|
[10] | 2676 | |
---|
[15] | 2677 | //---------------------------------------------------------- |
---|
| 2678 | bool Project::get_strategy (const cmt_string& name) const |
---|
| 2679 | { |
---|
| 2680 | static StrategyMgr& mgr = StrategyMgr::instance (); |
---|
[10] | 2681 | |
---|
[15] | 2682 | StrategyDef* def = mgr.find_strategy (name); |
---|
| 2683 | if (def == 0) |
---|
[2] | 2684 | { |
---|
[459] | 2685 | CmtMessage::warning ("strategy " + name + " undefined"); |
---|
| 2686 | // cerr << "#CMT> strategy " << name << " undefined" << endl; |
---|
[15] | 2687 | return (false); |
---|
[2] | 2688 | } |
---|
[15] | 2689 | |
---|
| 2690 | return (get_strategy (def)); |
---|
| 2691 | } |
---|
| 2692 | |
---|
| 2693 | //---------------------------------------------------------- |
---|
| 2694 | bool Project::is_specified (const StrategyDef* definition) const |
---|
| 2695 | { |
---|
| 2696 | int i; |
---|
| 2697 | |
---|
| 2698 | for (i = 0; i < m_strategies.size (); i++) |
---|
[10] | 2699 | { |
---|
[15] | 2700 | Strategy& s = m_strategies[i]; |
---|
| 2701 | if (s.m_definition == definition) |
---|
[10] | 2702 | { |
---|
[15] | 2703 | // This strategy is applied in this project |
---|
| 2704 | return (s.m_specified); |
---|
[10] | 2705 | } |
---|
[15] | 2706 | } |
---|
[2] | 2707 | |
---|
[15] | 2708 | // This strategy is not applied in this project |
---|
| 2709 | return (false); |
---|
| 2710 | } |
---|
| 2711 | |
---|
| 2712 | //---------------------------------------------------------- |
---|
| 2713 | bool Project::get_strategy (const StrategyDef* def) const |
---|
| 2714 | { |
---|
| 2715 | int i; |
---|
| 2716 | |
---|
| 2717 | for (i = 0; i < m_strategies.size (); i++) |
---|
| 2718 | { |
---|
| 2719 | Strategy& s = m_strategies[i]; |
---|
| 2720 | if (s.m_definition == def) |
---|
[10] | 2721 | { |
---|
[15] | 2722 | // This strategy is applied in this project |
---|
| 2723 | if (s.m_specified) |
---|
| 2724 | { |
---|
| 2725 | return (s.m_specified_value); |
---|
| 2726 | } |
---|
| 2727 | return (s.m_value); |
---|
[10] | 2728 | } |
---|
| 2729 | } |
---|
| 2730 | |
---|
[15] | 2731 | // This strategy is not applied in this project |
---|
| 2732 | return (def->m_default_value); |
---|
[2] | 2733 | } |
---|
| 2734 | |
---|
| 2735 | //---------------------------------------------------------- |
---|
[15] | 2736 | void Project::set_default_strategy (const cmt_string& name) |
---|
[2] | 2737 | { |
---|
[15] | 2738 | static StrategyMgr& mgr = StrategyMgr::instance (); |
---|
[2] | 2739 | |
---|
[15] | 2740 | StrategyDef* def = mgr.find_strategy (name); |
---|
| 2741 | if (def == 0) |
---|
| 2742 | { |
---|
[459] | 2743 | CmtMessage::warning ("strategy " + name + " undefined"); |
---|
| 2744 | // cerr << "#CMT> strategy " << name << " undefined" << endl; |
---|
[15] | 2745 | return; |
---|
| 2746 | } |
---|
[2] | 2747 | |
---|
[15] | 2748 | update_strategy (def, def->m_default_value); |
---|
| 2749 | } |
---|
[9] | 2750 | |
---|
[15] | 2751 | |
---|
| 2752 | //---------------------------------------------------------- |
---|
[16] | 2753 | void Project::set_strategy (const cmt_string& name, const cmt_string& value, const cmt_string& context) |
---|
[15] | 2754 | { |
---|
| 2755 | static StrategyMgr& mgr = StrategyMgr::instance (); |
---|
| 2756 | |
---|
| 2757 | StrategyDef* def = mgr.find_strategy (name); |
---|
| 2758 | if (def == 0) |
---|
[2] | 2759 | { |
---|
[459] | 2760 | CmtMessage::warning ("strategy " + name + " undefined"); |
---|
| 2761 | // cerr << "#CMT> strategy " << name << " undefined" << endl; |
---|
[15] | 2762 | return; |
---|
[2] | 2763 | } |
---|
| 2764 | |
---|
[15] | 2765 | bool b_value = false; |
---|
| 2766 | |
---|
| 2767 | if (value == def->m_on_value) |
---|
| 2768 | { |
---|
| 2769 | b_value = true; |
---|
| 2770 | } |
---|
| 2771 | else if (value == def->m_off_value) |
---|
| 2772 | { |
---|
| 2773 | b_value = false; |
---|
| 2774 | } |
---|
| 2775 | else |
---|
| 2776 | { |
---|
[459] | 2777 | CmtMessage::warning ("requested strategy value " + value + " undefined in strategy " + name); |
---|
| 2778 | // cerr << "#CMT> requested strategy value " << value << " undefined in strategy " << name << endl; |
---|
[15] | 2779 | return; |
---|
| 2780 | } |
---|
| 2781 | |
---|
[16] | 2782 | set_strategy (def, b_value, context); |
---|
[2] | 2783 | } |
---|
| 2784 | |
---|
| 2785 | //---------------------------------------------------------- |
---|
[16] | 2786 | void Project::set_strategy (StrategyDef* definition, bool b_value, const cmt_string& context) |
---|
[2] | 2787 | { |
---|
[15] | 2788 | bool need_strategy = true; |
---|
[2] | 2789 | |
---|
[15] | 2790 | int i; |
---|
[2] | 2791 | |
---|
[15] | 2792 | for (i = 0; i < m_strategies.size (); i++) |
---|
| 2793 | { |
---|
| 2794 | Strategy& s = m_strategies[i]; |
---|
| 2795 | if (s.m_definition == definition) |
---|
| 2796 | { |
---|
| 2797 | // This strategy is already applied in this project. Let's change it's value |
---|
| 2798 | s.set (definition, b_value, get_name ()); |
---|
[16] | 2799 | if (context != "") |
---|
| 2800 | { |
---|
| 2801 | if (s.m_context != "") s.m_context += " "; |
---|
| 2802 | s.m_context += context; |
---|
| 2803 | } |
---|
[15] | 2804 | need_strategy = false; |
---|
| 2805 | break; |
---|
| 2806 | } |
---|
| 2807 | } |
---|
[2] | 2808 | |
---|
[15] | 2809 | if (need_strategy) |
---|
[2] | 2810 | { |
---|
[15] | 2811 | // This strategy is not yet applied in this project. |
---|
| 2812 | |
---|
| 2813 | Strategy& s = m_strategies.add (); |
---|
[16] | 2814 | s.clear (); |
---|
[15] | 2815 | s.set (definition, b_value, get_name ()); |
---|
[16] | 2816 | s.m_context = context; |
---|
[2] | 2817 | } |
---|
[15] | 2818 | |
---|
| 2819 | for (i = 0; i < m_parents.size (); i++) |
---|
| 2820 | { |
---|
| 2821 | Project* project = m_parents[i]; |
---|
[2] | 2822 | |
---|
[15] | 2823 | project->update_strategy (definition, b_value); |
---|
| 2824 | } |
---|
| 2825 | } |
---|
[2] | 2826 | |
---|
[15] | 2827 | /**---------------------------------------------------------- |
---|
| 2828 | The strategy value is changed because of indirect influences |
---|
| 2829 | - default strategy at initialization time |
---|
| 2830 | - change in the children |
---|
| 2831 | - change in the children list |
---|
| 2832 | |
---|
| 2833 | (This is not a specification : see the set_strategy method) |
---|
[400] | 2834 | */ |
---|
[15] | 2835 | void Project::update_strategy (StrategyDef* definition, bool b_value) |
---|
| 2836 | { |
---|
| 2837 | bool need_strategy = true; |
---|
[16] | 2838 | bool specified = false; |
---|
[15] | 2839 | |
---|
| 2840 | int i; |
---|
| 2841 | |
---|
| 2842 | for (i = 0; i < m_strategies.size (); i++) |
---|
[2] | 2843 | { |
---|
[15] | 2844 | Strategy& s = m_strategies[i]; |
---|
| 2845 | if (s.m_definition == definition) |
---|
| 2846 | { |
---|
| 2847 | need_strategy = false; |
---|
[16] | 2848 | |
---|
| 2849 | if (!s.m_specified) |
---|
| 2850 | { |
---|
| 2851 | // This strategy is already applied in this project. Let's change it's value |
---|
| 2852 | s.update (definition, b_value, get_name ()); |
---|
| 2853 | } |
---|
| 2854 | else |
---|
| 2855 | { |
---|
| 2856 | specified = true; |
---|
| 2857 | } |
---|
[15] | 2858 | break; |
---|
| 2859 | } |
---|
[2] | 2860 | } |
---|
| 2861 | |
---|
[15] | 2862 | if (need_strategy) |
---|
[2] | 2863 | { |
---|
[15] | 2864 | // This strategy is not yet applied in this project. |
---|
| 2865 | |
---|
| 2866 | Strategy& s = m_strategies.add (); |
---|
[16] | 2867 | s.clear (); |
---|
[15] | 2868 | s.update (definition, b_value, get_name ()); |
---|
[2] | 2869 | } |
---|
[16] | 2870 | |
---|
| 2871 | if (!specified) |
---|
[2] | 2872 | { |
---|
[16] | 2873 | for (i = 0; i < m_parents.size (); i++) |
---|
| 2874 | { |
---|
| 2875 | Project* project = m_parents[i]; |
---|
[2] | 2876 | |
---|
[15] | 2877 | project->update_strategy (definition, b_value); |
---|
[2] | 2878 | } |
---|
| 2879 | } |
---|
| 2880 | } |
---|
| 2881 | |
---|
[15] | 2882 | /**---------------------------------------------------------- |
---|
| 2883 | At least one of the children has changed this strategy |
---|
| 2884 | Or the list of children has changed. |
---|
| 2885 | We need to update the strategy value accordingly |
---|
| 2886 | This will not change the specified value for this strategy |
---|
[400] | 2887 | */ |
---|
[15] | 2888 | void Project::update_strategy_from_children (StrategyDef* definition) |
---|
[2] | 2889 | { |
---|
[15] | 2890 | // If this strategy is specified we don't care what happens from the children |
---|
[2] | 2891 | |
---|
[16] | 2892 | //cerr << "Updating strategy " << definition->m_name << " from children for project " << m_name << endl; |
---|
[2] | 2893 | |
---|
[15] | 2894 | int i; |
---|
[2] | 2895 | |
---|
[15] | 2896 | for (i = 0; i < m_strategies.size (); i++) |
---|
[2] | 2897 | { |
---|
[15] | 2898 | Strategy& s = m_strategies[i]; |
---|
| 2899 | if (s.m_definition == definition) |
---|
| 2900 | { |
---|
| 2901 | // This strategy is applied in this project. |
---|
| 2902 | |
---|
| 2903 | if (s.m_specified) |
---|
| 2904 | { |
---|
| 2905 | // There will be no impact since the strategy is specified |
---|
| 2906 | |
---|
[16] | 2907 | //cerr << "This strategy is specified in this project" << endl; |
---|
[15] | 2908 | return; |
---|
| 2909 | } |
---|
| 2910 | |
---|
| 2911 | break; |
---|
| 2912 | } |
---|
[2] | 2913 | } |
---|
| 2914 | |
---|
[15] | 2915 | // The strategy is not specified locally so we will now figure out |
---|
| 2916 | // which strategy has to be considered from the mixture of specifications |
---|
| 2917 | // from all children. |
---|
[2] | 2918 | |
---|
[15] | 2919 | // Algorithm: |
---|
| 2920 | // - We consider children by pairs |
---|
| 2921 | // - a child that specifies its strategy wins over a child that does not |
---|
| 2922 | // - when the two children have the same level of priority we consider the priority value |
---|
| 2923 | |
---|
| 2924 | Project* selected = 0; |
---|
| 2925 | bool selected_is_specified = false; |
---|
[16] | 2926 | bool selected_value = definition->m_default_value; |
---|
[15] | 2927 | |
---|
| 2928 | for (i = 0; i < m_children.size (); i++) |
---|
[2] | 2929 | { |
---|
[15] | 2930 | Project* p = m_children[i]; |
---|
| 2931 | |
---|
[16] | 2932 | //cerr << "Checking strategy for child " << p->get_name () << endl; |
---|
[15] | 2933 | |
---|
| 2934 | bool is_specified = p->is_specified (definition); |
---|
| 2935 | bool value = p->get_strategy (definition); |
---|
| 2936 | |
---|
| 2937 | if (selected == 0) |
---|
| 2938 | { |
---|
| 2939 | selected = p; |
---|
| 2940 | selected_is_specified = is_specified; |
---|
| 2941 | selected_value = value; |
---|
| 2942 | continue; |
---|
| 2943 | } |
---|
| 2944 | |
---|
| 2945 | if (is_specified == selected_is_specified) |
---|
| 2946 | { |
---|
| 2947 | if (selected_value != value) |
---|
| 2948 | { |
---|
| 2949 | // same level of priority but different values -> we must decide |
---|
| 2950 | bool priority_value = definition->m_priority_value; |
---|
| 2951 | if (value == priority_value) |
---|
| 2952 | { |
---|
| 2953 | selected = p; |
---|
| 2954 | selected_is_specified = is_specified; |
---|
| 2955 | selected_value = value; |
---|
| 2956 | } |
---|
| 2957 | } |
---|
| 2958 | } |
---|
| 2959 | else |
---|
| 2960 | { |
---|
| 2961 | if (is_specified) |
---|
| 2962 | { |
---|
| 2963 | selected = p; |
---|
| 2964 | selected_is_specified = is_specified; |
---|
| 2965 | selected_value = value; |
---|
| 2966 | } |
---|
| 2967 | } |
---|
[2] | 2968 | } |
---|
| 2969 | |
---|
[15] | 2970 | update_strategy (definition, selected_value); |
---|
| 2971 | } |
---|
| 2972 | |
---|
| 2973 | /**---------------------------------------------------------- |
---|
| 2974 | At least one of the children has changed its strategies |
---|
| 2975 | Or the list of children has changed. |
---|
| 2976 | We need to update the strategy values accordingly |
---|
| 2977 | This will not change the specified values |
---|
[400] | 2978 | */ |
---|
[15] | 2979 | void Project::update_strategies_from_children () |
---|
| 2980 | { |
---|
| 2981 | StrategyDef::StrategyDefs& defs = StrategyMgr::get_definitions (); |
---|
| 2982 | |
---|
[16] | 2983 | //cerr << "Updating strategies from children for project " << m_name << endl; |
---|
[15] | 2984 | |
---|
| 2985 | int i; |
---|
| 2986 | |
---|
| 2987 | for (i = 0; i < defs.size (); i++) |
---|
[2] | 2988 | { |
---|
[15] | 2989 | StrategyDef* def = defs[i]; |
---|
[16] | 2990 | |
---|
[15] | 2991 | update_strategy_from_children (def); |
---|
[2] | 2992 | } |
---|
[16] | 2993 | |
---|
| 2994 | for (i = 0; i < m_parents.size (); i++) |
---|
| 2995 | { |
---|
| 2996 | Project* p = m_parents[i]; |
---|
| 2997 | p->update_strategies_from_children (); |
---|
| 2998 | } |
---|
[15] | 2999 | } |
---|
| 3000 | |
---|
| 3001 | /**---------------------------------------------------------- |
---|
| 3002 | The StrategyMgr singleton |
---|
[400] | 3003 | */ |
---|
[15] | 3004 | StrategyMgr& StrategyMgr::instance () |
---|
| 3005 | { |
---|
| 3006 | static StrategyMgr me; |
---|
| 3007 | return (me); |
---|
| 3008 | } |
---|
| 3009 | |
---|
| 3010 | /**---------------------------------------------------------- |
---|
| 3011 | The StrategyMgr constructor |
---|
| 3012 | Here are primarily constructed all strategy definitions |
---|
[400] | 3013 | */ |
---|
[15] | 3014 | StrategyMgr::StrategyMgr () |
---|
| 3015 | { |
---|
| 3016 | m_defs.clear (); |
---|
| 3017 | |
---|
| 3018 | StrategyDef* s; |
---|
| 3019 | |
---|
| 3020 | s = new StrategyDef; |
---|
[16] | 3021 | s->m_keyword = "build"; |
---|
[15] | 3022 | s->m_name = "BuildPrototypes"; |
---|
| 3023 | s->m_on_value = "prototypes"; |
---|
| 3024 | s->m_off_value = "no_prototypes"; |
---|
| 3025 | s->m_default_value = true; |
---|
| 3026 | s->m_priority_value = false; |
---|
| 3027 | |
---|
| 3028 | m_defs.push_back (s); |
---|
| 3029 | |
---|
| 3030 | s = new StrategyDef; |
---|
[16] | 3031 | s->m_keyword = "build"; |
---|
[15] | 3032 | s->m_name = "InstallArea"; |
---|
| 3033 | s->m_on_value = "with_installarea"; |
---|
| 3034 | s->m_off_value = "without_installarea"; |
---|
| 3035 | s->m_default_value = false; |
---|
| 3036 | s->m_priority_value = true; |
---|
| 3037 | |
---|
| 3038 | m_defs.push_back (s); |
---|
| 3039 | |
---|
| 3040 | s = new StrategyDef; |
---|
[16] | 3041 | s->m_keyword = "setup"; |
---|
[15] | 3042 | s->m_name = "SetupConfig"; |
---|
| 3043 | s->m_on_value = "config"; |
---|
| 3044 | s->m_off_value = "no_config"; |
---|
| 3045 | s->m_default_value = true; |
---|
| 3046 | s->m_priority_value = false; |
---|
| 3047 | |
---|
| 3048 | m_defs.push_back (s); |
---|
| 3049 | |
---|
| 3050 | s = new StrategyDef; |
---|
[16] | 3051 | s->m_keyword = "setup"; |
---|
[15] | 3052 | s->m_name = "SetupRoot"; |
---|
| 3053 | s->m_on_value = "root"; |
---|
| 3054 | s->m_off_value = "no_root"; |
---|
| 3055 | s->m_default_value = true; |
---|
| 3056 | s->m_priority_value = false; |
---|
| 3057 | |
---|
| 3058 | m_defs.push_back (s); |
---|
| 3059 | |
---|
| 3060 | s = new StrategyDef; |
---|
[16] | 3061 | s->m_keyword = "setup"; |
---|
[15] | 3062 | s->m_name = "SetupCleanup"; |
---|
| 3063 | s->m_on_value = "cleanup"; |
---|
| 3064 | s->m_off_value = "no_cleanup"; |
---|
| 3065 | s->m_default_value = true; |
---|
| 3066 | s->m_priority_value = false; |
---|
| 3067 | |
---|
| 3068 | m_defs.push_back (s); |
---|
[83] | 3069 | |
---|
| 3070 | s = new StrategyDef; |
---|
[523] | 3071 | s->m_keyword = "setup"; |
---|
| 3072 | s->m_name = "SetupScripts"; |
---|
| 3073 | s->m_on_value = "scripts"; |
---|
| 3074 | s->m_off_value = "no_scripts"; |
---|
| 3075 | s->m_default_value = true; |
---|
| 3076 | s->m_priority_value = false; |
---|
| 3077 | |
---|
| 3078 | m_defs.push_back (s); |
---|
| 3079 | |
---|
| 3080 | s = new StrategyDef; |
---|
[83] | 3081 | s->m_keyword = "structure"; |
---|
| 3082 | s->m_name = "VersionDirectory"; |
---|
| 3083 | s->m_on_value = "with_version_directory"; |
---|
| 3084 | s->m_off_value = "without_version_directory"; |
---|
[84] | 3085 | if (Cmt::get_current_structuring_style () != without_version_directory) |
---|
[83] | 3086 | { |
---|
| 3087 | s->m_default_value = true; |
---|
| 3088 | s->m_priority_value = false; |
---|
| 3089 | } |
---|
| 3090 | else |
---|
| 3091 | { |
---|
| 3092 | s->m_default_value = false; |
---|
| 3093 | s->m_priority_value = true; |
---|
| 3094 | } |
---|
| 3095 | |
---|
| 3096 | m_defs.push_back (s); |
---|
[15] | 3097 | } |
---|
| 3098 | |
---|
| 3099 | /**---------------------------------------------------------- |
---|
| 3100 | Find a strategy definition by its name |
---|
[400] | 3101 | */ |
---|
[15] | 3102 | StrategyDef* StrategyMgr::find_strategy (const cmt_string& name) |
---|
| 3103 | { |
---|
| 3104 | static StrategyMgr& me = instance (); |
---|
| 3105 | |
---|
| 3106 | int i; |
---|
| 3107 | |
---|
| 3108 | for (i = 0; i < me.m_defs.size (); i++) |
---|
[2] | 3109 | { |
---|
[15] | 3110 | StrategyDef* def = me.m_defs[i]; |
---|
| 3111 | if (def->m_name == name) |
---|
[2] | 3112 | { |
---|
[15] | 3113 | return (def); |
---|
[2] | 3114 | } |
---|
| 3115 | } |
---|
[15] | 3116 | |
---|
| 3117 | return (0); |
---|
[2] | 3118 | } |
---|
| 3119 | |
---|
[15] | 3120 | /**---------------------------------------------------------- |
---|
| 3121 | Retreive the default value defined for a given strategy |
---|
[400] | 3122 | */ |
---|
[15] | 3123 | bool StrategyMgr::get_default_strategy (const cmt_string& name) |
---|
| 3124 | { |
---|
| 3125 | StrategyDef* def = find_strategy (name); |
---|
| 3126 | if (def == 0) return (false); |
---|
| 3127 | return (def->m_default_value); |
---|
| 3128 | } |
---|
| 3129 | |
---|
| 3130 | /**---------------------------------------------------------- |
---|
| 3131 | Retreive the priority value defined for a given strategy |
---|
| 3132 | This value is used when two children of a project request two conflicting strategy values |
---|
[400] | 3133 | */ |
---|
[15] | 3134 | bool StrategyMgr::get_priority_strategy (const cmt_string& name) |
---|
| 3135 | { |
---|
| 3136 | StrategyDef* def = find_strategy (name); |
---|
| 3137 | if (def == 0) return (false); |
---|
| 3138 | return (def->m_priority_value); |
---|
| 3139 | } |
---|
| 3140 | |
---|
| 3141 | /**---------------------------------------------------------- |
---|
| 3142 | Return the vector of all existing strategy definitions |
---|
[400] | 3143 | */ |
---|
[15] | 3144 | StrategyDef::StrategyDefs& StrategyMgr::get_definitions () |
---|
| 3145 | { |
---|
| 3146 | static StrategyMgr& me = instance (); |
---|
| 3147 | |
---|
| 3148 | return (me.m_defs); |
---|
| 3149 | } |
---|
| 3150 | |
---|
[16] | 3151 | //----------------------------------------------------------- |
---|
| 3152 | Strategy::Strategy () |
---|
| 3153 | { |
---|
| 3154 | clear (); |
---|
| 3155 | } |
---|
| 3156 | |
---|
| 3157 | //----------------------------------------------------------- |
---|
| 3158 | void Strategy::clear () |
---|
| 3159 | { |
---|
| 3160 | m_definition = 0; |
---|
| 3161 | m_specified = false; |
---|
| 3162 | m_specified_value = false; |
---|
| 3163 | m_value = false; |
---|
| 3164 | m_on_tag = 0; |
---|
| 3165 | m_off_tag = 0; |
---|
| 3166 | } |
---|
| 3167 | |
---|
[15] | 3168 | /**---------------------------------------------------------- |
---|
| 3169 | Specify a new value for this strategy. |
---|
| 3170 | This only happens when a strategy statement is met in a project file or in a requirements file. |
---|
[400] | 3171 | */ |
---|
[15] | 3172 | void Strategy::set (StrategyDef* definition, bool value, const cmt_string& project_name) |
---|
| 3173 | { |
---|
[16] | 3174 | //cerr << "Setting strategy " << definition->m_name << " for project " << project_name << " to " << value << endl; |
---|
| 3175 | |
---|
[15] | 3176 | m_definition = definition; |
---|
| 3177 | m_specified = true; |
---|
| 3178 | m_specified_value = value; |
---|
| 3179 | |
---|
| 3180 | update (definition, value, project_name); |
---|
| 3181 | } |
---|
| 3182 | |
---|
| 3183 | /**---------------------------------------------------------- |
---|
| 3184 | Change the effective value for this strategy. |
---|
| 3185 | This has no impact on to the specified value. |
---|
| 3186 | This will adapt the tag settings |
---|
[400] | 3187 | */ |
---|
[15] | 3188 | void Strategy::update (StrategyDef* definition, bool value, const cmt_string& project_name) |
---|
| 3189 | { |
---|
[16] | 3190 | //cerr << "Updating strategy " << definition->m_name << " for project " << project_name << " to " << value << endl; |
---|
| 3191 | |
---|
[15] | 3192 | m_value = value; |
---|
[16] | 3193 | m_definition = definition; |
---|
[15] | 3194 | |
---|
| 3195 | cmt_string to_tag_name = project_name; |
---|
| 3196 | cmt_string to_untag_name = project_name; |
---|
| 3197 | |
---|
| 3198 | to_tag_name += "_"; |
---|
| 3199 | to_untag_name += "_"; |
---|
| 3200 | |
---|
| 3201 | if (m_value) |
---|
| 3202 | { |
---|
| 3203 | to_tag_name += m_definition->m_on_value; |
---|
| 3204 | to_untag_name += m_definition->m_off_value; |
---|
| 3205 | } |
---|
| 3206 | else |
---|
| 3207 | { |
---|
| 3208 | to_tag_name += m_definition->m_off_value; |
---|
| 3209 | to_untag_name += m_definition->m_on_value; |
---|
| 3210 | } |
---|
| 3211 | |
---|
| 3212 | m_on_tag = Tag::find (to_tag_name); |
---|
| 3213 | m_off_tag = Tag::find (to_untag_name); |
---|
| 3214 | |
---|
[523] | 3215 | if (m_on_tag == 0 || m_off_tag == 0) |
---|
[15] | 3216 | { |
---|
| 3217 | m_on_tag = Tag::add (to_tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 3218 | m_off_tag = Tag::add (to_untag_name, PriorityConfig, "PROJECT", 0); |
---|
| 3219 | |
---|
| 3220 | m_on_tag->add_tag_exclude (m_off_tag); |
---|
| 3221 | m_off_tag->add_tag_exclude (m_on_tag); |
---|
| 3222 | } |
---|
| 3223 | |
---|
| 3224 | m_off_tag->unmark (); |
---|
| 3225 | m_on_tag->mark (); |
---|
| 3226 | } |
---|
[400] | 3227 | |
---|
[272] | 3228 | //----------------------------------------------------------- |
---|
[15] | 3229 | const cmt_string& StrategyDef::get_default_value () const |
---|
| 3230 | { |
---|
| 3231 | if (m_default_value) |
---|
| 3232 | { |
---|
| 3233 | return (m_on_value); |
---|
| 3234 | } |
---|
| 3235 | else |
---|
| 3236 | { |
---|
| 3237 | return (m_off_value); |
---|
| 3238 | } |
---|
| 3239 | } |
---|
[400] | 3240 | |
---|
[272] | 3241 | //----------------------------------------------------------- |
---|
| 3242 | void Project::set_author (const cmt_string& name) |
---|
| 3243 | { |
---|
[400] | 3244 | // cerr << "set_author" << name << endl; |
---|
[272] | 3245 | this->m_author = name; |
---|
| 3246 | } |
---|
[400] | 3247 | |
---|
[272] | 3248 | //----------------------------------------------------------- |
---|
| 3249 | const cmt_string& Project::get_author () const |
---|
| 3250 | { |
---|
| 3251 | return (m_author); |
---|
| 3252 | } |
---|
[400] | 3253 | |
---|
[272] | 3254 | //----------------------------------------------------------- |
---|
| 3255 | void Project::project_author_action (const CmtSystem::cmt_string_vector& words) |
---|
| 3256 | { |
---|
| 3257 | if (m_author != "") m_author += "\n"; |
---|
[400] | 3258 | |
---|
[272] | 3259 | for (int i = 1; i < words.size (); i++) |
---|
| 3260 | { |
---|
| 3261 | const cmt_string& w = words[i]; |
---|
| 3262 | |
---|
| 3263 | if (i > 1) m_author += " "; |
---|
| 3264 | m_author += w; |
---|
| 3265 | } |
---|
| 3266 | } |
---|
[400] | 3267 | |
---|
[283] | 3268 | //----------------------------------------------------------- |
---|
[295] | 3269 | Use* Project::get_use () const |
---|
| 3270 | { |
---|
[400] | 3271 | return m_use; |
---|
[295] | 3272 | } |
---|
[400] | 3273 | |
---|
[295] | 3274 | //----------------------------------------------------------- |
---|
| 3275 | void Project::set_use (Use* use) |
---|
| 3276 | { |
---|
[400] | 3277 | this->m_use = use; |
---|
[295] | 3278 | } |
---|
[400] | 3279 | |
---|
[295] | 3280 | //----------------------------------------------------------- |
---|