CMakePM: Copy auto package-manager to ${buildDir}/.qtc/ directory

By copying the ${IDE:ResourcePath}/package-manager to
${buildDir}/.qtc/ the problem with hardcoding paths
to old an Qt Creator version can no longer occur.

This also fixes the issue with remote projects by reffering
to the code residing on the host.

With the above issues fixed, enable "Package manager auto setup"
by default.

Change-Id: Ia49654a3b9059f83886e64d065019b2d55e9299c
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Cristian Adam
2023-02-07 18:15:58 +01:00
parent f5bd330277
commit a6ccfb09e5
7 changed files with 31 additions and 13 deletions

View File

@@ -14,6 +14,7 @@
#include <projectexplorer/toolchain.h> #include <projectexplorer/toolchain.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/macroexpander.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -28,20 +29,20 @@ BuildDirParameters::BuildDirParameters(CMakeBuildSystem *buildSystem)
auto bc = buildSystem->cmakeBuildConfiguration(); auto bc = buildSystem->cmakeBuildConfiguration();
QTC_ASSERT(bc, return); QTC_ASSERT(bc, return);
const Utils::MacroExpander *expander = bc->macroExpander(); expander = bc->macroExpander();
const QStringList expandedArguments = Utils::transform(buildSystem->initialCMakeArguments(), const QStringList expandedArguments = Utils::transform(buildSystem->initialCMakeArguments(),
[expander](const QString &s) { [this](const QString &s) {
return expander->expand(s); return expander->expand(s);
}); });
initialCMakeArguments = Utils::filtered(expandedArguments, initialCMakeArguments = Utils::filtered(expandedArguments,
[](const QString &s) { return !s.isEmpty(); }); [](const QString &s) { return !s.isEmpty(); });
configurationChangesArguments = Utils::transform(buildSystem->configurationChangesArguments(), configurationChangesArguments = Utils::transform(buildSystem->configurationChangesArguments(),
[expander](const QString &s) { [this](const QString &s) {
return expander->expand(s); return expander->expand(s);
}); });
additionalCMakeArguments = Utils::transform(buildSystem->additionalCMakeArguments(), additionalCMakeArguments = Utils::transform(buildSystem->additionalCMakeArguments(),
[expander](const QString &s) { [this](const QString &s) {
return expander->expand(s); return expander->expand(s);
}); });
const Target *t = bc->target(); const Target *t = bc->target();

View File

@@ -8,6 +8,8 @@
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/filepath.h> #include <utils/filepath.h>
namespace Utils { class MacroExpander; }
namespace CMakeProjectManager::Internal { namespace CMakeProjectManager::Internal {
class CMakeBuildSystem; class CMakeBuildSystem;
@@ -34,6 +36,8 @@ public:
QStringList initialCMakeArguments; QStringList initialCMakeArguments;
QStringList configurationChangesArguments; QStringList configurationChangesArguments;
QStringList additionalCMakeArguments; QStringList additionalCMakeArguments;
Utils::MacroExpander* expander = nullptr;
}; };
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -1126,13 +1126,11 @@ static CommandLine defaultInitialCMakeCommand(const Kit *k, const QString buildT
if (!buildType.isEmpty() && !CMakeGeneratorKitAspect::isMultiConfigGenerator(k)) if (!buildType.isEmpty() && !CMakeGeneratorKitAspect::isMultiConfigGenerator(k))
cmd.addArg("-DCMAKE_BUILD_TYPE:STRING=" + buildType); cmd.addArg("-DCMAKE_BUILD_TYPE:STRING=" + buildType);
auto settings = Internal::CMakeSpecificSettings::instance(); // Package manager auto setup
if (Internal::CMakeSpecificSettings::instance()->packageManagerAutoSetup.value()) {
// Package manager auto setup. The file auto-setup.cmake resides on the host, cmd.addArg(QString("-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH="
// so it's not accessible for remotely running cmakes. We need to exclude that case. "%{buildDir}/%1/auto-setup.cmake")
if (!cmd.executable().needsDevice() && settings->packageManagerAutoSetup.value()) { .arg(Constants::PACKAGE_MANAGER_DIR));
cmd.addArg("-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH="
"%{IDE:ResourcePath}/package-manager/auto-setup.cmake");
} }
// Cross-compilation settings: // Cross-compilation settings:

View File

@@ -467,7 +467,8 @@ void CMakeBuildSystem::clearCMakeCache()
m_parameters.buildDirectory / "CMakeCache.txt.prev", m_parameters.buildDirectory / "CMakeCache.txt.prev",
m_parameters.buildDirectory / "CMakeFiles", m_parameters.buildDirectory / "CMakeFiles",
m_parameters.buildDirectory / ".cmake/api/v1/reply", m_parameters.buildDirectory / ".cmake/api/v1/reply",
m_parameters.buildDirectory / ".cmake/api/v1/reply.prev" m_parameters.buildDirectory / ".cmake/api/v1/reply.prev",
m_parameters.buildDirectory / Constants::PACKAGE_MANAGER_DIR
}; };
for (const FilePath &path : pathsToDelete) for (const FilePath &path : pathsToDelete)

View File

@@ -5,7 +5,9 @@
#include "builddirparameters.h" #include "builddirparameters.h"
#include "cmakeparser.h" #include "cmakeparser.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include "cmakespecificsettings.h"
#include <coreplugin/progressmanager/processprogress.h> #include <coreplugin/progressmanager/processprogress.h>
#include <projectexplorer/buildsystem.h> #include <projectexplorer/buildsystem.h>
@@ -87,6 +89,16 @@ void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &
} }
} }
// Copy the "package-manager" CMake code from the ${IDE:ResourcePath} to the build directory
if (Internal::CMakeSpecificSettings::instance()->packageManagerAutoSetup.value()) {
const FilePath localPackageManagerDir = buildDirectory.pathAppended(Constants::PACKAGE_MANAGER_DIR);
const FilePath idePackageManagerDir = FilePath::fromString(
parameters.expander->expand(QStringLiteral("%{IDE:ResourcePath}/package-manager")));
if (!localPackageManagerDir.exists() && idePackageManagerDir.exists())
idePackageManagerDir.copyRecursively(localPackageManagerDir);
}
const auto parser = new CMakeParser; const auto parser = new CMakeParser;
parser->setSourceDirectory(parameters.sourceDirectory); parser->setSourceDirectory(parameters.sourceDirectory);
m_parser.addLineParser(parser); m_parser.addLineParser(parser);

View File

@@ -23,6 +23,8 @@ const char CMAKEFORMATTER_GENERAL_GROUP[] = "General";
const char CMAKEFORMATTER_ACTION_ID[] = "CMakeFormatter.Action"; const char CMAKEFORMATTER_ACTION_ID[] = "CMakeFormatter.Action";
const char CMAKEFORMATTER_MENU_ID[] = "CMakeFormatter.Menu"; const char CMAKEFORMATTER_MENU_ID[] = "CMakeFormatter.Menu";
const char PACKAGE_MANAGER_DIR[] = ".qtc/package-manager";
// Project // Project
const char CMAKE_PROJECT_ID[] = "CMakeProjectManager.CMakeProject"; const char CMAKE_PROJECT_ID[] = "CMakeProjectManager.CMakeProject";

View File

@@ -48,7 +48,7 @@ CMakeSpecificSettings::CMakeSpecificSettings()
registerAspect(&packageManagerAutoSetup); registerAspect(&packageManagerAutoSetup);
packageManagerAutoSetup.setSettingsKey("PackageManagerAutoSetup"); packageManagerAutoSetup.setSettingsKey("PackageManagerAutoSetup");
packageManagerAutoSetup.setDefaultValue(false); packageManagerAutoSetup.setDefaultValue(true);
packageManagerAutoSetup.setLabelText(::CMakeProjectManager::Tr::tr("Package manager auto setup")); packageManagerAutoSetup.setLabelText(::CMakeProjectManager::Tr::tr("Package manager auto setup"));
packageManagerAutoSetup.setToolTip(::CMakeProjectManager::Tr::tr("Add the CMAKE_PROJECT_INCLUDE_BEFORE variable " packageManagerAutoSetup.setToolTip(::CMakeProjectManager::Tr::tr("Add the CMAKE_PROJECT_INCLUDE_BEFORE variable "
"pointing to a CMake script that will install dependencies from the conanfile.txt, " "pointing to a CMake script that will install dependencies from the conanfile.txt, "