Utils: Replace Environment::isSameExecutable()

... by FilePath::isSameExecutable().

The only non-mechanical case is the use inside QmakeBuildSystem::testToolChain
using a build environment instead of the FilePath's device environment.

This make a difference in theory due to the use of PATHEXT in the actual
check, but I believe the case that someone creates a 'qmake.foo' and
a 'qmake.bar', adds .foo and .bar to PATHEXT and then complains that
there's a warning missing about not-matching mkspecs has zero
likelihood in reality (and will break other places in Creator anyway).

Change-Id: Id6a8d1e4dc2eb74ca81610ccb1c4ee94c6f47e12
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-11-21 12:29:17 +01:00
parent bf325fd6af
commit c7c6ddb8b0
9 changed files with 11 additions and 40 deletions

View File

@@ -168,21 +168,6 @@ static QStringList appendExeExtensions(const Environment &env, const QString &ex
return execs; return execs;
} }
bool Environment::isSameExecutable(const QString &exe1, const QString &exe2) const
{
const QStringList exe1List = appendExeExtensions(*this, exe1);
const QStringList exe2List = appendExeExtensions(*this, exe2);
for (const QString &i1 : exe1List) {
for (const QString &i2 : exe2List) {
const FilePath f1 = FilePath::fromString(i1);
const FilePath f2 = FilePath::fromString(i2);
if (f1.isSameFile(f2))
return true;
}
}
return false;
}
QString Environment::expandedValueForKey(const QString &key) const QString Environment::expandedValueForKey(const QString &key) const
{ {
return expandVariables(m_dict.value(key)); return expandVariables(m_dict.value(key));

View File

@@ -65,8 +65,6 @@ public:
FilePaths path() const; FilePaths path() const;
FilePaths pathListValue(const QString &varName) const; FilePaths pathListValue(const QString &varName) const;
bool isSameExecutable(const QString &exe1, const QString &exe2) const;
QString expandedValueForKey(const QString &key) const; QString expandedValueForKey(const QString &key) const;
QString expandVariables(const QString &input) const; QString expandVariables(const QString &input) const;
FilePath expandVariables(const FilePath &input) const; FilePath expandVariables(const FilePath &input) const;

View File

@@ -1189,9 +1189,7 @@ Toolchains GccToolChainFactory::autoDetectToolchains(
|| compilerPath.toString().contains("ccache")) { || compilerPath.toString().contains("ccache")) {
existingTcMatches = existingCommand == compilerPath; existingTcMatches = existingCommand == compilerPath;
} else { } else {
existingTcMatches = Environment::systemEnvironment() existingTcMatches = existingCommand.isSameExecutable(compilerPath);
.isSameExecutable(existingCommand.toString(),
compilerPath.toString());
if (!existingTcMatches if (!existingTcMatches
&& HostOsInfo::isWindowsHost() && HostOsInfo::isWindowsHost()
&& !existingCommand.needsDevice() && !existingCommand.needsDevice()
@@ -1560,8 +1558,7 @@ ClangToolChain::~ClangToolChain()
QObject::disconnect(m_mingwToolchainAddedConnection); QObject::disconnect(m_mingwToolchainAddedConnection);
} }
bool ClangToolChain::matchesCompilerCommand(const Utils::FilePath &command, bool ClangToolChain::matchesCompilerCommand(const FilePath &command) const
const Utils::Environment &env) const
{ {
if (!m_resolvedCompilerCommand) { if (!m_resolvedCompilerCommand) {
m_resolvedCompilerCommand = FilePath(); m_resolvedCompilerCommand = FilePath();
@@ -1576,9 +1573,9 @@ bool ClangToolChain::matchesCompilerCommand(const Utils::FilePath &command,
} }
} }
if (!m_resolvedCompilerCommand->isEmpty() if (!m_resolvedCompilerCommand->isEmpty()
&& env.isSameExecutable(m_resolvedCompilerCommand->toString(), command.toString())) && m_resolvedCompilerCommand->isSameExecutable(command))
return true; return true;
return GccToolChain::matchesCompilerCommand(command, env); return GccToolChain::matchesCompilerCommand(command);
} }
static FilePath mingwAwareMakeCommand(const Environment &environment) static FilePath mingwAwareMakeCommand(const Environment &environment)

View File

@@ -190,9 +190,7 @@ public:
explicit ClangToolChain(Utils::Id typeId); explicit ClangToolChain(Utils::Id typeId);
~ClangToolChain() override; ~ClangToolChain() override;
bool matchesCompilerCommand( bool matchesCompilerCommand(const Utils::FilePath &command) const override;
const Utils::FilePath &command,
const Utils::Environment &env = Utils::Environment::systemEnvironment()) const override;
Utils::FilePath makeCommand(const Utils::Environment &environment) const override; Utils::FilePath makeCommand(const Utils::Environment &environment) const override;

View File

@@ -1598,7 +1598,6 @@ static Toolchains detectClangClToolChainInPath(const FilePath &clangClPath,
return res; return res;
} }
Utils::Environment systemEnvironment = Utils::Environment::systemEnvironment();
const Abi targetAbi = toolChain->targetAbi(); const Abi targetAbi = toolChain->targetAbi();
const QString name = QString("%1LLVM %2 bit based on %3") const QString name = QString("%1LLVM %2 bit based on %3")
.arg(QLatin1String(isDefault ? "Default " : "")) .arg(QLatin1String(isDefault ? "Default " : ""))
@@ -1613,8 +1612,7 @@ static Toolchains detectClangClToolChainInPath(const FilePath &clangClPath,
return false; return false;
if (tc->language() != language) if (tc->language() != language)
return false; return false;
return systemEnvironment.isSameExecutable(tc->compilerCommand().toString(), return tc->compilerCommand().isSameExecutable(clangClPath);
clangClPath.toString());
})); }));
if (tc) { if (tc) {
res << tc; res << tc;

View File

@@ -325,9 +325,9 @@ void ToolChain::setCompilerCommand(const FilePath &command)
toolChainUpdated(); toolChainUpdated();
} }
bool ToolChain::matchesCompilerCommand(const Utils::FilePath &command, const Environment &env) const bool ToolChain::matchesCompilerCommand(const FilePath &command) const
{ {
return env.isSameExecutable(compilerCommand().toString(), command.toString()); return compilerCommand().isSameExecutable(command);
} }
void ToolChain::setCompilerCommandKey(const QString &commandKey) void ToolChain::setCompilerCommandKey(const QString &commandKey)

View File

@@ -134,9 +134,7 @@ public:
virtual Utils::FilePath compilerCommand() const; // FIXME: De-virtualize. virtual Utils::FilePath compilerCommand() const; // FIXME: De-virtualize.
void setCompilerCommand(const Utils::FilePath &command); void setCompilerCommand(const Utils::FilePath &command);
virtual bool matchesCompilerCommand( virtual bool matchesCompilerCommand(const Utils::FilePath &command) const;
const Utils::FilePath &command,
const Utils::Environment &env = Utils::Environment::systemEnvironment()) const;
virtual QList<Utils::OutputLineParser *> createOutputParsers() const = 0; virtual QList<Utils::OutputLineParser *> createOutputParsers() const = 0;

View File

@@ -1395,9 +1395,7 @@ void QmakeBuildSystem::testToolChain(ToolChain *tc, const FilePath &path) const
return; return;
const FilePath expected = tc->compilerCommand(); const FilePath expected = tc->compilerCommand();
Environment env = buildConfiguration()->environment(); if (tc->matchesCompilerCommand(expected))
if (tc->matchesCompilerCommand(expected, env))
return; return;
const QPair<FilePath, FilePath> pair{expected, path}; const QPair<FilePath, FilePath> pair{expected, path};
if (m_toolChainWarnings.contains(pair)) if (m_toolChainWarnings.contains(pair))

View File

@@ -421,8 +421,7 @@ static void findSystemQt()
if (BuildableHelperLibrary::isQtChooser(qmakePath)) if (BuildableHelperLibrary::isQtChooser(qmakePath))
continue; continue;
const auto isSameQmake = [qmakePath](const QtVersion *version) { const auto isSameQmake = [qmakePath](const QtVersion *version) {
return Environment::systemEnvironment(). return qmakePath.isSameExecutable(version->qmakeFilePath());
isSameExecutable(qmakePath.toString(), version->qmakeFilePath().toString());
}; };
if (contains(m_versions, isSameQmake)) if (contains(m_versions, isSameQmake))
continue; continue;