[1] | 1 | //----------------------------------------------------------- |
---|
| 2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
| 3 | // arnault@lal.in2p3.fr |
---|
| 4 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
| 5 | //----------------------------------------------------------- |
---|
| 6 | |
---|
| 7 | #include <stdio.h> |
---|
| 8 | #include <stdlib.h> |
---|
| 9 | #include <string.h> |
---|
| 10 | #include <ctype.h> |
---|
| 11 | |
---|
| 12 | #include "cmt_project.h" |
---|
| 13 | #include "cmt_database.h" |
---|
| 14 | #include "cmt_system.h" |
---|
| 15 | #include "cmt_awk.h" |
---|
| 16 | #include "cmt_syntax.h" |
---|
| 17 | #include "cmt_tag.h" |
---|
| 18 | |
---|
| 19 | class ProjectReader : public Awk |
---|
| 20 | { |
---|
| 21 | public: |
---|
| 22 | |
---|
| 23 | ProjectReader () |
---|
| 24 | { |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | const cmt_string& get_project_name () const |
---|
| 28 | { |
---|
| 29 | return (m_project); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | void filter (const cmt_string& line) |
---|
| 33 | { |
---|
| 34 | CmtSystem::cmt_string_vector words; |
---|
| 35 | CmtSystem::split (line, " \t", words); |
---|
| 36 | if (words[0] == "project") |
---|
| 37 | { |
---|
| 38 | m_project = words[1]; |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | private: |
---|
| 43 | cmt_string m_project; |
---|
| 44 | }; |
---|
| 45 | |
---|
| 46 | class ProjectPatcher : public Awk |
---|
| 47 | { |
---|
| 48 | public: |
---|
| 49 | |
---|
| 50 | ProjectPatcher (const cmt_string& p) : m_project (p) |
---|
| 51 | { |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | void commit () |
---|
| 55 | { |
---|
| 56 | m_output.write (Project::get_project_file_name ()); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void filter (const cmt_string& line) |
---|
| 60 | { |
---|
| 61 | if (m_output != "") |
---|
| 62 | { |
---|
| 63 | m_output += "\n"; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | CmtSystem::cmt_string_vector words; |
---|
| 67 | CmtSystem::split (line, " \t", words); |
---|
| 68 | if (words[0] == "project") |
---|
| 69 | { |
---|
| 70 | m_output += "project "; |
---|
| 71 | m_output += m_project; |
---|
| 72 | } |
---|
| 73 | else |
---|
| 74 | { |
---|
| 75 | m_output += line; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | private: |
---|
| 80 | cmt_string m_output; |
---|
| 81 | const cmt_string& m_project; |
---|
| 82 | }; |
---|
| 83 | |
---|
| 84 | IProjectFactory& ProjectFactory::instance () |
---|
| 85 | { |
---|
| 86 | static ProjectFactory me; |
---|
| 87 | |
---|
| 88 | return (me); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void ProjectFactory::reset () |
---|
| 92 | { |
---|
| 93 | Project::clear_all (); |
---|
| 94 | m_first = 0; |
---|
| 95 | m_previous = 0; |
---|
| 96 | m_id = 0; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | void ProjectFactory::create_project (const cmt_string& path, |
---|
| 100 | const cmt_string& source) |
---|
| 101 | { |
---|
| 102 | cmt_string compressed_path = path; |
---|
| 103 | CmtSystem::compress_path (compressed_path); |
---|
| 104 | |
---|
| 105 | static Project::ProjectVector& Projects = Project::projects (); |
---|
| 106 | |
---|
| 107 | for (int i = 0; i < Projects.size (); i++) |
---|
| 108 | { |
---|
| 109 | Project& p = Projects[i]; |
---|
| 110 | |
---|
| 111 | if (p.get_cmtpath () == compressed_path) return; |
---|
| 112 | if (p.get_cmtpath_pwd () == compressed_path) return; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | Project* project = 0; |
---|
| 116 | Project* cmt = 0; |
---|
| 117 | |
---|
| 118 | bool is_current = false; |
---|
| 119 | |
---|
| 120 | cmt_string here = CmtSystem::pwd (); |
---|
| 121 | if (!CmtSystem::cd (compressed_path)) return; |
---|
| 122 | |
---|
| 123 | cmt_string pwd = CmtSystem::pwd (); |
---|
| 124 | if (here.find (pwd) == 0) is_current = true; |
---|
| 125 | |
---|
| 126 | cmt_string text; |
---|
| 127 | |
---|
| 128 | if (CmtSystem::cd ("cmt") && CmtSystem::test_file (Project::get_project_file_name ())) |
---|
| 129 | { |
---|
| 130 | text.read (Project::get_project_file_name ()); |
---|
| 131 | |
---|
| 132 | ProjectReader reader; |
---|
| 133 | |
---|
| 134 | reader.run (text); |
---|
| 135 | |
---|
| 136 | cmt_string name = reader.get_project_name (); |
---|
| 137 | if (name == "") |
---|
| 138 | { |
---|
| 139 | char buffer[20]; |
---|
| 140 | m_id++; |
---|
| 141 | sprintf (buffer, "Project%d", m_id); |
---|
| 142 | name = buffer; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | project = Project::add (name); |
---|
| 146 | |
---|
| 147 | } |
---|
| 148 | else |
---|
| 149 | { |
---|
| 150 | char buffer[20]; |
---|
| 151 | if (source == "default path") |
---|
| 152 | { |
---|
| 153 | strcpy (buffer, "CMT"); |
---|
| 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
| 157 | m_id++; |
---|
| 158 | sprintf (buffer, "Project%d", m_id); |
---|
| 159 | } |
---|
| 160 | project = Project::add (buffer); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | if (source == "default path") |
---|
| 164 | { |
---|
| 165 | cmt = project; |
---|
| 166 | is_current = false; |
---|
| 167 | } |
---|
| 168 | else |
---|
| 169 | { |
---|
| 170 | if (m_first == 0) |
---|
| 171 | { |
---|
| 172 | m_first = project; |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | project->set_cmtpath (compressed_path); |
---|
| 177 | project->set_cmtpath_pwd (pwd); |
---|
| 178 | project->set_cmtpath_source (source); |
---|
| 179 | |
---|
| 180 | if (is_current) |
---|
| 181 | { |
---|
| 182 | Tag* tag; |
---|
| 183 | |
---|
| 184 | tag = Tag::add (project->get_name (), PriorityConfig, "PROJECT", 0); |
---|
| 185 | tag->mark (); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | if (m_previous != 0) m_previous->set_predecessor (project); |
---|
| 189 | m_previous = project; |
---|
| 190 | |
---|
| 191 | if (text != "") |
---|
| 192 | { |
---|
| 193 | SyntaxParser::parse_project_file_text (text, |
---|
| 194 | Project::get_project_file_name (), |
---|
| 195 | project); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | CmtSystem::cd (here); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | /*----------------------------------------------------------*/ |
---|
| 202 | /* */ |
---|
| 203 | /* Operations on Projects */ |
---|
| 204 | /* */ |
---|
| 205 | /*----------------------------------------------------------*/ |
---|
| 206 | |
---|
| 207 | //---------------------------------------------------------- |
---|
| 208 | void Project::create (const cmt_string& name) |
---|
| 209 | { |
---|
| 210 | cout << "------------------------------------------" << endl; |
---|
| 211 | cout << "Configuring environment for project " << name << endl; |
---|
| 212 | cout << "CMT version " << Cmt::get_cmt_version () << "." << endl; |
---|
| 213 | cout << "------------------------------------------" << endl; |
---|
| 214 | |
---|
| 215 | if (!CmtSystem::test_directory ("cmt")) |
---|
| 216 | { |
---|
| 217 | if (!CmtSystem::mkdir ("cmt")) |
---|
| 218 | { |
---|
| 219 | cout << "Cannot create the cmt directory" << endl; |
---|
| 220 | return; |
---|
| 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
| 224 | cout << "Installing the cmt directory" << endl; |
---|
| 225 | } |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | CmtSystem::cd ("cmt"); |
---|
| 229 | |
---|
| 230 | if (!CmtSystem::test_file (get_project_file_name ())) |
---|
| 231 | { |
---|
| 232 | cout << "Creating a new project file" << endl; |
---|
| 233 | |
---|
| 234 | ofstream f (get_project_file_name ()); |
---|
| 235 | if (f) |
---|
| 236 | { |
---|
| 237 | f << "project " << name << endl; |
---|
| 238 | f << endl; |
---|
| 239 | f.close (); |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | else |
---|
| 243 | { |
---|
| 244 | cmt_string text; |
---|
| 245 | text.read (get_project_file_name ()); |
---|
| 246 | |
---|
| 247 | ProjectPatcher p (name); |
---|
| 248 | |
---|
| 249 | p.run (text); |
---|
| 250 | p.commit (); |
---|
| 251 | |
---|
| 252 | cout << "project file already there" << endl; |
---|
| 253 | } |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | //---------------------------------------------------------- |
---|
| 257 | Project* Project::find_by_name (const cmt_string& name) |
---|
| 258 | { |
---|
| 259 | static ProjectVector& Projects = projects (); |
---|
| 260 | |
---|
| 261 | for (int i = 0; i < Projects.size (); i++) |
---|
| 262 | { |
---|
| 263 | Project& p = Projects[i]; |
---|
| 264 | |
---|
| 265 | if (p.m_name == name) return (&p); |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | return (0); |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | //---------------------------------------------------------- |
---|
| 272 | Project* Project::find_by_cmtpath (const cmt_string& cmtpath) |
---|
| 273 | { |
---|
| 274 | cmt_string compressed_path = cmtpath; |
---|
| 275 | CmtSystem::compress_path (compressed_path); |
---|
| 276 | |
---|
| 277 | static ProjectVector& Projects = projects (); |
---|
| 278 | |
---|
| 279 | for (int i = 0; i < Projects.size (); i++) |
---|
| 280 | { |
---|
| 281 | Project& p = Projects[i]; |
---|
| 282 | |
---|
| 283 | if (p.m_cmtpath == compressed_path) return (&p); |
---|
| 284 | if (p.m_cmtpath_pwd == compressed_path) return (&p); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | return (0); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | //---------------------------------------------------------- |
---|
| 291 | Project* Project::get_current () |
---|
| 292 | { |
---|
| 293 | cmt_string here = CmtSystem::pwd (); |
---|
| 294 | |
---|
| 295 | static ProjectVector& Projects = projects (); |
---|
| 296 | |
---|
| 297 | Project* result = 0; |
---|
| 298 | |
---|
| 299 | for (int i = (Projects.size () - 1); i >= 0; i--) |
---|
| 300 | { |
---|
| 301 | Project& p = Projects[i]; |
---|
| 302 | |
---|
| 303 | if (here.find (p.m_cmtpath_pwd) == 0) |
---|
| 304 | { |
---|
| 305 | result = &p; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | if (here.find (p.m_cmtpath) == 0) |
---|
| 309 | { |
---|
| 310 | result = &p; |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | return (result); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | //---------------------------------------------------------- |
---|
| 318 | Project* Project::add (const cmt_string& name) |
---|
| 319 | { |
---|
| 320 | static ProjectVector& Projects = projects (); |
---|
| 321 | |
---|
| 322 | //cout << "Project::add> name=" << name << endl; |
---|
| 323 | |
---|
| 324 | { |
---|
| 325 | Project* project; |
---|
| 326 | |
---|
| 327 | project = find_by_name (name); |
---|
| 328 | if (project != 0) |
---|
| 329 | { |
---|
| 330 | Project& p = Projects.add (); |
---|
| 331 | |
---|
| 332 | project->set_reference (&p); |
---|
| 333 | p.set_name (name); |
---|
| 334 | |
---|
| 335 | return (&p); |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | Project& project = Projects.add (); |
---|
| 340 | project.set_name (name); |
---|
| 341 | |
---|
| 342 | return (&project); |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | //---------------------------------------------------------- |
---|
| 346 | Project::ProjectVector& Project::projects () |
---|
| 347 | { |
---|
| 348 | static Database& db = Database::instance (); |
---|
| 349 | static ProjectVector& Projects = db.projects (); |
---|
| 350 | |
---|
| 351 | return (Projects); |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | /*----------------------------------------------------------*/ |
---|
| 355 | void Project::clear_all () |
---|
| 356 | { |
---|
| 357 | static ProjectVector& Projects = projects (); |
---|
| 358 | |
---|
| 359 | for (int i = 0; i < Projects.size (); i++) |
---|
| 360 | { |
---|
| 361 | Project& project = Projects[i]; |
---|
| 362 | project.clear (); |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | Projects.clear (); |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | /*----------------------------------------------------------*/ |
---|
| 369 | void Project::show_all () |
---|
| 370 | { |
---|
| 371 | static ProjectVector& Projects = projects (); |
---|
| 372 | |
---|
| 373 | for (int i = 0; i < Projects.size (); i++) |
---|
| 374 | { |
---|
| 375 | const Project& project = Projects[i]; |
---|
| 376 | project.show (); |
---|
| 377 | } |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | /*----------------------------------------------------------*/ |
---|
| 381 | void Project::show_paths () |
---|
| 382 | { |
---|
| 383 | static ProjectVector& Projects = projects (); |
---|
| 384 | |
---|
| 385 | if (!Cmt::get_quiet ()) |
---|
| 386 | { |
---|
| 387 | for (int i = 0; i < Projects.size (); i++) |
---|
| 388 | { |
---|
| 389 | const Project& project = Projects[i]; |
---|
| 390 | |
---|
| 391 | const cmt_string& path = project.get_cmtpath (); |
---|
| 392 | const cmt_string& source = project.get_cmtpath_source (); |
---|
| 393 | |
---|
| 394 | cout << "# Add path " << path << " from " << source << endl; |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | cout << "#" << endl; |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | for (int i = 0; i < Projects.size (); i++) |
---|
| 401 | { |
---|
| 402 | const Project& project = Projects[i]; |
---|
| 403 | |
---|
| 404 | const cmt_string& path = project.get_cmtpath (); |
---|
| 405 | const cmt_string& source = project.get_cmtpath_source (); |
---|
| 406 | |
---|
| 407 | if (i > 0) cout << CmtSystem::path_separator (); |
---|
| 408 | |
---|
| 409 | cout << path; |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | cout << endl; |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | //---------------------------------------------------------- |
---|
| 416 | const cmt_string& Project::get_project_file_name () |
---|
| 417 | { |
---|
| 418 | static const cmt_string name = "project.cmt"; |
---|
| 419 | |
---|
| 420 | return (name); |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | //---------------------------------------------------------- |
---|
| 424 | void Project::fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections) |
---|
| 425 | { |
---|
| 426 | static ProjectVector& Projects = projects (); |
---|
| 427 | |
---|
| 428 | for (int i = 0; i < Projects.size (); i++) |
---|
| 429 | { |
---|
| 430 | Project& project = Projects[i]; |
---|
| 431 | |
---|
| 432 | const cmt_string& p = project.get_cmtpath (); |
---|
| 433 | const cmt_string& pwd = project.get_cmtpath_pwd (); |
---|
| 434 | const cmt_string& src = project.get_cmtpath_source (); |
---|
| 435 | |
---|
| 436 | if (src != "default path") |
---|
| 437 | { |
---|
| 438 | if (depth > 0) |
---|
| 439 | { |
---|
| 440 | cmt_string& s1 = path_selections.add (); |
---|
| 441 | s1 = p; |
---|
| 442 | cmt_string& s2 = path_selections.add (); |
---|
| 443 | s2 = pwd; |
---|
| 444 | depth--; |
---|
| 445 | |
---|
| 446 | if (depth == 0) break; |
---|
| 447 | } |
---|
| 448 | } |
---|
| 449 | } |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | //---------------------------------------------------------- |
---|
| 453 | void Project::broadcast (IProjectAction& action) |
---|
| 454 | { |
---|
| 455 | static ProjectVector& Projects = projects (); |
---|
| 456 | |
---|
| 457 | for (int i = 0; i < Projects.size (); i++) |
---|
| 458 | { |
---|
| 459 | const Project& project = Projects[i]; |
---|
| 460 | |
---|
| 461 | if (!action.run (project)) break; |
---|
| 462 | } |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | //---------------------------------------------------------- |
---|
| 466 | void Project::reverse_broadcast (IProjectAction& action) |
---|
| 467 | { |
---|
| 468 | static ProjectVector& Projects = projects (); |
---|
| 469 | |
---|
| 470 | for (int i = (Projects.size () - 1); i >= 0; i--) |
---|
| 471 | { |
---|
| 472 | const Project& project = Projects[i]; |
---|
| 473 | |
---|
| 474 | if (!action.run (project)) break; |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | //---------------------------------------------------------- |
---|
| 479 | void Project::scan_paths (PathScanner& scanner, PathScanner::actor& a) |
---|
| 480 | { |
---|
| 481 | static ProjectVector& Projects = projects (); |
---|
| 482 | |
---|
| 483 | for (int i = 0; i < Projects.size (); i++) |
---|
| 484 | { |
---|
| 485 | const Project& project = Projects[i]; |
---|
| 486 | |
---|
| 487 | const cmt_string& p = project.m_cmtpath; |
---|
| 488 | scanner.scan_path (p, a); |
---|
| 489 | } |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | //---------------------------------------------------------- |
---|
| 493 | void Project::scan_paths_for_package (PathScanner& scanner, const cmt_string& name) |
---|
| 494 | { |
---|
| 495 | static ProjectVector& Projects = projects (); |
---|
| 496 | |
---|
| 497 | for (int i = 0; i < Projects.size (); i++) |
---|
| 498 | { |
---|
| 499 | const Project& project = Projects[i]; |
---|
| 500 | |
---|
| 501 | const cmt_string& p = project.m_cmtpath; |
---|
| 502 | scanner.scan_package (p, name); |
---|
| 503 | } |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | //---------------------------------------------------------- |
---|
| 507 | cmt_string Project::find_in_cmt_paths (const cmt_string& path) |
---|
| 508 | { |
---|
| 509 | const cmt_string pwd = CmtSystem::pwd (); |
---|
| 510 | |
---|
| 511 | static ProjectVector& Projects = projects (); |
---|
| 512 | |
---|
| 513 | for (int i = 0; i < Projects.size (); i++) |
---|
| 514 | { |
---|
| 515 | const Project& project = Projects[i]; |
---|
| 516 | |
---|
| 517 | const cmt_string& p = project.m_cmtpath; |
---|
| 518 | const cmt_string& w = project.m_cmtpath_pwd; |
---|
| 519 | const cmt_string& s = project.m_cmtpath_source; |
---|
| 520 | |
---|
| 521 | if (s == "default path") continue; |
---|
| 522 | |
---|
| 523 | if (CmtSystem::test_directory (p)) |
---|
| 524 | { |
---|
| 525 | if (path.find (p) != cmt_string::npos) |
---|
| 526 | { |
---|
| 527 | return (p); |
---|
| 528 | } |
---|
| 529 | |
---|
| 530 | // To become the current area, a path must correspond to the current package |
---|
| 531 | if (path.find (w) != cmt_string::npos) |
---|
| 532 | { |
---|
| 533 | return (p); |
---|
| 534 | } |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | if (p == w) continue; |
---|
| 538 | |
---|
| 539 | if (CmtSystem::test_directory (w)) |
---|
| 540 | { |
---|
| 541 | if (path.find (w) != cmt_string::npos) |
---|
| 542 | { |
---|
| 543 | return (w); |
---|
| 544 | } |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | return (""); |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | //---------------------------------------------------------- |
---|
| 552 | Project::Project () : m_name (""), m_reference (0), m_predecessor (0) |
---|
| 553 | { |
---|
| 554 | clear (); |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | //---------------------------------------------------------- |
---|
| 558 | const cmt_string& Project::get_name () const |
---|
| 559 | { |
---|
| 560 | return (m_name); |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | //---------------------------------------------------------- |
---|
| 564 | const cmt_string& Project::get_cmtpath () const |
---|
| 565 | { |
---|
| 566 | return (m_cmtpath); |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | //---------------------------------------------------------- |
---|
| 570 | const cmt_string& Project::get_cmtpath_pwd () const |
---|
| 571 | { |
---|
| 572 | return (m_cmtpath_pwd); |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | //---------------------------------------------------------- |
---|
| 576 | const cmt_string& Project::get_cmtpath_source () const |
---|
| 577 | { |
---|
| 578 | return (m_cmtpath_source); |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | //---------------------------------------------------------- |
---|
| 582 | void Project::set_name (const cmt_string& name) |
---|
| 583 | { |
---|
| 584 | m_name = name; |
---|
| 585 | configure (); |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | //---------------------------------------------------------- |
---|
| 589 | void Project::set_cmtpath (const cmt_string& path) |
---|
| 590 | { |
---|
| 591 | m_cmtpath = path; |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | //---------------------------------------------------------- |
---|
| 595 | void Project::set_cmtpath_pwd (const cmt_string& path) |
---|
| 596 | { |
---|
| 597 | m_cmtpath_pwd = path; |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | //---------------------------------------------------------- |
---|
| 601 | void Project::set_cmtpath_source (const cmt_string& source) |
---|
| 602 | { |
---|
| 603 | m_cmtpath_source = source; |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | //---------------------------------------------------------- |
---|
| 607 | void Project::set_predecessor (Project* predecessor) |
---|
| 608 | { |
---|
| 609 | m_predecessor = predecessor; |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | //---------------------------------------------------------- |
---|
| 613 | void Project::set_reference (Project* reference) |
---|
| 614 | { |
---|
| 615 | m_reference = reference; |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | //---------------------------------------------------------- |
---|
| 619 | void Project::clear () |
---|
| 620 | { |
---|
| 621 | m_name = ""; |
---|
| 622 | m_cmtpath = ""; |
---|
| 623 | m_cmtpath_pwd = ""; |
---|
| 624 | m_cmtpath_source = ""; |
---|
| 625 | |
---|
| 626 | m_build_strategy_mask = 0; |
---|
| 627 | m_build_strategy = DefaultBuildStrategy; |
---|
| 628 | m_setup_strategy_mask = 0; |
---|
| 629 | m_setup_strategy = DefaultSetupStrategy; |
---|
| 630 | |
---|
| 631 | m_configured = false; |
---|
| 632 | |
---|
| 633 | m_prototypes_tag = 0; |
---|
| 634 | m_no_prototypes_tag = 0; |
---|
| 635 | m_with_installarea_tag = 0; |
---|
| 636 | m_without_installarea_tag = 0; |
---|
| 637 | |
---|
| 638 | m_setup_config_tag = 0; |
---|
| 639 | m_setup_no_config_tag = 0; |
---|
| 640 | m_setup_root_tag = 0; |
---|
| 641 | m_setup_no_root_tag = 0; |
---|
| 642 | m_setup_cleanup_tag = 0; |
---|
| 643 | m_setup_no_cleanup_tag = 0; |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | //---------------------------------------------------------- |
---|
| 647 | void Project::configure () |
---|
| 648 | { |
---|
| 649 | /* |
---|
| 650 | |
---|
| 651 | <project>_prototypes |
---|
| 652 | <project>_no_prototypes |
---|
| 653 | <project>_rebuild_makefile |
---|
| 654 | <project>_keep_makefile |
---|
| 655 | <project>_with_installarea |
---|
| 656 | <project>_without_installarea |
---|
| 657 | |
---|
| 658 | <project>_setup_config |
---|
| 659 | <project>_setup_no_config |
---|
| 660 | <project>_setup_root |
---|
| 661 | <project>_setup_no_root |
---|
| 662 | <project>_setup_cleanup |
---|
| 663 | <project>_setup_no_cleanup |
---|
| 664 | |
---|
| 665 | */ |
---|
| 666 | |
---|
| 667 | if (m_configured) return; |
---|
| 668 | m_configured = true; |
---|
| 669 | |
---|
| 670 | cmt_string tag_name; |
---|
| 671 | |
---|
| 672 | tag_name = m_name; |
---|
| 673 | tag_name += "_prototypes"; |
---|
| 674 | m_prototypes_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 675 | |
---|
| 676 | tag_name = m_name; |
---|
| 677 | tag_name += "_no_prototypes"; |
---|
| 678 | m_no_prototypes_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 679 | |
---|
| 680 | m_prototypes_tag->add_tag_exclude (m_no_prototypes_tag); |
---|
| 681 | m_no_prototypes_tag->add_tag_exclude (m_prototypes_tag); |
---|
| 682 | m_prototypes_tag->mark (); |
---|
| 683 | |
---|
| 684 | tag_name = m_name; |
---|
| 685 | tag_name += "_with_installarea"; |
---|
| 686 | m_with_installarea_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 687 | |
---|
| 688 | tag_name = m_name; |
---|
| 689 | tag_name += "_without_installarea"; |
---|
| 690 | m_without_installarea_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 691 | |
---|
| 692 | m_with_installarea_tag->add_tag_exclude (m_without_installarea_tag); |
---|
| 693 | m_without_installarea_tag->add_tag_exclude (m_with_installarea_tag); |
---|
| 694 | m_without_installarea_tag->mark (); |
---|
| 695 | |
---|
| 696 | |
---|
| 697 | |
---|
| 698 | tag_name = m_name; |
---|
| 699 | tag_name += "_setup_config"; |
---|
| 700 | m_setup_config_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 701 | |
---|
| 702 | tag_name = m_name; |
---|
| 703 | tag_name += "_setup_no_config"; |
---|
| 704 | m_setup_no_config_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 705 | |
---|
| 706 | m_setup_config_tag->add_tag_exclude (m_setup_no_config_tag); |
---|
| 707 | m_setup_no_config_tag->add_tag_exclude (m_setup_config_tag); |
---|
| 708 | m_setup_config_tag->mark (); |
---|
| 709 | |
---|
| 710 | tag_name = m_name; |
---|
| 711 | tag_name += "_setup_root"; |
---|
| 712 | m_setup_root_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 713 | |
---|
| 714 | tag_name = m_name; |
---|
| 715 | tag_name += "_setup_no_root"; |
---|
| 716 | m_setup_no_root_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 717 | |
---|
| 718 | m_setup_root_tag->add_tag_exclude (m_setup_no_root_tag); |
---|
| 719 | m_setup_no_root_tag->add_tag_exclude (m_setup_root_tag); |
---|
| 720 | m_setup_root_tag->mark (); |
---|
| 721 | |
---|
| 722 | tag_name = m_name; |
---|
| 723 | tag_name += "_setup_cleanup"; |
---|
| 724 | m_setup_cleanup_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 725 | |
---|
| 726 | tag_name = m_name; |
---|
| 727 | tag_name += "_setup_no_cleanup"; |
---|
| 728 | m_setup_no_cleanup_tag = Tag::add (tag_name, PriorityConfig, "PROJECT", 0); |
---|
| 729 | |
---|
| 730 | m_setup_cleanup_tag->add_tag_exclude (m_setup_no_cleanup_tag); |
---|
| 731 | m_setup_no_cleanup_tag->add_tag_exclude (m_setup_cleanup_tag); |
---|
| 732 | m_setup_cleanup_tag->mark (); |
---|
| 733 | |
---|
| 734 | if (Cmt::get_debug ()) |
---|
| 735 | { |
---|
| 736 | cout << "Project::configure> " << m_name |
---|
| 737 | << " " << m_prototypes_tag |
---|
| 738 | << " " << m_no_prototypes_tag |
---|
| 739 | << " " << m_with_installarea_tag |
---|
| 740 | << " " << m_without_installarea_tag |
---|
| 741 | << " " << m_setup_config_tag |
---|
| 742 | << " " << m_setup_no_config_tag |
---|
| 743 | << " " << m_setup_root_tag |
---|
| 744 | << " " << m_setup_no_root_tag |
---|
| 745 | << " " << m_setup_cleanup_tag |
---|
| 746 | << " " << m_setup_no_cleanup_tag |
---|
| 747 | << endl; |
---|
| 748 | } |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | //---------------------------------------------------------- |
---|
| 752 | Project& Project::operator = (const Project& other) |
---|
| 753 | { |
---|
| 754 | m_name = other.m_name; |
---|
| 755 | m_cmtpath = other.m_cmtpath; |
---|
| 756 | m_cmtpath_pwd = other.m_cmtpath_pwd; |
---|
| 757 | m_cmtpath_source = other.m_cmtpath_source; |
---|
| 758 | |
---|
| 759 | return (*this); |
---|
| 760 | } |
---|
| 761 | |
---|
| 762 | //---------------------------------------------------------- |
---|
| 763 | bool Project::operator == (const cmt_string& name) const |
---|
| 764 | { |
---|
| 765 | return ((m_name == name)); |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | //---------------------------------------------------------- |
---|
| 769 | bool Project::operator != (const cmt_string& name) const |
---|
| 770 | { |
---|
| 771 | return ((m_name != name)); |
---|
| 772 | } |
---|
| 773 | |
---|
| 774 | //---------------------------------------------------------- |
---|
| 775 | void Project::show () const |
---|
| 776 | { |
---|
| 777 | bool is_current = false; |
---|
| 778 | |
---|
| 779 | cmt_string here = CmtSystem::pwd (); |
---|
| 780 | |
---|
| 781 | if (here.find (m_cmtpath) == 0) |
---|
| 782 | { |
---|
| 783 | if (m_cmtpath_source != "default path") |
---|
| 784 | { |
---|
| 785 | is_current = true; |
---|
| 786 | } |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | cout << m_name << " (in " << m_cmtpath << ")"; |
---|
| 790 | |
---|
| 791 | if (is_current) cout << " (current)"; |
---|
| 792 | |
---|
| 793 | cout << endl; |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | |
---|
| 797 | //---------------------------------------------------------- |
---|
| 798 | void Project::show_strategies () const |
---|
| 799 | { |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | //---------------------------------------------------------- |
---|
| 803 | int Project::get_build_strategy () const |
---|
| 804 | { |
---|
| 805 | int result = 0; |
---|
| 806 | |
---|
| 807 | if (m_reference != 0) result = m_reference->get_build_strategy (); |
---|
| 808 | else if (m_predecessor != 0) result = m_predecessor->get_build_strategy (); |
---|
| 809 | else result = Cmt::get_current_build_strategy (); |
---|
| 810 | |
---|
| 811 | if (m_build_strategy_mask != 0) |
---|
| 812 | { |
---|
| 813 | result &= ~m_build_strategy_mask; |
---|
| 814 | result |= m_build_strategy; |
---|
| 815 | } |
---|
| 816 | |
---|
| 817 | return (result); |
---|
| 818 | } |
---|
| 819 | |
---|
| 820 | //---------------------------------------------------------- |
---|
| 821 | int Project::get_setup_strategy () const |
---|
| 822 | { |
---|
| 823 | int result = 0; |
---|
| 824 | |
---|
| 825 | if (m_reference != 0) result = m_reference->get_setup_strategy (); |
---|
| 826 | else if (m_predecessor != 0) result = m_predecessor->get_setup_strategy (); |
---|
| 827 | else result = Cmt::get_current_setup_strategy (); |
---|
| 828 | |
---|
| 829 | if (m_setup_strategy_mask != 0) |
---|
| 830 | { |
---|
| 831 | result &= ~m_setup_strategy_mask; |
---|
| 832 | result |= m_setup_strategy; |
---|
| 833 | } |
---|
| 834 | |
---|
| 835 | return (result); |
---|
| 836 | } |
---|
| 837 | |
---|
| 838 | //---------------------------------------------------------- |
---|
| 839 | void Project::set_build_strategy (int mask, int strategy) |
---|
| 840 | { |
---|
| 841 | m_build_strategy_mask |= mask; |
---|
| 842 | m_build_strategy &= ~mask; |
---|
| 843 | m_build_strategy |= strategy; |
---|
| 844 | |
---|
| 845 | cmt_string to_tag_name = m_name; |
---|
| 846 | cmt_string to_untag_name = m_name; |
---|
| 847 | |
---|
| 848 | Tag* to_tag = 0; |
---|
| 849 | Tag* to_untag = 0; |
---|
| 850 | |
---|
| 851 | switch (strategy) |
---|
| 852 | { |
---|
| 853 | case Prototypes: |
---|
| 854 | to_tag_name += "_prototypes"; |
---|
| 855 | to_untag_name += "_no_prototypes"; |
---|
| 856 | break; |
---|
| 857 | case NoPrototypes: |
---|
| 858 | to_tag_name += "_no_prototypes"; |
---|
| 859 | to_untag_name += "_prototypes"; |
---|
| 860 | break; |
---|
| 861 | case WithInstallArea: |
---|
| 862 | to_tag_name += "_with_installarea"; |
---|
| 863 | to_untag_name += "_without_installarea"; |
---|
| 864 | break; |
---|
| 865 | case WithoutInstallArea: |
---|
| 866 | to_tag_name += "_without_installarea"; |
---|
| 867 | to_untag_name += "_with_installarea"; |
---|
| 868 | break; |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | to_tag = Tag::find (to_tag_name); |
---|
| 872 | to_untag = Tag::find (to_untag_name); |
---|
| 873 | |
---|
| 874 | if (to_untag != 0) |
---|
| 875 | { |
---|
| 876 | to_untag->unmark (); |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | if (to_tag != 0) |
---|
| 880 | { |
---|
| 881 | to_tag->mark (); |
---|
| 882 | } |
---|
| 883 | |
---|
| 884 | static ProjectVector& Projects = projects (); |
---|
| 885 | |
---|
| 886 | for (int i = 0; i < Projects.size (); i++) |
---|
| 887 | { |
---|
| 888 | Project& project = Projects[i]; |
---|
| 889 | |
---|
| 890 | if ((project.m_predecessor == this) || |
---|
| 891 | (project.m_reference == this)) |
---|
| 892 | { |
---|
| 893 | if ((project.m_build_strategy_mask & mask) == 0) |
---|
| 894 | { |
---|
| 895 | project.set_build_strategy (mask, strategy); |
---|
| 896 | } |
---|
| 897 | } |
---|
| 898 | } |
---|
| 899 | |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | //---------------------------------------------------------- |
---|
| 903 | void Project::set_setup_strategy (int mask, int strategy) |
---|
| 904 | { |
---|
| 905 | m_setup_strategy_mask |= mask; |
---|
| 906 | m_setup_strategy &= ~mask; |
---|
| 907 | m_setup_strategy |= strategy; |
---|
| 908 | |
---|
| 909 | cmt_string to_tag_name = m_name; |
---|
| 910 | cmt_string to_untag_name = m_name; |
---|
| 911 | |
---|
| 912 | Tag* to_tag = 0; |
---|
| 913 | Tag* to_untag = 0; |
---|
| 914 | |
---|
| 915 | switch (strategy) |
---|
| 916 | { |
---|
| 917 | case SetupConfig: |
---|
| 918 | to_tag_name += "_setup_config"; |
---|
| 919 | to_untag_name += "_setup_no_config"; |
---|
| 920 | break; |
---|
| 921 | case SetupNoConfig: |
---|
| 922 | to_tag_name += "_setup_no_config"; |
---|
| 923 | to_untag_name += "_setup_config"; |
---|
| 924 | break; |
---|
| 925 | case SetupRoot: |
---|
| 926 | to_tag_name += "_setup_root"; |
---|
| 927 | to_untag_name += "_setup_no_root"; |
---|
| 928 | break; |
---|
| 929 | case SetupNoRoot: |
---|
| 930 | to_tag_name += "_setup_no_root"; |
---|
| 931 | to_untag_name += "_setup_root"; |
---|
| 932 | break; |
---|
| 933 | case SetupCleanup: |
---|
| 934 | to_tag_name += "_setup_cleanup"; |
---|
| 935 | to_untag_name += "_setup_no_cleanup"; |
---|
| 936 | break; |
---|
| 937 | case SetupNoCleanup: |
---|
| 938 | to_tag_name += "_setup_no_cleanup"; |
---|
| 939 | to_untag_name += "_setup_cleanup"; |
---|
| 940 | break; |
---|
| 941 | } |
---|
| 942 | |
---|
| 943 | to_tag = Tag::find (to_tag_name); |
---|
| 944 | to_untag = Tag::find (to_untag_name); |
---|
| 945 | |
---|
| 946 | if (to_untag != 0) |
---|
| 947 | { |
---|
| 948 | to_untag->unmark (); |
---|
| 949 | } |
---|
| 950 | |
---|
| 951 | if (to_tag != 0) |
---|
| 952 | { |
---|
| 953 | to_tag->mark (); |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | static ProjectVector& Projects = projects (); |
---|
| 957 | |
---|
| 958 | for (int i = 0; i < Projects.size (); i++) |
---|
| 959 | { |
---|
| 960 | Project& project = Projects[i]; |
---|
| 961 | |
---|
| 962 | if ((project.m_predecessor == this) || |
---|
| 963 | (project.m_reference == this)) |
---|
| 964 | { |
---|
| 965 | if ((project.m_setup_strategy_mask & mask) == 0) |
---|
| 966 | { |
---|
| 967 | project.set_setup_strategy (mask, strategy); |
---|
| 968 | } |
---|
| 969 | } |
---|
| 970 | } |
---|
| 971 | } |
---|
| 972 | |
---|