From f7240bd665b325d0a67b80426a3fcbc31b5c19b2 Mon Sep 17 00:00:00 2001
From: dt <qtc-committer@nokia.com>
Date: Thu, 19 Mar 2009 18:15:33 +0100
Subject: [PATCH] Fixes:  bin dir of msvc qt versions was not added to the path

The setting of msvc environments variables overwrote that. Fix that by running the script with the correct environment.
---
 src/libs/cplusplus/pp-engine.cpp                   |  4 ++--
 src/libs/utils/process_stub_win.c                  |  1 +
 src/plugins/projectexplorer/environment.cpp        | 12 ++++++++++++
 src/plugins/projectexplorer/environment.h          |  2 ++
 src/plugins/projectexplorer/toolchain.cpp          | 12 ++++--------
 src/plugins/projectexplorer/toolchain.h            |  1 +
 src/plugins/qt4projectmanager/qtversionmanager.cpp |  1 -
 7 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp
index 95effec40c0..1fee4192529 100644
--- a/src/libs/cplusplus/pp-engine.cpp
+++ b/src/libs/cplusplus/pp-engine.cpp
@@ -1,5 +1,4 @@
-/**************************************************************************
-**
+/**
 ** This file is part of Qt Creator
 **
 ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
@@ -51,6 +50,7 @@
 #include <Lexer.h>
 #include <Token.h>
 #include <Literals.h>
+#include <cctype>
 
 #include <QtDebug>
 #include <algorithm>
diff --git a/src/libs/utils/process_stub_win.c b/src/libs/utils/process_stub_win.c
index 3d99a685395..0ca484eb751 100644
--- a/src/libs/utils/process_stub_win.c
+++ b/src/libs/utils/process_stub_win.c
@@ -34,6 +34,7 @@
 #define _WIN32_WINNT 0x0501 /* WinXP, needed for DebugActiveProcessStop() */
 
 #include <windows.h>
+#include <shellapi.h>
 #include <string.h>
 #include <stdio.h>
 #include <errno.h>
diff --git a/src/plugins/projectexplorer/environment.cpp b/src/plugins/projectexplorer/environment.cpp
index 0c2e74f67e4..541445cf99e 100644
--- a/src/plugins/projectexplorer/environment.cpp
+++ b/src/plugins/projectexplorer/environment.cpp
@@ -288,6 +288,16 @@ void Environment::modify(const QList<EnvironmentItem> & list)
     *this = resultEnvironment;
 }
 
+bool Environment::operator!=(const Environment &other)
+{
+    return !(*this == other);
+}
+
+bool Environment::operator==(const Environment &other)
+{
+    return m_values == other.m_values;
+}
+
 QStringList Environment::parseCombinedArgString(const QString &program)
 {
     QStringList args;
@@ -341,3 +351,5 @@ QString Environment::joinArgumentList(const QStringList &arguments)
     return result;
 }
 
+
+
diff --git a/src/plugins/projectexplorer/environment.h b/src/plugins/projectexplorer/environment.h
index 91cd958d4b0..367aee5a802 100644
--- a/src/plugins/projectexplorer/environment.h
+++ b/src/plugins/projectexplorer/environment.h
@@ -89,6 +89,8 @@ public:
     static QStringList parseCombinedArgString(const QString &program);
     static QString joinArgumentList(const QStringList &arguments);
 
+    bool operator!=(const Environment &other);
+    bool operator==(const Environment &other);
 private:
     QMap<QString, QString> m_values;
 };
diff --git a/src/plugins/projectexplorer/toolchain.cpp b/src/plugins/projectexplorer/toolchain.cpp
index 7c080aad8e2..e827a5a3d42 100644
--- a/src/plugins/projectexplorer/toolchain.cpp
+++ b/src/plugins/projectexplorer/toolchain.cpp
@@ -246,13 +246,13 @@ QList<HeaderPath> MSVCToolChain::systemHeaderPaths()
 
 void MSVCToolChain::addToEnvironment(ProjectExplorer::Environment &env)
 {
-    if (!m_valuesSet) {
+    if (!m_valuesSet || env != m_lastEnvironment) {
+        m_lastEnvironment = env;
         QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7",
                        QSettings::NativeFormat);
         if (m_name.isEmpty())
             return;
         QString path = registry.value(m_name).toString();
-        ProjectExplorer::Environment oldEnv(env);
         QString desc;
         QString varsbat = path + "Common7\\Tools\\vsvars32.bat";
         if (QFileInfo(varsbat).exists()) {
@@ -265,7 +265,8 @@ void MSVCToolChain::addToEnvironment(ProjectExplorer::Environment &env)
             tf.flush();
             tf.waitForBytesWritten(30000);
 
-            QProcess run; // TODO run in the environment we want to add to...
+            QProcess run;
+            run.setEnvironment(env.toStringList());
             QString cmdPath = env.searchInPath("cmd");
             run.start(cmdPath, QStringList()<<"/c"<<filename);
             run.waitForFinished();
@@ -281,9 +282,7 @@ void MSVCToolChain::addToEnvironment(ProjectExplorer::Environment &env)
                     if (regexp.exactMatch(line2)) {
                         QString variable = regexp.cap(1);
                         QString value = regexp.cap(2);
-                        value.replace('%' + variable + '%', oldEnv.value(variable));
                         m_values.append(QPair<QString, QString>(variable, value));
-
                     }
                 }
                 vars.close();
@@ -293,14 +292,11 @@ void MSVCToolChain::addToEnvironment(ProjectExplorer::Environment &env)
         m_valuesSet = true;
     }
 
-    //qDebug()<<"MSVC Environment:";
     QList< QPair<QString, QString> >::const_iterator it, end;
     end = m_values.constEnd();
     for (it = m_values.constBegin(); it != end; ++it) {
         env.set((*it).first, (*it).second);
-        //qDebug()<<"variable:"<<(*it).first<<"value:"<<(*it).second;
     }
-
 }
 
 QString MSVCToolChain::makeCommand() const
diff --git a/src/plugins/projectexplorer/toolchain.h b/src/plugins/projectexplorer/toolchain.h
index a977c125bf3..813092d7bc1 100644
--- a/src/plugins/projectexplorer/toolchain.h
+++ b/src/plugins/projectexplorer/toolchain.h
@@ -119,6 +119,7 @@ protected:
 private:
     mutable QList<QPair<QString, QString> > m_values;
     mutable bool m_valuesSet;
+    mutable ProjectExplorer::Environment m_lastEnvironment;
 };
 
 // TODO some stuff needs to be moved into here
diff --git a/src/plugins/qt4projectmanager/qtversionmanager.cpp b/src/plugins/qt4projectmanager/qtversionmanager.cpp
index 013e7b1ca74..c6024a869c3 100644
--- a/src/plugins/qt4projectmanager/qtversionmanager.cpp
+++ b/src/plugins/qt4projectmanager/qtversionmanager.cpp
@@ -1235,7 +1235,6 @@ void QtVersion::addToEnvironment(Environment &env)
     // add libdir, includedir and bindir
     // or add Mingw dirs
     // or do nothing on other
-
 }
 
 int QtVersion::uniqueId() const
-- 
GitLab