From 8f49da6c18a2a86576f06deb9a6ff1deef748837 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 18 Nov 2016 16:24:31 +0100 Subject: ... and so configureapp.exe disappeareth Change-Id: I3fd9f2b0d4cf05a625484fce21532da8563cd62c Reviewed-by: Thiago Macieira --- tools/configure/environment.cpp | 318 ---------------------------------------- 1 file changed, 318 deletions(-) delete mode 100644 tools/configure/environment.cpp (limited to 'tools/configure/environment.cpp') diff --git a/tools/configure/environment.cpp b/tools/configure/environment.cpp deleted file mode 100644 index 312e2f9e56..0000000000 --- a/tools/configure/environment.cpp +++ /dev/null @@ -1,318 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "environment.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -//#define CONFIGURE_DEBUG_EXECUTE -//#define CONFIGURE_DEBUG_CP_DIR - -using namespace std; - -#ifdef Q_OS_WIN32 -#include -#endif - -QT_BEGIN_NAMESPACE - -struct CompilerInfo{ - Compiler compiler; - const char *compilerStr; - const char *executable; -} compiler_info[] = { - // The compilers here are sorted in a reversed-preferred order - {CC_MINGW, "MinGW (Minimalist GNU for Windows)", "g++.exe"}, - {CC_INTEL, "Intel(R) C++ Compiler for 32-bit applications", "icl.exe"}, // xilink.exe, xilink5.exe, xilink6.exe, xilib.exe - {CC_MSVC, "Microsoft (R) Visual Studio C/C++ Compiler", "cl.exe"}, // link.exe, lib.exe - {CC_UNKNOWN, "Unknown", 0}, -}; - - -// Initialize static variables -Compiler Environment::detectedCompiler = CC_UNKNOWN; - -/*! - Returns the pointer to the CompilerInfo for a \a compiler. -*/ -CompilerInfo *Environment::compilerInfo(Compiler compiler) -{ - int i = 0; - while(compiler_info[i].compiler != compiler && compiler_info[i].compiler != CC_UNKNOWN) - ++i; - return &(compiler_info[i]); -} - -/*! - Returns the qmakespec for the compiler detected on the system. -*/ -QString Environment::detectQMakeSpec() -{ - QString spec; - switch (detectCompiler()) { - case CC_MSVC: - spec = "win32-msvc"; - break; - case CC_INTEL: - spec = "win32-icc"; - break; - case CC_MINGW: - spec = "win32-g++"; - break; - default: - break; - } - - return spec; -} - -/*! - Returns the enum of the compiler which was detected on the system. - The compilers are detected in the order as entered into the - compiler_info list. - - If more than one compiler is found, CC_UNKNOWN is returned. -*/ -Compiler Environment::detectCompiler() -{ - if(detectedCompiler != CC_UNKNOWN) - return detectedCompiler; - - int installed = 0; - for (int i = 0; compiler_info[i].compiler; ++i) { - if (!QStandardPaths::findExecutable(compiler_info[i].executable).isEmpty()) { - if (detectedCompiler == CC_UNKNOWN) - detectedCompiler = compiler_info[i].compiler; - ++installed; - } - } - - if (installed > 1) { - cout << "Found more than one known compiler! Using \"" << compilerInfo(detectedCompiler)->compilerStr << "\"" << endl; - detectedCompiler = CC_UNKNOWN; - } - return detectedCompiler; -}; - -/*! - Creates a commandling from \a program and it \a arguments, - escaping characters that needs it. -*/ -static QString qt_create_commandline(const QString &program, const QStringList &arguments) -{ - QString programName = program; - if (!programName.startsWith("\"") && !programName.endsWith("\"") && programName.contains(" ")) - programName = "\"" + programName + "\""; - programName.replace("/", "\\"); - - QString args; - // add the prgram as the first arrg ... it works better - args = programName + " "; - for (int i=0; i0 && tmp.at(i-1) == '\\') { - --i; - endQuote += "\\"; - } - args += QString(" \"") + tmp.left(i) + endQuote; - } else { - args += ' ' + tmp; - } - } - return args; -} - -/*! - Creates a QByteArray of the \a environment. -*/ -static QByteArray qt_create_environment(const QStringList &environment) -{ - QByteArray envlist; - if (environment.isEmpty()) - return envlist; - - int pos = 0; - // add PATH if necessary (for DLL loading) - QByteArray path = qgetenv("PATH"); - if (environment.filter(QRegExp("^PATH=",Qt::CaseInsensitive)).isEmpty() && !path.isNull()) { - QString tmp = QString(QLatin1String("PATH=%1")).arg(QString::fromLocal8Bit(path)); - uint tmpSize = sizeof(wchar_t) * (tmp.length() + 1); - envlist.resize(envlist.size() + tmpSize); - memcpy(envlist.data() + pos, tmp.utf16(), tmpSize); - pos += tmpSize; - } - // add the user environment - foreach (const QString &tmp, environment) { - uint tmpSize = sizeof(wchar_t) * (tmp.length() + 1); - envlist.resize(envlist.size() + tmpSize); - memcpy(envlist.data() + pos, tmp.utf16(), tmpSize); - pos += tmpSize; - } - // add the 2 terminating 0 (actually 4, just to be on the safe side) - envlist.resize(envlist.size() + 4); - envlist[pos++] = 0; - envlist[pos++] = 0; - envlist[pos++] = 0; - envlist[pos++] = 0; - - return envlist; -} - -/*! - Executes the command described in \a arguments, in the - environment inherited from the parent process, with the - \a additionalEnv settings applied. - \a removeEnv removes the specified environment variables from - the environment of the executed process. - - Returns the exit value of the process, or -1 if the command could - not be executed. - - This function uses _(w)spawnvpe to spawn a process by searching - through the PATH environment variable. -*/ -int Environment::execute(QStringList arguments, const QStringList &additionalEnv, const QStringList &removeEnv) -{ -#ifdef CONFIGURE_DEBUG_EXECUTE - qDebug() << "About to Execute: " << arguments; - qDebug() << " " << QDir::currentPath(); - qDebug() << " " << additionalEnv; - qDebug() << " " << removeEnv; -#endif - // Create the full environment from the current environment and - // the additionalEnv strings, then remove all variables defined - // in removeEnv - QMap fullEnvMap; - LPWSTR envStrings = GetEnvironmentStrings(); - if (envStrings) { - int strLen = 0; - for (LPWSTR envString = envStrings; *(envString); envString += strLen + 1) { - strLen = int(wcslen(envString)); - QString str = QString((const QChar*)envString, strLen); - if (!str.startsWith("=")) { // These are added by the system - int sepIndex = str.indexOf('='); - fullEnvMap.insert(str.left(sepIndex).toUpper(), str.mid(sepIndex +1)); - } - } - } - FreeEnvironmentStrings(envStrings); - - // Add additionalEnv variables - for (int i = 0; i < additionalEnv.count(); ++i) { - const QString &str = additionalEnv.at(i); - int sepIndex = str.indexOf('='); - fullEnvMap.insert(str.left(sepIndex).toUpper(), str.mid(sepIndex +1)); - } - - // Remove removeEnv variables - for (int j = 0; j < removeEnv.count(); ++j) - fullEnvMap.remove(removeEnv.at(j).toUpper()); - - // Add all variables to a QStringList - QStringList fullEnv; - QMapIterator it(fullEnvMap); - while (it.hasNext()) { - it.next(); - fullEnv += QString(it.key() + "=" + it.value()); - } - - // ---------------------------- - QString program = arguments.takeAt(0); - QString args = qt_create_commandline(program, arguments); - QByteArray envlist = qt_create_environment(fullEnv); - - DWORD exitCode = DWORD(-1); - PROCESS_INFORMATION procInfo; - memset(&procInfo, 0, sizeof(procInfo)); - - STARTUPINFO startInfo; - memset(&startInfo, 0, sizeof(startInfo)); - startInfo.cb = sizeof(startInfo); - - bool couldExecute = CreateProcess(0, (wchar_t*)args.utf16(), - 0, 0, true, CREATE_UNICODE_ENVIRONMENT, - envlist.isEmpty() ? 0 : envlist.data(), - 0, &startInfo, &procInfo); - - if (couldExecute) { - WaitForSingleObject(procInfo.hProcess, INFINITE); - GetExitCodeProcess(procInfo.hProcess, &exitCode); - CloseHandle(procInfo.hThread); - CloseHandle(procInfo.hProcess); - } - - - if (exitCode == DWORD(-1)) { - switch(GetLastError()) { - case E2BIG: - cerr << "execute: Argument list exceeds 1024 bytes" << endl; - foreach (const QString &arg, arguments) - cerr << " (" << arg.toLocal8Bit().constData() << ")" << endl; - break; - case ENOENT: - cerr << "execute: File or path is not found (" << program.toLocal8Bit().constData() << ")" << endl; - break; - case ENOEXEC: - cerr << "execute: Specified file is not executable or has invalid executable-file format (" << program.toLocal8Bit().constData() << ")" << endl; - break; - case ENOMEM: - cerr << "execute: Not enough memory is available to execute new process." << endl; - break; - default: - cerr << "execute: Unknown error" << endl; - foreach (const QString &arg, arguments) - cerr << " (" << arg.toLocal8Bit().constData() << ")" << endl; - break; - } - } - return exitCode; -} - -QT_END_NAMESPACE -- cgit v1.2.3