summaryrefslogtreecommitdiffstats
path: root/qmake
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2021-02-26 17:01:51 +0100
committerAlexey Edelev <alexey.edelev@qt.io>2021-03-01 17:37:03 +0100
commit5dab1e931d20f87fb35812fb64f6a2e344290cfa (patch)
treebffa7f9b7a5251680db03d6e3abf0787c158c03a /qmake
parentd1101c460e173e3554fa4e5c800ab3e82ddc3aad (diff)
Improve QMakeLibraryInfo encapsulation
QMakeLibraryInfo uses external data to produce paths. This causes issues when trying to use it out of the existing qmake environment. Add data fields that contain the path to the binary that uses QMakeLibraryInfo and manually specified qtconf. Task-number: QTBUG-75870 Change-Id: Ic6fa274ede3a9287826ff66c79f155b10d0d455c Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'qmake')
-rw-r--r--qmake/library/ioutils.cpp34
-rw-r--r--qmake/library/ioutils.h1
-rw-r--r--qmake/option.cpp62
-rw-r--r--qmake/qmakelibraryinfo.cpp29
-rw-r--r--qmake/qmakelibraryinfo.h7
5 files changed, 72 insertions, 61 deletions
diff --git a/qmake/library/ioutils.cpp b/qmake/library/ioutils.cpp
index 3a93298ffa..719d3b514a 100644
--- a/qmake/library/ioutils.cpp
+++ b/qmake/library/ioutils.cpp
@@ -49,6 +49,40 @@ QT_BEGIN_NAMESPACE
using namespace QMakeInternal;
+QString IoUtils::binaryAbsLocation(const QString &argv0)
+{
+ QString ret;
+ if (!argv0.isEmpty() && isAbsolutePath(argv0)) {
+ ret = argv0;
+ } else if (argv0.contains(QLatin1Char('/'))
+#ifdef Q_OS_WIN
+ || argv0.contains(QLatin1Char('\\'))
+#endif
+ ) { // relative PWD
+ ret = QDir::current().absoluteFilePath(argv0);
+ } else { // in the PATH
+ QByteArray pEnv = qgetenv("PATH");
+ QDir currentDir = QDir::current();
+#ifdef Q_OS_WIN
+ QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(";"));
+ paths.prepend(QLatin1String("."));
+#else
+ QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(":"));
+#endif
+ for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) {
+ if ((*p).isEmpty())
+ continue;
+ QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0);
+ if (QFile::exists(candidate)) {
+ ret = candidate;
+ break;
+ }
+ }
+ }
+
+ return QDir::cleanPath(ret);
+}
+
IoUtils::FileType IoUtils::fileType(const QString &fileName)
{
Q_ASSERT(fileName.isEmpty() || isAbsolutePath(fileName));
diff --git a/qmake/library/ioutils.h b/qmake/library/ioutils.h
index f4555e8eeb..c2b85dba04 100644
--- a/qmake/library/ioutils.h
+++ b/qmake/library/ioutils.h
@@ -49,6 +49,7 @@ public:
FileIsDir = 2
};
+ static QString binaryAbsLocation(const QString &argv0);
static FileType fileType(const QString &fileName);
static bool exists(const QString &fileName) { return fileType(fileName) != FileNotFound; }
static bool isRelativePath(const QString &fileName);
diff --git a/qmake/option.cpp b/qmake/option.cpp
index 09d790c9c2..1f9d60d7a8 100644
--- a/qmake/option.cpp
+++ b/qmake/option.cpp
@@ -202,8 +202,10 @@ Option::parseCommandLine(QStringList &args, QMakeCmdLineParserState &state)
continue;
default:
QMakeGlobals::ArgumentReturn cmdRet = globals->addCommandLineArguments(state, args, &x);
- if (cmdRet == QMakeGlobals::ArgumentsOk)
+ if (cmdRet == QMakeGlobals::ArgumentsOk) {
+ QMakeLibraryInfo::qtconfManualPath = globals->qtconf;
break;
+ }
if (cmdRet == QMakeGlobals::ArgumentMalformed) {
fprintf(stderr, "***Option %s requires a parameter\n", qPrintable(args.at(x - 1)));
return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
@@ -326,46 +328,19 @@ Option::init(int argc, char **argv)
#endif
if(Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
Option::qmake_mode = default_mode(argv0);
- if (!argv0.isEmpty() && IoUtils::isAbsolutePath(argv0)) {
- globals->qmake_abslocation = argv0;
- } else if (argv0.contains(QLatin1Char('/'))
-#ifdef Q_OS_WIN
- || argv0.contains(QLatin1Char('\\'))
-#endif
- ) { //relative PWD
- globals->qmake_abslocation = QDir::current().absoluteFilePath(argv0);
- } else { //in the PATH
- QByteArray pEnv = qgetenv("PATH");
- QDir currentDir = QDir::current();
-#ifdef Q_OS_WIN
- QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(";"));
- paths.prepend(QLatin1String("."));
-#else
- QStringList paths = QString::fromLocal8Bit(pEnv).split(QLatin1String(":"));
-#endif
- for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) {
- if ((*p).isEmpty())
- continue;
- QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0);
- if (QFile::exists(candidate)) {
- globals->qmake_abslocation = candidate;
- break;
- }
- }
- }
+ globals->qmake_abslocation = IoUtils::binaryAbsLocation(argv0);
if (Q_UNLIKELY(globals->qmake_abslocation.isNull())) {
// This is rather unlikely to ever happen on a modern system ...
globals->qmake_abslocation =
QMakeLibraryInfo::rawLocation(QMakeLibraryInfo::HostBinariesPath,
QMakeLibraryInfo::EffectivePaths)
+ + "/qmake"
#ifdef Q_OS_WIN
- + "/qmake.exe";
-#else
- + "/qmake";
+ ".exe"
#endif
- } else {
- globals->qmake_abslocation = QDir::cleanPath(globals->qmake_abslocation);
+ ;
}
+ QMakeLibraryInfo::binaryAbsLocation = globals->qmake_abslocation;
} else {
Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE;
}
@@ -656,25 +631,4 @@ qmakeAddCacheClear(qmakeCacheClearFunc func, void **data)
cache_items.append(new QMakeCacheClearItem(func, data));
}
-QString qmake_libraryInfoFile()
-{
- if (!Option::globals->qtconf.isEmpty())
- return Option::globals->qtconf;
- if (!Option::globals->qmake_abslocation.isEmpty()) {
- QDir dir(QFileInfo(Option::globals->qmake_abslocation).absolutePath());
- QString qtconfig = dir.filePath("qt" QT_STRINGIFY(QT_VERSION_MAJOR) ".conf");
- if (QFile::exists(qtconfig))
- return qtconfig;
- qtconfig = dir.filePath("qt.conf");
- if (QFile::exists(qtconfig))
- return qtconfig;
- }
- return QString();
-}
-
-QString qmake_abslocation()
-{
- return Option::globals->qmake_abslocation;
-}
-
QT_END_NAMESPACE
diff --git a/qmake/qmakelibraryinfo.cpp b/qmake/qmakelibraryinfo.cpp
index ac8d191248..e8bb70071e 100644
--- a/qmake/qmakelibraryinfo.cpp
+++ b/qmake/qmakelibraryinfo.cpp
@@ -51,9 +51,8 @@
QT_BEGIN_NAMESPACE
-// qmake_libraryInfoFile and qmake_abslocation are defined in option.cpp
-QString qmake_libraryInfoFile();
-QString qmake_abslocation();
+QString QMakeLibraryInfo::binaryAbsLocation;
+QString QMakeLibraryInfo::qtconfManualPath;
struct QMakeLibrarySettings
{
@@ -72,7 +71,7 @@ Q_GLOBAL_STATIC(QMakeLibrarySettings, qmake_library_settings)
QSettings *QMakeLibraryInfo::findConfiguration()
{
- QString qtconfig = qmake_libraryInfoFile();
+ QString qtconfig = libraryInfoFile();
if (!qtconfig.isEmpty())
return new QSettings(qtconfig, QSettings::IniFormat);
return nullptr; // no luck
@@ -139,9 +138,9 @@ void QMakeLibraryInfo::sysrootify(QString &path)
}
}
-static QString getPrefix()
+QString QMakeLibraryInfo::getPrefix()
{
- const QString canonicalQMakePath = QFileInfo(qmake_abslocation()).canonicalPath();
+ const QString canonicalQMakePath = QFileInfo(binaryAbsLocation).canonicalPath();
return QDir::cleanPath(canonicalQMakePath + QLatin1Char('/')
+ QLatin1String(QT_CONFIGURE_RELATIVE_PREFIX_PATH));
}
@@ -274,7 +273,7 @@ QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group
// We make the prefix/sysroot path absolute to the executable's directory.
// loc == PrefixPath while a sysroot is set would make no sense here.
// loc == SysrootPath only makes sense if qmake lives inside the sysroot itself.
- baseDir = QFileInfo(qmake_libraryInfoFile()).absolutePath();
+ baseDir = QFileInfo(libraryInfoFile()).absolutePath();
} else if (loc > SysrootPath && loc <= LastHostPath) {
// We make any other host path absolute to the host prefix directory.
baseDir = rawLocation(HostPrefixPath, group);
@@ -289,4 +288,20 @@ QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group
return ret;
}
+QString QMakeLibraryInfo::libraryInfoFile()
+{
+ if (!qtconfManualPath.isEmpty())
+ return qtconfManualPath;
+ if (!binaryAbsLocation.isEmpty()) {
+ QDir dir(QFileInfo(binaryAbsLocation).absolutePath());
+ QString qtconfig = dir.filePath("qt" QT_STRINGIFY(QT_VERSION_MAJOR) ".conf");
+ if (QFile::exists(qtconfig))
+ return qtconfig;
+ qtconfig = dir.filePath("qt.conf");
+ if (QFile::exists(qtconfig))
+ return qtconfig;
+ }
+ return QString();
+}
+
QT_END_NAMESPACE
diff --git a/qmake/qmakelibraryinfo.h b/qmake/qmakelibraryinfo.h
index 69b62e9876..a198395127 100644
--- a/qmake/qmakelibraryinfo.h
+++ b/qmake/qmakelibraryinfo.h
@@ -75,6 +75,13 @@ struct QMakeLibraryInfo
static void reload();
static bool haveGroup(PathGroup group);
static void sysrootify(QString &path);
+
+ static QString binaryAbsLocation;
+ static QString qtconfManualPath;
+
+private:
+ static QString getPrefix();
+ static QString libraryInfoFile();
};
QT_END_NAMESPACE