author | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
commit | 155d68c1e7d7dc0fed2534ac43d6d77ce2781f55 (patch) (unidiff) | |
tree | e6edaa5a7040fe6c224c3943d1094dcf02e4f74c /qmake/project.cpp | |
parent | 86703e8a5527ef114facd02c005b6b3a7e62e263 (diff) | |
download | opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.zip opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.gz opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.bz2 |
update qmake to 1.05a
-rw-r--r-- | qmake/project.cpp | 407 |
1 files changed, 245 insertions, 162 deletions
diff --git a/qmake/project.cpp b/qmake/project.cpp index 44eb503..834823d 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp | |||
@@ -65,11 +65,16 @@ static void qmake_error_msg(const char *msg) | |||
65 | 65 | ||
66 | static QString varMap(const QString &x) | 66 | static QString varMap(const QString &x) |
67 | { | 67 | { |
68 | QString ret(x); | 68 | QString ret(x); |
69 | ret.replace(QRegExp("^TMAKE"), "QMAKE"); | 69 | if(ret.startsWith("TMAKE")) //tmake no more! |
70 | ret = "QMAKE" + ret.mid(5); | ||
70 | if(ret == "INTERFACES") | 71 | if(ret == "INTERFACES") |
71 | ret = "FORMS"; | 72 | ret = "FORMS"; |
73 | if(ret == "QMAKE_POST_BUILD") | ||
74 | ret = "QMAKE_POST_LINK"; | ||
75 | if(ret == "TARGETDEPS") | ||
76 | ret = "POST_TARGETDEPS"; | ||
72 | return ret; | 77 | return ret; |
73 | } | 78 | } |
74 | 79 | ||
75 | static QStringList split_arg_list(const QString ¶ms) | 80 | static QStringList split_arg_list(const QString ¶ms) |
@@ -105,9 +110,9 @@ static QStringList split_value_list(const QString &vals, bool do_semicolon=FALSE | |||
105 | if(!quote.isEmpty() && vals[x] == quote.top()) { | 110 | if(!quote.isEmpty() && vals[x] == quote.top()) { |
106 | quote.pop(); | 111 | quote.pop(); |
107 | } else if(vals[x] == '\'' || vals[x] == '"') { | 112 | } else if(vals[x] == '\'' || vals[x] == '"') { |
108 | quote.push(vals[x]); | 113 | quote.push(vals[x]); |
109 | } else if(quote.isEmpty() && | 114 | } else if(quote.isEmpty() && |
110 | ((do_semicolon && vals[x] == ';') || vals[x] == ' ')) { | 115 | ((do_semicolon && vals[x] == ';') || vals[x] == ' ')) { |
111 | ret << vals.mid(last, x - last); | 116 | ret << vals.mid(last, x - last); |
112 | last = x+1; | 117 | last = x+1; |
113 | } | 118 | } |
@@ -121,12 +126,14 @@ QMakeProject::QMakeProject() | |||
121 | { | 126 | { |
122 | } | 127 | } |
123 | 128 | ||
124 | bool | 129 | bool |
125 | QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | 130 | QMakeProject::parse(const QString &t, QMap<QString, QStringList> &place) |
126 | { | 131 | { |
127 | QString s = t.simplifyWhiteSpace(); | 132 | QString s = t.simplifyWhiteSpace(); |
128 | s.replace(QRegExp("#.*$"), ""); /* bye comments */ | 133 | int hash_mark = s.find('#'); |
134 | if(hash_mark != -1) //good bye comments | ||
135 | s = s.left(hash_mark); | ||
129 | if(s.isEmpty()) /* blank_line */ | 136 | if(s.isEmpty()) /* blank_line */ |
130 | return TRUE; | 137 | return TRUE; |
131 | 138 | ||
132 | if(s.stripWhiteSpace().left(1) == "}") { | 139 | if(s.stripWhiteSpace().left(1) == "}") { |
@@ -153,19 +160,23 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | |||
153 | const char *d = s.latin1(); | 160 | const char *d = s.latin1(); |
154 | SKIP_WS(d); | 161 | SKIP_WS(d); |
155 | bool scope_failed = FALSE, else_line = FALSE, or_op=FALSE; | 162 | bool scope_failed = FALSE, else_line = FALSE, or_op=FALSE; |
156 | int parens = 0, scope_count=0; | 163 | int parens = 0, scope_count=0; |
157 | while(*d && *d != '=') { | 164 | while(*d) { |
158 | if((*d == '+' || *d == '-' || *d == '*' || *d == '~')) { | 165 | if(!parens) { |
159 | if(*(d+1) == '=') { | 166 | if(*d == '=') |
160 | break; | 167 | break; |
161 | } else if(*(d+1) == ' ') { | 168 | if(*d == '+' || *d == '-' || *d == '*' || *d == '~') { |
162 | const char *k = d + 1; | 169 | if(*(d+1) == '=') { |
163 | SKIP_WS(k); | 170 | break; |
164 | if(*k == '=') { | 171 | } else if(*(d+1) == ' ') { |
165 | QString msg; | 172 | const char *k = d + 1; |
166 | qmake_error_msg(*d + "must be followed immediatly by ="); | 173 | SKIP_WS(k); |
167 | return FALSE; | 174 | if(*k == '=') { |
175 | QString msg; | ||
176 | qmake_error_msg(*d + "must be followed immediately by ="); | ||
177 | return FALSE; | ||
178 | } | ||
168 | } | 179 | } |
169 | } | 180 | } |
170 | } | 181 | } |
171 | 182 | ||
@@ -216,9 +227,9 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | |||
216 | test_status = (test ? TestFound : TestSeek); | 227 | test_status = (test ? TestFound : TestSeek); |
217 | return TRUE; /* assume we are done */ | 228 | return TRUE; /* assume we are done */ |
218 | } | 229 | } |
219 | } else { | 230 | } else { |
220 | test = isActiveConfig(comp_scope.stripWhiteSpace()); | 231 | test = isActiveConfig(comp_scope.stripWhiteSpace(), TRUE); |
221 | } | 232 | } |
222 | if(invert_test) | 233 | if(invert_test) |
223 | test = !test; | 234 | test = !test; |
224 | } | 235 | } |
@@ -286,9 +297,9 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | |||
286 | } | 297 | } |
287 | var = varMap(var); //backwards compatability | 298 | var = varMap(var); //backwards compatability |
288 | 299 | ||
289 | /* vallist is the broken up list of values */ | 300 | /* vallist is the broken up list of values */ |
290 | QStringList vallist = split_value_list(vals, (var == "DEPENDPATH" || var == "INCLUDEPATH")); | 301 | QStringList vallist = split_value_list(vals, (var == "DEPENDPATH" || var == "INCLUDEPATH")); |
291 | if(!vallist.grep("=").isEmpty()) | 302 | if(!vallist.grep("=").isEmpty()) |
292 | warn_msg(WarnParser, "Detected possible line continuation: {%s} %s:%d", | 303 | warn_msg(WarnParser, "Detected possible line continuation: {%s} %s:%d", |
293 | var.latin1(), parser.file.latin1(), parser.line_no); | 304 | var.latin1(), parser.file.latin1(), parser.line_no); |
294 | 305 | ||
@@ -354,38 +365,42 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | |||
354 | return TRUE; | 365 | return TRUE; |
355 | } | 366 | } |
356 | 367 | ||
357 | bool | 368 | bool |
358 | QMakeProject::read(QString file, QMap<QString, QStringList> &place) | 369 | QMakeProject::read(const QString &file, QMap<QString, QStringList> &place) |
359 | { | 370 | { |
360 | parser_info pi = parser; | 371 | parser_info pi = parser; |
361 | /* scope blocks start at true */ | 372 | /* scope blocks start at true */ |
362 | test_status = TestNone; | 373 | test_status = TestNone; |
363 | scope_flag = 0x01; | 374 | scope_flag = 0x01; |
364 | scope_block = 0; | 375 | scope_block = 0; |
365 | 376 | ||
366 | file = Option::fixPathToLocalOS(file); | 377 | QString filename = Option::fixPathToLocalOS(file); |
367 | doVariableReplace(file, place); | 378 | doVariableReplace(filename, place); |
368 | bool ret = FALSE, using_stdin = FALSE; | 379 | bool ret = FALSE, using_stdin = FALSE; |
369 | QFile qfile; | 380 | QFile qfile; |
370 | if(!strcmp(file, "-")) { | 381 | if(!strcmp(filename, "-")) { |
371 | qfile.setName(""); | 382 | qfile.setName(""); |
372 | ret = qfile.open(IO_ReadOnly, stdin); | 383 | ret = qfile.open(IO_ReadOnly, stdin); |
373 | using_stdin = TRUE; | 384 | using_stdin = TRUE; |
374 | } else { | 385 | } else { |
375 | qfile.setName(file); | 386 | qfile.setName(filename); |
376 | ret = qfile.open(IO_ReadOnly); | 387 | ret = qfile.open(IO_ReadOnly); |
377 | } | 388 | } |
378 | if ( ret ) { | 389 | if ( ret ) { |
379 | QTextStream t( &qfile ); | 390 | QTextStream t( &qfile ); |
380 | QString s, line; | 391 | QString s, line; |
381 | parser.file = file; | 392 | parser.file = filename; |
382 | parser.line_no = 0; | 393 | parser.line_no = 0; |
383 | while ( !t.eof() ) { | 394 | while ( !t.eof() ) { |
384 | parser.line_no++; | 395 | parser.line_no++; |
385 | line = t.readLine().stripWhiteSpace(); | 396 | line = t.readLine().stripWhiteSpace(); |
386 | int prelen = line.length(); | 397 | int prelen = line.length(); |
387 | line.replace(QRegExp("#.*$"), ""); // bye comments | 398 | { |
399 | int hash_mark = line.find('#'); | ||
400 | if(hash_mark != -1) //bye comments | ||
401 | line = line.left(hash_mark); | ||
402 | } | ||
388 | if(!line.isEmpty() && line.right(1) == "\\") { | 403 | if(!line.isEmpty() && line.right(1) == "\\") { |
389 | line.truncate(line.length() - 1); | 404 | line.truncate(line.length() - 1); |
390 | s += line + " "; | 405 | s += line + " "; |
391 | } else if(!line.isEmpty() || (line.isEmpty() && !prelen)) { | 406 | } else if(!line.isEmpty() || (line.isEmpty() && !prelen)) { |
@@ -407,14 +422,23 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place) | |||
407 | return ret; | 422 | return ret; |
408 | } | 423 | } |
409 | 424 | ||
410 | bool | 425 | bool |
411 | QMakeProject::read(QString project, QString) | 426 | QMakeProject::read(const QString &project, const QString &, bool just_project) |
412 | { | 427 | { |
428 | if(just_project) { //nothing more, nothing less | ||
429 | pfile = project; | ||
430 | if(pfile != "-" && !QFile::exists(pfile) && pfile.right(4) != ".pro") | ||
431 | pfile += ".pro"; | ||
432 | return read(pfile, vars); | ||
433 | } | ||
434 | |||
413 | if(cfile.isEmpty()) { | 435 | if(cfile.isEmpty()) { |
414 | // hack to get the Option stuff in there | 436 | // hack to get the Option stuff in there |
415 | base_vars["QMAKE_EXT_CPP"] = Option::cpp_ext; | 437 | base_vars["QMAKE_EXT_CPP"] = Option::cpp_ext; |
416 | base_vars["QMAKE_EXT_H"] = Option::h_ext; | 438 | base_vars["QMAKE_EXT_H"] = Option::h_ext; |
439 | if(!Option::user_template_prefix.isEmpty()) | ||
440 | base_vars["TEMPLATE_PREFIX"] = Option::user_template_prefix; | ||
417 | 441 | ||
418 | /* parse the cache */ | 442 | /* parse the cache */ |
419 | if(Option::mkfile::do_cache) { | 443 | if(Option::mkfile::do_cache) { |
420 | if(Option::mkfile::cachefile.isEmpty()) { //find it as it has not been specified | 444 | if(Option::mkfile::cachefile.isEmpty()) { //find it as it has not been specified |
@@ -440,22 +464,11 @@ QMakeProject::read(QString project, QString) | |||
440 | } | 464 | } |
441 | /* parse mkspec */ | 465 | /* parse mkspec */ |
442 | QStringList mkspec_roots; | 466 | QStringList mkspec_roots; |
443 | /* prefer $QTDIR if it is set */ | 467 | /* prefer $QTDIR if it is set */ |
444 | /* prefer QMAKESPECSDIR -cl */ | 468 | if (getenv("QTDIR")) |
445 | |||
446 | if (getenv("QTDIR")) { | ||
447 | mkspec_roots << getenv("QTDIR"); | 469 | mkspec_roots << getenv("QTDIR"); |
448 | } | ||
449 | mkspec_roots << qInstallPathData(); | 470 | mkspec_roots << qInstallPathData(); |
450 | |||
451 | if (Option::mkfile::qmakespec.isEmpty() && getenv("QMAKESPECSDIR")){ | ||
452 | QString mkspec = QString(getenv("QMAKESPECSDIR")) + QDir::separator() + | ||
453 | QDir::separator() + "default"; | ||
454 | if(QFile::exists(mkspec)) | ||
455 | Option::mkfile::qmakespec = mkspec; | ||
456 | } | ||
457 | |||
458 | if(Option::mkfile::qmakespec.isEmpty()) { | 471 | if(Option::mkfile::qmakespec.isEmpty()) { |
459 | for(QStringList::Iterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) { | 472 | for(QStringList::Iterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) { |
460 | QString mkspec = (*it) + QDir::separator() + QString("mkspecs") + | 473 | QString mkspec = (*it) + QDir::separator() + QString("mkspecs") + |
461 | QDir::separator() + "default"; | 474 | QDir::separator() + "default"; |
@@ -463,13 +476,12 @@ QMakeProject::read(QString project, QString) | |||
463 | Option::mkfile::qmakespec = mkspec; | 476 | Option::mkfile::qmakespec = mkspec; |
464 | break; | 477 | break; |
465 | } | 478 | } |
466 | } | 479 | } |
467 | } | 480 | if(Option::mkfile::qmakespec.isEmpty()) { |
468 | 481 | fprintf(stderr, "QMAKESPEC has not been set, so configuration cannot be deduced.\n"); | |
469 | if(Option::mkfile::qmakespec.isEmpty()) { | 482 | return FALSE; |
470 | fprintf(stderr, "QMAKESPEC has not been set, so configuration cannot be deduced.\n"); | 483 | } |
471 | return FALSE; | ||
472 | } | 484 | } |
473 | 485 | ||
474 | if(QDir::isRelativePath(Option::mkfile::qmakespec)) { | 486 | if(QDir::isRelativePath(Option::mkfile::qmakespec)) { |
475 | bool found_mkspec = FALSE; | 487 | bool found_mkspec = FALSE; |
@@ -543,14 +555,16 @@ QMakeProject::read(QString project, QString) | |||
543 | vars["TEMPLATE"].clear(); | 555 | vars["TEMPLATE"].clear(); |
544 | vars["TEMPLATE"].append(Option::user_template); | 556 | vars["TEMPLATE"].append(Option::user_template); |
545 | } | 557 | } |
546 | 558 | ||
547 | if(vars["TEMPLATE"].isEmpty()) | 559 | QStringList &templ = vars["TEMPLATE"]; |
548 | vars["TEMPLATE"].append(QString("app")); | 560 | if(templ.isEmpty()) |
549 | else | 561 | templ.append(QString("app")); |
550 | vars["TEMPLATE"].first().replace(QRegExp("\\.t$"), ""); | 562 | else if(vars["TEMPLATE"].first().endsWith(".t")) |
551 | if(!Option::user_template_prefix.isEmpty()) | 563 | templ = QStringList(templ.first().left(templ.first().length() - 2)); |
552 | vars["TEMPLATE"].first().prepend(Option::user_template_prefix); | 564 | if ( !Option::user_template_prefix.isEmpty() ) { |
565 | templ.first().prepend(Option::user_template_prefix); | ||
566 | } | ||
553 | 567 | ||
554 | if(vars["TARGET"].isEmpty()) { | 568 | if(vars["TARGET"].isEmpty()) { |
555 | // ### why not simply use: | 569 | // ### why not simply use: |
556 | // QFileInfo fi(pfile); | 570 | // QFileInfo fi(pfile); |
@@ -578,16 +592,15 @@ QMakeProject::read(QString project, QString) | |||
578 | return TRUE; | 592 | return TRUE; |
579 | } | 593 | } |
580 | 594 | ||
581 | bool | 595 | bool |
582 | QMakeProject::isActiveConfig(const QString &x) | 596 | QMakeProject::isActiveConfig(const QString &x, bool regex) |
583 | { | 597 | { |
584 | if(x.isEmpty()) | 598 | if(x.isEmpty()) |
585 | return TRUE; | 599 | return TRUE; |
586 | 600 | ||
587 | QRegExp re(x, FALSE, TRUE); | 601 | if((Option::target_mode == Option::TARG_MACX_MODE || Option::target_mode == Option::TARG_QNX6_MODE || |
588 | if((Option::target_mode == Option::TARG_MACX_MODE || Option::target_mode == Option::TARG_QNX6_MODE || Option::target_mode == Option::TARG_UNIX_MODE) && | 602 | Option::target_mode == Option::TARG_UNIX_MODE) && x == "unix") |
589 | x == "unix") | ||
590 | return TRUE; | 603 | return TRUE; |
591 | else if(Option::target_mode == Option::TARG_MACX_MODE && x == "macx") | 604 | else if(Option::target_mode == Option::TARG_MACX_MODE && x == "macx") |
592 | return TRUE; | 605 | return TRUE; |
593 | else if(Option::target_mode == Option::TARG_QNX6_MODE && x == "qnx6") | 606 | else if(Option::target_mode == Option::TARG_QNX6_MODE && x == "qnx6") |
@@ -600,11 +613,12 @@ QMakeProject::isActiveConfig(const QString &x) | |||
600 | else if(Option::target_mode == Option::TARG_WIN_MODE && x == "win32") | 613 | else if(Option::target_mode == Option::TARG_WIN_MODE && x == "win32") |
601 | return TRUE; | 614 | return TRUE; |
602 | 615 | ||
603 | 616 | ||
617 | QRegExp re(x, FALSE, TRUE); | ||
604 | QString spec = Option::mkfile::qmakespec.right(Option::mkfile::qmakespec.length() - | 618 | QString spec = Option::mkfile::qmakespec.right(Option::mkfile::qmakespec.length() - |
605 | (Option::mkfile::qmakespec.findRev(QDir::separator())+1)); | 619 | (Option::mkfile::qmakespec.findRev(QDir::separator())+1)); |
606 | if(re.exactMatch(spec)) | 620 | if((regex && re.exactMatch(spec)) || (!regex && spec == x)) |
607 | return TRUE; | 621 | return TRUE; |
608 | #ifdef Q_OS_UNIX | 622 | #ifdef Q_OS_UNIX |
609 | else if(spec == "default") { | 623 | else if(spec == "default") { |
610 | static char *buffer = NULL; | 624 | static char *buffer = NULL; |
@@ -615,25 +629,26 @@ QMakeProject::isActiveConfig(const QString &x) | |||
615 | buffer[l] = '\0'; | 629 | buffer[l] = '\0'; |
616 | QString r = buffer; | 630 | QString r = buffer; |
617 | if(r.findRev('/') != -1) | 631 | if(r.findRev('/') != -1) |
618 | r = r.mid(r.findRev('/') + 1); | 632 | r = r.mid(r.findRev('/') + 1); |
619 | if(re.exactMatch(r)) | 633 | if((regex && re.exactMatch(r)) || (!regex && r == x)) |
620 | return TRUE; | 634 | return TRUE; |
621 | } | 635 | } |
622 | } | 636 | } |
623 | #endif | 637 | #endif |
624 | 638 | ||
625 | 639 | ||
626 | QStringList &configs = vars["CONFIG"]; | 640 | QStringList &configs = vars["CONFIG"]; |
627 | for(QStringList::Iterator it = configs.begin(); it != configs.end(); ++it) { | 641 | for(QStringList::Iterator it = configs.begin(); it != configs.end(); ++it) { |
642 | if((regex && re.exactMatch((*it))) || (!regex && (*it) == x)) | ||
628 | if(re.exactMatch((*it))) | 643 | if(re.exactMatch((*it))) |
629 | return TRUE; | 644 | return TRUE; |
630 | } | 645 | } |
631 | return FALSE; | 646 | return FALSE; |
632 | } | 647 | } |
633 | 648 | ||
634 | bool | 649 | bool |
635 | QMakeProject::doProjectTest(QString func, const QString ¶ms, QMap<QString, QStringList> &place) | 650 | QMakeProject::doProjectTest(const QString& func, const QString ¶ms, QMap<QString, QStringList> &place) |
636 | { | 651 | { |
637 | QStringList args = split_arg_list(params); | 652 | QStringList args = split_arg_list(params); |
638 | for(QStringList::Iterator arit = args.begin(); arit != args.end(); ++arit) { | 653 | for(QStringList::Iterator arit = args.begin(); arit != args.end(); ++arit) { |
639 | QString tmp = (*arit).stripWhiteSpace(); | 654 | QString tmp = (*arit).stripWhiteSpace(); |
@@ -643,9 +658,9 @@ QMakeProject::doProjectTest(QString func, const QString ¶ms, QMap<QString, Q | |||
643 | return doProjectTest(func.stripWhiteSpace(), args, place); | 658 | return doProjectTest(func.stripWhiteSpace(), args, place); |
644 | } | 659 | } |
645 | 660 | ||
646 | bool | 661 | bool |
647 | QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStringList> &place) | 662 | QMakeProject::doProjectTest(const QString& func, QStringList args, QMap<QString, QStringList> &place) |
648 | { | 663 | { |
649 | for(QStringList::Iterator arit = args.begin(); arit != args.end(); ++arit) { | 664 | for(QStringList::Iterator arit = args.begin(); arit != args.end(); ++arit) { |
650 | (*arit) = (*arit).stripWhiteSpace(); // blah, get rid of space | 665 | (*arit) = (*arit).stripWhiteSpace(); // blah, get rid of space |
651 | doVariableReplace((*arit), place); | 666 | doVariableReplace((*arit), place); |
@@ -653,8 +668,18 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin | |||
653 | debug_msg(1, "Running project test: %s( %s )", func.latin1(), args.join("::").latin1()); | 668 | debug_msg(1, "Running project test: %s( %s )", func.latin1(), args.join("::").latin1()); |
654 | 669 | ||
655 | if(func == "requires") { | 670 | if(func == "requires") { |
656 | return doProjectCheckReqs(args, place); | 671 | return doProjectCheckReqs(args, place); |
672 | } else if(func == "equals") { | ||
673 | if(args.count() != 2) { | ||
674 | fprintf(stderr, "%s:%d: equals(variable, value) requires two arguments.\n", parser.file.latin1(), | ||
675 | parser.line_no); | ||
676 | return FALSE; | ||
677 | } | ||
678 | QString value = args[1]; | ||
679 | if((value.left(1) == "\"" || value.left(1) == "'") && value.right(1) == value.left(1)) | ||
680 | value = value.mid(1, value.length()-2); | ||
681 | return vars[args[0]].join(" ") == value; | ||
657 | } else if(func == "exists") { | 682 | } else if(func == "exists") { |
658 | if(args.count() != 1) { | 683 | if(args.count() != 1) { |
659 | fprintf(stderr, "%s:%d: exists(file) requires one argument.\n", parser.file.latin1(), | 684 | fprintf(stderr, "%s:%d: exists(file) requires one argument.\n", parser.file.latin1(), |
660 | parser.line_no); | 685 | parser.line_no); |
@@ -690,9 +715,9 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin | |||
690 | } | 715 | } |
691 | QRegExp regx(args[1]); | 716 | QRegExp regx(args[1]); |
692 | QStringList &l = place[args[0]]; | 717 | QStringList &l = place[args[0]]; |
693 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { | 718 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { |
694 | if(regx.exactMatch((*it))) | 719 | if(regx.exactMatch((*it))) |
695 | return TRUE; | 720 | return TRUE; |
696 | } | 721 | } |
697 | return FALSE; | 722 | return FALSE; |
698 | } else if(func == "infile") { | 723 | } else if(func == "infile") { |
@@ -804,10 +829,13 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin | |||
804 | int sb = scope_block; | 829 | int sb = scope_block; |
805 | int sf = scope_flag; | 830 | int sf = scope_flag; |
806 | TestStatus sc = test_status; | 831 | TestStatus sc = test_status; |
807 | bool r = read(file.latin1(), place); | 832 | bool r = read(file.latin1(), place); |
808 | if(r) | 833 | if(r) |
809 | vars["QMAKE_INTERNAL_INCLUDED_FILES"].append(file); | 834 | vars["QMAKE_INTERNAL_INCLUDED_FILES"].append(file); |
835 | else | ||
836 | warn_msg(WarnParser, "%s:%d: Failure to include file %s.", | ||
837 | pi.file.latin1(), pi.line_no, file.latin1()); | ||
810 | parser = pi; | 838 | parser = pi; |
811 | test_status = sc; | 839 | test_status = sc; |
812 | scope_flag = sf; | 840 | scope_flag = sf; |
813 | scope_block = sb; | 841 | scope_block = sb; |
@@ -818,8 +846,13 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin | |||
818 | parser.line_no, func.latin1()); | 846 | parser.line_no, func.latin1()); |
819 | return FALSE; | 847 | return FALSE; |
820 | } | 848 | } |
821 | QString msg = args.first(); | 849 | QString msg = args.first(); |
850 | if((msg.startsWith("\"") || msg.startsWith("'")) && msg.endsWith(msg.left(1))) | ||
851 | msg = msg.mid(1, msg.length()-2); | ||
852 | msg.replace(QString("${QMAKE_FILE}"), parser.file.latin1()); | ||
853 | msg.replace(QString("${QMAKE_LINE_NUMBER}"), QString::number(parser.line_no)); | ||
854 | msg.replace(QString("${QMAKE_DATE}"), QDateTime::currentDateTime().toString()); | ||
822 | doVariableReplace(msg, place); | 855 | doVariableReplace(msg, place); |
823 | fixEnvVariables(msg); | 856 | fixEnvVariables(msg); |
824 | printf("Project %s: %s\n", func.upper().latin1(), msg.latin1()); | 857 | printf("Project %s: %s\n", func.upper().latin1(), msg.latin1()); |
825 | if(func == "message") | 858 | if(func == "message") |
@@ -856,9 +889,9 @@ QMakeProject::doProjectCheckReqs(const QStringList &deps, QMap<QString, QStringL | |||
856 | QString func = chk.left(lparen); | 889 | QString func = chk.left(lparen); |
857 | test = doProjectTest(func, chk.mid(lparen+1, rparen - lparen - 1), place); | 890 | test = doProjectTest(func, chk.mid(lparen+1, rparen - lparen - 1), place); |
858 | } | 891 | } |
859 | } else { | 892 | } else { |
860 | test = isActiveConfig(chk); | 893 | test = isActiveConfig(chk, TRUE); |
861 | } | 894 | } |
862 | if(invert_test) { | 895 | if(invert_test) { |
863 | chk.prepend("!"); | 896 | chk.prepend("!"); |
864 | test = !test; | 897 | test = !test; |
@@ -876,119 +909,169 @@ QMakeProject::doProjectCheckReqs(const QStringList &deps, QMap<QString, QStringL | |||
876 | 909 | ||
877 | QString | 910 | QString |
878 | QMakeProject::doVariableReplace(QString &str, const QMap<QString, QStringList> &place) | 911 | QMakeProject::doVariableReplace(QString &str, const QMap<QString, QStringList> &place) |
879 | { | 912 | { |
880 | for(int x = 0, rep; x < 5; x++) { | 913 | for(int var_begin, var_last=0; (var_begin = str.find("$$", var_last)) != -1; var_last = var_begin) { |
881 | QRegExp reg_var; | 914 | if(var_begin >= int( str.length() + 2 ) ) { |
882 | reg_var.setMinimal(TRUE); | 915 | break; |
883 | if( x == 0 ) //function blocked out by {}'s | 916 | } else if(var_begin != 0 && str[var_begin-1] == '\\') { |
884 | reg_var = QRegExp("\\$\\$\\{([a-zA-Z0-9_]*)\\((\\(.|(.*)\\)*)\\)\\}"); | 917 | str.replace(var_begin-1, 1, ""); |
885 | else if( x == 1 ) //variables blocked out by {}'s | 918 | var_begin += 1; |
886 | reg_var = QRegExp("\\$\\$\\{([a-zA-Z0-9_\\.-]*)\\}"); | 919 | continue; |
887 | else if(x == 2) //environment | 920 | } |
888 | reg_var = QRegExp("\\$\\$\\(([a-zA-Z0-9_\\.-]*)\\)"); | 921 | |
889 | else if(x == 3) //function | 922 | int var_incr = var_begin + 2; |
890 | reg_var = QRegExp("\\$\\$([a-zA-Z0-9_]*)\\((\\(.|(.*)\\)*)\\)"); | 923 | bool in_braces = FALSE, as_env = FALSE; |
891 | else if(x == 4) //normal variable | 924 | if(str[var_incr] == '{') { |
892 | reg_var = QRegExp("\\$\\$([a-zA-Z0-9_\\.-]*)"); | 925 | in_braces = TRUE; |
893 | while((rep = reg_var.search(str)) != -1) { | 926 | var_incr++; |
894 | QString replacement; | 927 | while(var_incr < int( str.length() ) && |
895 | if(x == 2) {//environment | 928 | (str[var_incr] == ' ' || str[var_incr] == '\t' || str[var_incr] == '\n')) |
896 | replacement = getenv(reg_var.cap(1)); | 929 | var_incr++; |
897 | } else if(x == 0 || x == 3) { //function | 930 | } |
898 | QStringList args = split_arg_list(reg_var.cap(2)); | 931 | if(str[var_incr] == '(') { |
899 | for(QStringList::Iterator arit = args.begin(); arit != args.end(); ++arit) { | 932 | as_env = TRUE; |
900 | (*arit) = (*arit).stripWhiteSpace(); // blah, get rid of space | 933 | var_incr++; |
901 | doVariableReplace((*arit), place); | 934 | } |
902 | } | 935 | QString val, args; |
903 | debug_msg(1, "Running function: %s( %s )", reg_var.cap(1).latin1(), args.join("::").latin1()); | 936 | while(var_incr < int( str.length() ) && |
904 | if(reg_var.cap(1).lower() == "member") { | 937 | (str[var_incr].isLetter() || str[var_incr].isNumber() || str[var_incr] == '.' || str[var_incr] == '_')) |
905 | if(args.count() < 1 || args.count() > 2) { | 938 | val += str[var_incr++]; |
906 | fprintf(stderr, "%s:%d: member(var, place) requires two arguments.\n", | 939 | if(as_env) { |
907 | parser.file.latin1(), parser.line_no); | 940 | if(str[var_incr] != ')') { |
908 | } else { | 941 | var_incr++; |
909 | uint pos = 0; | 942 | warn_msg(WarnParser, "%s:%d: Unterminated env-variable replacement '%s' (%s)", |
910 | if(args.count() == 2) | 943 | parser.file.latin1(), parser.line_no, |
911 | pos = args[1].toInt(); | 944 | str.mid(var_begin, QMAX(var_incr - var_begin, int(str.length()))).latin1(), str.latin1()); |
912 | const QStringList &var = place[varMap(args.first())]; | 945 | var_begin += var_incr; |
913 | if(var.count() >= pos) | 946 | continue; |
914 | replacement = var[pos]; | 947 | } |
915 | } | 948 | var_incr++; |
916 | } else if(reg_var.cap(1).lower() == "list") { | 949 | } else if(str[var_incr] == '(') { //args |
917 | if(args.count() != 1) { | 950 | for(int parens = 0; var_incr < int( str.length() ); var_incr++) { |
918 | fprintf(stderr, "%s:%d: list(vals) requires one" | 951 | if(str[var_incr] == '(') { |
919 | "argument.\n", parser.file.latin1(), parser.line_no); | 952 | parens++; |
920 | } else { | 953 | if(parens == 1) |
921 | static int x = 0; | 954 | continue; |
922 | replacement.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++); | 955 | } else if(str[var_incr] == ')') { |
923 | (*((QMap<QString, QStringList>*)&place))[replacement] = split_value_list(args.first()); | 956 | parens--; |
924 | } | 957 | if(!parens) { |
925 | } else if(reg_var.cap(1).lower() == "join") { | 958 | var_incr++; |
926 | if(args.count() < 1 || args.count() > 4) { | 959 | break; |
927 | fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four" | ||
928 | "arguments.\n", parser.file.latin1(), parser.line_no); | ||
929 | } else { | ||
930 | QString glue, before, after; | ||
931 | if(args.count() >= 2) | ||
932 | glue = args[1].replace("\"", "" ); | ||
933 | if(args.count() >= 3) | ||
934 | before = args[2].replace("\"", "" ); | ||
935 | if(args.count() == 4) | ||
936 | after = args[3].replace("\"", "" ); | ||
937 | const QStringList &var = place[varMap(args.first())]; | ||
938 | if(!var.isEmpty()) | ||
939 | replacement = before + var.join(glue) + after; | ||
940 | } | 960 | } |
941 | } else if(reg_var.cap(1).lower() == "find") { | 961 | } |
942 | if(args.count() != 2) { | 962 | args += str[var_incr]; |
943 | fprintf(stderr, "%s:%d find(var, str) requires two arguments\n", | 963 | } |
944 | parser.file.latin1(), parser.line_no); | 964 | } |
945 | } else { | 965 | if(var_incr > int( str.length() ) || (in_braces && str[var_incr] != '}')) { |
946 | QRegExp regx(args[1]); | 966 | var_incr++; |
947 | const QStringList &var = place[varMap(args.first())]; | 967 | warn_msg(WarnParser, "%s:%d: Unterminated variable replacement '%s' (%s)", |
948 | for(QStringList::ConstIterator vit = var.begin(); | 968 | parser.file.latin1(), parser.line_no, |
949 | vit != var.end(); ++vit) { | 969 | str.mid(var_begin, QMAX(var_incr - var_begin, int( str.length() ))).latin1(), str.latin1()); |
950 | if(regx.search(*vit) != -1) { | 970 | var_begin += var_incr; |
951 | if(!replacement.isEmpty()) | 971 | continue; |
952 | replacement += " "; | 972 | } else if(in_braces) { |
953 | replacement += (*vit); | 973 | var_incr++; |
954 | } | 974 | } |
975 | |||
976 | QString replacement; | ||
977 | if(as_env) { | ||
978 | replacement = getenv(val); | ||
979 | } else if(args.isEmpty()) { | ||
980 | if(val.left(1) == ".") | ||
981 | replacement = ""; | ||
982 | else if(val == "LITERAL_WHITESPACE") | ||
983 | replacement = "\t"; | ||
984 | else | ||
985 | replacement = place[varMap(val)].join(" "); | ||
986 | } else { | ||
987 | QStringList arg_list = split_arg_list(args); | ||
988 | for(QStringList::Iterator arit = arg_list.begin(); arit != arg_list.end(); ++arit) { | ||
989 | (*arit) = (*arit).stripWhiteSpace(); // blah, get rid of space | ||
990 | doVariableReplace((*arit), place); | ||
991 | } | ||
992 | debug_msg(1, "Running function: %s( %s )", val.latin1(), arg_list.join("::").latin1()); | ||
993 | if(val.lower() == "member") { | ||
994 | if(arg_list.count() < 1 || arg_list.count() > 2) { | ||
995 | fprintf(stderr, "%s:%d: member(var, place) requires two arguments.\n", | ||
996 | parser.file.latin1(), parser.line_no); | ||
997 | } else { | ||
998 | uint pos = 0; | ||
999 | if(arg_list.count() == 2) | ||
1000 | pos = arg_list[1].toInt(); | ||
1001 | const QStringList &var = place[varMap(arg_list.first())]; | ||
1002 | if(var.count() >= pos) | ||
1003 | replacement = var[pos]; | ||
1004 | } | ||
1005 | } else if(val.lower() == "list") { | ||
1006 | static int x = 0; | ||
1007 | replacement.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++); | ||
1008 | QStringList &lst = (*((QMap<QString, QStringList>*)&place))[replacement]; | ||
1009 | lst.clear(); | ||
1010 | for(QStringList::ConstIterator arg_it = arg_list.begin(); | ||
1011 | arg_it != arg_list.end(); ++arg_it) | ||
1012 | lst += split_value_list((*arg_it)); | ||
1013 | } else if(val.lower() == "join") { | ||
1014 | if(arg_list.count() < 1 || arg_list.count() > 4) { | ||
1015 | fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four" | ||
1016 | "arguments.\n", parser.file.latin1(), parser.line_no); | ||
1017 | } else { | ||
1018 | QString glue, before, after; | ||
1019 | if(arg_list.count() >= 2) | ||
1020 | glue = arg_list[1].replace("\"", "" ); | ||
1021 | if(arg_list.count() >= 3) | ||
1022 | before = arg_list[2].replace("\"", "" ); | ||
1023 | if(arg_list.count() == 4) | ||
1024 | after = arg_list[3].replace("\"", "" ); | ||
1025 | const QStringList &var = place[varMap(arg_list.first())]; | ||
1026 | if(!var.isEmpty()) | ||
1027 | replacement = before + var.join(glue) + after; | ||
1028 | } | ||
1029 | } else if(val.lower() == "find") { | ||
1030 | if(arg_list.count() != 2) { | ||
1031 | fprintf(stderr, "%s:%d find(var, str) requires two arguments\n", | ||
1032 | parser.file.latin1(), parser.line_no); | ||
1033 | } else { | ||
1034 | QRegExp regx(arg_list[1]); | ||
1035 | const QStringList &var = place[varMap(arg_list.first())]; | ||
1036 | for(QStringList::ConstIterator vit = var.begin(); | ||
1037 | vit != var.end(); ++vit) { | ||
1038 | if(regx.search(*vit) != -1) { | ||
1039 | if(!replacement.isEmpty()) | ||
1040 | replacement += " "; | ||
1041 | replacement += (*vit); | ||
955 | } | 1042 | } |
956 | } | 1043 | } |
957 | } else if(reg_var.cap(1).lower() == "system") { | 1044 | } |
958 | if(args.count() != 1) { | 1045 | } else if(val.lower() == "system") { |
959 | fprintf(stderr, "%s:%d system(execut) requires one argument\n", | 1046 | if(arg_list.count() != 1) { |
960 | parser.file.latin1(), parser.line_no); | 1047 | fprintf(stderr, "%s:%d system(execut) requires one argument\n", |
961 | } else { | 1048 | parser.file.latin1(), parser.line_no); |
962 | char buff[256]; | 1049 | } else { |
963 | FILE *proc = QT_POPEN(args.join(" ").latin1(), "r"); | 1050 | char buff[256]; |
964 | while(proc && !feof(proc)) { | 1051 | FILE *proc = QT_POPEN(arg_list.join(" ").latin1(), "r"); |
965 | int read_in = fread(buff, 1, 255, proc); | 1052 | while(proc && !feof(proc)) { |
966 | if(!read_in) | 1053 | int read_in = fread(buff, 1, 255, proc); |
967 | break; | 1054 | if(!read_in) |
968 | for(int i = 0; i < read_in; i++) { | 1055 | break; |
969 | if(buff[i] == '\n' || buff[i] == '\t') | 1056 | for(int i = 0; i < read_in; i++) { |
970 | buff[i] = ' '; | 1057 | if(buff[i] == '\n' || buff[i] == '\t') |
971 | } | 1058 | buff[i] = ' '; |
972 | buff[read_in] = '\0'; | ||
973 | replacement += buff; | ||
974 | } | 1059 | } |
1060 | buff[read_in] = '\0'; | ||
1061 | replacement += buff; | ||
975 | } | 1062 | } |
976 | } else { | ||
977 | fprintf(stderr, "%s:%d: Unknown replace function: %s\n", | ||
978 | parser.file.latin1(), parser.line_no, reg_var.cap(1).latin1()); | ||
979 | } | 1063 | } |
980 | } else { //variable | 1064 | } else { |
981 | if(reg_var.cap(1).left(1) == ".") | 1065 | fprintf(stderr, "%s:%d: Unknown replace function: %s\n", |
982 | replacement = ""; | 1066 | parser.file.latin1(), parser.line_no, val.latin1()); |
983 | else if(reg_var.cap(1) == "LITERAL_WHITESPACE") | ||
984 | replacement = "\t"; | ||
985 | else | ||
986 | replacement = place[varMap(reg_var.cap(1))].join(" "); | ||
987 | } | 1067 | } |
988 | debug_msg(2, "Project parser: %d (%s) :: %s -> %s", x, str.latin1(), | ||
989 | reg_var.capturedTexts().join("::").latin1(), replacement.latin1()); | ||
990 | str.replace(rep, reg_var.matchedLength(), replacement); | ||
991 | } | 1068 | } |
1069 | //actually do replacement now.. | ||
1070 | int mlen = var_incr - var_begin; | ||
1071 | debug_msg(2, "Project Parser [var replace]: '%s' :: %s -> %s", str.latin1(), | ||
1072 | str.mid(var_begin, mlen).latin1(), replacement.latin1()); | ||
1073 | str.replace(var_begin, mlen, replacement); | ||
1074 | var_begin += replacement.length(); | ||
992 | } | 1075 | } |
993 | return str; | 1076 | return str; |
994 | } | 1077 | } |