[2] | 1 | //-----------------------------------------------------------
|
---|
| 2 | // Copyright Christian Arnault LAL-Orsay CNRS
|
---|
| 3 | // arnault@lal.in2p3.fr
|
---|
[272] | 4 | // Modified by garonne@lal.in2p3.fr
|
---|
[2] | 5 | // See the complete license in cmt_license.txt "http://www.cecill.info".
|
---|
| 6 | //-----------------------------------------------------------
|
---|
| 7 |
|
---|
| 8 | #include <stdio.h>
|
---|
| 9 | #include <stdlib.h>
|
---|
| 10 | #include <string.h>
|
---|
| 11 | #include <ctype.h>
|
---|
| 12 |
|
---|
| 13 | #include "cmt_project.h"
|
---|
| 14 | #include "cmt_database.h"
|
---|
| 15 | #include "cmt_system.h"
|
---|
| 16 | #include "cmt_awk.h"
|
---|
| 17 | #include "cmt_syntax.h"
|
---|
| 18 | #include "cmt_tag.h"
|
---|
[8] | 19 | #include "cmt_error.h"
|
---|
[2] | 20 |
|
---|
| 21 | class ProjectReader : public Awk
|
---|
| 22 | {
|
---|
| 23 | public:
|
---|
| 24 |
|
---|
| 25 | ProjectReader ()
|
---|
| 26 | {
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | const cmt_string& get_project_name () const
|
---|
| 30 | {
|
---|
| 31 | return (m_project);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | void filter (const cmt_string& line)
|
---|
| 35 | {
|
---|
| 36 | CmtSystem::cmt_string_vector words;
|
---|
| 37 | CmtSystem::split (line, " \t", words);
|
---|
| 38 | if (words[0] == "project")
|
---|
| 39 | {
|
---|
| 40 | m_project = words[1];
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | private:
|
---|
| 45 | cmt_string m_project;
|
---|
| 46 | };
|
---|
| 47 |
|
---|
| 48 | class ProjectPatcher : public Awk
|
---|
| 49 | {
|
---|
| 50 | public:
|
---|
| 51 |
|
---|
| 52 | ProjectPatcher (const cmt_string& p) : m_project (p)
|
---|
| 53 | {
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | void commit ()
|
---|
| 57 | {
|
---|
| 58 | m_output.write (Project::get_project_file_name ());
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | void filter (const cmt_string& line)
|
---|
| 62 | {
|
---|
| 63 | CmtSystem::cmt_string_vector words;
|
---|
| 64 | CmtSystem::split (line, " \t", words);
|
---|
| 65 | if (words[0] == "project")
|
---|
| 66 | {
|
---|
| 67 | m_output += "project ";
|
---|
| 68 | m_output += m_project;
|
---|
| 69 | }
|
---|
| 70 | else
|
---|
| 71 | {
|
---|
| 72 | m_output += line;
|
---|
| 73 | }
|
---|
[79] | 74 |
|
---|
| 75 | m_output += "\n";
|
---|
[2] | 76 | }
|
---|
| 77 |
|
---|
| 78 | private:
|
---|
| 79 | cmt_string m_output;
|
---|
| 80 | const cmt_string& m_project;
|
---|
| 81 | };
|
---|
| 82 |
|
---|
| 83 | IProjectFactory& ProjectFactory::instance ()
|
---|
| 84 | {
|
---|
| 85 | static ProjectFactory me;
|
---|
| 86 |
|
---|
| 87 | return (me);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | void ProjectFactory::reset ()
|
---|
| 91 | {
|
---|
| 92 | Project::clear_all ();
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[36] | 95 | static bool get_release_from_path (const CmtSystem::cmt_string_vector& items,
|
---|
| 96 | const cmt_string& path,
|
---|
| 97 | const cmt_string& name,
|
---|
| 98 | cmt_string& real_name,
|
---|
| 99 | cmt_string& release)
|
---|
[18] | 100 | {
|
---|
| 101 | bool result = false;
|
---|
| 102 |
|
---|
| 103 | release = "";
|
---|
[36] | 104 | real_name = "";
|
---|
[18] | 105 |
|
---|
| 106 | cmt_string p = path;
|
---|
| 107 |
|
---|
[36] | 108 | if ((items.size () == 0) && (name == ""))
|
---|
| 109 | {
|
---|
| 110 | // There is no CMTPROJECTPATH and no expected project name.
|
---|
| 111 | // We have no way to find a project structure
|
---|
| 112 | // So we only expect a 2-level structure.
|
---|
| 113 |
|
---|
| 114 | CmtSystem::basename (p, release);
|
---|
| 115 | CmtSystem::dirname (p, p);
|
---|
| 116 | CmtSystem::basename (p, real_name);
|
---|
| 117 |
|
---|
| 118 | return (false);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[18] | 121 | for (;;)
|
---|
| 122 | {
|
---|
[36] | 123 | if (p == "")
|
---|
| 124 | {
|
---|
| 125 | // Protection: we found no matching project name
|
---|
| 126 | // and path was outside any CMTPROJECTPATH
|
---|
| 127 |
|
---|
| 128 | p = path;
|
---|
| 129 |
|
---|
| 130 | CmtSystem::basename (p, release);
|
---|
| 131 | CmtSystem::dirname (p, p);
|
---|
| 132 | CmtSystem::basename (p, real_name);
|
---|
| 133 |
|
---|
| 134 | return (false);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[18] | 137 | cmt_string n;
|
---|
| 138 |
|
---|
| 139 | CmtSystem::basename (p, n);
|
---|
| 140 | CmtSystem::dirname (p, p);
|
---|
| 141 |
|
---|
| 142 | if (n == name)
|
---|
| 143 | {
|
---|
[36] | 144 | real_name = name;
|
---|
[18] | 145 | result = true;
|
---|
| 146 | break;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[36] | 149 | CmtSystem::basename (p, real_name);
|
---|
| 150 |
|
---|
| 151 | for (int i = 0; i < items.size (); i++)
|
---|
| 152 | {
|
---|
| 153 | const cmt_string& item = items[i];
|
---|
| 154 | if (p == item)
|
---|
| 155 | {
|
---|
| 156 | // We have reached an item of CMTPROJECTPATH, no need to continue
|
---|
| 157 | return (false);
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[18] | 161 | if (release == "")
|
---|
| 162 | {
|
---|
| 163 | release = n;
|
---|
| 164 | }
|
---|
| 165 | else
|
---|
| 166 | {
|
---|
| 167 | cmt_string r;
|
---|
| 168 |
|
---|
| 169 | r = n;
|
---|
| 170 | r += CmtSystem::file_separator ();
|
---|
| 171 | r += release;
|
---|
| 172 | release = r;
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | //cerr << "$CMT> GRFP> path=" << path << " name=" << name << " rel=" << release << endl;
|
---|
| 177 |
|
---|
| 178 | return (result);
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 |
|
---|
[3] | 182 | /*
|
---|
| 183 | Every new CMTPATH entry becomes associated with a dedicated PROJECT
|
---|
| 184 | This function will understand this new entry to CMTPATH and understand it:
|
---|
| 185 | - it can correspond to an existing project (ie already declared)
|
---|
| 186 | - it's a new project
|
---|
| 187 | - then it tries to read and parse its project file
|
---|
| 188 | */
|
---|
[18] | 189 | Project* ProjectFactory::create_project (const cmt_string& specified_name,
|
---|
| 190 | const cmt_string& path,
|
---|
[9] | 191 | const cmt_string& source,
|
---|
| 192 | Project* parent)
|
---|
[2] | 193 | {
|
---|
| 194 | cmt_string compressed_path = path;
|
---|
| 195 | CmtSystem::compress_path (compressed_path);
|
---|
[18] | 196 | bool specify_name = (specified_name != "");
|
---|
[2] | 197 |
|
---|
[36] | 198 | if (Cmt::get_debug ())
|
---|
| 199 | {
|
---|
| 200 | cout << "Creating project " << path << " with parent " << ((parent==0)? "0" : parent->get_name ()) << endl;
|
---|
| 201 | Project::show_all ();
|
---|
| 202 | }
|
---|
[16] | 203 |
|
---|
[36] | 204 | cmt_string sep;
|
---|
| 205 | sep = CmtSystem::path_separator ();
|
---|
| 206 |
|
---|
[138] | 207 | cmt_string cmtprojectpath = Symbol::get_env_value ("CMTPROJECTPATH");
|
---|
[36] | 208 | CmtSystem::cmt_string_vector items;
|
---|
| 209 | CmtSystem::split (cmtprojectpath, sep, items);
|
---|
| 210 |
|
---|
[39] | 211 | cmt_string here = CmtSystem::pwd ();
|
---|
| 212 | if (!CmtSystem::cd (compressed_path)) return (0);
|
---|
| 213 | cmt_string pwd = CmtSystem::pwd ();
|
---|
| 214 |
|
---|
[2] | 215 | static Project::ProjectVector& Projects = Project::projects ();
|
---|
[79] | 216 |
|
---|
| 217 | int i;
|
---|
[2] | 218 |
|
---|
[79] | 219 | for (i = 0; i < Projects.size (); i++)
|
---|
[2] | 220 | {
|
---|
| 221 | Project& p = Projects[i];
|
---|
| 222 |
|
---|
[9] | 223 | if ((p.get_cmtpath () == compressed_path) ||
|
---|
[39] | 224 | (p.get_cmtpath_pwd () == pwd) ||
|
---|
[18] | 225 | (specify_name && (p.get_name () == specified_name)))
|
---|
[9] | 226 | {
|
---|
[18] | 227 | cmt_string r;
|
---|
[36] | 228 | cmt_string n;
|
---|
[18] | 229 |
|
---|
[36] | 230 | get_release_from_path (items, compressed_path, p.get_name (), n, r);
|
---|
[18] | 231 |
|
---|
| 232 | if (r != p.get_release ())
|
---|
| 233 | {
|
---|
[36] | 234 | cerr << "#CMT> Project " << p.get_name ()
|
---|
| 235 | << " requested with conflicting releases " << p.get_release () << " and " << r << endl;
|
---|
[18] | 236 | CmtError::set (CmtError::project_release_conflict, p.get_name ());
|
---|
| 237 | }
|
---|
| 238 |
|
---|
[9] | 239 | if (parent != 0)
|
---|
| 240 | {
|
---|
| 241 | p.add_parent (parent);
|
---|
| 242 | parent->add_child (&p);
|
---|
[16] | 243 |
|
---|
| 244 | // Since p is a new parent, we should propagate the settings UP.
|
---|
| 245 |
|
---|
| 246 | parent->update_strategies_from_children ();
|
---|
[9] | 247 | }
|
---|
[16] | 248 |
|
---|
[39] | 249 | CmtSystem::cd (here);
|
---|
[9] | 250 | return (&p);
|
---|
| 251 | }
|
---|
[2] | 252 | }
|
---|
[18] | 253 |
|
---|
| 254 |
|
---|
[2] | 255 | Project* project = 0;
|
---|
| 256 | Project* cmt = 0;
|
---|
| 257 |
|
---|
| 258 | bool is_current = false;
|
---|
| 259 |
|
---|
[24] | 260 | cmt_string name = specified_name;
|
---|
[36] | 261 | cmt_string project_name;
|
---|
[8] | 262 | cmt_string release;
|
---|
| 263 |
|
---|
[272] | 264 |
|
---|
[3] | 265 | //
|
---|
| 266 | // Figure out if this is the current project
|
---|
| 267 | //
|
---|
[2] | 268 | if (here.find (pwd) == 0) is_current = true;
|
---|
| 269 |
|
---|
| 270 | cmt_string text;
|
---|
| 271 |
|
---|
[3] | 272 | /*
|
---|
| 273 | Now Figure out the project name from the project file
|
---|
[15] | 274 | or does not specify the project name
|
---|
[3] | 275 | */
|
---|
[36] | 276 | bool has_project_file = false;
|
---|
| 277 |
|
---|
[2] | 278 | if (CmtSystem::cd ("cmt") && CmtSystem::test_file (Project::get_project_file_name ()))
|
---|
| 279 | {
|
---|
[36] | 280 | has_project_file = true;
|
---|
[2] | 281 | text.read (Project::get_project_file_name ());
|
---|
| 282 |
|
---|
| 283 | ProjectReader reader;
|
---|
| 284 |
|
---|
| 285 | reader.run (text);
|
---|
| 286 |
|
---|
[36] | 287 | project_name = reader.get_project_name ();
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | enum
|
---|
| 291 | {
|
---|
| 292 | without_project_file = 0x01,
|
---|
| 293 | with_project_file = 0x02,
|
---|
| 294 | without_project_name = 0x04,
|
---|
| 295 | with_project_name = 0x08,
|
---|
| 296 | without_specified_name = 0x10,
|
---|
| 297 | with_specified_name = 0x20,
|
---|
| 298 | names_mismatch = 0x40,
|
---|
| 299 | names_match = 0x80
|
---|
| 300 | };
|
---|
| 301 |
|
---|
| 302 | int status = ((has_project_file) ? with_project_file : without_project_file) |
|
---|
| 303 | ((has_project_file && (project_name != "")) ? with_project_name : without_project_name) |
|
---|
| 304 | ((specify_name) ? with_specified_name : without_specified_name) |
|
---|
| 305 | ((specify_name && has_project_file && (project_name == specified_name)) ? names_match : names_mismatch);
|
---|
| 306 |
|
---|
| 307 | if (source == "default path")
|
---|
| 308 | {
|
---|
| 309 | name = "CMT";
|
---|
| 310 | }
|
---|
| 311 | else
|
---|
| 312 | {
|
---|
| 313 | cmt_string n;
|
---|
| 314 |
|
---|
| 315 | switch (status)
|
---|
[2] | 316 | {
|
---|
[36] | 317 | case with_project_file | without_project_name | without_specified_name | names_mismatch:
|
---|
| 318 |
|
---|
| 319 | // The project is neither specified from the caller nor from the project file
|
---|
| 320 |
|
---|
| 321 | /*
|
---|
| 322 | if (!Cmt::get_quiet ())
|
---|
[18] | 323 | {
|
---|
[36] | 324 | cerr << "#CMT> Warning: project name unspecified in project file." << endl;
|
---|
| 325 | }
|
---|
| 326 | */
|
---|
| 327 |
|
---|
| 328 | get_release_from_path (items, compressed_path, "", name, release);
|
---|
[18] | 329 |
|
---|
[36] | 330 | break;
|
---|
| 331 |
|
---|
| 332 | case with_project_file | without_project_name | with_specified_name | names_mismatch:
|
---|
| 333 |
|
---|
| 334 | // The name is only specified from the caller
|
---|
| 335 | // find this specified name in the path
|
---|
| 336 |
|
---|
| 337 | if (get_release_from_path (items, compressed_path, specified_name, name, release))
|
---|
| 338 | {
|
---|
| 339 | // The specified name has been found from the path.
|
---|
| 340 | // We believe in the release spec.
|
---|
| 341 | }
|
---|
| 342 | else
|
---|
| 343 | {
|
---|
| 344 | // The specified name is not in the path.
|
---|
[38] | 345 | /*
|
---|
[23] | 346 | if (!Cmt::get_quiet ())
|
---|
| 347 | {
|
---|
[36] | 348 | cerr << "#CMT> Warning: specified project name "
|
---|
| 349 | << specified_name
|
---|
| 350 | << " from the caller does not match path." << endl;
|
---|
[23] | 351 | }
|
---|
[38] | 352 | */
|
---|
| 353 | name = specified_name;
|
---|
[18] | 354 | }
|
---|
[36] | 355 |
|
---|
| 356 | break;
|
---|
| 357 |
|
---|
| 358 | case with_project_file | with_project_name | with_specified_name | names_match:
|
---|
| 359 |
|
---|
| 360 | // We have a double specification: from the caller and from the project file.
|
---|
| 361 | // And both specifications are consistent.
|
---|
| 362 |
|
---|
| 363 | if (get_release_from_path (items, compressed_path, specified_name, name, release))
|
---|
| 364 | {
|
---|
| 365 | // The specified name has been found from the path.
|
---|
| 366 | // We believe in the release spec.
|
---|
| 367 | }
|
---|
[18] | 368 | else
|
---|
| 369 | {
|
---|
[36] | 370 | // The specified name is not in the path.
|
---|
[38] | 371 | /*
|
---|
[36] | 372 | if (!Cmt::get_quiet ())
|
---|
[18] | 373 | {
|
---|
[36] | 374 | cerr << "#CMT> Warning: specified project name "
|
---|
| 375 | << specified_name
|
---|
| 376 | << " from project file and from caller does not match path." << endl;
|
---|
[18] | 377 | }
|
---|
[38] | 378 | */
|
---|
| 379 | name = specified_name;
|
---|
[18] | 380 | }
|
---|
[36] | 381 |
|
---|
| 382 | break;
|
---|
| 383 |
|
---|
| 384 | case with_project_file | with_project_name | with_specified_name | names_mismatch:
|
---|
| 385 |
|
---|
| 386 | // We have a double specification: from the caller and from the project file.
|
---|
| 387 | // Specifications are inconsistent!!
|
---|
| 388 |
|
---|
[151] | 389 | /*
|
---|
[36] | 390 | if (!Cmt::get_quiet ())
|
---|
[18] | 391 | {
|
---|
[36] | 392 | cerr << "#CMT> Warning: specified project name "
|
---|
| 393 | << specified_name
|
---|
| 394 | << " inconsistent with name "
|
---|
| 395 | << project_name
|
---|
| 396 | << " from project file." << endl;
|
---|
| 397 | }
|
---|
[151] | 398 | */
|
---|
[36] | 399 |
|
---|
| 400 | if (get_release_from_path (items, compressed_path, specified_name, n, release))
|
---|
| 401 | {
|
---|
| 402 | // name from caller wins.
|
---|
| 403 | }
|
---|
| 404 | else if (get_release_from_path (items, compressed_path, project_name, name, release))
|
---|
| 405 | {
|
---|
| 406 | // name from project file wins.
|
---|
| 407 | }
|
---|
| 408 | else
|
---|
| 409 | {
|
---|
| 410 | // The specified name is not in the path.
|
---|
| 411 |
|
---|
| 412 | if (!Cmt::get_quiet ())
|
---|
[18] | 413 | {
|
---|
[36] | 414 | cerr << "#CMT> Warning: none of specified project names "
|
---|
| 415 | << specified_name
|
---|
| 416 | << " from graph and "
|
---|
| 417 | << project_name
|
---|
| 418 | << " from project file 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 | without_specified_name | names_mismatch:
|
---|
| 427 |
|
---|
| 428 | // Project name is specified in the project file but not from the caller.
|
---|
| 429 |
|
---|
| 430 | if (get_release_from_path (items, compressed_path, project_name, name, release))
|
---|
[18] | 431 | {
|
---|
[36] | 432 | // The specified name has been found from the path.
|
---|
| 433 | // We believe in the release spec.
|
---|
[38] | 434 |
|
---|
[36] | 435 | }
|
---|
| 436 | else
|
---|
| 437 | {
|
---|
| 438 | // The specified name is not in the path.
|
---|
[18] | 439 |
|
---|
[23] | 440 | /*
|
---|
| 441 | if (!Cmt::get_quiet ())
|
---|
| 442 | {
|
---|
[36] | 443 | cerr << "#CMT> Warning: specified project name "
|
---|
| 444 | << project_name
|
---|
| 445 | << " from project file does not match path." << endl;
|
---|
[23] | 446 | }
|
---|
| 447 | */
|
---|
[38] | 448 |
|
---|
| 449 | name = project_name;
|
---|
[18] | 450 | }
|
---|
[36] | 451 |
|
---|
| 452 | break;
|
---|
| 453 |
|
---|
| 454 | case without_project_file | without_project_name | without_specified_name | names_mismatch:
|
---|
| 455 |
|
---|
| 456 | // The project is not specified from the caller and there is no project file
|
---|
| 457 | // This corresponds to the backward compatibility
|
---|
| 458 | // For the moment, assume /name/release/ structure where release is one level only
|
---|
| 459 |
|
---|
| 460 | /*
|
---|
| 461 | if (!Cmt::get_quiet ())
|
---|
| 462 | {
|
---|
| 463 | cerr << "#CMT> Warning: project name is not specified "
|
---|
| 464 | << " (no project file)." << endl;
|
---|
| 465 | }
|
---|
| 466 | */
|
---|
| 467 |
|
---|
| 468 | CmtSystem::basename (compressed_path, release);
|
---|
| 469 | CmtSystem::dirname (compressed_path, name);
|
---|
| 470 | CmtSystem::basename (name, name);
|
---|
[97] | 471 |
|
---|
| 472 | if (name == "")
|
---|
| 473 | {
|
---|
| 474 | name = release;
|
---|
| 475 | release = "";
|
---|
| 476 | }
|
---|
[36] | 477 |
|
---|
| 478 | break;
|
---|
| 479 |
|
---|
| 480 | case without_project_file | without_project_name | with_specified_name | names_mismatch:
|
---|
| 481 |
|
---|
| 482 | // The name is only specified from the caller
|
---|
| 483 | // find this specified name in the path
|
---|
| 484 |
|
---|
| 485 | if (get_release_from_path (items, compressed_path, specified_name, name, release))
|
---|
| 486 | {
|
---|
| 487 | // The specified name has been found from the path.
|
---|
| 488 | // We believe in the release spec.
|
---|
| 489 | }
|
---|
[18] | 490 | else
|
---|
| 491 | {
|
---|
[36] | 492 | // The specified name is not in the path.
|
---|
[38] | 493 | /*
|
---|
[36] | 494 | if (!Cmt::get_quiet ())
|
---|
[18] | 495 | {
|
---|
[36] | 496 | cerr << "#CMT> Warning: specified project name "
|
---|
| 497 | << specified_name
|
---|
| 498 | << " from project graph does not match path." << endl;
|
---|
[18] | 499 | }
|
---|
[38] | 500 | */
|
---|
| 501 | name = specified_name;
|
---|
[18] | 502 | }
|
---|
[36] | 503 |
|
---|
| 504 | break;
|
---|
[2] | 505 | }
|
---|
| 506 | }
|
---|
| 507 |
|
---|
[97] | 508 | if (name == "")
|
---|
| 509 | {
|
---|
| 510 | name = "Project";
|
---|
| 511 | }
|
---|
| 512 |
|
---|
[8] | 513 | project = Project::add (name, release);
|
---|
[36] | 514 |
|
---|
[9] | 515 | if (parent != 0)
|
---|
| 516 | {
|
---|
| 517 | project->add_parent (parent);
|
---|
| 518 | parent->add_child (project);
|
---|
[16] | 519 |
|
---|
[79] | 520 | // Since project is a new child, we should propagate the settings UP.
|
---|
[16] | 521 |
|
---|
| 522 | parent->update_strategies_from_children ();
|
---|
[9] | 523 | }
|
---|
[79] | 524 | else
|
---|
| 525 | {
|
---|
| 526 | // this project has no parent thus it should become the top project.
|
---|
| 527 | // Let's look for all projects without parent.
|
---|
| 528 | // they will become children of this project.
|
---|
[9] | 529 |
|
---|
[79] | 530 | for (i = 0; i < Projects.size (); i++)
|
---|
| 531 | {
|
---|
| 532 | Project* p = &(Projects[i]);
|
---|
| 533 | if (p->get_name () == name) continue;
|
---|
| 534 | if (!p->has_parents ())
|
---|
| 535 | {
|
---|
| 536 | project->add_child (p);
|
---|
| 537 | p->add_parent (project);
|
---|
| 538 | }
|
---|
| 539 | }
|
---|
| 540 |
|
---|
| 541 | // Since project is a new parent, we should upgrade its settings
|
---|
| 542 |
|
---|
| 543 | project->update_strategies_from_children ();
|
---|
| 544 | }
|
---|
| 545 |
|
---|
[2] | 546 | if (source == "default path")
|
---|
| 547 | {
|
---|
| 548 | cmt = project;
|
---|
| 549 | is_current = false;
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | project->set_cmtpath (compressed_path);
|
---|
| 553 | project->set_cmtpath_pwd (pwd);
|
---|
| 554 | project->set_cmtpath_source (source);
|
---|
| 555 |
|
---|
| 556 | if (is_current)
|
---|
| 557 | {
|
---|
[3] | 558 | //
|
---|
| 559 | // The current project defines a tag with its name
|
---|
| 560 | //
|
---|
| 561 |
|
---|
[2] | 562 | Tag* tag;
|
---|
| 563 |
|
---|
| 564 | tag = Tag::add (project->get_name (), PriorityConfig, "PROJECT", 0);
|
---|
| 565 | tag->mark ();
|
---|
| 566 | }
|
---|
| 567 |
|
---|
| 568 | if (text != "")
|
---|
| 569 | {
|
---|
[3] | 570 | // Last step is to parse the project file
|
---|
| 571 |
|
---|
[100] | 572 | if (Cmt::get_debug ())
|
---|
| 573 | {
|
---|
| 574 | cout << "About to parse project file [" << text << "]" << endl;
|
---|
| 575 | }
|
---|
| 576 |
|
---|
[2] | 577 | SyntaxParser::parse_project_file_text (text,
|
---|
| 578 | Project::get_project_file_name (),
|
---|
| 579 | project);
|
---|
| 580 | }
|
---|
| 581 |
|
---|
| 582 | CmtSystem::cd (here);
|
---|
[9] | 583 |
|
---|
| 584 | return (project);
|
---|
[2] | 585 | }
|
---|
| 586 |
|
---|
| 587 | /*----------------------------------------------------------*/
|
---|
| 588 | /* */
|
---|
| 589 | /* Operations on Projects */
|
---|
| 590 | /* */
|
---|
| 591 | /*----------------------------------------------------------*/
|
---|
| 592 |
|
---|
| 593 | //----------------------------------------------------------
|
---|
[79] | 594 | bool Project::create (const cmt_string& name,
|
---|
[22] | 595 | const cmt_string& release,
|
---|
| 596 | const cmt_string& path)
|
---|
[2] | 597 | {
|
---|
| 598 | cout << "------------------------------------------" << endl;
|
---|
[22] | 599 | cout << "Configuring environment for project " << name << " " << release;
|
---|
| 600 |
|
---|
| 601 | if (path != "")
|
---|
| 602 | {
|
---|
| 603 | cout << " in " << path;
|
---|
| 604 | }
|
---|
| 605 |
|
---|
| 606 | cout << endl;
|
---|
[2] | 607 | cout << "CMT version " << Cmt::get_cmt_version () << "." << endl;
|
---|
| 608 | cout << "------------------------------------------" << endl;
|
---|
| 609 |
|
---|
[22] | 610 | if (path != "")
|
---|
| 611 | {
|
---|
| 612 | if (!CmtSystem::mkdir (path))
|
---|
| 613 | {
|
---|
| 614 | cout << "Cannot create the " << path << " directory" << endl;
|
---|
[79] | 615 | return (false);
|
---|
[22] | 616 | }
|
---|
| 617 |
|
---|
| 618 | if (!CmtSystem::cd (path))
|
---|
| 619 | {
|
---|
| 620 | cout << "Cannot access the " << path << " directory" << endl;
|
---|
[79] | 621 | return (false);
|
---|
[22] | 622 | }
|
---|
| 623 | }
|
---|
| 624 |
|
---|
| 625 | if (!CmtSystem::mkdir (name))
|
---|
| 626 | {
|
---|
| 627 | cout << "Cannot create the " << name << " directory" << endl;
|
---|
[79] | 628 | return (false);
|
---|
[22] | 629 | }
|
---|
| 630 |
|
---|
| 631 | if (!CmtSystem::cd (name))
|
---|
| 632 | {
|
---|
| 633 | cout << "Cannot access the " << name << " directory" << endl;
|
---|
[79] | 634 | return (false);
|
---|
[22] | 635 | }
|
---|
| 636 |
|
---|
| 637 | if (release != "")
|
---|
| 638 | {
|
---|
| 639 | if (!CmtSystem::mkdir (release))
|
---|
| 640 | {
|
---|
| 641 | cout << "Cannot create the " << release << " directory" << endl;
|
---|
[79] | 642 | return (false);
|
---|
[22] | 643 | }
|
---|
| 644 |
|
---|
| 645 | if (!CmtSystem::cd (release))
|
---|
| 646 | {
|
---|
| 647 | cout << "Cannot access the " << release << " directory" << endl;
|
---|
[79] | 648 | return (false);
|
---|
[22] | 649 | }
|
---|
| 650 | }
|
---|
| 651 |
|
---|
[2] | 652 | if (!CmtSystem::test_directory ("cmt"))
|
---|
| 653 | {
|
---|
| 654 | if (!CmtSystem::mkdir ("cmt"))
|
---|
| 655 | {
|
---|
| 656 | cout << "Cannot create the cmt directory" << endl;
|
---|
[79] | 657 | return (false);
|
---|
[2] | 658 | }
|
---|
| 659 | else
|
---|
| 660 | {
|
---|
| 661 | cout << "Installing the cmt directory" << endl;
|
---|
| 662 | }
|
---|
| 663 | }
|
---|
| 664 |
|
---|
| 665 | CmtSystem::cd ("cmt");
|
---|
| 666 |
|
---|
| 667 | if (!CmtSystem::test_file (get_project_file_name ()))
|
---|
| 668 | {
|
---|
| 669 | cout << "Creating a new project file" << endl;
|
---|
| 670 |
|
---|
| 671 | ofstream f (get_project_file_name ());
|
---|
| 672 | if (f)
|
---|
| 673 | {
|
---|
| 674 | f << "project " << name << endl;
|
---|
| 675 | f << endl;
|
---|
| 676 | f.close ();
|
---|
| 677 | }
|
---|
[79] | 678 | else
|
---|
| 679 | {
|
---|
| 680 | cout << "Cannot create the project file" << endl;
|
---|
| 681 | return (false);
|
---|
| 682 | }
|
---|
[2] | 683 | }
|
---|
| 684 | else
|
---|
| 685 | {
|
---|
| 686 | cmt_string text;
|
---|
| 687 | text.read (get_project_file_name ());
|
---|
| 688 |
|
---|
| 689 | ProjectPatcher p (name);
|
---|
| 690 |
|
---|
| 691 | p.run (text);
|
---|
| 692 | p.commit ();
|
---|
| 693 |
|
---|
| 694 | cout << "project file already there" << endl;
|
---|
| 695 | }
|
---|
[79] | 696 |
|
---|
| 697 | return (true);
|
---|
[2] | 698 | }
|
---|
| 699 |
|
---|
| 700 | //----------------------------------------------------------
|
---|
| 701 | Project* Project::find_by_name (const cmt_string& name)
|
---|
| 702 | {
|
---|
| 703 | static ProjectVector& Projects = projects ();
|
---|
| 704 |
|
---|
| 705 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 706 | {
|
---|
| 707 | Project& p = Projects[i];
|
---|
| 708 | if (p.m_name == name) return (&p);
|
---|
[273] | 709 |
|
---|
[2] | 710 | }
|
---|
| 711 |
|
---|
| 712 | return (0);
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | //----------------------------------------------------------
|
---|
| 716 | Project* Project::find_by_cmtpath (const cmt_string& cmtpath)
|
---|
| 717 | {
|
---|
| 718 | cmt_string compressed_path = cmtpath;
|
---|
| 719 | CmtSystem::compress_path (compressed_path);
|
---|
| 720 |
|
---|
| 721 | static ProjectVector& Projects = projects ();
|
---|
| 722 |
|
---|
| 723 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 724 | {
|
---|
| 725 | Project& p = Projects[i];
|
---|
| 726 |
|
---|
| 727 | if (p.m_cmtpath == compressed_path) return (&p);
|
---|
| 728 | if (p.m_cmtpath_pwd == compressed_path) return (&p);
|
---|
| 729 | }
|
---|
| 730 |
|
---|
| 731 | return (0);
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | //----------------------------------------------------------
|
---|
| 735 | Project* Project::get_current ()
|
---|
| 736 | {
|
---|
| 737 | cmt_string here = CmtSystem::pwd ();
|
---|
| 738 |
|
---|
| 739 | static ProjectVector& Projects = projects ();
|
---|
| 740 |
|
---|
| 741 | Project* result = 0;
|
---|
| 742 |
|
---|
| 743 | for (int i = (Projects.size () - 1); i >= 0; i--)
|
---|
| 744 | {
|
---|
| 745 | Project& p = Projects[i];
|
---|
| 746 |
|
---|
| 747 | if (here.find (p.m_cmtpath_pwd) == 0)
|
---|
| 748 | {
|
---|
| 749 | result = &p;
|
---|
| 750 | }
|
---|
| 751 |
|
---|
| 752 | if (here.find (p.m_cmtpath) == 0)
|
---|
| 753 | {
|
---|
| 754 | result = &p;
|
---|
| 755 | }
|
---|
| 756 | }
|
---|
| 757 |
|
---|
| 758 | return (result);
|
---|
| 759 | }
|
---|
| 760 |
|
---|
| 761 | //----------------------------------------------------------
|
---|
[8] | 762 | Project* Project::add (const cmt_string& name,
|
---|
| 763 | const cmt_string& release)
|
---|
[2] | 764 | {
|
---|
| 765 | static ProjectVector& Projects = projects ();
|
---|
| 766 |
|
---|
| 767 | //cout << "Project::add> name=" << name << endl;
|
---|
| 768 |
|
---|
| 769 | {
|
---|
| 770 | Project* project;
|
---|
| 771 |
|
---|
| 772 | project = find_by_name (name);
|
---|
| 773 | if (project != 0)
|
---|
| 774 | {
|
---|
[8] | 775 | if (!Cmt::get_quiet ())
|
---|
| 776 | {
|
---|
| 777 | if (release != project->get_release ())
|
---|
| 778 | {
|
---|
| 779 | cerr << "#CMT> Project " << name << " requested with conflicting releases " << project->get_release () << " and " << release << endl;
|
---|
| 780 | CmtError::set (CmtError::project_release_conflict, name);
|
---|
| 781 | }
|
---|
| 782 | }
|
---|
| 783 |
|
---|
| 784 | // Project objects are recreated here to follow the hierarchy
|
---|
| 785 | // This duplication is needed for properly applying the strategies
|
---|
[2] | 786 | Project& p = Projects.add ();
|
---|
| 787 |
|
---|
| 788 | p.set_name (name);
|
---|
[8] | 789 | p.set_release (release);
|
---|
[10] | 790 | p.configure ();
|
---|
[2] | 791 |
|
---|
| 792 | return (&p);
|
---|
[8] | 793 |
|
---|
| 794 | //return (project);
|
---|
[2] | 795 | }
|
---|
| 796 | }
|
---|
| 797 |
|
---|
| 798 | Project& project = Projects.add ();
|
---|
[16] | 799 | project.clear ();
|
---|
[2] | 800 | project.set_name (name);
|
---|
[8] | 801 | project.set_release (release);
|
---|
[10] | 802 | project.configure ();
|
---|
[2] | 803 |
|
---|
| 804 | return (&project);
|
---|
| 805 | }
|
---|
| 806 |
|
---|
| 807 | //----------------------------------------------------------
|
---|
| 808 | Project::ProjectVector& Project::projects ()
|
---|
| 809 | {
|
---|
| 810 | static Database& db = Database::instance ();
|
---|
| 811 | static ProjectVector& Projects = db.projects ();
|
---|
| 812 |
|
---|
| 813 | return (Projects);
|
---|
| 814 | }
|
---|
| 815 |
|
---|
| 816 | /*----------------------------------------------------------*/
|
---|
| 817 | void Project::clear_all ()
|
---|
| 818 | {
|
---|
| 819 | static ProjectVector& Projects = projects ();
|
---|
| 820 |
|
---|
| 821 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 822 | {
|
---|
| 823 | Project& project = Projects[i];
|
---|
| 824 | project.clear ();
|
---|
| 825 | }
|
---|
| 826 |
|
---|
| 827 | Projects.clear ();
|
---|
| 828 | }
|
---|
| 829 |
|
---|
| 830 | /*----------------------------------------------------------*/
|
---|
| 831 | void Project::show_all ()
|
---|
| 832 | {
|
---|
[9] | 833 | static Project::ProjectVector& Projects = Project::projects ();
|
---|
| 834 |
|
---|
| 835 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 836 | {
|
---|
| 837 | Project& p = Projects[i];
|
---|
| 838 | p.m_visited = false;
|
---|
| 839 | }
|
---|
| 840 |
|
---|
[78] | 841 | Project* p = get_current ();
|
---|
[9] | 842 |
|
---|
[78] | 843 | if (p == 0)
|
---|
| 844 | {
|
---|
| 845 | if (Projects.size () == 0) return;
|
---|
| 846 |
|
---|
| 847 | p = &(Projects[0]);
|
---|
| 848 | }
|
---|
| 849 |
|
---|
| 850 | p->show ();
|
---|
[2] | 851 | }
|
---|
| 852 |
|
---|
[16] | 853 | /*----------------------------------------------------------*/
|
---|
| 854 | void Project::show_specified_strategies_for_all ()
|
---|
| 855 | {
|
---|
| 856 | static ProjectVector& Projects = projects ();
|
---|
| 857 |
|
---|
| 858 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 859 | {
|
---|
| 860 | const Project& project = Projects[i];
|
---|
| 861 | project.show_specified_strategies ();
|
---|
| 862 | }
|
---|
| 863 | }
|
---|
| 864 |
|
---|
| 865 | /*----------------------------------------------------------*/
|
---|
[9] | 866 | class VisitorForShowPaths : public IProjectVisitor
|
---|
[2] | 867 | {
|
---|
[9] | 868 | public:
|
---|
| 869 | VisitorForShowPaths ()
|
---|
| 870 | {
|
---|
| 871 | }
|
---|
[2] | 872 |
|
---|
[9] | 873 | void pre (Project* p)
|
---|
| 874 | {
|
---|
| 875 | const cmt_string& w = p->get_cmtpath_pwd ();
|
---|
| 876 | const cmt_string& s = p->get_cmtpath_source ();
|
---|
[2] | 877 |
|
---|
[9] | 878 | if (s == "default path") return;
|
---|
[2] | 879 |
|
---|
[9] | 880 | if (CmtSystem::test_directory (w))
|
---|
| 881 | {
|
---|
| 882 | cout << "# Add path " << w << " from " << s << endl;
|
---|
| 883 | }
|
---|
| 884 | }
|
---|
[2] | 885 |
|
---|
[9] | 886 | void in (Project* p)
|
---|
| 887 | {
|
---|
| 888 | const cmt_string& w = p->get_cmtpath_pwd ();
|
---|
| 889 | const cmt_string& s = p->get_cmtpath_source ();
|
---|
[2] | 890 |
|
---|
[9] | 891 | if (s == "default path") return;
|
---|
[2] | 892 |
|
---|
[9] | 893 | if (CmtSystem::test_directory (w))
|
---|
| 894 | {
|
---|
| 895 | cout << "# Add path " << w << " from " << s << endl;
|
---|
| 896 | }
|
---|
| 897 | }
|
---|
| 898 |
|
---|
| 899 | void post (Project* p)
|
---|
| 900 | {
|
---|
| 901 | }
|
---|
| 902 | };
|
---|
| 903 |
|
---|
| 904 | /*----------------------------------------------------------*/
|
---|
| 905 | void Project::show_paths ()
|
---|
| 906 | {
|
---|
| 907 | VisitorForShowPaths visitor;
|
---|
| 908 |
|
---|
| 909 | start_visit (visitor);
|
---|
[2] | 910 | }
|
---|
| 911 |
|
---|
| 912 | //----------------------------------------------------------
|
---|
| 913 | const cmt_string& Project::get_project_file_name ()
|
---|
| 914 | {
|
---|
| 915 | static const cmt_string name = "project.cmt";
|
---|
| 916 |
|
---|
| 917 | return (name);
|
---|
| 918 | }
|
---|
| 919 |
|
---|
| 920 | //----------------------------------------------------------
|
---|
| 921 | void Project::fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections)
|
---|
| 922 | {
|
---|
| 923 | static ProjectVector& Projects = projects ();
|
---|
| 924 |
|
---|
| 925 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 926 | {
|
---|
| 927 | Project& project = Projects[i];
|
---|
| 928 |
|
---|
| 929 | const cmt_string& p = project.get_cmtpath ();
|
---|
| 930 | const cmt_string& pwd = project.get_cmtpath_pwd ();
|
---|
| 931 | const cmt_string& src = project.get_cmtpath_source ();
|
---|
| 932 |
|
---|
| 933 | if (src != "default path")
|
---|
| 934 | {
|
---|
| 935 | if (depth > 0)
|
---|
| 936 | {
|
---|
| 937 | cmt_string& s1 = path_selections.add ();
|
---|
| 938 | s1 = p;
|
---|
| 939 | cmt_string& s2 = path_selections.add ();
|
---|
| 940 | s2 = pwd;
|
---|
| 941 | depth--;
|
---|
| 942 |
|
---|
| 943 | if (depth == 0) break;
|
---|
| 944 | }
|
---|
| 945 | }
|
---|
| 946 | }
|
---|
| 947 | }
|
---|
| 948 |
|
---|
| 949 | //----------------------------------------------------------
|
---|
| 950 | void Project::broadcast (IProjectAction& action)
|
---|
| 951 | {
|
---|
| 952 | static ProjectVector& Projects = projects ();
|
---|
| 953 |
|
---|
| 954 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 955 | {
|
---|
| 956 | const Project& project = Projects[i];
|
---|
| 957 |
|
---|
| 958 | if (!action.run (project)) break;
|
---|
| 959 | }
|
---|
| 960 | }
|
---|
| 961 |
|
---|
| 962 | //----------------------------------------------------------
|
---|
| 963 | void Project::reverse_broadcast (IProjectAction& action)
|
---|
| 964 | {
|
---|
| 965 | static ProjectVector& Projects = projects ();
|
---|
| 966 |
|
---|
| 967 | for (int i = (Projects.size () - 1); i >= 0; i--)
|
---|
| 968 | {
|
---|
| 969 | const Project& project = Projects[i];
|
---|
| 970 |
|
---|
| 971 | if (!action.run (project)) break;
|
---|
| 972 | }
|
---|
| 973 | }
|
---|
| 974 |
|
---|
| 975 | //----------------------------------------------------------
|
---|
| 976 | void Project::scan_paths (PathScanner& scanner, PathScanner::actor& a)
|
---|
| 977 | {
|
---|
| 978 | static ProjectVector& Projects = projects ();
|
---|
| 979 |
|
---|
[79] | 980 | int i;
|
---|
| 981 |
|
---|
| 982 | for (i = 0; i < Projects.size (); i++)
|
---|
[2] | 983 | {
|
---|
[138] | 984 | Project& p = Projects[i];
|
---|
[79] | 985 | p.m_visited = false;
|
---|
| 986 | }
|
---|
| 987 |
|
---|
| 988 | for (i = 0; i < Projects.size (); i++)
|
---|
| 989 | {
|
---|
[2] | 990 | const Project& project = Projects[i];
|
---|
[138] | 991 |
|
---|
[2] | 992 | const cmt_string& p = project.m_cmtpath;
|
---|
| 993 | scanner.scan_path (p, a);
|
---|
| 994 | }
|
---|
| 995 | }
|
---|
| 996 |
|
---|
| 997 | //----------------------------------------------------------
|
---|
| 998 | void Project::scan_paths_for_package (PathScanner& scanner, const cmt_string& name)
|
---|
| 999 | {
|
---|
| 1000 | static ProjectVector& Projects = projects ();
|
---|
| 1001 |
|
---|
| 1002 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 1003 | {
|
---|
| 1004 | const Project& project = Projects[i];
|
---|
| 1005 |
|
---|
| 1006 | const cmt_string& p = project.m_cmtpath;
|
---|
| 1007 | scanner.scan_package (p, name);
|
---|
| 1008 | }
|
---|
| 1009 | }
|
---|
| 1010 |
|
---|
| 1011 | //----------------------------------------------------------
|
---|
| 1012 | cmt_string Project::find_in_cmt_paths (const cmt_string& path)
|
---|
| 1013 | {
|
---|
| 1014 | const cmt_string pwd = CmtSystem::pwd ();
|
---|
| 1015 |
|
---|
| 1016 | static ProjectVector& Projects = projects ();
|
---|
| 1017 |
|
---|
| 1018 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 1019 | {
|
---|
| 1020 | const Project& project = Projects[i];
|
---|
| 1021 |
|
---|
| 1022 | const cmt_string& p = project.m_cmtpath;
|
---|
| 1023 | const cmt_string& w = project.m_cmtpath_pwd;
|
---|
| 1024 | const cmt_string& s = project.m_cmtpath_source;
|
---|
| 1025 |
|
---|
| 1026 | if (s == "default path") continue;
|
---|
| 1027 |
|
---|
| 1028 | if (CmtSystem::test_directory (p))
|
---|
| 1029 | {
|
---|
| 1030 | if (path.find (p) != cmt_string::npos)
|
---|
| 1031 | {
|
---|
| 1032 | return (p);
|
---|
| 1033 | }
|
---|
| 1034 |
|
---|
| 1035 | // To become the current area, a path must correspond to the current package
|
---|
| 1036 | if (path.find (w) != cmt_string::npos)
|
---|
| 1037 | {
|
---|
| 1038 | return (p);
|
---|
| 1039 | }
|
---|
| 1040 | }
|
---|
| 1041 |
|
---|
| 1042 | if (p == w) continue;
|
---|
| 1043 |
|
---|
| 1044 | if (CmtSystem::test_directory (w))
|
---|
| 1045 | {
|
---|
| 1046 | if (path.find (w) != cmt_string::npos)
|
---|
| 1047 | {
|
---|
| 1048 | return (w);
|
---|
| 1049 | }
|
---|
| 1050 | }
|
---|
| 1051 | }
|
---|
| 1052 |
|
---|
| 1053 | return ("");
|
---|
| 1054 | }
|
---|
| 1055 |
|
---|
| 1056 | //----------------------------------------------------------
|
---|
[9] | 1057 | void Project::visit (IProjectVisitor& visitor)
|
---|
[3] | 1058 | {
|
---|
[9] | 1059 | if (m_visited) return;
|
---|
| 1060 | m_visited = true;
|
---|
[3] | 1061 |
|
---|
[9] | 1062 | int i;
|
---|
[3] | 1063 |
|
---|
[9] | 1064 | for (i = 0; i < get_children_size (); i++)
|
---|
[3] | 1065 | {
|
---|
[9] | 1066 | Project* child = get_child (i);
|
---|
[3] | 1067 |
|
---|
[9] | 1068 | if (child->visited ()) continue;
|
---|
[3] | 1069 |
|
---|
[9] | 1070 | visitor.in (child);
|
---|
| 1071 | }
|
---|
[3] | 1072 |
|
---|
[9] | 1073 | for (i = 0; i < m_children.size (); i++)
|
---|
| 1074 | {
|
---|
| 1075 | Project* child = m_children[i];
|
---|
| 1076 | child->visit (visitor);
|
---|
[3] | 1077 | }
|
---|
| 1078 | }
|
---|
| 1079 |
|
---|
| 1080 | //----------------------------------------------------------
|
---|
[9] | 1081 | void Project::start_visit (IProjectVisitor& visitor)
|
---|
[2] | 1082 | {
|
---|
[9] | 1083 | static Project::ProjectVector& Projects = Project::projects ();
|
---|
| 1084 |
|
---|
| 1085 | for (int i = 0; i < Projects.size (); i++)
|
---|
| 1086 | {
|
---|
| 1087 | Project& p = Projects[i];
|
---|
| 1088 | p.m_visited = false;
|
---|
| 1089 | }
|
---|
| 1090 |
|
---|
| 1091 | Project* p = get_current ();
|
---|
| 1092 |
|
---|
[78] | 1093 | if (p == 0)
|
---|
| 1094 | {
|
---|
| 1095 | if (Projects.size () == 0) return;
|
---|
[9] | 1096 |
|
---|
[78] | 1097 | p = &(Projects[0]);
|
---|
| 1098 | }
|
---|
| 1099 |
|
---|
[9] | 1100 | visitor.pre (p);
|
---|
| 1101 | p->visit (visitor);
|
---|
| 1102 | visitor.post (p);
|
---|
| 1103 | }
|
---|
| 1104 |
|
---|
| 1105 | //----------------------------------------------------------
|
---|
| 1106 | class VisitorForFillCMTPATH : public IProjectVisitor
|
---|
| 1107 | {
|
---|
| 1108 | public:
|
---|
| 1109 | VisitorForFillCMTPATH (cmt_string& buffer) : m_buffer (buffer)
|
---|
| 1110 | {
|
---|
[78] | 1111 | buffer = "path CMTPATH \"\" \n";
|
---|
[9] | 1112 | }
|
---|
| 1113 |
|
---|
| 1114 | void pre (Project* p)
|
---|
| 1115 | {
|
---|
| 1116 | const cmt_string& w = p->get_cmtpath_pwd ();
|
---|
| 1117 | const cmt_string& s = p->get_cmtpath_source ();
|
---|
| 1118 |
|
---|
| 1119 | if (s == "default path") return;
|
---|
| 1120 |
|
---|
| 1121 | if (CmtSystem::test_directory (w))
|
---|
| 1122 | {
|
---|
| 1123 | m_buffer += "path_append CMTPATH \"";
|
---|
| 1124 | m_buffer += w;
|
---|
[79] | 1125 | m_buffer += "\" \n";
|
---|
[9] | 1126 | }
|
---|
| 1127 | }
|
---|
| 1128 |
|
---|
| 1129 | void in (Project* p)
|
---|
| 1130 | {
|
---|
| 1131 | const cmt_string& w = p->get_cmtpath_pwd ();
|
---|
| 1132 | const cmt_string& s = p->get_cmtpath_source ();
|
---|
| 1133 |
|
---|
| 1134 | if (s == "default path") return;
|
---|
| 1135 |
|
---|
| 1136 | if (CmtSystem::test_directory (w))
|
---|
| 1137 | {
|
---|
| 1138 | m_buffer += "path_append CMTPATH \"";
|
---|
| 1139 | m_buffer += w;
|
---|
[79] | 1140 | m_buffer += "\" \n";
|
---|
[9] | 1141 | }
|
---|
| 1142 | }
|
---|
| 1143 |
|
---|
| 1144 | void post (Project* p)
|
---|
| 1145 | {
|
---|
| 1146 | //cerr << "Buffer = " << m_buffer << endl;
|
---|
| 1147 | }
|
---|
| 1148 |
|
---|
| 1149 | private:
|
---|
| 1150 | cmt_string& m_buffer;
|
---|
| 1151 |
|
---|
| 1152 | };
|
---|
| 1153 |
|
---|
| 1154 | //----------------------------------------------------------
|
---|
| 1155 | void Project::fill_cmtpaths (cmt_string& buffer)
|
---|
| 1156 | {
|
---|
| 1157 | /*
|
---|
| 1158 | Try to re-create all CMTPATH items from project definitions.
|
---|
| 1159 | The goal is to generate CMTPATH even if this EV was not pre-set
|
---|
| 1160 | which is the case when CMTPROJECTPATH is only used
|
---|
| 1161 | */
|
---|
| 1162 |
|
---|
| 1163 | VisitorForFillCMTPATH visitor (buffer);
|
---|
| 1164 |
|
---|
| 1165 | start_visit (visitor);
|
---|
| 1166 | }
|
---|
| 1167 |
|
---|
| 1168 | //----------------------------------------------------------
|
---|
[272] | 1169 | Project::Project () : m_name (""), m_author("")
|
---|
[9] | 1170 | {
|
---|
[2] | 1171 | clear ();
|
---|
| 1172 | }
|
---|
| 1173 |
|
---|
| 1174 | //----------------------------------------------------------
|
---|
| 1175 | const cmt_string& Project::get_name () const
|
---|
| 1176 | {
|
---|
| 1177 | return (m_name);
|
---|
| 1178 | }
|
---|
| 1179 |
|
---|
| 1180 | //----------------------------------------------------------
|
---|
[8] | 1181 | const cmt_string& Project::get_release () const
|
---|
| 1182 | {
|
---|
| 1183 | return (m_release);
|
---|
| 1184 | }
|
---|
| 1185 |
|
---|
| 1186 | //----------------------------------------------------------
|
---|
[41] | 1187 | const cmt_string& Project::get_container () const
|
---|
| 1188 | {
|
---|
| 1189 | return (m_container);
|
---|
| 1190 | }
|
---|
| 1191 |
|
---|
| 1192 | //----------------------------------------------------------
|
---|
| 1193 | const cmt_string& Project::get_container_version () const
|
---|
| 1194 | {
|
---|
| 1195 | return (m_container_version);
|
---|
| 1196 | }
|
---|
| 1197 |
|
---|
| 1198 | //----------------------------------------------------------
|
---|
[2] | 1199 | const cmt_string& Project::get_cmtpath () const
|
---|
| 1200 | {
|
---|
| 1201 | return (m_cmtpath);
|
---|
| 1202 | }
|
---|
| 1203 |
|
---|
| 1204 | //----------------------------------------------------------
|
---|
| 1205 | const cmt_string& Project::get_cmtpath_pwd () const
|
---|
| 1206 | {
|
---|
| 1207 | return (m_cmtpath_pwd);
|
---|
| 1208 | }
|
---|
| 1209 |
|
---|
| 1210 | //----------------------------------------------------------
|
---|
| 1211 | const cmt_string& Project::get_cmtpath_source () const
|
---|
| 1212 | {
|
---|
| 1213 | return (m_cmtpath_source);
|
---|
| 1214 | }
|
---|
| 1215 |
|
---|
| 1216 | //----------------------------------------------------------
|
---|
[9] | 1217 | int Project::get_children_size () const
|
---|
| 1218 | {
|
---|
| 1219 | return (m_children.size ());
|
---|
| 1220 | }
|
---|
| 1221 |
|
---|
| 1222 | //----------------------------------------------------------
|
---|
| 1223 | Project* Project::get_child (int index) const
|
---|
| 1224 | {
|
---|
| 1225 | if (index < 0) return (0);
|
---|
| 1226 | if (index >= m_children.size ()) return (0);
|
---|
| 1227 | return (m_children[index]);
|
---|
| 1228 | }
|
---|
| 1229 |
|
---|
| 1230 | //----------------------------------------------------------
|
---|
| 1231 | bool Project::visited () const
|
---|
| 1232 | {
|
---|
| 1233 | return (m_visited);
|
---|
| 1234 | }
|
---|
| 1235 |
|
---|
| 1236 | //----------------------------------------------------------
|
---|
[2] | 1237 | void Project::set_name (const cmt_string& name)
|
---|
| 1238 | {
|
---|
| 1239 | m_name = name;
|
---|
| 1240 | }
|
---|
| 1241 |
|
---|
| 1242 | //----------------------------------------------------------
|
---|
[8] | 1243 | void Project::set_release (const cmt_string& release)
|
---|
| 1244 | {
|
---|
| 1245 | m_release = release;
|
---|
| 1246 | }
|
---|
| 1247 |
|
---|
| 1248 | //----------------------------------------------------------
|
---|
[41] | 1249 | void Project::set_container (const cmt_string& container)
|
---|
| 1250 | {
|
---|
| 1251 | m_container = container;
|
---|
| 1252 | }
|
---|
| 1253 |
|
---|
| 1254 | //----------------------------------------------------------
|
---|
| 1255 | void Project::set_container_version (const cmt_string& container_version)
|
---|
| 1256 | {
|
---|
| 1257 | m_container_version = container_version;
|
---|
| 1258 | }
|
---|
| 1259 |
|
---|
| 1260 | //----------------------------------------------------------
|
---|
[2] | 1261 | void Project::set_cmtpath (const cmt_string& path)
|
---|
| 1262 | {
|
---|
| 1263 | m_cmtpath = path;
|
---|
| 1264 | }
|
---|
| 1265 |
|
---|
| 1266 | //----------------------------------------------------------
|
---|
| 1267 | void Project::set_cmtpath_pwd (const cmt_string& path)
|
---|
| 1268 | {
|
---|
| 1269 | m_cmtpath_pwd = path;
|
---|
| 1270 | }
|
---|
| 1271 |
|
---|
| 1272 | //----------------------------------------------------------
|
---|
| 1273 | void Project::set_cmtpath_source (const cmt_string& source)
|
---|
| 1274 | {
|
---|
| 1275 | m_cmtpath_source = source;
|
---|
| 1276 | }
|
---|
| 1277 |
|
---|
| 1278 | //----------------------------------------------------------
|
---|
| 1279 | void Project::clear ()
|
---|
| 1280 | {
|
---|
| 1281 | m_name = "";
|
---|
[8] | 1282 | m_release = "";
|
---|
[2] | 1283 | m_cmtpath = "";
|
---|
| 1284 | m_cmtpath_pwd = "";
|
---|
| 1285 | m_cmtpath_source = "";
|
---|
| 1286 |
|
---|
[9] | 1287 | m_parents.clear ();
|
---|
| 1288 | m_children.clear ();
|
---|
| 1289 |
|
---|
[2] | 1290 | m_configured = false;
|
---|
| 1291 |
|
---|
[15] | 1292 | m_strategies.clear ();
|
---|
[2] | 1293 | }
|
---|
| 1294 |
|
---|
| 1295 | //----------------------------------------------------------
|
---|
[79] | 1296 | bool Project::has_parents () const
|
---|
| 1297 | {
|
---|
| 1298 | return ((m_parents.size () > 0));
|
---|
| 1299 | }
|
---|
| 1300 |
|
---|
| 1301 | //----------------------------------------------------------
|
---|
[36] | 1302 | bool Project::has_parent (Project* p) const
|
---|
[9] | 1303 | {
|
---|
[36] | 1304 | if (p == 0) return (false);
|
---|
| 1305 | if (p == this) return (false);
|
---|
[9] | 1306 |
|
---|
[36] | 1307 | const cmt_string& name = p->get_name ();
|
---|
[16] | 1308 |
|
---|
[9] | 1309 | int i;
|
---|
| 1310 |
|
---|
[36] | 1311 | for (i = 0; i < m_parents.size (); i++)
|
---|
[9] | 1312 | {
|
---|
[36] | 1313 | const Project* parent = m_parents[i];
|
---|
| 1314 | if (parent == 0) continue;
|
---|
[9] | 1315 |
|
---|
[36] | 1316 | if (parent->get_name () == name)
|
---|
[9] | 1317 | {
|
---|
[36] | 1318 | // registered as a parent
|
---|
| 1319 | return (true);
|
---|
[9] | 1320 | }
|
---|
| 1321 |
|
---|
[36] | 1322 | if (parent->has_parent (p))
|
---|
[9] | 1323 | {
|
---|
[36] | 1324 | // recurse
|
---|
| 1325 | return (true);
|
---|
[9] | 1326 | }
|
---|
| 1327 | }
|
---|
| 1328 |
|
---|
[36] | 1329 | return (false);
|
---|
[9] | 1330 | }
|
---|
| 1331 |
|
---|
| 1332 | //----------------------------------------------------------
|
---|
[36] | 1333 | bool Project::has_child (Project* p) const
|
---|
[9] | 1334 | {
|
---|
[36] | 1335 | if (p == 0) return (false);
|
---|
| 1336 | if (p == this) return (false);
|
---|
[9] | 1337 |
|
---|
[36] | 1338 | const cmt_string& name = p->get_name ();
|
---|
| 1339 |
|
---|
[9] | 1340 | int i;
|
---|
| 1341 |
|
---|
[36] | 1342 | for (i = 0; i < m_children.size (); i++)
|
---|
[9] | 1343 | {
|
---|
[36] | 1344 | const Project* child = m_children[i];
|
---|
| 1345 | if (child == 0) continue;
|
---|
[9] | 1346 |
|
---|
[36] | 1347 | if (child->get_name () == name)
|
---|
[9] | 1348 | {
|
---|
[36] | 1349 | // registered as a child
|
---|
| 1350 | return (true);
|
---|
[9] | 1351 | }
|
---|
| 1352 |
|
---|
[36] | 1353 | if (child->has_child (p))
|
---|
[9] | 1354 | {
|
---|
[36] | 1355 | // recurse
|
---|
| 1356 | return (true);
|
---|
[9] | 1357 | }
|
---|
| 1358 | }
|
---|
| 1359 |
|
---|
[36] | 1360 | return (false);
|
---|
| 1361 | }
|
---|
| 1362 |
|
---|
| 1363 | //----------------------------------------------------------
|
---|
| 1364 | void Project::add_parent (Project* p)
|
---|
| 1365 | {
|
---|
| 1366 | if (p == 0) return;
|
---|
| 1367 | if (p == this) return;
|
---|
| 1368 |
|
---|
| 1369 | //cerr << "Adding parent " << p->get_name () << " to " << m_name << endl;
|
---|
| 1370 |
|
---|
| 1371 | if (has_child (p)) return;
|
---|
| 1372 | if (has_parent (p)) return;
|
---|
| 1373 |
|
---|
| 1374 | m_parents.push_back (p);
|
---|
| 1375 | }
|
---|
| 1376 |
|
---|
| 1377 | //----------------------------------------------------------
|
---|
| 1378 | void Project::add_child (Project* p)
|
---|
| 1379 | {
|
---|
| 1380 | if (p == 0) return;
|
---|
| 1381 | if (p == this) return;
|
---|
| 1382 |
|
---|
| 1383 | if (has_child (p)) return;
|
---|
| 1384 | if (has_parent (p)) return;
|
---|
| 1385 |
|
---|
[9] | 1386 | m_children.push_back (p);
|
---|
| 1387 | }
|
---|
| 1388 |
|
---|
| 1389 | //----------------------------------------------------------
|
---|
[2] | 1390 | void Project::configure ()
|
---|
| 1391 | {
|
---|
| 1392 | if (m_configured) return;
|
---|
| 1393 | m_configured = true;
|
---|
| 1394 |
|
---|
[15] | 1395 | set_default_strategy ("SetupConfig");
|
---|
| 1396 | set_default_strategy ("SetupRoot");
|
---|
| 1397 | set_default_strategy ("SetupCleanup");
|
---|
| 1398 | set_default_strategy ("BuildPrototypes");
|
---|
| 1399 | set_default_strategy ("InstallArea");
|
---|
[83] | 1400 | set_default_strategy ("VersionDirectory");
|
---|
[2] | 1401 | }
|
---|
| 1402 |
|
---|
[15] | 1403 | /**---------------------------------------------------------
|
---|
[41] | 1404 | A container statement is met in the project file
|
---|
| 1405 | */
|
---|
| 1406 | void Project::container_action (const cmt_string& name, const cmt_string& version)
|
---|
| 1407 | {
|
---|
| 1408 | //cerr << "Container action " << name << " " << version << endl;
|
---|
| 1409 |
|
---|
| 1410 | set_container (name);
|
---|
| 1411 | set_container_version (version);
|
---|
| 1412 | }
|
---|
| 1413 |
|
---|
| 1414 | /**---------------------------------------------------------
|
---|
[15] | 1415 | A use statement is met in the project file
|
---|
| 1416 | */
|
---|
[3] | 1417 | void Project::use_action (const cmt_string& name, const cmt_string& release)
|
---|
| 1418 | {
|
---|
[100] | 1419 | if (Cmt::get_debug ())
|
---|
| 1420 | {
|
---|
| 1421 | cout << "Use action " << name << " " << release << endl;
|
---|
| 1422 | }
|
---|
[3] | 1423 |
|
---|
| 1424 | // A project with its release is specified
|
---|
| 1425 | //
|
---|
| 1426 | // Is this project already visible?
|
---|
| 1427 | // If not: look for it
|
---|
| 1428 | // + get CMTPROJECTPATH
|
---|
[15] | 1429 | // + search from all entries of CMTPROJECTPATH : p(i)/<name>/<release>
|
---|
[3] | 1430 | // + when found, this should become a new CMTPATH entry
|
---|
| 1431 | // + the new project is then parsed ... etc...
|
---|
| 1432 |
|
---|
[273] | 1433 | // First test it wilcard is used
|
---|
| 1434 | int v = -1;
|
---|
| 1435 | int r = -1;
|
---|
| 1436 | int p = -1;
|
---|
| 1437 | cmt_string new_release = release;
|
---|
| 1438 | CmtSystem::is_version_directory (new_release, v, r, p);
|
---|
| 1439 | bool use_has_wild_card = (v == -1) || (r == -1) || (p == -1);
|
---|
| 1440 | if (use_has_wild_card)
|
---|
| 1441 | {
|
---|
| 1442 | cmt_string selected_release = "";
|
---|
| 1443 | if (select_release(name, new_release,selected_release))
|
---|
| 1444 | { // yes
|
---|
| 1445 | // cout <<"selected_release: "<<selected_release<<endl;
|
---|
| 1446 | new_release = selected_release;
|
---|
| 1447 | }
|
---|
| 1448 | }
|
---|
| 1449 |
|
---|
[136] | 1450 | cmt_string cmtprojectpath = Symbol::get_env_value ("CMTPROJECTPATH");
|
---|
[3] | 1451 | cmt_string sep;
|
---|
[15] | 1452 | sep = CmtSystem::path_separator ();
|
---|
[3] | 1453 |
|
---|
| 1454 | //cerr << "cmtprojectpath = " << cmtprojectpath << endl;
|
---|
| 1455 | CmtSystem::cmt_string_vector items;
|
---|
| 1456 | CmtSystem::split (cmtprojectpath, sep, items);
|
---|
[16] | 1457 |
|
---|
| 1458 | bool found = false;
|
---|
| 1459 |
|
---|
[3] | 1460 | for (int i = 0; i < items.size (); i++)
|
---|
| 1461 | {
|
---|
| 1462 | const cmt_string& item = items[i];
|
---|
| 1463 | cmt_string p = item;
|
---|
| 1464 | p += CmtSystem::file_separator ();
|
---|
| 1465 | p += name;
|
---|
[273] | 1466 | if (new_release != "")
|
---|
[100] | 1467 | {
|
---|
| 1468 | p += CmtSystem::file_separator ();
|
---|
[273] | 1469 | p += new_release;
|
---|
[100] | 1470 | }
|
---|
[3] | 1471 |
|
---|
[273] | 1472 | if (CmtSystem::test_directory (p))
|
---|
[3] | 1473 | {
|
---|
[15] | 1474 | //cerr << "Project directory " << p << " exists " << endl;
|
---|
[3] | 1475 |
|
---|
[16] | 1476 | found = true;
|
---|
| 1477 |
|
---|
[3] | 1478 | IProjectFactory& factory = ProjectFactory::instance ();
|
---|
| 1479 |
|
---|
[18] | 1480 | factory.create_project (name, p, "ProjectPath", this);
|
---|
[3] | 1481 |
|
---|
| 1482 | break;
|
---|
| 1483 | }
|
---|
| 1484 | }
|
---|
[16] | 1485 |
|
---|
| 1486 | if (!found)
|
---|
| 1487 | {
|
---|
| 1488 | Project* p = Project::find_by_name (name);
|
---|
| 1489 |
|
---|
| 1490 | if (p != 0)
|
---|
[273] | 1491 | {
|
---|
| 1492 | found = true;
|
---|
| 1493 | p->add_parent (this);
|
---|
| 1494 | add_child (p);
|
---|
[16] | 1495 |
|
---|
[273] | 1496 | update_strategies_from_children ();
|
---|
| 1497 | }
|
---|
[16] | 1498 | }
|
---|
[273] | 1499 |
|
---|
[16] | 1500 | if (!found && (cmtprojectpath != ""))
|
---|
| 1501 | {
|
---|
| 1502 | cerr << "#CMT> Project " << name << " " << release << " requested by " << m_name << " not found in CMTPROJECTPATH" << endl;
|
---|
| 1503 | }
|
---|
[3] | 1504 | }
|
---|
| 1505 |
|
---|
[273] | 1506 | //---------------------------------------------------------
|
---|
| 1507 | bool Project::select_release(const cmt_string& name, const cmt_string& release, cmt_string& result)
|
---|
| 1508 | {
|
---|
| 1509 | cmt_string selected_release = "";
|
---|
[3] | 1510 |
|
---|
[273] | 1511 | int v = -1;
|
---|
| 1512 | int r = -1;
|
---|
| 1513 | int p = -1;
|
---|
| 1514 | CmtSystem::is_version_directory (release, v, r, p);
|
---|
| 1515 |
|
---|
| 1516 | int selected_v = -1;
|
---|
| 1517 | int selected_r = -1;
|
---|
| 1518 | int selected_p = -1;
|
---|
| 1519 | CmtSystem::cmt_string_vector releases = get_project_releases(name);
|
---|
| 1520 | for (int j = 0; j < releases.size (); j++)
|
---|
| 1521 | {
|
---|
| 1522 | //cout <<releases[j]<<endl;
|
---|
| 1523 | int new_v = -1;
|
---|
| 1524 | int new_r = -1;
|
---|
| 1525 | int new_p = -1;
|
---|
| 1526 | CmtSystem::is_version_directory (releases[j], new_v, new_r, new_p);
|
---|
| 1527 | if (v == -1)
|
---|
| 1528 | {
|
---|
| 1529 | if (selected_v<new_v)
|
---|
| 1530 | {
|
---|
| 1531 | selected_v = new_v;
|
---|
| 1532 | selected_r = -1;
|
---|
| 1533 | selected_p = -1;
|
---|
| 1534 | selected_release = releases[j];
|
---|
| 1535 | }
|
---|
| 1536 | else if (selected_v==new_v)
|
---|
| 1537 | { // We compare the r
|
---|
| 1538 | if (selected_r<new_r)
|
---|
| 1539 | {
|
---|
| 1540 | selected_r = new_r;
|
---|
| 1541 | selected_p = -1;
|
---|
| 1542 | selected_release = releases[j];
|
---|
| 1543 | }
|
---|
| 1544 | else if (selected_r==new_r)
|
---|
| 1545 | { // We compare the p
|
---|
| 1546 | if (selected_p<new_p)
|
---|
| 1547 | {
|
---|
| 1548 | selected_p = new_p;
|
---|
| 1549 | selected_release = releases[j];
|
---|
| 1550 | }
|
---|
| 1551 | // else if ? not possible
|
---|
| 1552 | }
|
---|
| 1553 | }
|
---|
| 1554 | }
|
---|
| 1555 | else if (r == -1)
|
---|
| 1556 | {
|
---|
| 1557 | if (v==new_v)
|
---|
| 1558 | { // We compare the r
|
---|
| 1559 | if (selected_r<new_r)
|
---|
| 1560 | {
|
---|
| 1561 | selected_r = new_r;
|
---|
| 1562 | selected_p = -1;
|
---|
| 1563 | selected_release = releases[j];
|
---|
| 1564 | }
|
---|
| 1565 | else if (selected_r==new_r)
|
---|
| 1566 | { // We compare the p
|
---|
| 1567 | if (selected_p<new_p)
|
---|
| 1568 | {
|
---|
| 1569 | selected_p = new_p;
|
---|
| 1570 | selected_release = releases[j];
|
---|
| 1571 | }
|
---|
| 1572 | // else if ? not possible
|
---|
| 1573 | }
|
---|
| 1574 | }
|
---|
| 1575 | }
|
---|
| 1576 | else if (p == -1)
|
---|
| 1577 | {
|
---|
| 1578 | if (v==new_v && r==new_r)
|
---|
| 1579 | { // We compare the p
|
---|
| 1580 | if (selected_p<new_p)
|
---|
| 1581 | {
|
---|
| 1582 | selected_p = new_p;
|
---|
| 1583 | selected_release = releases[j];
|
---|
| 1584 | }
|
---|
| 1585 | // else if ? not possible
|
---|
| 1586 | }
|
---|
| 1587 | }
|
---|
| 1588 | //cerr<<"v:"<<new_v<<", r:"<<new_r<<", p:"<<new_p<<endl;
|
---|
| 1589 | //cerr<<"req v:"<<v<<", req r:"<<r<<", req p:"<<p<<endl;
|
---|
| 1590 | }
|
---|
| 1591 | //cerr <<"selected release: "<<selected_release<<endl;
|
---|
| 1592 | if (selected_release == "")
|
---|
| 1593 | return false;
|
---|
| 1594 | result = selected_release;
|
---|
| 1595 | return true;
|
---|
| 1596 | }
|
---|
| 1597 |
|
---|
| 1598 | //---------------------------------------------------------
|
---|
| 1599 | const CmtSystem::cmt_string_vector Project::get_project_releases(const cmt_string& name) const
|
---|
| 1600 | {
|
---|
| 1601 | CmtSystem::cmt_string_vector releases;
|
---|
| 1602 | cmt_string cmtprojectpath = Symbol::get_env_value ("CMTPROJECTPATH");
|
---|
| 1603 | cmt_string sep;
|
---|
| 1604 | sep = CmtSystem::path_separator ();
|
---|
| 1605 |
|
---|
| 1606 | CmtSystem::cmt_string_vector items;
|
---|
| 1607 | CmtSystem::split (cmtprojectpath, sep, items);
|
---|
| 1608 | for (int i = 0; i < items.size (); i++)
|
---|
| 1609 | {
|
---|
| 1610 | const cmt_string& item = items[i];
|
---|
| 1611 | cmt_string p = item;
|
---|
| 1612 | p += CmtSystem::file_separator ();
|
---|
| 1613 | p += name;
|
---|
| 1614 | if (CmtSystem::test_directory (p))
|
---|
| 1615 | {
|
---|
| 1616 | CmtSystem::cmt_string_vector directories;
|
---|
| 1617 | CmtSystem::scan_dir (p, directories);
|
---|
| 1618 | for (int j = 0; j < directories.size (); j++)
|
---|
| 1619 | {
|
---|
| 1620 | if (CmtSystem::test_directory(directories[j]))
|
---|
| 1621 | {
|
---|
| 1622 | cmt_string release;
|
---|
| 1623 | CmtSystem:: basename(directories[j], release);
|
---|
| 1624 | if (CmtSystem::is_version_directory(release))
|
---|
| 1625 | {
|
---|
| 1626 | cmt_string& name_entry = releases.add ();
|
---|
| 1627 | name_entry = release;
|
---|
| 1628 | //cout << release <<endl;
|
---|
| 1629 | }
|
---|
| 1630 | }
|
---|
| 1631 | }
|
---|
| 1632 | }
|
---|
| 1633 | }
|
---|
| 1634 | return (releases);
|
---|
| 1635 | }
|
---|
| 1636 |
|
---|
[3] | 1637 | //----------------------------------------------------------
|
---|
[2] | 1638 | Project& Project::operator = (const Project& other)
|
---|
| 1639 | {
|
---|
| 1640 | m_name = other.m_name;
|
---|
| 1641 | m_cmtpath = other.m_cmtpath;
|
---|
| 1642 | m_cmtpath_pwd = other.m_cmtpath_pwd;
|
---|
| 1643 | m_cmtpath_source = other.m_cmtpath_source;
|
---|
| 1644 |
|
---|
| 1645 | return (*this);
|
---|
| 1646 | }
|
---|
| 1647 |
|
---|
| 1648 | //----------------------------------------------------------
|
---|
| 1649 | bool Project::operator == (const cmt_string& name) const
|
---|
| 1650 | {
|
---|
| 1651 | return ((m_name == name));
|
---|
| 1652 | }
|
---|
| 1653 |
|
---|
| 1654 | //----------------------------------------------------------
|
---|
| 1655 | bool Project::operator != (const cmt_string& name) const
|
---|
| 1656 | {
|
---|
| 1657 | return ((m_name != name));
|
---|
| 1658 | }
|
---|
| 1659 |
|
---|
| 1660 | //----------------------------------------------------------
|
---|
[9] | 1661 | void Project::show ()
|
---|
[2] | 1662 | {
|
---|
[9] | 1663 | static int level = 0;
|
---|
| 1664 |
|
---|
[2] | 1665 | bool is_current = false;
|
---|
| 1666 |
|
---|
| 1667 | cmt_string here = CmtSystem::pwd ();
|
---|
| 1668 |
|
---|
| 1669 | if (here.find (m_cmtpath) == 0)
|
---|
| 1670 | {
|
---|
| 1671 | if (m_cmtpath_source != "default path")
|
---|
| 1672 | {
|
---|
| 1673 | is_current = true;
|
---|
| 1674 | }
|
---|
| 1675 | }
|
---|
| 1676 |
|
---|
[9] | 1677 | for (int tab = 0; tab < level; tab++) cout << " ";
|
---|
[8] | 1678 | cout << m_name << " " << m_release << " (in " << m_cmtpath << ")";
|
---|
[2] | 1679 |
|
---|
| 1680 | if (is_current) cout << " (current)";
|
---|
| 1681 |
|
---|
[9] | 1682 | int i;
|
---|
| 1683 |
|
---|
| 1684 | for (i = 0; i < m_parents.size (); i++)
|
---|
| 1685 | {
|
---|
| 1686 | Project* p = m_parents[i];
|
---|
| 1687 | if (p == 0) continue;
|
---|
| 1688 | cout << " P=" << p->get_name ();
|
---|
| 1689 | }
|
---|
| 1690 |
|
---|
| 1691 | for (i = 0; i < m_children.size (); i++)
|
---|
| 1692 | {
|
---|
| 1693 | Project* p = m_children[i];
|
---|
| 1694 | if (p == 0) continue;
|
---|
| 1695 | cout << " C=" << p->get_name ();
|
---|
| 1696 | }
|
---|
| 1697 |
|
---|
[2] | 1698 | cout << endl;
|
---|
[9] | 1699 |
|
---|
| 1700 | if (m_visited) return;
|
---|
| 1701 |
|
---|
| 1702 | m_visited = true;
|
---|
| 1703 |
|
---|
| 1704 | for (i = 0; i < m_children.size (); i++)
|
---|
| 1705 | {
|
---|
| 1706 | Project* p = m_children[i];
|
---|
| 1707 | if (p == 0) continue;
|
---|
| 1708 | level++;
|
---|
| 1709 | p->show ();
|
---|
| 1710 | level--;
|
---|
| 1711 | }
|
---|
[2] | 1712 | }
|
---|
| 1713 |
|
---|
| 1714 |
|
---|
| 1715 | //----------------------------------------------------------
|
---|
[16] | 1716 | void Project::show_specified_strategies () const
|
---|
[2] | 1717 | {
|
---|
[16] | 1718 | int i;
|
---|
| 1719 |
|
---|
| 1720 | for (i = 0; i < m_strategies.size (); i++)
|
---|
| 1721 | {
|
---|
| 1722 | const Strategy& s = m_strategies[i];
|
---|
| 1723 | if (s.m_specified)
|
---|
| 1724 | {
|
---|
| 1725 | const StrategyDef* def = s.m_definition;
|
---|
| 1726 |
|
---|
| 1727 | cout << "# Project " << m_name
|
---|
| 1728 | << " sets " << def->m_keyword
|
---|
| 1729 | << " strategy to " << ((s.m_value) ? def->m_on_value : def->m_off_value);
|
---|
| 1730 |
|
---|
| 1731 | if (s.m_context != "")
|
---|
| 1732 | {
|
---|
| 1733 | cout << " (from package " << s.m_context << ")";
|
---|
| 1734 | }
|
---|
| 1735 |
|
---|
| 1736 | cout << endl;
|
---|
| 1737 | }
|
---|
| 1738 | }
|
---|
[2] | 1739 | }
|
---|
| 1740 |
|
---|
| 1741 | //----------------------------------------------------------
|
---|
[15] | 1742 | bool Project::has_strategy (const StrategyDef* definition) const
|
---|
[2] | 1743 | {
|
---|
[10] | 1744 | int i;
|
---|
| 1745 |
|
---|
[15] | 1746 | for (i = 0; i < m_strategies.size (); i++)
|
---|
[10] | 1747 | {
|
---|
[15] | 1748 | const Strategy& s = m_strategies[i];
|
---|
| 1749 | if (s.m_definition == definition)
|
---|
[10] | 1750 | {
|
---|
[15] | 1751 | return (true);
|
---|
[10] | 1752 | }
|
---|
[15] | 1753 | }
|
---|
[10] | 1754 |
|
---|
[15] | 1755 | return (false);
|
---|
| 1756 | }
|
---|
[10] | 1757 |
|
---|
[15] | 1758 | //----------------------------------------------------------
|
---|
| 1759 | bool Project::get_strategy (const cmt_string& name) const
|
---|
| 1760 | {
|
---|
| 1761 | static StrategyMgr& mgr = StrategyMgr::instance ();
|
---|
[10] | 1762 |
|
---|
[15] | 1763 | StrategyDef* def = mgr.find_strategy (name);
|
---|
| 1764 | if (def == 0)
|
---|
[2] | 1765 | {
|
---|
[15] | 1766 | cerr << "#CMT> strategy " << name << " undefined" << endl;
|
---|
| 1767 | return (false);
|
---|
[2] | 1768 | }
|
---|
[15] | 1769 |
|
---|
| 1770 | return (get_strategy (def));
|
---|
| 1771 | }
|
---|
| 1772 |
|
---|
| 1773 | //----------------------------------------------------------
|
---|
| 1774 | bool Project::is_specified (const StrategyDef* definition) const
|
---|
| 1775 | {
|
---|
| 1776 | int i;
|
---|
| 1777 |
|
---|
| 1778 | for (i = 0; i < m_strategies.size (); i++)
|
---|
[10] | 1779 | {
|
---|
[15] | 1780 | Strategy& s = m_strategies[i];
|
---|
| 1781 | if (s.m_definition == definition)
|
---|
[10] | 1782 | {
|
---|
[15] | 1783 | // This strategy is applied in this project
|
---|
| 1784 | return (s.m_specified);
|
---|
[10] | 1785 | }
|
---|
[15] | 1786 | }
|
---|
[2] | 1787 |
|
---|
[15] | 1788 | // This strategy is not applied in this project
|
---|
| 1789 | return (false);
|
---|
| 1790 | }
|
---|
| 1791 |
|
---|
| 1792 | //----------------------------------------------------------
|
---|
| 1793 | bool Project::get_strategy (const StrategyDef* def) const
|
---|
| 1794 | {
|
---|
| 1795 | int i;
|
---|
| 1796 |
|
---|
| 1797 | for (i = 0; i < m_strategies.size (); i++)
|
---|
| 1798 | {
|
---|
| 1799 | Strategy& s = m_strategies[i];
|
---|
| 1800 | if (s.m_definition == def)
|
---|
[10] | 1801 | {
|
---|
[15] | 1802 | // This strategy is applied in this project
|
---|
| 1803 | if (s.m_specified)
|
---|
| 1804 | {
|
---|
| 1805 | return (s.m_specified_value);
|
---|
| 1806 | }
|
---|
| 1807 | return (s.m_value);
|
---|
[10] | 1808 | }
|
---|
| 1809 | }
|
---|
| 1810 |
|
---|
[15] | 1811 | // This strategy is not applied in this project
|
---|
| 1812 | return (def->m_default_value);
|
---|
[2] | 1813 | }
|
---|
| 1814 |
|
---|
| 1815 | //----------------------------------------------------------
|
---|
[15] | 1816 | void Project::set_default_strategy (const cmt_string& name)
|
---|
[2] | 1817 | {
|
---|
[15] | 1818 | static StrategyMgr& mgr = StrategyMgr::instance ();
|
---|
[2] | 1819 |
|
---|
[15] | 1820 | StrategyDef* def = mgr.find_strategy (name);
|
---|
| 1821 | if (def == 0)
|
---|
| 1822 | {
|
---|
| 1823 | cerr << "#CMT> strategy " << name << " undefined" << endl;
|
---|
| 1824 | return;
|
---|
| 1825 | }
|
---|
[2] | 1826 |
|
---|
[15] | 1827 | update_strategy (def, def->m_default_value);
|
---|
| 1828 | }
|
---|
[9] | 1829 |
|
---|
[15] | 1830 |
|
---|
| 1831 | //----------------------------------------------------------
|
---|
[16] | 1832 | void Project::set_strategy (const cmt_string& name, const cmt_string& value, const cmt_string& context)
|
---|
[15] | 1833 | {
|
---|
| 1834 | static StrategyMgr& mgr = StrategyMgr::instance ();
|
---|
| 1835 |
|
---|
| 1836 | StrategyDef* def = mgr.find_strategy (name);
|
---|
| 1837 | if (def == 0)
|
---|
[2] | 1838 | {
|
---|
[15] | 1839 | cerr << "#CMT> strategy " << name << " undefined" << endl;
|
---|
| 1840 | return;
|
---|
[2] | 1841 | }
|
---|
| 1842 |
|
---|
[15] | 1843 | bool b_value = false;
|
---|
| 1844 |
|
---|
| 1845 | if (value == def->m_on_value)
|
---|
| 1846 | {
|
---|
| 1847 | b_value = true;
|
---|
| 1848 | }
|
---|
| 1849 | else if (value == def->m_off_value)
|
---|
| 1850 | {
|
---|
| 1851 | b_value = false;
|
---|
| 1852 | }
|
---|
| 1853 | else
|
---|
| 1854 | {
|
---|
| 1855 | cerr << "#CMT> requested strategy value " << value << " undefined in strategy " << name << endl;
|
---|
| 1856 | return;
|
---|
| 1857 | }
|
---|
| 1858 |
|
---|
[16] | 1859 | set_strategy (def, b_value, context);
|
---|
[2] | 1860 | }
|
---|
| 1861 |
|
---|
| 1862 | //----------------------------------------------------------
|
---|
[16] | 1863 | void Project::set_strategy (StrategyDef* definition, bool b_value, const cmt_string& context)
|
---|
[2] | 1864 | {
|
---|
[15] | 1865 | bool need_strategy = true;
|
---|
[2] | 1866 |
|
---|
[15] | 1867 | int i;
|
---|
[2] | 1868 |
|
---|
[15] | 1869 | for (i = 0; i < m_strategies.size (); i++)
|
---|
| 1870 | {
|
---|
| 1871 | Strategy& s = m_strategies[i];
|
---|
| 1872 | if (s.m_definition == definition)
|
---|
| 1873 | {
|
---|
| 1874 | // This strategy is already applied in this project. Let's change it's value
|
---|
| 1875 | s.set (definition, b_value, get_name ());
|
---|
[16] | 1876 | if (context != "")
|
---|
| 1877 | {
|
---|
| 1878 | if (s.m_context != "") s.m_context += " ";
|
---|
| 1879 | s.m_context += context;
|
---|
| 1880 | }
|
---|
[15] | 1881 | need_strategy = false;
|
---|
| 1882 | break;
|
---|
| 1883 | }
|
---|
| 1884 | }
|
---|
[2] | 1885 |
|
---|
[15] | 1886 | if (need_strategy)
|
---|
[2] | 1887 | {
|
---|
[15] | 1888 | // This strategy is not yet applied in this project.
|
---|
| 1889 |
|
---|
| 1890 | Strategy& s = m_strategies.add ();
|
---|
[16] | 1891 | s.clear ();
|
---|
[15] | 1892 | s.set (definition, b_value, get_name ());
|
---|
[16] | 1893 | s.m_context = context;
|
---|
[2] | 1894 | }
|
---|
[15] | 1895 |
|
---|
| 1896 | for (i = 0; i < m_parents.size (); i++)
|
---|
| 1897 | {
|
---|
| 1898 | Project* project = m_parents[i];
|
---|
[2] | 1899 |
|
---|
[15] | 1900 | project->update_strategy (definition, b_value);
|
---|
| 1901 | }
|
---|
| 1902 | }
|
---|
[2] | 1903 |
|
---|
[15] | 1904 | /**----------------------------------------------------------
|
---|
| 1905 | The strategy value is changed because of indirect influences
|
---|
| 1906 | - default strategy at initialization time
|
---|
| 1907 | - change in the children
|
---|
| 1908 | - change in the children list
|
---|
| 1909 |
|
---|
| 1910 | (This is not a specification : see the set_strategy method)
|
---|
| 1911 | */
|
---|
| 1912 | void Project::update_strategy (StrategyDef* definition, bool b_value)
|
---|
| 1913 | {
|
---|
| 1914 | bool need_strategy = true;
|
---|
[16] | 1915 | bool specified = false;
|
---|
[15] | 1916 |
|
---|
| 1917 | int i;
|
---|
| 1918 |
|
---|
| 1919 | for (i = 0; i < m_strategies.size (); i++)
|
---|
[2] | 1920 | {
|
---|
[15] | 1921 | Strategy& s = m_strategies[i];
|
---|
| 1922 | if (s.m_definition == definition)
|
---|
| 1923 | {
|
---|
| 1924 | need_strategy = false;
|
---|
[16] | 1925 |
|
---|
| 1926 | if (!s.m_specified)
|
---|
| 1927 | {
|
---|
| 1928 | // This strategy is already applied in this project. Let's change it's value
|
---|
| 1929 | s.update (definition, b_value, get_name ());
|
---|
| 1930 | }
|
---|
| 1931 | else
|
---|
| 1932 | {
|
---|
| 1933 | specified = true;
|
---|
| 1934 | }
|
---|
[15] | 1935 | break;
|
---|
| 1936 | }
|
---|
[2] | 1937 | }
|
---|
| 1938 |
|
---|
[15] | 1939 | if (need_strategy)
|
---|
[2] | 1940 | {
|
---|
[15] | 1941 | // This strategy is not yet applied in this project.
|
---|
| 1942 |
|
---|
| 1943 | Strategy& s = m_strategies.add ();
|
---|
[16] | 1944 | s.clear ();
|
---|
[15] | 1945 | s.update (definition, b_value, get_name ());
|
---|
[2] | 1946 | }
|
---|
[16] | 1947 |
|
---|
| 1948 | if (!specified)
|
---|
[2] | 1949 | {
|
---|
[16] | 1950 | for (i = 0; i < m_parents.size (); i++)
|
---|
| 1951 | {
|
---|
| 1952 | Project* project = m_parents[i];
|
---|
[2] | 1953 |
|
---|
[15] | 1954 | project->update_strategy (definition, b_value);
|
---|
[2] | 1955 | }
|
---|
| 1956 | }
|
---|
| 1957 | }
|
---|
| 1958 |
|
---|
[15] | 1959 | /**----------------------------------------------------------
|
---|
| 1960 | At least one of the children has changed this strategy
|
---|
| 1961 | Or the list of children has changed.
|
---|
| 1962 | We need to update the strategy value accordingly
|
---|
| 1963 | This will not change the specified value for this strategy
|
---|
| 1964 | */
|
---|
| 1965 | void Project::update_strategy_from_children (StrategyDef* definition)
|
---|
[2] | 1966 | {
|
---|
[15] | 1967 | // If this strategy is specified we don't care what happens from the children
|
---|
[2] | 1968 |
|
---|
[16] | 1969 | //cerr << "Updating strategy " << definition->m_name << " from children for project " << m_name << endl;
|
---|
[2] | 1970 |
|
---|
[15] | 1971 | int i;
|
---|
[2] | 1972 |
|
---|
[15] | 1973 | for (i = 0; i < m_strategies.size (); i++)
|
---|
[2] | 1974 | {
|
---|
[15] | 1975 | Strategy& s = m_strategies[i];
|
---|
| 1976 | if (s.m_definition == definition)
|
---|
| 1977 | {
|
---|
| 1978 | // This strategy is applied in this project.
|
---|
| 1979 |
|
---|
| 1980 | if (s.m_specified)
|
---|
| 1981 | {
|
---|
| 1982 | // There will be no impact since the strategy is specified
|
---|
| 1983 |
|
---|
[16] | 1984 | //cerr << "This strategy is specified in this project" << endl;
|
---|
[15] | 1985 | return;
|
---|
| 1986 | }
|
---|
| 1987 |
|
---|
| 1988 | break;
|
---|
| 1989 | }
|
---|
[2] | 1990 | }
|
---|
| 1991 |
|
---|
[15] | 1992 | // The strategy is not specified locally so we will now figure out
|
---|
| 1993 | // which strategy has to be considered from the mixture of specifications
|
---|
| 1994 | // from all children.
|
---|
[2] | 1995 |
|
---|
[15] | 1996 | // Algorithm:
|
---|
| 1997 | // - We consider children by pairs
|
---|
| 1998 | // - a child that specifies its strategy wins over a child that does not
|
---|
| 1999 | // - when the two children have the same level of priority we consider the priority value
|
---|
| 2000 |
|
---|
| 2001 | Project* selected = 0;
|
---|
| 2002 | bool selected_is_specified = false;
|
---|
[16] | 2003 | bool selected_value = definition->m_default_value;
|
---|
[15] | 2004 |
|
---|
| 2005 | for (i = 0; i < m_children.size (); i++)
|
---|
[2] | 2006 | {
|
---|
[15] | 2007 | Project* p = m_children[i];
|
---|
| 2008 |
|
---|
[16] | 2009 | //cerr << "Checking strategy for child " << p->get_name () << endl;
|
---|
[15] | 2010 |
|
---|
| 2011 | bool is_specified = p->is_specified (definition);
|
---|
| 2012 | bool value = p->get_strategy (definition);
|
---|
| 2013 |
|
---|
| 2014 | if (selected == 0)
|
---|
| 2015 | {
|
---|
| 2016 | selected = p;
|
---|
| 2017 | selected_is_specified = is_specified;
|
---|
| 2018 | selected_value = value;
|
---|
| 2019 | continue;
|
---|
| 2020 | }
|
---|
| 2021 |
|
---|
| 2022 | if (is_specified == selected_is_specified)
|
---|
| 2023 | {
|
---|
| 2024 | if (selected_value != value)
|
---|
| 2025 | {
|
---|
| 2026 | // same level of priority but different values -> we must decide
|
---|
| 2027 | bool priority_value = definition->m_priority_value;
|
---|
| 2028 | if (value == priority_value)
|
---|
| 2029 | {
|
---|
| 2030 | selected = p;
|
---|
| 2031 | selected_is_specified = is_specified;
|
---|
| 2032 | selected_value = value;
|
---|
| 2033 | }
|
---|
| 2034 | }
|
---|
| 2035 | }
|
---|
| 2036 | else
|
---|
| 2037 | {
|
---|
| 2038 | if (is_specified)
|
---|
| 2039 | {
|
---|
| 2040 | selected = p;
|
---|
| 2041 | selected_is_specified = is_specified;
|
---|
| 2042 | selected_value = value;
|
---|
| 2043 | }
|
---|
| 2044 | }
|
---|
[2] | 2045 | }
|
---|
| 2046 |
|
---|
[15] | 2047 | update_strategy (definition, selected_value);
|
---|
| 2048 | }
|
---|
| 2049 |
|
---|
| 2050 | /**----------------------------------------------------------
|
---|
| 2051 | At least one of the children has changed its strategies
|
---|
| 2052 | Or the list of children has changed.
|
---|
| 2053 | We need to update the strategy values accordingly
|
---|
| 2054 | This will not change the specified values
|
---|
| 2055 | */
|
---|
| 2056 | void Project::update_strategies_from_children ()
|
---|
| 2057 | {
|
---|
| 2058 | StrategyDef::StrategyDefs& defs = StrategyMgr::get_definitions ();
|
---|
| 2059 |
|
---|
[16] | 2060 | //cerr << "Updating strategies from children for project " << m_name << endl;
|
---|
[15] | 2061 |
|
---|
| 2062 | int i;
|
---|
| 2063 |
|
---|
| 2064 | for (i = 0; i < defs.size (); i++)
|
---|
[2] | 2065 | {
|
---|
[15] | 2066 | StrategyDef* def = defs[i];
|
---|
[16] | 2067 |
|
---|
[15] | 2068 | update_strategy_from_children (def);
|
---|
[2] | 2069 | }
|
---|
[16] | 2070 |
|
---|
| 2071 | for (i = 0; i < m_parents.size (); i++)
|
---|
| 2072 | {
|
---|
| 2073 | Project* p = m_parents[i];
|
---|
| 2074 | p->update_strategies_from_children ();
|
---|
| 2075 | }
|
---|
[15] | 2076 | }
|
---|
| 2077 |
|
---|
| 2078 | /**----------------------------------------------------------
|
---|
| 2079 | The StrategyMgr singleton
|
---|
| 2080 | */
|
---|
| 2081 | StrategyMgr& StrategyMgr::instance ()
|
---|
| 2082 | {
|
---|
| 2083 | static StrategyMgr me;
|
---|
| 2084 | return (me);
|
---|
| 2085 | }
|
---|
| 2086 |
|
---|
| 2087 | /**----------------------------------------------------------
|
---|
| 2088 | The StrategyMgr constructor
|
---|
| 2089 | Here are primarily constructed all strategy definitions
|
---|
| 2090 | */
|
---|
| 2091 | StrategyMgr::StrategyMgr ()
|
---|
| 2092 | {
|
---|
| 2093 | m_defs.clear ();
|
---|
| 2094 |
|
---|
| 2095 | StrategyDef* s;
|
---|
| 2096 |
|
---|
| 2097 | s = new StrategyDef;
|
---|
[16] | 2098 | s->m_keyword = "build";
|
---|
[15] | 2099 | s->m_name = "BuildPrototypes";
|
---|
| 2100 | s->m_on_value = "prototypes";
|
---|
| 2101 | s->m_off_value = "no_prototypes";
|
---|
| 2102 | s->m_default_value = true;
|
---|
| 2103 | s->m_priority_value = false;
|
---|
| 2104 |
|
---|
| 2105 | m_defs.push_back (s);
|
---|
| 2106 |
|
---|
| 2107 | s = new StrategyDef;
|
---|
[16] | 2108 | s->m_keyword = "build";
|
---|
[15] | 2109 | s->m_name = "InstallArea";
|
---|
| 2110 | s->m_on_value = "with_installarea";
|
---|
| 2111 | s->m_off_value = "without_installarea";
|
---|
| 2112 | s->m_default_value = false;
|
---|
| 2113 | s->m_priority_value = true;
|
---|
| 2114 |
|
---|
| 2115 | m_defs.push_back (s);
|
---|
| 2116 |
|
---|
| 2117 | s = new StrategyDef;
|
---|
[16] | 2118 | s->m_keyword = "setup";
|
---|
[15] | 2119 | s->m_name = "SetupConfig";
|
---|
| 2120 | s->m_on_value = "config";
|
---|
| 2121 | s->m_off_value = "no_config";
|
---|
| 2122 | s->m_default_value = true;
|
---|
| 2123 | s->m_priority_value = false;
|
---|
| 2124 |
|
---|
| 2125 | m_defs.push_back (s);
|
---|
| 2126 |
|
---|
| 2127 | s = new StrategyDef;
|
---|
[16] | 2128 | s->m_keyword = "setup";
|
---|
[15] | 2129 | s->m_name = "SetupRoot";
|
---|
| 2130 | s->m_on_value = "root";
|
---|
| 2131 | s->m_off_value = "no_root";
|
---|
| 2132 | s->m_default_value = true;
|
---|
| 2133 | s->m_priority_value = false;
|
---|
| 2134 |
|
---|
| 2135 | m_defs.push_back (s);
|
---|
| 2136 |
|
---|
| 2137 | s = new StrategyDef;
|
---|
[16] | 2138 | s->m_keyword = "setup";
|
---|
[15] | 2139 | s->m_name = "SetupCleanup";
|
---|
| 2140 | s->m_on_value = "cleanup";
|
---|
| 2141 | s->m_off_value = "no_cleanup";
|
---|
| 2142 | s->m_default_value = true;
|
---|
| 2143 | s->m_priority_value = false;
|
---|
| 2144 |
|
---|
| 2145 | m_defs.push_back (s);
|
---|
[83] | 2146 |
|
---|
| 2147 | s = new StrategyDef;
|
---|
| 2148 | s->m_keyword = "structure";
|
---|
| 2149 | s->m_name = "VersionDirectory";
|
---|
| 2150 | s->m_on_value = "with_version_directory";
|
---|
| 2151 | s->m_off_value = "without_version_directory";
|
---|
[84] | 2152 | if (Cmt::get_current_structuring_style () != without_version_directory)
|
---|
[83] | 2153 | {
|
---|
| 2154 | s->m_default_value = true;
|
---|
| 2155 | s->m_priority_value = false;
|
---|
| 2156 | }
|
---|
| 2157 | else
|
---|
| 2158 | {
|
---|
| 2159 | s->m_default_value = false;
|
---|
| 2160 | s->m_priority_value = true;
|
---|
| 2161 | }
|
---|
| 2162 |
|
---|
| 2163 | m_defs.push_back (s);
|
---|
[15] | 2164 | }
|
---|
| 2165 |
|
---|
| 2166 | /**----------------------------------------------------------
|
---|
| 2167 | Find a strategy definition by its name
|
---|
| 2168 | */
|
---|
| 2169 | StrategyDef* StrategyMgr::find_strategy (const cmt_string& name)
|
---|
| 2170 | {
|
---|
| 2171 | static StrategyMgr& me = instance ();
|
---|
| 2172 |
|
---|
| 2173 | int i;
|
---|
| 2174 |
|
---|
| 2175 | for (i = 0; i < me.m_defs.size (); i++)
|
---|
[2] | 2176 | {
|
---|
[15] | 2177 | StrategyDef* def = me.m_defs[i];
|
---|
| 2178 | if (def->m_name == name)
|
---|
[2] | 2179 | {
|
---|
[15] | 2180 | return (def);
|
---|
[2] | 2181 | }
|
---|
| 2182 | }
|
---|
[15] | 2183 |
|
---|
| 2184 | return (0);
|
---|
[2] | 2185 | }
|
---|
| 2186 |
|
---|
[15] | 2187 | /**----------------------------------------------------------
|
---|
| 2188 | Retreive the default value defined for a given strategy
|
---|
| 2189 | */
|
---|
| 2190 | bool StrategyMgr::get_default_strategy (const cmt_string& name)
|
---|
| 2191 | {
|
---|
| 2192 | StrategyDef* def = find_strategy (name);
|
---|
| 2193 | if (def == 0) return (false);
|
---|
| 2194 | return (def->m_default_value);
|
---|
| 2195 | }
|
---|
| 2196 |
|
---|
| 2197 | /**----------------------------------------------------------
|
---|
| 2198 | Retreive the priority value defined for a given strategy
|
---|
| 2199 | This value is used when two children of a project request two conflicting strategy values
|
---|
| 2200 | */
|
---|
| 2201 | bool StrategyMgr::get_priority_strategy (const cmt_string& name)
|
---|
| 2202 | {
|
---|
| 2203 | StrategyDef* def = find_strategy (name);
|
---|
| 2204 | if (def == 0) return (false);
|
---|
| 2205 | return (def->m_priority_value);
|
---|
| 2206 | }
|
---|
| 2207 |
|
---|
| 2208 | /**----------------------------------------------------------
|
---|
| 2209 | Return the vector of all existing strategy definitions
|
---|
| 2210 | */
|
---|
| 2211 | StrategyDef::StrategyDefs& StrategyMgr::get_definitions ()
|
---|
| 2212 | {
|
---|
| 2213 | static StrategyMgr& me = instance ();
|
---|
| 2214 |
|
---|
| 2215 | return (me.m_defs);
|
---|
| 2216 | }
|
---|
| 2217 |
|
---|
[16] | 2218 | //-----------------------------------------------------------
|
---|
| 2219 | Strategy::Strategy ()
|
---|
| 2220 | {
|
---|
| 2221 | clear ();
|
---|
| 2222 | }
|
---|
| 2223 |
|
---|
| 2224 | //-----------------------------------------------------------
|
---|
| 2225 | void Strategy::clear ()
|
---|
| 2226 | {
|
---|
| 2227 | m_definition = 0;
|
---|
| 2228 | m_specified = false;
|
---|
| 2229 | m_specified_value = false;
|
---|
| 2230 | m_value = false;
|
---|
| 2231 | m_on_tag = 0;
|
---|
| 2232 | m_off_tag = 0;
|
---|
| 2233 | }
|
---|
| 2234 |
|
---|
[15] | 2235 | /**----------------------------------------------------------
|
---|
| 2236 | Specify a new value for this strategy.
|
---|
| 2237 | This only happens when a strategy statement is met in a project file or in a requirements file.
|
---|
| 2238 | */
|
---|
| 2239 | void Strategy::set (StrategyDef* definition, bool value, const cmt_string& project_name)
|
---|
| 2240 | {
|
---|
[16] | 2241 | //cerr << "Setting strategy " << definition->m_name << " for project " << project_name << " to " << value << endl;
|
---|
| 2242 |
|
---|
[15] | 2243 | m_definition = definition;
|
---|
| 2244 | m_specified = true;
|
---|
| 2245 | m_specified_value = value;
|
---|
| 2246 |
|
---|
| 2247 | update (definition, value, project_name);
|
---|
| 2248 | }
|
---|
| 2249 |
|
---|
| 2250 | /**----------------------------------------------------------
|
---|
| 2251 | Change the effective value for this strategy.
|
---|
| 2252 | This has no impact on to the specified value.
|
---|
| 2253 | This will adapt the tag settings
|
---|
| 2254 | */
|
---|
| 2255 | void Strategy::update (StrategyDef* definition, bool value, const cmt_string& project_name)
|
---|
| 2256 | {
|
---|
[16] | 2257 | //cerr << "Updating strategy " << definition->m_name << " for project " << project_name << " to " << value << endl;
|
---|
| 2258 |
|
---|
[15] | 2259 | m_value = value;
|
---|
[16] | 2260 | m_definition = definition;
|
---|
[15] | 2261 |
|
---|
| 2262 | cmt_string to_tag_name = project_name;
|
---|
| 2263 | cmt_string to_untag_name = project_name;
|
---|
| 2264 |
|
---|
| 2265 | to_tag_name += "_";
|
---|
| 2266 | to_untag_name += "_";
|
---|
| 2267 |
|
---|
| 2268 | if (m_value)
|
---|
| 2269 | {
|
---|
| 2270 | to_tag_name += m_definition->m_on_value;
|
---|
| 2271 | to_untag_name += m_definition->m_off_value;
|
---|
| 2272 | }
|
---|
| 2273 | else
|
---|
| 2274 | {
|
---|
| 2275 | to_tag_name += m_definition->m_off_value;
|
---|
| 2276 | to_untag_name += m_definition->m_on_value;
|
---|
| 2277 | }
|
---|
| 2278 |
|
---|
| 2279 | m_on_tag = Tag::find (to_tag_name);
|
---|
| 2280 | m_off_tag = Tag::find (to_untag_name);
|
---|
| 2281 |
|
---|
| 2282 | if (m_on_tag == 0)
|
---|
| 2283 | {
|
---|
| 2284 | m_on_tag = Tag::add (to_tag_name, PriorityConfig, "PROJECT", 0);
|
---|
| 2285 | m_off_tag = Tag::add (to_untag_name, PriorityConfig, "PROJECT", 0);
|
---|
| 2286 |
|
---|
| 2287 | m_on_tag->add_tag_exclude (m_off_tag);
|
---|
| 2288 | m_off_tag->add_tag_exclude (m_on_tag);
|
---|
| 2289 | }
|
---|
| 2290 |
|
---|
| 2291 | m_off_tag->unmark ();
|
---|
| 2292 | m_on_tag->mark ();
|
---|
| 2293 | }
|
---|
[272] | 2294 | //-----------------------------------------------------------
|
---|
[15] | 2295 | const cmt_string& StrategyDef::get_default_value () const
|
---|
| 2296 | {
|
---|
| 2297 | if (m_default_value)
|
---|
| 2298 | {
|
---|
| 2299 | return (m_on_value);
|
---|
| 2300 | }
|
---|
| 2301 | else
|
---|
| 2302 | {
|
---|
| 2303 | return (m_off_value);
|
---|
| 2304 | }
|
---|
| 2305 | }
|
---|
[272] | 2306 | //-----------------------------------------------------------
|
---|
| 2307 | void Project::set_author (const cmt_string& name)
|
---|
| 2308 | {
|
---|
| 2309 | cout<<"set_author"<<name<<endl;
|
---|
| 2310 | this->m_author = name;
|
---|
| 2311 | }
|
---|
| 2312 | //-----------------------------------------------------------
|
---|
| 2313 | const cmt_string& Project::get_author () const
|
---|
| 2314 | {
|
---|
| 2315 | return (m_author);
|
---|
| 2316 | }
|
---|
| 2317 | //-----------------------------------------------------------
|
---|
| 2318 | void Project::project_author_action (const CmtSystem::cmt_string_vector& words)
|
---|
| 2319 | {
|
---|
| 2320 | if (m_author != "") m_author += "\n";
|
---|
| 2321 | for (int i = 1; i < words.size (); i++)
|
---|
| 2322 | {
|
---|
| 2323 | const cmt_string& w = words[i];
|
---|
| 2324 |
|
---|
| 2325 | if (i > 1) m_author += " ";
|
---|
| 2326 | m_author += w;
|
---|
| 2327 | }
|
---|
| 2328 | }
|
---|
| 2329 | //----------------------------------------------------------- |
---|