2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2013-08-13 10:52:57 +02:00
|
|
|
|
|
|
|
|
#include "qmakeprojectimporter.h"
|
|
|
|
|
|
2022-09-25 22:42:53 +02:00
|
|
|
#include "makefileparse.h"
|
|
|
|
|
#include "qmakebuildconfiguration.h"
|
2013-08-13 10:52:57 +02:00
|
|
|
#include "qmakebuildinfo.h"
|
2023-08-21 14:38:22 +02:00
|
|
|
#include "qmakekitaspect.h"
|
2013-10-16 12:10:22 +02:00
|
|
|
#include "qmakeproject.h"
|
2022-09-25 22:42:53 +02:00
|
|
|
#include "qmakeprojectmanagertr.h"
|
2015-03-04 17:14:28 +01:00
|
|
|
#include "qmakestep.h"
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2019-01-29 16:51:17 +01:00
|
|
|
#include <projectexplorer/buildinfo.h>
|
2016-12-16 00:43:14 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2013-08-13 10:52:57 +02:00
|
|
|
#include <projectexplorer/kitmanager.h>
|
2014-08-04 15:17:28 +02:00
|
|
|
#include <projectexplorer/toolchain.h>
|
|
|
|
|
#include <projectexplorer/toolchainmanager.h>
|
2019-01-29 16:51:17 +01:00
|
|
|
|
2023-08-11 11:23:12 +02:00
|
|
|
#include <qtsupport/qtkitaspect.h>
|
2013-08-13 10:52:57 +02:00
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
|
|
|
|
#include <qtsupport/qtversionfactory.h>
|
|
|
|
|
#include <qtsupport/qtversionmanager.h>
|
2016-08-24 15:53:50 +02:00
|
|
|
|
2014-08-04 15:17:28 +02:00
|
|
|
#include <utils/algorithm.h>
|
2023-05-03 17:05:35 +02:00
|
|
|
#include <utils/process.h>
|
2016-08-24 15:53:50 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2013-08-13 10:52:57 +02:00
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
2014-10-23 18:13:15 +02:00
|
|
|
#include <QStringList>
|
2015-03-04 17:14:28 +01:00
|
|
|
#include <QLoggingCategory>
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2016-08-25 14:32:48 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
2014-10-23 18:13:15 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace QtSupport;
|
|
|
|
|
using namespace Utils;
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2022-09-26 14:50:52 +02:00
|
|
|
namespace QmakeProjectManager::Internal {
|
|
|
|
|
|
2022-09-30 12:42:20 +02:00
|
|
|
const Id QT_IS_TEMPORARY("Qmake.TempQt");
|
2022-09-26 14:50:52 +02:00
|
|
|
const char IOSQT[] = "Qt4ProjectManager.QtVersion.Ios"; // ugly
|
2016-08-25 14:32:48 +02:00
|
|
|
|
|
|
|
|
struct DirectoryData
|
|
|
|
|
{
|
|
|
|
|
QString makefile;
|
2022-09-30 12:42:20 +02:00
|
|
|
FilePath buildDirectory;
|
|
|
|
|
FilePath canonicalQmakeBinary;
|
2016-08-25 14:32:48 +02:00
|
|
|
QtProjectImporter::QtVersionData qtVersionData;
|
2019-05-27 15:19:36 +02:00
|
|
|
QString parsedSpec;
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion::QmakeBuildConfigs buildConfig;
|
2016-08-25 14:32:48 +02:00
|
|
|
QString additionalArguments;
|
|
|
|
|
QMakeStepConfig config;
|
|
|
|
|
QMakeStepConfig::OsType osType;
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
QmakeProjectImporter::QmakeProjectImporter(const FilePath &path) :
|
2016-08-24 15:53:50 +02:00
|
|
|
QtProjectImporter(path)
|
2013-08-13 10:52:57 +02:00
|
|
|
{ }
|
|
|
|
|
|
2022-09-26 14:21:12 +02:00
|
|
|
FilePaths QmakeProjectImporter::importCandidates()
|
2013-08-13 10:52:57 +02:00
|
|
|
{
|
2022-09-26 14:50:52 +02:00
|
|
|
FilePaths candidates;
|
2015-03-04 17:14:28 +01:00
|
|
|
|
2022-09-26 14:50:52 +02:00
|
|
|
const FilePath pfp = projectFilePath();
|
|
|
|
|
const QString prefix = pfp.baseName();
|
|
|
|
|
candidates << pfp.absolutePath();
|
2016-08-25 14:32:48 +02:00
|
|
|
|
2022-09-26 14:50:52 +02:00
|
|
|
for (Kit *k : KitManager::kits()) {
|
2019-12-04 13:19:34 +01:00
|
|
|
const FilePath sbdir = QmakeBuildConfiguration::shadowBuildDirectory
|
|
|
|
|
(projectFilePath(), k, QString(), BuildConfiguration::Unknown);
|
|
|
|
|
|
2022-09-26 14:50:52 +02:00
|
|
|
const FilePath baseDir = sbdir.absolutePath();
|
|
|
|
|
for (const FilePath &path : baseDir.dirEntries(QDir::Filters())) {
|
|
|
|
|
if (path.fileName().startsWith(prefix) && !candidates.contains(path))
|
2016-08-25 14:32:48 +02:00
|
|
|
candidates << path;
|
|
|
|
|
}
|
2015-03-04 17:14:28 +01:00
|
|
|
}
|
2022-09-26 14:50:52 +02:00
|
|
|
return candidates;
|
2016-08-25 14:32:48 +02:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 19:16:40 +01:00
|
|
|
QList<void *> QmakeProjectImporter::examineDirectory(const FilePath &importPath,
|
|
|
|
|
QString *warningMessage) const
|
2016-08-25 14:32:48 +02:00
|
|
|
{
|
2020-12-02 19:16:40 +01:00
|
|
|
Q_UNUSED(warningMessage)
|
2016-08-25 14:32:48 +02:00
|
|
|
QList<void *> result;
|
|
|
|
|
const QLoggingCategory &logs = MakeFileParse::logging();
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2022-09-30 13:13:35 +02:00
|
|
|
const QStringList makefiles = QDir(importPath.toString()).entryList(QStringList(("Makefile*")));
|
2015-03-04 17:14:28 +01:00
|
|
|
qCDebug(logs) << " Makefiles:" << makefiles;
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2022-09-30 13:13:35 +02:00
|
|
|
for (const QString &file : makefiles) {
|
2016-08-25 14:32:48 +02:00
|
|
|
std::unique_ptr<DirectoryData> data(new DirectoryData);
|
|
|
|
|
data->makefile = file;
|
|
|
|
|
data->buildDirectory = importPath;
|
|
|
|
|
|
2015-03-04 17:14:28 +01:00
|
|
|
qCDebug(logs) << " Parsing makefile" << file;
|
2013-08-13 10:52:57 +02:00
|
|
|
// find interesting makefiles
|
2021-08-12 15:04:18 +02:00
|
|
|
const FilePath makefile = importPath / file;
|
2020-09-08 10:32:17 +02:00
|
|
|
MakeFileParse parse(makefile, MakeFileParse::Mode::FilterKnownConfigValues);
|
2016-08-25 14:32:48 +02:00
|
|
|
if (parse.makeFileState() != MakeFileParse::Okay) {
|
|
|
|
|
qCDebug(logs) << " Parsing the makefile failed" << makefile;
|
2013-08-13 10:52:57 +02:00
|
|
|
continue;
|
2015-03-04 17:14:28 +01:00
|
|
|
}
|
2021-08-12 15:04:18 +02:00
|
|
|
if (parse.srcProFile() != projectFilePath()) {
|
2015-03-04 17:14:28 +01:00
|
|
|
qCDebug(logs) << " pro files doesn't match" << parse.srcProFile() << projectFilePath();
|
2013-08-13 10:52:57 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 15:04:18 +02:00
|
|
|
data->canonicalQmakeBinary = parse.qmakePath().canonicalPath();
|
2016-08-25 14:32:48 +02:00
|
|
|
if (data->canonicalQmakeBinary.isEmpty()) {
|
|
|
|
|
qCDebug(logs) << " " << parse.qmakePath() << "doesn't exist anymore";
|
|
|
|
|
continue;
|
2015-03-04 17:14:28 +01:00
|
|
|
}
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2016-08-25 14:32:48 +02:00
|
|
|
qCDebug(logs) << " QMake:" << data->canonicalQmakeBinary;
|
|
|
|
|
|
|
|
|
|
data->qtVersionData = QtProjectImporter::findOrCreateQtVersion(data->canonicalQmakeBinary);
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion *version = data->qtVersionData.qt;
|
2016-08-25 14:32:48 +02:00
|
|
|
bool isTemporaryVersion = data->qtVersionData.isTemporary;
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(version, continue);
|
|
|
|
|
|
|
|
|
|
qCDebug(logs) << " qt version:" << version->displayName() << " temporary:" << isTemporaryVersion;
|
|
|
|
|
|
|
|
|
|
data->osType = parse.config().osType;
|
|
|
|
|
|
|
|
|
|
qCDebug(logs) << " osType: " << data->osType;
|
|
|
|
|
if (version->type() == QLatin1String(IOSQT)
|
|
|
|
|
&& data->osType == QMakeStepConfig::NoOsType) {
|
|
|
|
|
data->osType = QMakeStepConfig::IphoneOS;
|
|
|
|
|
qCDebug(logs) << " IOS found without osType, adjusting osType" << data->osType;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 17:14:28 +01:00
|
|
|
// find qmake arguments and mkspec
|
2016-08-25 14:32:48 +02:00
|
|
|
data->additionalArguments = parse.unparsedArguments();
|
|
|
|
|
qCDebug(logs) << " Unparsed arguments:" << data->additionalArguments;
|
|
|
|
|
data->parsedSpec =
|
2021-08-12 15:04:18 +02:00
|
|
|
QmakeBuildConfiguration::extractSpecFromArguments(&(data->additionalArguments), importPath, version);
|
2016-08-25 14:32:48 +02:00
|
|
|
qCDebug(logs) << " Extracted spec:" << data->parsedSpec;
|
|
|
|
|
qCDebug(logs) << " Arguments now:" << data->additionalArguments;
|
|
|
|
|
|
2019-05-27 15:19:36 +02:00
|
|
|
const QString versionSpec = version->mkspec();
|
|
|
|
|
if (data->parsedSpec.isEmpty() || data->parsedSpec == "default") {
|
2016-08-25 14:32:48 +02:00
|
|
|
data->parsedSpec = versionSpec;
|
|
|
|
|
qCDebug(logs) << " No parsed spec or default spec => parsed spec now:" << data->parsedSpec;
|
2015-03-04 17:14:28 +01:00
|
|
|
}
|
2016-08-25 14:32:48 +02:00
|
|
|
data->buildConfig = parse.effectiveBuildConfig(data->qtVersionData.qt->defaultBuildConfig());
|
|
|
|
|
data->config = parse.config();
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2016-08-25 14:32:48 +02:00
|
|
|
result.append(data.release());
|
2013-08-13 10:52:57 +02:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 14:32:48 +02:00
|
|
|
bool QmakeProjectImporter::matchKit(void *directoryData, const Kit *k) const
|
2013-08-13 10:52:57 +02:00
|
|
|
{
|
2018-07-12 23:59:51 +02:00
|
|
|
auto *data = static_cast<DirectoryData *>(directoryData);
|
2016-08-25 14:32:48 +02:00
|
|
|
const QLoggingCategory &logs = MakeFileParse::logging();
|
|
|
|
|
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion *kitVersion = QtKitAspect::qtVersion(k);
|
2019-05-27 15:19:36 +02:00
|
|
|
QString kitSpec = QmakeKitAspect::mkspec(k);
|
2020-02-18 18:25:26 +01:00
|
|
|
ToolChain *tc = ToolChainKitAspect::cxxToolChain(k);
|
2016-08-25 14:32:48 +02:00
|
|
|
if (kitSpec.isEmpty() && kitVersion)
|
|
|
|
|
kitSpec = kitVersion->mkspecFor(tc);
|
|
|
|
|
QMakeStepConfig::OsType kitOsType = QMakeStepConfig::NoOsType;
|
|
|
|
|
if (tc) {
|
|
|
|
|
kitOsType = QMakeStepConfig::osTypeFor(tc->targetAbi(), kitVersion);
|
|
|
|
|
}
|
|
|
|
|
qCDebug(logs) << k->displayName()
|
|
|
|
|
<< "version:" << (kitVersion == data->qtVersionData.qt)
|
|
|
|
|
<< "spec:" << (kitSpec == data->parsedSpec)
|
|
|
|
|
<< "ostype:" << (kitOsType == data->osType);
|
|
|
|
|
return kitVersion == data->qtVersionData.qt
|
|
|
|
|
&& kitSpec == data->parsedSpec
|
|
|
|
|
&& kitOsType == data->osType;
|
|
|
|
|
}
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2016-08-25 14:32:48 +02:00
|
|
|
Kit *QmakeProjectImporter::createKit(void *directoryData) const
|
|
|
|
|
{
|
2018-07-12 23:59:51 +02:00
|
|
|
auto *data = static_cast<DirectoryData *>(directoryData);
|
2021-09-06 09:31:48 +02:00
|
|
|
return createTemporaryKit(data->qtVersionData, data->parsedSpec, data->osType);
|
2016-08-25 14:32:48 +02:00
|
|
|
}
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2020-01-09 18:42:28 +01:00
|
|
|
const QList<BuildInfo> QmakeProjectImporter::buildInfoList(void *directoryData) const
|
2016-08-25 14:32:48 +02:00
|
|
|
{
|
2018-07-12 23:59:51 +02:00
|
|
|
auto *data = static_cast<DirectoryData *>(directoryData);
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2016-08-25 14:32:48 +02:00
|
|
|
// create info:
|
2020-01-09 18:42:28 +01:00
|
|
|
BuildInfo info;
|
2022-01-21 16:06:36 +01:00
|
|
|
if (data->buildConfig & QtVersion::DebugBuild) {
|
2019-01-29 16:51:17 +01:00
|
|
|
info.buildType = BuildConfiguration::Debug;
|
2022-09-25 22:42:53 +02:00
|
|
|
info.displayName = Tr::tr("Debug");
|
2016-08-25 14:32:48 +02:00
|
|
|
} else {
|
2019-01-29 16:51:17 +01:00
|
|
|
info.buildType = BuildConfiguration::Release;
|
2022-09-25 22:42:53 +02:00
|
|
|
info.displayName = Tr::tr("Release");
|
2016-08-25 14:32:48 +02:00
|
|
|
}
|
2019-01-29 16:51:17 +01:00
|
|
|
info.buildDirectory = data->buildDirectory;
|
|
|
|
|
|
|
|
|
|
QmakeExtraBuildInfo extra;
|
|
|
|
|
extra.additionalArguments = data->additionalArguments;
|
|
|
|
|
extra.config = data->config;
|
|
|
|
|
extra.makefile = data->makefile;
|
|
|
|
|
info.extraInfo = QVariant::fromValue(extra);
|
2016-08-25 14:32:48 +02:00
|
|
|
|
2019-01-30 12:10:24 +01:00
|
|
|
return {info};
|
2013-08-13 10:52:57 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-16 14:13:02 +02:00
|
|
|
void QmakeProjectImporter::deleteDirectoryData(void *directoryData) const
|
|
|
|
|
{
|
|
|
|
|
delete static_cast<DirectoryData *>(directoryData);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-21 16:06:36 +01:00
|
|
|
static const Toolchains preferredToolChains(QtVersion *qtVersion, const QString &ms)
|
2014-08-04 15:17:28 +02:00
|
|
|
{
|
2019-05-27 15:19:36 +02:00
|
|
|
const QString spec = ms.isEmpty() ? qtVersion->mkspec() : ms;
|
2014-08-04 15:17:28 +02:00
|
|
|
|
2022-01-18 18:40:41 +01:00
|
|
|
const Toolchains toolchains = ToolChainManager::toolchains();
|
2019-05-27 11:04:18 +02:00
|
|
|
const Abis qtAbis = qtVersion->qtAbis();
|
2019-02-27 15:45:17 +01:00
|
|
|
const auto matcher = [&](const ToolChain *tc) {
|
2021-09-06 09:31:48 +02:00
|
|
|
return qtAbis.contains(tc->targetAbi()) && tc->suggestedMkspecList().contains(spec);
|
2019-02-27 15:45:17 +01:00
|
|
|
};
|
|
|
|
|
ToolChain * const cxxToolchain = findOrDefault(toolchains, [matcher](const ToolChain *tc) {
|
|
|
|
|
return tc->language() == ProjectExplorer::Constants::CXX_LANGUAGE_ID && matcher(tc);
|
2017-01-11 16:12:32 +01:00
|
|
|
});
|
2019-02-27 15:45:17 +01:00
|
|
|
ToolChain * const cToolchain = findOrDefault(toolchains, [matcher](const ToolChain *tc) {
|
|
|
|
|
return tc->language() == ProjectExplorer::Constants::C_LANGUAGE_ID && matcher(tc);
|
|
|
|
|
});
|
2022-01-18 18:40:41 +01:00
|
|
|
Toolchains chosenToolchains;
|
2019-02-27 15:45:17 +01:00
|
|
|
for (ToolChain * const tc : {cxxToolchain, cToolchain}) {
|
|
|
|
|
if (tc)
|
|
|
|
|
chosenToolchains << tc;
|
|
|
|
|
};
|
|
|
|
|
return chosenToolchains;
|
2014-08-04 15:17:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-24 15:53:50 +02:00
|
|
|
Kit *QmakeProjectImporter::createTemporaryKit(const QtProjectImporter::QtVersionData &data,
|
2019-05-27 15:19:36 +02:00
|
|
|
const QString &parsedSpec,
|
2016-08-25 14:32:48 +02:00
|
|
|
const QMakeStepConfig::OsType &osType) const
|
2013-08-13 10:52:57 +02:00
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(osType) // TODO use this to select the right toolchain?
|
2021-09-06 09:31:48 +02:00
|
|
|
return QtProjectImporter::createTemporaryKit(data, [&data, parsedSpec](Kit *k) -> void {
|
|
|
|
|
for (ToolChain *const tc : preferredToolChains(data.qt, parsedSpec))
|
2019-03-01 12:20:57 +02:00
|
|
|
ToolChainKitAspect::setToolChain(k, tc);
|
2016-08-25 14:32:48 +02:00
|
|
|
if (parsedSpec != data.qt->mkspec())
|
2019-05-02 09:58:21 +02:00
|
|
|
QmakeKitAspect::setMkspec(k, parsedSpec, QmakeKitAspect::MkspecSource::Code);
|
2016-08-24 15:20:28 +02:00
|
|
|
});
|
2013-08-13 10:52:57 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 14:21:12 +02:00
|
|
|
} // QmakeProjectManager::Internal
|