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