Utils: Replace Environment.isValid() with .hasChanges()

That's closer to the intended semantics. The "other" use in docker
will be changed to an optional<Environment> as follow-up to
keep this here mechanical.

Change-Id: I43ef9da6c9c7731b28f9d6fab6413ce9c4f428b4
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2023-01-27 12:30:03 +01:00
parent 930cbdf68b
commit dab859e776
12 changed files with 14 additions and 14 deletions

View File

@@ -23,7 +23,7 @@ NameValueItems Environment::diff(const Environment &other, bool checkAppendPrepe
return m_dict.diff(other.m_dict, checkAppendPrepend); return m_dict.diff(other.m_dict, checkAppendPrepend);
} }
int Environment::isValid() const bool Environment::hasChanges() const
{ {
return m_dict.size() != 0; return m_dict.size() != 0;
} }

View File

@@ -35,7 +35,7 @@ public:
void unset(const QString &key) { m_dict.unset(key); } void unset(const QString &key) { m_dict.unset(key); }
void modify(const NameValueItems &items) { m_dict.modify(items); } void modify(const NameValueItems &items) { m_dict.modify(items); }
int isValid() const; bool hasChanges() const;
void clear() { return m_dict.clear(); } void clear() { return m_dict.clear(); }
QStringList toStringList() const { return m_dict.toStringList(); } QStringList toStringList() const { return m_dict.toStringList(); }

View File

@@ -668,7 +668,7 @@ public:
Environment fullEnvironment() const Environment fullEnvironment() const
{ {
Environment env = m_setup.m_environment; Environment env = m_setup.m_environment;
if (!env.isValid()) { if (!env.hasChanges()) {
// FIXME: Either switch to using EnvironmentChange instead of full Environments, or // FIXME: Either switch to using EnvironmentChange instead of full Environments, or
// feed the full environment into the QtcProcess instead of fixing it up here. // feed the full environment into the QtcProcess instead of fixing it up here.
// qWarning("QtcProcess::start: Empty environment set when running '%s'.", // qWarning("QtcProcess::start: Empty environment set when running '%s'.",
@@ -1190,7 +1190,7 @@ QString QtcProcess::toStandaloneCommandLine() const
d->m_setup.m_workingDirectory.path(); d->m_setup.m_workingDirectory.path();
} }
parts.append("-i"); parts.append("-i");
if (d->m_setup.m_environment.isValid()) { if (d->m_setup.m_environment.hasChanges()) {
const QStringList envVars = d->m_setup.m_environment.toStringList(); const QStringList envVars = d->m_setup.m_environment.toStringList();
std::transform(envVars.cbegin(), envVars.cend(), std::transform(envVars.cbegin(), envVars.cend(),
std::back_inserter(parts), ProcessArgs::quoteArgUnix); std::back_inserter(parts), ProcessArgs::quoteArgUnix);

View File

@@ -605,7 +605,7 @@ void AndroidRunnerWorker::asyncStartHelper()
<< QString::fromLatin1(appArgs.join(' ').toUtf8().toBase64()); << QString::fromLatin1(appArgs.join(' ').toUtf8().toBase64());
} }
if (m_extraEnvVars.isValid()) { if (m_extraEnvVars.hasChanges()) {
args << "-e" << "extraenvvars" args << "-e" << "extraenvvars"
<< QString::fromLatin1(m_extraEnvVars.toStringList().join('\t') << QString::fromLatin1(m_extraEnvVars.toStringList().join('\t')
.toUtf8().toBase64()); .toUtf8().toBase64());

View File

@@ -61,7 +61,7 @@ FilePath ITestConfiguration::executableFilePath() const
if (!hasExecutable()) if (!hasExecutable())
return {}; return {};
const Environment env = m_runnable.environment.isValid() const Environment env = m_runnable.environment.hasChanges()
? m_runnable.environment : Environment::systemEnvironment(); ? m_runnable.environment : Environment::systemEnvironment();
return env.searchInPath(m_runnable.command.executable().path()); return env.searchInPath(m_runnable.command.executable().path());
} }

View File

@@ -146,7 +146,7 @@ static Environment projectBuildEnvironment(Project *project)
if (BuildConfiguration *buildConfig = target->activeBuildConfiguration()) if (BuildConfiguration *buildConfig = target->activeBuildConfiguration())
env = buildConfig->environment(); env = buildConfig->environment();
} }
if (!env.isValid()) if (!env.hasChanges())
env = Environment::systemEnvironment(); env = Environment::systemEnvironment();
return env; return env;
} }

View File

@@ -411,7 +411,7 @@ void CdbEngine::setupEngine()
m_autoBreakPointCorrection = false; m_autoBreakPointCorrection = false;
Environment inferiorEnvironment = sp.inferior.environment.isValid() Environment inferiorEnvironment = sp.inferior.environment.hasChanges()
? sp.inferior.environment : Environment::systemEnvironment(); ? sp.inferior.environment : Environment::systemEnvironment();
// Make sure that QTestLib uses OutputDebugString for logging. // Make sure that QTestLib uses OutputDebugString for logging.

View File

@@ -1137,10 +1137,10 @@ bool DockerDevicePrivate::addTemporaryMount(const FilePath &path, const FilePath
Environment DockerDevicePrivate::environment() Environment DockerDevicePrivate::environment()
{ {
if (!m_cachedEnviroment.isValid()) if (!m_cachedEnviroment.hasChanges())
fetchSystemEnviroment(); fetchSystemEnviroment();
QTC_CHECK(m_cachedEnviroment.isValid()); QTC_CHECK(m_cachedEnviroment.hasChanges());
return m_cachedEnviroment; return m_cachedEnviroment;
} }

View File

@@ -113,7 +113,7 @@ void StdIOClientInterface::startImpl()
m_logFile.write(QString("Starting server: %1\nOutput:\n\n").arg(m_cmd.toUserOutput()).toUtf8()); m_logFile.write(QString("Starting server: %1\nOutput:\n\n").arg(m_cmd.toUserOutput()).toUtf8());
m_process->setCommand(m_cmd); m_process->setCommand(m_cmd);
m_process->setWorkingDirectory(m_workingDirectory); m_process->setWorkingDirectory(m_workingDirectory);
if (m_env.isValid()) if (m_env.hasChanges())
m_process->setEnvironment(m_env); m_process->setEnvironment(m_env);
m_process->start(); m_process->start();
} }

View File

@@ -64,7 +64,7 @@ QStringList SshParameters::connectionOptions(const FilePath &binary) const
bool SshParameters::setupSshEnvironment(QtcProcess *process) bool SshParameters::setupSshEnvironment(QtcProcess *process)
{ {
Environment env = process->controlEnvironment(); Environment env = process->controlEnvironment();
if (!env.isValid()) if (!env.hasChanges())
env = Environment::systemEnvironment(); env = Environment::systemEnvironment();
const bool hasDisplay = env.hasKey("DISPLAY") && (env.value("DISPLAY") != QString(":0")); const bool hasDisplay = env.hasKey("DISPLAY") && (env.value("DISPLAY") != QString(":0"));
if (SshSettings::askpassFilePath().exists()) { if (SshSettings::askpassFilePath().exists()) {

View File

@@ -1154,7 +1154,7 @@ ToolChain::BuiltInHeaderPathsRunner MsvcToolChain::createBuiltInHeaderPathsRunne
void MsvcToolChain::addToEnvironment(Utils::Environment &env) const void MsvcToolChain::addToEnvironment(Utils::Environment &env) const
{ {
// We cache the full environment (incoming + modifications by setup script). // We cache the full environment (incoming + modifications by setup script).
if (!m_resultEnvironment.isValid() || env != m_lastEnvironment) { if (!m_resultEnvironment.hasChanges() || env != m_lastEnvironment) {
qCDebug(Log) << "addToEnvironment: " << displayName(); qCDebug(Log) << "addToEnvironment: " << displayName();
m_lastEnvironment = env; m_lastEnvironment = env;
m_resultEnvironment = readEnvironmentSetting(env); m_resultEnvironment = readEnvironmentSetting(env);

View File

@@ -170,7 +170,7 @@ bool MakeInstallStep::init()
} }
const MakeInstallCommand cmd = buildSystem()->makeInstallCommand(rootDir); const MakeInstallCommand cmd = buildSystem()->makeInstallCommand(rootDir);
if (cmd.environment.isValid()) { if (cmd.environment.hasChanges()) {
Environment env = processParameters()->environment(); Environment env = processParameters()->environment();
for (auto it = cmd.environment.constBegin(); it != cmd.environment.constEnd(); ++it) { for (auto it = cmd.environment.constBegin(); it != cmd.environment.constEnd(); ++it) {
if (cmd.environment.isEnabled(it)) { if (cmd.environment.isEnabled(it)) {