diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 22589c9ed34..6465b44495f 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -1384,6 +1384,26 @@ FilePath FilePath::onDevice(const FilePath &deviceTemplate) const return res; } +/*! + Returns a FilePath with local path \a newPath on the same device + as the current object. + + Example usage: + \code + devicePath = FilePath::fromString("docker://123/tmp"); + newPath = devicePath.withNewPath("/bin/ls"); + assert(realDir == FilePath::fromUrl("docker://123/bin/ls")) + \endcode +*/ +FilePath FilePath::withNewPath(const QString &newPath) const +{ + FilePath res; + res.m_data = newPath; + res.m_host = m_host; + res.m_scheme = m_scheme; + return res; +} + /*! Searched a binary corresponding to this object in the PATH of the device implied by this object's scheme and host. diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h index 3939b5e243b..84dcb756784 100644 --- a/src/libs/utils/fileutils.h +++ b/src/libs/utils/fileutils.h @@ -113,6 +113,7 @@ public: QString toString() const; FilePath onDevice(const FilePath &deviceTemplate) const; + FilePath withNewPath(const QString &newPath) const; QFileInfo toFileInfo() const; QVariant toVariant() const; diff --git a/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp b/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp index 55b47891e4a..76639697640 100644 --- a/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp @@ -185,7 +185,7 @@ void CMakeToolManager::autoDetectCMakeForDevice(const FilePath &deviceRoot, QString *logMessage) { QStringList messages{tr("Searching CMake binaries...")}; - const FilePaths candidates = {FilePath::fromString("cmake").onDevice(deviceRoot)}; + const FilePaths candidates = {deviceRoot.withNewPath("cmake")}; const Environment env = deviceRoot.deviceEnvironment(); for (const FilePath &candidate : candidates) { const FilePath cmake = candidate.searchOnDevice(env.path()); diff --git a/src/plugins/projectexplorer/gcctoolchain.cpp b/src/plugins/projectexplorer/gcctoolchain.cpp index 167db34f42b..72da8fe626f 100644 --- a/src/plugins/projectexplorer/gcctoolchain.cpp +++ b/src/plugins/projectexplorer/gcctoolchain.cpp @@ -238,13 +238,13 @@ static QString gccVersion(const FilePath &path, return QString::fromLocal8Bit(runGcc(path, arguments, env)).trimmed(); } -static FilePath gccInstallDir(const FilePath &path, +static FilePath gccInstallDir(const FilePath &compiler, const Environment &env, const QStringList &extraArgs = {}) { QStringList arguments = extraArgs; arguments << "-print-search-dirs"; - QString output = QString::fromLocal8Bit(runGcc(path, arguments, env)).trimmed(); + QString output = QString::fromLocal8Bit(runGcc(compiler, arguments, env)).trimmed(); // Expected output looks like this: // install: /usr/lib/gcc/x86_64-linux-gnu/7/ // ... @@ -255,7 +255,7 @@ static FilePath gccInstallDir(const FilePath &path, const QString line = QTextStream(&output).readLine(); if (!line.startsWith(prefix)) return {}; - return FilePath::fromString(QDir::cleanPath(line.mid(prefix.size()))).onDevice(path); + return compiler.withNewPath(QDir::cleanPath(line.mid(prefix.size()))); } // -------------------------------------------------------------------------- diff --git a/src/plugins/webassembly/webassemblyemsdk.cpp b/src/plugins/webassembly/webassemblyemsdk.cpp index 2449dbed7ac..1fd109514f0 100644 --- a/src/plugins/webassembly/webassemblyemsdk.cpp +++ b/src/plugins/webassembly/webassemblyemsdk.cpp @@ -60,8 +60,7 @@ static QString emSdkEnvOutput(const FilePath &sdkRoot) emSdkEnv.setCommand(CommandLine(scriptFile)); } else { // File needs to be source'd, not executed. - emSdkEnv.setCommand({FilePath::fromString("bash").onDevice(sdkRoot), - {"-c", ". " + scriptFile}}); + emSdkEnv.setCommand({sdkRoot.withNewPath("bash"), {"-c", ". " + scriptFile}}); } emSdkEnv.runBlocking(); const QString output = emSdkEnv.allOutput(); @@ -108,8 +107,7 @@ QVersionNumber WebAssemblyEmSdk::version(const FilePath &sdkRoot) Environment env; WebAssemblyEmSdk::addToEnvironment(sdkRoot, env); QLatin1String scriptFile{sdkRoot.osType() == OsType::OsTypeWindows ? "emcc.bat" : "emcc"}; - FilePath script = - FilePath::fromString(scriptFile).onDevice(sdkRoot).searchOnDevice(env.path()); + FilePath script = sdkRoot.withNewPath(scriptFile).searchOnDevice(env.path()); const CommandLine command(script, {"-dumpversion"}); QtcProcess emcc; emcc.setCommand(command); diff --git a/src/plugins/webassembly/webassemblytoolchain.cpp b/src/plugins/webassembly/webassemblytoolchain.cpp index 276b324ba64..816c745ca02 100644 --- a/src/plugins/webassembly/webassemblytoolchain.cpp +++ b/src/plugins/webassembly/webassemblytoolchain.cpp @@ -162,7 +162,6 @@ QList WebAssemblyToolChainFactory::autoDetect( const IDevice::Ptr &device) { Q_UNUSED(alreadyKnown) - Q_UNUSED(device) const FilePath sdk = WebAssemblyEmSdk::registeredEmSdk(); if (!WebAssemblyEmSdk::isValid(sdk)) @@ -187,8 +186,7 @@ QList WebAssemblyToolChainFactory::autoDetect( const bool cLanguage = languageId == ProjectExplorer::Constants::C_LANGUAGE_ID; const QString script = QLatin1String(cLanguage ? "emcc" : "em++") + QLatin1String(sdk.osType() == OsTypeWindows ? ".bat" : ""); - const FilePath scriptFile = - FilePath::fromString(script).onDevice(sdk).searchOnDevice(env.path()); + const FilePath scriptFile = sdk.withNewPath(script).searchOnDevice(env.path()); toolChain->setCompilerCommand(scriptFile); const QString displayName = WebAssemblyToolChain::tr("Emscripten Compiler %1 for %2")