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;
|
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
|
Searched a binary corresponding to this object in the PATH of
|
||||||
the device implied by this object's scheme and host.
|
the device implied by this object's scheme and host.
|
||||||
|
@@ -113,6 +113,7 @@ public:
|
|||||||
|
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
FilePath onDevice(const FilePath &deviceTemplate) const;
|
FilePath onDevice(const FilePath &deviceTemplate) const;
|
||||||
|
FilePath withNewPath(const QString &newPath) const;
|
||||||
|
|
||||||
QFileInfo toFileInfo() const;
|
QFileInfo toFileInfo() const;
|
||||||
QVariant toVariant() const;
|
QVariant toVariant() const;
|
||||||
|
@@ -185,7 +185,7 @@ void CMakeToolManager::autoDetectCMakeForDevice(const FilePath &deviceRoot,
|
|||||||
QString *logMessage)
|
QString *logMessage)
|
||||||
{
|
{
|
||||||
QStringList messages{tr("Searching CMake binaries...")};
|
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();
|
const Environment env = deviceRoot.deviceEnvironment();
|
||||||
for (const FilePath &candidate : candidates) {
|
for (const FilePath &candidate : candidates) {
|
||||||
const FilePath cmake = candidate.searchOnDevice(env.path());
|
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();
|
return QString::fromLocal8Bit(runGcc(path, arguments, env)).trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
static FilePath gccInstallDir(const FilePath &path,
|
static FilePath gccInstallDir(const FilePath &compiler,
|
||||||
const Environment &env,
|
const Environment &env,
|
||||||
const QStringList &extraArgs = {})
|
const QStringList &extraArgs = {})
|
||||||
{
|
{
|
||||||
QStringList arguments = extraArgs;
|
QStringList arguments = extraArgs;
|
||||||
arguments << "-print-search-dirs";
|
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:
|
// Expected output looks like this:
|
||||||
// install: /usr/lib/gcc/x86_64-linux-gnu/7/
|
// 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();
|
const QString line = QTextStream(&output).readLine();
|
||||||
if (!line.startsWith(prefix))
|
if (!line.startsWith(prefix))
|
||||||
return {};
|
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));
|
emSdkEnv.setCommand(CommandLine(scriptFile));
|
||||||
} else {
|
} else {
|
||||||
// File needs to be source'd, not executed.
|
// File needs to be source'd, not executed.
|
||||||
emSdkEnv.setCommand({FilePath::fromString("bash").onDevice(sdkRoot),
|
emSdkEnv.setCommand({sdkRoot.withNewPath("bash"), {"-c", ". " + scriptFile}});
|
||||||
{"-c", ". " + scriptFile}});
|
|
||||||
}
|
}
|
||||||
emSdkEnv.runBlocking();
|
emSdkEnv.runBlocking();
|
||||||
const QString output = emSdkEnv.allOutput();
|
const QString output = emSdkEnv.allOutput();
|
||||||
@@ -108,8 +107,7 @@ QVersionNumber WebAssemblyEmSdk::version(const FilePath &sdkRoot)
|
|||||||
Environment env;
|
Environment env;
|
||||||
WebAssemblyEmSdk::addToEnvironment(sdkRoot, env);
|
WebAssemblyEmSdk::addToEnvironment(sdkRoot, env);
|
||||||
QLatin1String scriptFile{sdkRoot.osType() == OsType::OsTypeWindows ? "emcc.bat" : "emcc"};
|
QLatin1String scriptFile{sdkRoot.osType() == OsType::OsTypeWindows ? "emcc.bat" : "emcc"};
|
||||||
FilePath script =
|
FilePath script = sdkRoot.withNewPath(scriptFile).searchOnDevice(env.path());
|
||||||
FilePath::fromString(scriptFile).onDevice(sdkRoot).searchOnDevice(env.path());
|
|
||||||
const CommandLine command(script, {"-dumpversion"});
|
const CommandLine command(script, {"-dumpversion"});
|
||||||
QtcProcess emcc;
|
QtcProcess emcc;
|
||||||
emcc.setCommand(command);
|
emcc.setCommand(command);
|
||||||
|
@@ -162,7 +162,6 @@ QList<ToolChain *> WebAssemblyToolChainFactory::autoDetect(
|
|||||||
const IDevice::Ptr &device)
|
const IDevice::Ptr &device)
|
||||||
{
|
{
|
||||||
Q_UNUSED(alreadyKnown)
|
Q_UNUSED(alreadyKnown)
|
||||||
Q_UNUSED(device)
|
|
||||||
|
|
||||||
const FilePath sdk = WebAssemblyEmSdk::registeredEmSdk();
|
const FilePath sdk = WebAssemblyEmSdk::registeredEmSdk();
|
||||||
if (!WebAssemblyEmSdk::isValid(sdk))
|
if (!WebAssemblyEmSdk::isValid(sdk))
|
||||||
@@ -187,8 +186,7 @@ QList<ToolChain *> WebAssemblyToolChainFactory::autoDetect(
|
|||||||
const bool cLanguage = languageId == ProjectExplorer::Constants::C_LANGUAGE_ID;
|
const bool cLanguage = languageId == ProjectExplorer::Constants::C_LANGUAGE_ID;
|
||||||
const QString script = QLatin1String(cLanguage ? "emcc" : "em++")
|
const QString script = QLatin1String(cLanguage ? "emcc" : "em++")
|
||||||
+ QLatin1String(sdk.osType() == OsTypeWindows ? ".bat" : "");
|
+ QLatin1String(sdk.osType() == OsTypeWindows ? ".bat" : "");
|
||||||
const FilePath scriptFile =
|
const FilePath scriptFile = sdk.withNewPath(script).searchOnDevice(env.path());
|
||||||
FilePath::fromString(script).onDevice(sdk).searchOnDevice(env.path());
|
|
||||||
toolChain->setCompilerCommand(scriptFile);
|
toolChain->setCompilerCommand(scriptFile);
|
||||||
|
|
||||||
const QString displayName = WebAssemblyToolChain::tr("Emscripten Compiler %1 for %2")
|
const QString displayName = WebAssemblyToolChain::tr("Emscripten Compiler %1 for %2")
|
||||||
|
Reference in New Issue
Block a user