2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2020-09-16 06:25:53 +00:00
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
2015-08-22 00:08:19 +00:00
|
|
|
** Copyright (C) 2016 Intel Corporation.
|
2016-01-15 12:36:27 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the qmake application of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "project.h"
|
|
|
|
#include "property.h"
|
|
|
|
#include "option.h"
|
|
|
|
#include "cachekeys.h"
|
|
|
|
#include "metamakefile.h"
|
|
|
|
#include <qnamespace.h>
|
|
|
|
#include <qdebug.h>
|
2020-04-03 15:11:36 +00:00
|
|
|
#include <qregularexpression.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <qdir.h>
|
2017-03-01 11:41:48 +00:00
|
|
|
#include <qdiriterator.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2017-03-01 11:41:48 +00:00
|
|
|
#if defined(Q_OS_UNIX)
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2015-08-22 00:08:19 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
# include <qt_windows.h>
|
|
|
|
#endif
|
|
|
|
|
2017-02-24 15:22:53 +00:00
|
|
|
using namespace QMakeInternal;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2013-10-11 14:25:01 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
|
|
|
struct SedSubst {
|
2020-04-03 15:11:36 +00:00
|
|
|
QRegularExpression from;
|
2013-10-11 14:25:01 +00:00
|
|
|
QString to;
|
|
|
|
};
|
2020-11-27 10:18:00 +00:00
|
|
|
Q_DECLARE_TYPEINFO(SedSubst, Q_RELOCATABLE_TYPE);
|
2013-10-11 14:25:01 +00:00
|
|
|
|
|
|
|
static int doSed(int argc, char **argv)
|
|
|
|
{
|
2020-07-06 09:11:44 +00:00
|
|
|
QList<SedSubst> substs;
|
2013-10-11 14:25:01 +00:00
|
|
|
QList<const char *> inFiles;
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "-e")) {
|
|
|
|
if (++i == argc) {
|
|
|
|
fprintf(stderr, "Error: sed option -e requires an argument\n");
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
QString cmd = QString::fromLocal8Bit(argv[i]);
|
|
|
|
for (int j = 0; j < cmd.length(); j++) {
|
|
|
|
QChar c = cmd.at(j);
|
|
|
|
if (c.isSpace())
|
|
|
|
continue;
|
|
|
|
if (c != QLatin1Char('s')) {
|
|
|
|
fprintf(stderr, "Error: unrecognized sed command '%c'\n", c.toLatin1());
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
QChar sep = ++j < cmd.length() ? cmd.at(j) : QChar();
|
2020-04-03 15:11:36 +00:00
|
|
|
QRegularExpression::PatternOptions matchcase = QRegularExpression::NoPatternOption;
|
2013-10-11 14:25:01 +00:00
|
|
|
bool escaped = false;
|
|
|
|
int phase = 1;
|
|
|
|
QStringList phases;
|
|
|
|
QString curr;
|
|
|
|
while (++j < cmd.length()) {
|
|
|
|
c = cmd.at(j);
|
|
|
|
if (!escaped) {
|
|
|
|
if (c == QLatin1Char(';'))
|
|
|
|
break;
|
|
|
|
if (c == QLatin1Char('\\')) {
|
|
|
|
escaped = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c == sep) {
|
|
|
|
phase++;
|
|
|
|
phases << curr;
|
|
|
|
curr.clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (phase == 1
|
2013-11-20 13:58:22 +00:00
|
|
|
&& (c == QLatin1Char('+') || c == QLatin1Char('?') || c == QLatin1Char('|')
|
2013-10-11 14:25:01 +00:00
|
|
|
|| c == QLatin1Char('{') || c == QLatin1Char('}')
|
|
|
|
|| c == QLatin1Char('(') || c == QLatin1Char(')'))) {
|
2020-06-29 14:54:15 +00:00
|
|
|
// translate sed rx to QRegularExpression
|
2013-10-11 14:25:01 +00:00
|
|
|
escaped ^= 1;
|
|
|
|
}
|
|
|
|
if (escaped) {
|
|
|
|
escaped = false;
|
|
|
|
curr += QLatin1Char('\\');
|
|
|
|
}
|
|
|
|
curr += c;
|
|
|
|
}
|
|
|
|
if (escaped) {
|
|
|
|
fprintf(stderr, "Error: unterminated escape sequence in sed s command\n");
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
if (phase != 3) {
|
|
|
|
fprintf(stderr, "Error: sed s command requires three arguments (%d, %c, %s)\n", phase, sep.toLatin1(), qPrintable(curr));
|
|
|
|
return 3;
|
|
|
|
}
|
2013-11-20 13:12:15 +00:00
|
|
|
if (curr.contains(QLatin1Char('i'))) {
|
|
|
|
curr.remove(QLatin1Char('i'));
|
2020-04-03 15:11:36 +00:00
|
|
|
matchcase = QRegularExpression::CaseInsensitiveOption;
|
2013-11-20 13:12:15 +00:00
|
|
|
}
|
2013-10-11 14:25:01 +00:00
|
|
|
if (curr != QLatin1String("g")) {
|
2013-11-20 13:12:15 +00:00
|
|
|
fprintf(stderr, "Error: sed s command supports only g & i options; g is required\n");
|
2013-10-11 14:25:01 +00:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
SedSubst subst;
|
2020-04-03 15:11:36 +00:00
|
|
|
subst.from = QRegularExpression(phases.at(0), matchcase);
|
2013-10-11 14:25:01 +00:00
|
|
|
subst.to = phases.at(1);
|
2016-02-04 14:12:03 +00:00
|
|
|
subst.to.replace(QLatin1String("\\\\"), QLatin1String("\\")); // QString::replace(rx, sub) groks \1, but not \\.
|
2013-10-11 14:25:01 +00:00
|
|
|
substs << subst;
|
|
|
|
}
|
|
|
|
} else if (argv[i][0] == '-' && argv[i][1] != 0) {
|
|
|
|
fprintf(stderr, "Error: unrecognized sed option '%s'\n", argv[i]);
|
|
|
|
return 3;
|
|
|
|
} else {
|
|
|
|
inFiles << argv[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inFiles.isEmpty())
|
|
|
|
inFiles << "-";
|
2016-01-26 13:38:54 +00:00
|
|
|
for (const char *inFile : qAsConst(inFiles)) {
|
2013-10-11 14:25:01 +00:00
|
|
|
FILE *f;
|
|
|
|
if (!strcmp(inFile, "-")) {
|
|
|
|
f = stdin;
|
2019-11-29 17:13:01 +00:00
|
|
|
} else if (!(f = fopen(inFile, "rb"))) {
|
2013-10-11 14:25:01 +00:00
|
|
|
perror(inFile);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
QTextStream is(f);
|
|
|
|
while (!is.atEnd()) {
|
|
|
|
QString line = is.readLine();
|
|
|
|
for (int i = 0; i < substs.size(); i++)
|
|
|
|
line.replace(substs.at(i).from, substs.at(i).to);
|
|
|
|
puts(qPrintable(line));
|
|
|
|
}
|
|
|
|
if (f != stdin)
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-28 16:19:51 +00:00
|
|
|
static int doLink(int argc, char **argv)
|
|
|
|
{
|
|
|
|
bool isSymlink = false;
|
|
|
|
bool force = false;
|
|
|
|
QList<const char *> inFiles;
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "-s")) {
|
|
|
|
isSymlink = true;
|
|
|
|
} else if (!strcmp(argv[i], "-f")) {
|
|
|
|
force = true;
|
|
|
|
} else if (argv[i][0] == '-') {
|
|
|
|
fprintf(stderr, "Error: unrecognized ln option '%s'\n", argv[i]);
|
|
|
|
return 3;
|
|
|
|
} else {
|
|
|
|
inFiles << argv[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inFiles.size() != 2) {
|
|
|
|
fprintf(stderr, "Error: this ln requires exactly two file arguments\n");
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
if (!isSymlink) {
|
|
|
|
fprintf(stderr, "Error: this ln supports faking symlinks only\n");
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
QString target = QString::fromLocal8Bit(inFiles[0]);
|
|
|
|
QString linkname = QString::fromLocal8Bit(inFiles[1]);
|
|
|
|
|
|
|
|
QDir destdir;
|
|
|
|
QFileInfo tfi(target);
|
|
|
|
QFileInfo lfi(linkname);
|
|
|
|
if (lfi.isDir()) {
|
|
|
|
destdir.setPath(linkname);
|
|
|
|
lfi.setFile(destdir, tfi.fileName());
|
|
|
|
} else {
|
|
|
|
destdir.setPath(lfi.path());
|
|
|
|
}
|
|
|
|
if (!destdir.exists()) {
|
|
|
|
fprintf(stderr, "Error: destination directory %s does not exist\n", qPrintable(destdir.path()));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
tfi.setFile(destdir.absoluteFilePath(tfi.filePath()));
|
|
|
|
if (!tfi.exists()) {
|
|
|
|
fprintf(stderr, "Error: this ln does not support symlinking non-existing targets\n");
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
if (tfi.isDir()) {
|
|
|
|
fprintf(stderr, "Error: this ln does not support symlinking directories\n");
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
if (lfi.exists()) {
|
|
|
|
if (!force) {
|
|
|
|
fprintf(stderr, "Error: %s exists\n", qPrintable(lfi.filePath()));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!QFile::remove(lfi.filePath())) {
|
|
|
|
fprintf(stderr, "Error: cannot overwrite %s\n", qPrintable(lfi.filePath()));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!QFile::copy(tfi.filePath(), lfi.filePath())) {
|
|
|
|
fprintf(stderr, "Error: cannot copy %s to %s\n",
|
|
|
|
qPrintable(tfi.filePath()), qPrintable(lfi.filePath()));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-24 15:22:53 +00:00
|
|
|
#endif
|
|
|
|
|
2019-08-06 07:52:34 +00:00
|
|
|
static bool setFilePermissions(QFile &file, QFileDevice::Permissions permissions)
|
|
|
|
{
|
|
|
|
if (file.setPermissions(permissions))
|
|
|
|
return true;
|
|
|
|
fprintf(stderr, "Error setting permissions on %s: %s\n",
|
|
|
|
qPrintable(file.fileName()), qPrintable(file.errorString()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool copyFileTimes(QFile &targetFile, const QString &sourceFilePath,
|
|
|
|
bool mustEnsureWritability, QString *errorString)
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
bool mustRestorePermissions = false;
|
|
|
|
QFileDevice::Permissions targetPermissions;
|
|
|
|
if (mustEnsureWritability) {
|
|
|
|
targetPermissions = targetFile.permissions();
|
|
|
|
if (!targetPermissions.testFlag(QFileDevice::WriteUser)) {
|
|
|
|
mustRestorePermissions = true;
|
|
|
|
if (!setFilePermissions(targetFile, targetPermissions | QFileDevice::WriteUser))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-10-15 08:42:30 +00:00
|
|
|
#else
|
|
|
|
Q_UNUSED(mustEnsureWritability);
|
2019-08-06 07:52:34 +00:00
|
|
|
#endif
|
|
|
|
if (!IoUtils::touchFile(targetFile.fileName(), sourceFilePath, errorString))
|
|
|
|
return false;
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
if (mustRestorePermissions && !setFilePermissions(targetFile, targetPermissions))
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-04 18:28:10 +00:00
|
|
|
static int installFile(const QString &source, const QString &target, bool exe = false,
|
|
|
|
bool preservePermissions = false)
|
2017-02-24 15:22:53 +00:00
|
|
|
{
|
|
|
|
QFile sourceFile(source);
|
2017-08-18 10:35:27 +00:00
|
|
|
QFile targetFile(target);
|
|
|
|
if (targetFile.exists()) {
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
targetFile.setPermissions(targetFile.permissions() | QFile::WriteUser);
|
|
|
|
#endif
|
|
|
|
QFile::remove(target);
|
|
|
|
} else {
|
|
|
|
QDir::root().mkpath(QFileInfo(target).absolutePath());
|
|
|
|
}
|
2017-02-24 15:22:53 +00:00
|
|
|
|
|
|
|
if (!sourceFile.copy(target)) {
|
|
|
|
fprintf(stderr, "Error copying %s to %s: %s\n", source.toLatin1().constData(), qPrintable(target), qPrintable(sourceFile.errorString()));
|
|
|
|
return 3;
|
|
|
|
}
|
2017-02-27 13:05:06 +00:00
|
|
|
|
2019-04-04 18:28:10 +00:00
|
|
|
QFileDevice::Permissions targetPermissions = preservePermissions
|
|
|
|
? sourceFile.permissions()
|
|
|
|
: (QFileDevice::ReadOwner | QFileDevice::WriteOwner
|
|
|
|
| QFileDevice::ReadUser | QFileDevice::WriteUser
|
|
|
|
| QFileDevice::ReadGroup | QFileDevice::ReadOther);
|
2017-02-27 13:05:06 +00:00
|
|
|
if (exe) {
|
2019-04-04 18:28:10 +00:00
|
|
|
targetPermissions |= QFileDevice::ExeOwner | QFileDevice::ExeUser |
|
|
|
|
QFileDevice::ExeGroup | QFileDevice::ExeOther;
|
|
|
|
}
|
2019-08-06 07:52:34 +00:00
|
|
|
if (!setFilePermissions(targetFile, targetPermissions))
|
2019-04-04 18:28:10 +00:00
|
|
|
return 3;
|
2017-02-27 13:05:06 +00:00
|
|
|
|
2017-02-24 15:22:53 +00:00
|
|
|
QString error;
|
2019-08-06 07:52:34 +00:00
|
|
|
if (!copyFileTimes(targetFile, sourceFile.fileName(), preservePermissions, &error)) {
|
2017-02-24 15:22:53 +00:00
|
|
|
fprintf(stderr, "%s", qPrintable(error));
|
|
|
|
return 3;
|
|
|
|
}
|
2019-08-06 07:52:34 +00:00
|
|
|
|
2017-02-24 15:22:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-04 18:28:10 +00:00
|
|
|
static int installFileOrDirectory(const QString &source, const QString &target,
|
|
|
|
bool preservePermissions = false)
|
2017-03-01 11:41:48 +00:00
|
|
|
{
|
|
|
|
QFileInfo fi(source);
|
|
|
|
if (false) {
|
|
|
|
#if defined(Q_OS_UNIX)
|
|
|
|
} else if (fi.isSymLink()) {
|
|
|
|
QString linkTarget;
|
|
|
|
if (!IoUtils::readLinkTarget(fi.absoluteFilePath(), &linkTarget)) {
|
|
|
|
fprintf(stderr, "Could not read link %s: %s\n", qPrintable(fi.absoluteFilePath()), strerror(errno));
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
QFile::remove(target);
|
|
|
|
if (::symlink(linkTarget.toLocal8Bit().constData(), target.toLocal8Bit().constData()) < 0) {
|
|
|
|
fprintf(stderr, "Could not create link: %s\n", strerror(errno));
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else if (fi.isDir()) {
|
|
|
|
QDir::current().mkpath(target);
|
|
|
|
|
2019-04-03 12:30:56 +00:00
|
|
|
QDirIterator it(source, QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);
|
2017-03-01 11:41:48 +00:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
const QFileInfo &entry = it.fileInfo();
|
|
|
|
const QString &entryTarget = target + QDir::separator() + entry.fileName();
|
|
|
|
|
2019-04-04 18:28:10 +00:00
|
|
|
const int recursionResult = installFileOrDirectory(entry.filePath(), entryTarget, true);
|
2017-03-01 11:41:48 +00:00
|
|
|
if (recursionResult != 0)
|
|
|
|
return recursionResult;
|
|
|
|
}
|
|
|
|
} else {
|
2019-04-04 18:28:10 +00:00
|
|
|
const int fileCopyResult = installFile(source, target, /*exe*/ false, preservePermissions);
|
2017-03-01 11:41:48 +00:00
|
|
|
if (fileCopyResult != 0)
|
|
|
|
return fileCopyResult;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-24 15:22:53 +00:00
|
|
|
static int doQInstall(int argc, char **argv)
|
|
|
|
{
|
2017-05-02 12:44:44 +00:00
|
|
|
bool installExecutable = false;
|
|
|
|
if (argc == 3 && !strcmp(argv[0], "-exe")) {
|
|
|
|
installExecutable = true;
|
|
|
|
--argc;
|
|
|
|
++argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc != 2 && !installExecutable) {
|
|
|
|
fprintf(stderr, "Error: usage: [-exe] source target\n");
|
2017-02-24 15:22:53 +00:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2017-05-02 12:44:44 +00:00
|
|
|
const QString source = QString::fromLocal8Bit(argv[0]);
|
|
|
|
const QString target = QString::fromLocal8Bit(argv[1]);
|
2017-02-24 15:22:53 +00:00
|
|
|
|
2017-05-02 12:44:44 +00:00
|
|
|
if (installExecutable)
|
2017-02-27 13:05:06 +00:00
|
|
|
return installFile(source, target, /*exe=*/true);
|
2017-05-02 12:44:44 +00:00
|
|
|
return installFileOrDirectory(source, target);
|
2017-02-24 15:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:25:01 +00:00
|
|
|
static int doInstall(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (!argc) {
|
|
|
|
fprintf(stderr, "Error: -install requires further arguments\n");
|
|
|
|
return 3;
|
|
|
|
}
|
2017-02-24 15:22:53 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2013-10-11 14:25:01 +00:00
|
|
|
if (!strcmp(argv[0], "sed"))
|
|
|
|
return doSed(argc - 1, argv + 1);
|
2015-05-28 16:19:51 +00:00
|
|
|
if (!strcmp(argv[0], "ln"))
|
|
|
|
return doLink(argc - 1, argv + 1);
|
2017-02-24 15:22:53 +00:00
|
|
|
#endif
|
|
|
|
if (!strcmp(argv[0], "qinstall"))
|
|
|
|
return doQInstall(argc - 1, argv + 1);
|
2013-10-11 14:25:01 +00:00
|
|
|
fprintf(stderr, "Error: unrecognized -install subcommand '%s'\n", argv[0]);
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2017-02-24 15:22:53 +00:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
2015-08-22 00:08:19 +00:00
|
|
|
static int dumpMacros(const wchar_t *cmdline)
|
|
|
|
{
|
|
|
|
// from http://stackoverflow.com/questions/3665537/how-to-find-out-cl-exes-built-in-macros
|
|
|
|
int argc;
|
|
|
|
wchar_t **argv = CommandLineToArgvW(cmdline, &argc);
|
|
|
|
if (!argv)
|
|
|
|
return 2;
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
if (argv[i][0] != L'-' || argv[i][1] != 'D')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wchar_t *value = wcschr(argv[i], L'=');
|
|
|
|
if (value) {
|
|
|
|
*value = 0;
|
|
|
|
++value;
|
|
|
|
} else {
|
|
|
|
// point to the NUL at the end, so we don't print anything
|
|
|
|
value = argv[i] + wcslen(argv[i]);
|
|
|
|
}
|
|
|
|
wprintf(L"#define %Ls %Ls\n", argv[i] + 2, value);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-11 14:25:01 +00:00
|
|
|
#endif // Q_OS_WIN
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/* This is to work around lame implementation on Darwin. It has been noted that the getpwd(3) function
|
|
|
|
is much too slow, and called much too often inside of Qt (every fileFixify). With this we use a locally
|
|
|
|
cached copy because I can control all the times it is set (because Qt never sets the pwd under me).
|
|
|
|
*/
|
|
|
|
static QString pwd;
|
|
|
|
QString qmake_getpwd()
|
|
|
|
{
|
|
|
|
if(pwd.isNull())
|
|
|
|
pwd = QDir::currentPath();
|
|
|
|
return pwd;
|
|
|
|
}
|
|
|
|
bool qmake_setpwd(const QString &p)
|
|
|
|
{
|
|
|
|
if(QDir::setCurrent(p)) {
|
|
|
|
pwd = QDir::currentPath();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int runQMake(int argc, char **argv)
|
|
|
|
{
|
2020-09-16 06:25:53 +00:00
|
|
|
qSetGlobalQHashSeed(0);
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// stderr is unbuffered by default, but stdout buffering depends on whether
|
|
|
|
// there is a terminal attached. Buffering can make output from stderr and stdout
|
|
|
|
// appear out of sync, so force stdout to be unbuffered as well.
|
|
|
|
// This is particularly important for things like QtCreator and scripted builds.
|
|
|
|
setvbuf(stdout, (char *)NULL, _IONBF, 0);
|
|
|
|
|
2013-10-11 14:25:01 +00:00
|
|
|
// Workaround for inferior/missing command line tools on Windows: make our own!
|
2020-10-23 08:19:17 +00:00
|
|
|
if (argc >= 4 && !strcmp(argv[1], "-qtconf") && !strcmp(argv[3], "-install"))
|
|
|
|
return doInstall(argc - 4, argv + 4);
|
2013-10-11 14:25:01 +00:00
|
|
|
if (argc >= 2 && !strcmp(argv[1], "-install"))
|
|
|
|
return doInstall(argc - 2, argv + 2);
|
2015-08-22 00:08:19 +00:00
|
|
|
|
2017-02-24 15:22:53 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2015-08-22 00:08:19 +00:00
|
|
|
{
|
|
|
|
// Support running as Visual C++'s compiler
|
|
|
|
const wchar_t *cmdline = _wgetenv(L"MSC_CMD_FLAGS");
|
|
|
|
if (!cmdline || !*cmdline)
|
|
|
|
cmdline = _wgetenv(L"MSC_IDE_FLAGS");
|
|
|
|
if (cmdline && *cmdline)
|
|
|
|
return dumpMacros(cmdline);
|
|
|
|
}
|
2013-10-11 14:25:01 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-29 18:18:51 +00:00
|
|
|
QMakeVfs vfs;
|
|
|
|
Option::vfs = &vfs;
|
2012-09-05 16:29:19 +00:00
|
|
|
QMakeGlobals globals;
|
|
|
|
Option::globals = &globals;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// parse command line
|
|
|
|
int ret = Option::init(argc, argv);
|
|
|
|
if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
|
|
|
|
if ((ret & Option::QMAKE_CMDLINE_ERROR) != 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString oldpwd = qmake_getpwd();
|
|
|
|
|
2013-02-25 14:11:45 +00:00
|
|
|
Option::output_dir = oldpwd; //for now this is the output dir
|
2018-07-17 13:11:07 +00:00
|
|
|
if (!Option::output.fileName().isEmpty() && Option::output.fileName() != "-") {
|
|
|
|
// The output 'filename', as given by the -o option, might include one
|
|
|
|
// or more directories, so we may need to rebase the output directory.
|
2011-04-27 10:05:43 +00:00
|
|
|
QFileInfo fi(Option::output);
|
2018-07-17 13:11:07 +00:00
|
|
|
|
|
|
|
QDir dir(QDir::cleanPath(fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath()));
|
|
|
|
|
|
|
|
// Don't treat Xcode project directory as part of OUT_PWD
|
|
|
|
if (dir.dirName().endsWith(QLatin1String(".xcodeproj"))) {
|
|
|
|
// Note: we're intentionally not using cdUp(), as the dir may not exist
|
|
|
|
dir.setPath(QDir::cleanPath(dir.filePath("..")));
|
2014-06-05 10:30:07 +00:00
|
|
|
}
|
2018-07-17 13:11:07 +00:00
|
|
|
|
|
|
|
Option::output_dir = dir.path();
|
|
|
|
QString absoluteFilePath = QDir::cleanPath(fi.absoluteFilePath());
|
|
|
|
Option::output.setFileName(absoluteFilePath.mid(Option::output_dir.length() + 1));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QMakeProperty prop;
|
2021-03-09 15:32:02 +00:00
|
|
|
switch (Option::qmake_mode) {
|
|
|
|
case Option::QMAKE_QUERY_PROPERTY:
|
|
|
|
return prop.queryProperty(Option::prop::properties);
|
|
|
|
case Option::QMAKE_SET_PROPERTY:
|
|
|
|
return prop.setProperty(Option::prop::properties);
|
|
|
|
case Option::QMAKE_UNSET_PROPERTY:
|
|
|
|
prop.unsetProperty(Option::prop::properties);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
globals.setQMakeProperty(&prop);
|
|
|
|
|
|
|
|
ProFileCache proFileCache;
|
|
|
|
Option::proFileCache = &proFileCache;
|
2013-05-29 18:18:51 +00:00
|
|
|
QMakeParser parser(&proFileCache, &vfs, &Option::evalHandler);
|
2012-09-05 16:29:19 +00:00
|
|
|
Option::parser = &parser;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QMakeProject project;
|
2011-04-27 10:05:43 +00:00
|
|
|
int exit_val = 0;
|
|
|
|
QStringList files;
|
|
|
|
if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
|
|
|
|
files << "(*hack*)"; //we don't even use files, but we do the for() body once
|
|
|
|
else
|
|
|
|
files = Option::mkfile::project_files;
|
|
|
|
for(QStringList::Iterator pfile = files.begin(); pfile != files.end(); pfile++) {
|
|
|
|
if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
|
|
|
|
Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
|
2011-11-15 08:34:38 +00:00
|
|
|
QString fn = Option::normalizePath(*pfile);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!QFile::exists(fn)) {
|
2011-11-15 08:34:38 +00:00
|
|
|
fprintf(stderr, "Cannot find file: %s.\n",
|
|
|
|
QDir::toNativeSeparators(fn).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
exit_val = 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup pwd properly
|
2011-11-15 08:34:38 +00:00
|
|
|
debug_msg(1, "Resetting dir to: %s",
|
|
|
|
QDir::toNativeSeparators(oldpwd).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
qmake_setpwd(oldpwd); //reset the old pwd
|
2011-11-15 08:34:38 +00:00
|
|
|
int di = fn.lastIndexOf(QLatin1Char('/'));
|
2011-04-27 10:05:43 +00:00
|
|
|
if(di != -1) {
|
2011-11-15 08:34:38 +00:00
|
|
|
debug_msg(1, "Changing dir to: %s",
|
|
|
|
QDir::toNativeSeparators(fn.left(di)).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!qmake_setpwd(fn.left(di)))
|
2011-11-15 08:34:38 +00:00
|
|
|
fprintf(stderr, "Cannot find directory: %s\n",
|
|
|
|
QDir::toNativeSeparators(fn.left(di)).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
fn = fn.right(fn.length() - di - 1);
|
|
|
|
}
|
|
|
|
|
2012-05-09 13:29:25 +00:00
|
|
|
Option::prepareProject(fn);
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// read project..
|
|
|
|
if(!project.read(fn)) {
|
|
|
|
fprintf(stderr, "Error processing project file: %s\n",
|
2012-08-28 08:12:36 +00:00
|
|
|
QDir::toNativeSeparators(*pfile).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
exit_val = 3;
|
|
|
|
continue;
|
|
|
|
}
|
2012-04-23 17:27:43 +00:00
|
|
|
if (Option::mkfile::do_preprocess) {
|
|
|
|
project.dump();
|
|
|
|
continue; //no need to create makefile
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool success = true;
|
|
|
|
MetaMakefileGenerator *mkfile = MetaMakefileGenerator::createMetaGenerator(&project, QString(), false, &success);
|
|
|
|
if (!success)
|
|
|
|
exit_val = 3;
|
|
|
|
|
2013-02-25 18:54:48 +00:00
|
|
|
if (mkfile && !mkfile->write()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
|
|
|
|
fprintf(stderr, "Unable to generate project file.\n");
|
|
|
|
else
|
2011-11-15 08:34:38 +00:00
|
|
|
fprintf(stderr, "Unable to generate makefile for: %s\n",
|
|
|
|
QDir::toNativeSeparators(*pfile).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
exit_val = 5;
|
|
|
|
}
|
|
|
|
delete mkfile;
|
2018-08-02 22:22:24 +00:00
|
|
|
mkfile = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
qmakeClearCaches();
|
|
|
|
return exit_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
return QT_PREPEND_NAMESPACE(runQMake)(argc, argv);
|
|
|
|
}
|