From a8a19767b452d8ae9dd25ea726e763533060d523 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Mon, 7 Oct 2024 16:24:53 +0200 Subject: [PATCH] ProjectExplorer: Allow ProcessStep to resolve relative paths Change-Id: I35a06f7d32e528cc8b524c6db86d8d62be2c8201 Reviewed-by: David Schulz --- src/plugins/projectexplorer/processstep.cpp | 14 +++++++++++++- src/plugins/projectexplorer/processstep.h | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/plugins/projectexplorer/processstep.cpp b/src/plugins/projectexplorer/processstep.cpp index 6d495335978..d899fb5e4d1 100644 --- a/src/plugins/projectexplorer/processstep.cpp +++ b/src/plugins/projectexplorer/processstep.cpp @@ -19,6 +19,8 @@ namespace ProjectExplorer::Internal { const char PROCESS_COMMAND_KEY[] = "ProjectExplorer.ProcessStep.Command"; const char PROCESS_WORKINGDIRECTORY_KEY[] = "ProjectExplorer.ProcessStep.WorkingDirectory"; +const char PROCESS_WORKINGDIRECTORYRELATIVEBASE_KEY[] + = "ProjectExplorer.ProcessStep.WorkingDirectoryRelativeBasePath"; const char PROCESS_ARGUMENTS_KEY[] = "ProjectExplorer.ProcessStep.Arguments"; ProcessStep::ProcessStep(BuildStepList *bsl, Id id) @@ -38,10 +40,18 @@ ProcessStep::ProcessStep(BuildStepList *bsl, Id id) m_workingDirectory.setLabelText(Tr::tr("Working directory:")); m_workingDirectory.setExpectedKind(PathChooser::Directory); + m_workingDirRelativeBasePath.setSettingsKey(PROCESS_WORKINGDIRECTORYRELATIVEBASE_KEY); + m_workingDirRelativeBasePath.setValue(QString()); + m_workingDirRelativeBasePath.setVisible(false); + m_workingDirRelativeBasePath.setExpectedKind(PathChooser::Directory); + setWorkingDirectoryProvider([this] { const FilePath workingDir = m_workingDirectory(); + const FilePath relativeBasePath = m_workingDirRelativeBasePath(); if (workingDir.isEmpty()) return FilePath::fromString(fallbackWorkingDirectory()); + else if (workingDir.isRelativePath() && !relativeBasePath.isEmpty()) + return relativeBasePath.resolvePath(workingDir); return workingDir; }); @@ -69,9 +79,11 @@ void ProcessStep::setArguments(const QStringList &arguments) m_arguments.setValue(arguments.join(" ")); } -void ProcessStep::setWorkingDirectory(const Utils::FilePath &workingDirectory) +void ProcessStep::setWorkingDirectory( + const Utils::FilePath &workingDirectory, const Utils::FilePath &relativeBasePath) { m_workingDirectory.setValue(workingDirectory); + m_workingDirRelativeBasePath.setValue(relativeBasePath); } void ProcessStep::setupOutputFormatter(OutputFormatter *formatter) diff --git a/src/plugins/projectexplorer/processstep.h b/src/plugins/projectexplorer/processstep.h index 09ffe26420b..ff36ebb28c3 100644 --- a/src/plugins/projectexplorer/processstep.h +++ b/src/plugins/projectexplorer/processstep.h @@ -15,7 +15,9 @@ public: void setCommand(const Utils::FilePath &command); void setArguments(const QStringList &arguments); - void setWorkingDirectory(const Utils::FilePath &workingDirectory); + void setWorkingDirectory( + const Utils::FilePath &workingDirectory, + const Utils::FilePath &relativeBasePath = Utils::FilePath()); private: void setupOutputFormatter(Utils::OutputFormatter *formatter) final; @@ -23,6 +25,7 @@ private: Utils::FilePathAspect m_command{this}; Utils::StringAspect m_arguments{this}; Utils::FilePathAspect m_workingDirectory{this}; + Utils::FilePathAspect m_workingDirRelativeBasePath{this}; }; class ProcessStepFactory final : public BuildStepFactory