CMakePM: Consider envvar QTC_CMAKE_USE_JUNCTIONS

This envrionment variable can be set globally or locally for a project
via '.shared' configuration.

See https://doc.qt.io/qtcreator/creator-sharing-project-settings.html
for details.

Task-number: QTCREATORBUG-30385
Change-Id: Ie28caac8f4232678c5761b54ce370d1aeb139389
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Cristian Adam
2024-02-22 16:22:46 +01:00
parent 462caec278
commit 2d7af40007

View File

@@ -16,6 +16,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/buildsystem.h> #include <projectexplorer/buildsystem.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/projecttree.h> #include <projectexplorer/projecttree.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
@@ -69,6 +70,7 @@ typedef struct _REPARSE_DATA_BUFFER {
#endif #endif
using namespace Core; using namespace Core;
using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace CMakeProjectManager { namespace CMakeProjectManager {
@@ -451,8 +453,19 @@ FilePath CMakeToolManager::mappedFilePath(const FilePath &path)
if (path.needsDevice()) if (path.needsDevice())
return path; return path;
Internal::settings(); auto project = ProjectManager::startupProject();
if (!Internal::settings().useJunctionsForSourceAndBuildDirectories()) auto environment = Environment::systemEnvironment();
if (project)
environment.modify(project->additionalEnvironment());
const bool enableJunctions
= QVariant(
environment.value_or("QTC_CMAKE_USE_JUNCTIONS",
Internal::settings().useJunctionsForSourceAndBuildDirectories()
? "1"
: "0"))
.toBool();
if (!enableJunctions)
return path; return path;
if (!d->m_junctionsDir.isDir()) if (!d->m_junctionsDir.isDir())
@@ -583,14 +596,17 @@ CMakeToolManagerPrivate::CMakeToolManagerPrivate()
m_junctionsDir = FilePath::fromString(*std::min_element(locations.begin(), locations.end())) m_junctionsDir = FilePath::fromString(*std::min_element(locations.begin(), locations.end()))
.pathAppended("QtCreator/Links"); .pathAppended("QtCreator/Links");
if (Utils::qtcEnvironmentVariableIsSet("QTC_CMAKE_JUNCTIONS_DIR")) { auto project = ProjectManager::startupProject();
m_junctionsDir = FilePath::fromUserInput( auto environment = Environment::systemEnvironment();
Utils::qtcEnvironmentVariable("QTC_CMAKE_JUNCTIONS_DIR")); if (project)
} environment.modify(project->additionalEnvironment());
if (Utils::qtcEnvironmentVariableIsSet("QTC_CMAKE_JUNCTIONS_HASH_LENGTH")) {
if (environment.hasKey("QTC_CMAKE_JUNCTIONS_DIR"))
m_junctionsDir = FilePath::fromUserInput(environment.value("QTC_CMAKE_JUNCTIONS_DIR"));
if (environment.hasKey("QTC_CMAKE_JUNCTIONS_HASH_LENGTH")) {
bool ok = false; bool ok = false;
const int hashLength const int hashLength = environment.value("QTC_CMAKE_JUNCTIONS_HASH_LENGTH").toInt(&ok);
= Utils::qtcEnvironmentVariableIntValue("QTC_CMAKE_JUNCTIONS_HASH_LENGTH", &ok);
if (ok && hashLength >= 4 && hashLength < 32) if (ok && hashLength >= 4 && hashLength < 32)
m_junctionsHashLength = hashLength; m_junctionsHashLength = hashLength;
} }