forked from qt-creator/qt-creator
Utils: Introduce a FilePath::withNewPath() convenience method
It's effectively the mirrored version of onDevice() with an equally odd name which is a bit more straightforward to use in some cases. Change-Id: I0cfedeb58871a857c93144e2a0d734bad1bcd887 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -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.
|
||||
|
@@ -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;
|
||||
|
@@ -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());
|
||||
|
@@ -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())));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
@@ -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);
|
||||
|
@@ -162,7 +162,6 @@ QList<ToolChain *> 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<ToolChain *> 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")
|
||||
|
Reference in New Issue
Block a user