From e2978d6097be2313e49c57ec14618033cbfa7414 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 18 Nov 2016 18:17:49 +0100 Subject: move license check to qmake-based configure system this also removes the need for passing pre-processed options via configure.cfg, so get rid of that. a somewhat unfortunate side effect is that the android-style-assets feature had to move back to the top level, as the licensing options depend on it. Started-by: Lars Knoll Change-Id: Id4d1e0ba18b3e3104400293b8f0c7f2f65e68dea Reviewed-by: Lars Knoll --- tools/configure/Makefile.mingw | 4 +- tools/configure/Makefile.win32 | 4 +- tools/configure/configure.pro | 4 +- tools/configure/configureapp.cpp | 216 +++------------------------------------ tools/configure/configureapp.h | 6 -- tools/configure/environment.cpp | 25 ----- tools/configure/environment.h | 1 - tools/configure/main.cpp | 7 -- tools/configure/tools.cpp | 79 -------------- tools/configure/tools.h | 43 -------- 10 files changed, 18 insertions(+), 371 deletions(-) delete mode 100644 tools/configure/tools.cpp delete mode 100644 tools/configure/tools.h (limited to 'tools') diff --git a/tools/configure/Makefile.mingw b/tools/configure/Makefile.mingw index ff960115f9..b61dc38de4 100644 --- a/tools/configure/Makefile.mingw +++ b/tools/configure/Makefile.mingw @@ -18,7 +18,6 @@ OBJECTS = \ main.o \ configureapp.o \ environment.o \ - tools.o \ qarraydata.o \ qbytearray.o \ qbytearraymatcher.o \ @@ -116,9 +115,8 @@ $(PCH): $(CONFSRC)/configure_pch.h VPATH = $(CONFSRC):$(TOOLSRC)/shared/windows:$(CORESRC)/global:$(CORESRC)/kernel:$(CORESRC)/tools:$(CORESRC)/codecs:$(CORESRC)/io:$(CORESRC)/xml:$(CORESRC)/plugin main.o: $(CONFSRC)/configureapp.h -configureapp.o: $(CONFSRC)/configureapp.h $(CONFSRC)/environment.h $(CONFSRC)/tools.h +configureapp.o: $(CONFSRC)/configureapp.h $(CONFSRC)/environment.h environment.o: $(CONFSRC)/environment.h -tools.o: $(CONFSRC)/tools.h # Make sure qstring_compat.obj isn't compiled with PCH enabled qstring_compat.o: $(CORESRC)/tools/qstring_compat.cpp diff --git a/tools/configure/Makefile.win32 b/tools/configure/Makefile.win32 index 8ed2ffd23f..8864d6fc8f 100644 --- a/tools/configure/Makefile.win32 +++ b/tools/configure/Makefile.win32 @@ -23,7 +23,6 @@ OBJECTS = \ main.obj \ configureapp.obj \ environment.obj \ - tools.obj \ qarraydata.obj \ qbytearray.obj \ qbytearraymatcher.obj \ @@ -97,9 +96,8 @@ $(PCH): $(CONFSRC)\configure_pch.h $(OBJECTS): $(PCH) main.obj: $(CONFSRC)\main.cpp $(CONFSRC)\configureapp.h $(PCH) -configureapp.obj: $(CONFSRC)\configureapp.cpp $(CONFSRC)\configureapp.h $(CONFSRC)\environment.h $(CONFSRC)\tools.h $(PCH) +configureapp.obj: $(CONFSRC)\configureapp.cpp $(CONFSRC)\configureapp.h $(CONFSRC)\environment.h $(PCH) environment.obj: $(CONFSRC)\environment.cpp $(CONFSRC)\environment.h $(PCH) -tools.obj: $(CONFSRC)\tools.cpp $(CONFSRC)\tools.h $(PCH) registry.obj: $(TOOLSRC)\shared\windows\registry.cpp $(PCH) qarraydata.obj: $(CORESRC)\tools\qarraydata.cpp $(PCH) qbytearray.obj: $(CORESRC)\tools\qbytearray.cpp $(PCH) diff --git a/tools/configure/configure.pro b/tools/configure/configure.pro index 9149a30e3e..93e6a197a2 100644 --- a/tools/configure/configure.pro +++ b/tools/configure/configure.pro @@ -31,7 +31,7 @@ INCLUDEPATH += \ $$QT_BUILD_TREE/include/QtCore/$$QT.core.VERSION/QtCore \ $$QT_SOURCE_TREE/tools/shared -HEADERS = configureapp.h environment.h tools.h\ +HEADERS = configureapp.h environment.h \ $$QT_SOURCE_TREE/src/corelib/tools/qarraydata.h \ $$QT_SOURCE_TREE/src/corelib/tools/qbytearray.h \ $$QT_SOURCE_TREE/src/corelib/tools/qarraydatapointer.h \ @@ -80,7 +80,7 @@ HEADERS = configureapp.h environment.h tools.h\ $$QT_SOURCE_TREE/tools/shared/windows/registry_p.h -SOURCES = main.cpp configureapp.cpp environment.cpp tools.cpp \ +SOURCES = main.cpp configureapp.cpp environment.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qbytearray.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qarraydata.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qbytearraymatcher.cpp \ diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 841aa66b8f..fc66220335 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -29,7 +29,6 @@ #include "configureapp.h" #include "environment.h" -#include "tools.h" #include #include @@ -46,7 +45,6 @@ #include #include #include -#include QT_BEGIN_NAMESPACE @@ -66,13 +64,6 @@ std::ostream &operator<<(std::ostream &s, const QString &val) { using namespace std; -static inline void promptKeyPress() -{ - cout << "(Press any key to continue...)"; - if (_getch() == 3) // _Any_ keypress w/no echo(eat for stdout) - exit(0); // Exit cleanly for Ctrl+C -} - Configure::Configure(int& argc, char** argv) { int i; @@ -183,7 +174,6 @@ void Configure::parseCmdLine() if (j == argCount) break; dictionary["XQMAKESPEC"] = configCmdLine.at(j); - applySpecSpecifics(); break; } } @@ -419,12 +409,6 @@ void Configure::parseCmdLine() break; dictionary[ "ANDROID_NDK_TOOLCHAIN_VERSION" ] = configCmdLine.at(i); } - - else if (configCmdLine.at(i) == "-no-android-style-assets") { - dictionary[ "ANDROID_STYLE_ASSETS" ] = "no"; - } else if (configCmdLine.at(i) == "-android-style-assets") { - dictionary[ "ANDROID_STYLE_ASSETS" ] = "yes"; - } } // Ensure that QMAKESPEC exists in the mkspecs folder @@ -495,16 +479,6 @@ void Configure::parseCmdLine() } } -/*! - Modifies the default configuration based on given -platform option. - Eg. switches to different default styles for Windows CE. -*/ -void Configure::applySpecSpecifics() -{ - if (platform() == ANDROID) - dictionary["ANDROID_STYLE_ASSETS"] = "yes"; -} - void Configure::prepareConfigTests() { // Generate an empty .qmake.cache file for config.tests @@ -914,16 +888,6 @@ void Configure::buildQmake() void Configure::configure() { - FileWriter ci(buildPath + "/config.tests/configure.cfg"); - ci << "# Feature defaults set by configure command line\n" - << "config.input.qt_edition = " << dictionary["EDITION"] << "\n" - << "config.input.qt_licheck = " << dictionary["LICHECK"] << "\n" - << "config.input.qt_release_date = " << dictionary["RELEASEDATE"]; - if (!ci.flush()) { - dictionary[ "DONE" ] = "error"; - return; - } - QStringList args; args << buildPath + "/bin/qmake" << sourcePathMangled @@ -941,155 +905,6 @@ void Configure::configure() saveCmdLine(); } -bool Configure::showLicense(QString orgLicenseFile) -{ - bool showGpl2 = true; - QString licenseFile = orgLicenseFile; - QString theLicense; - if (dictionary["EDITION"] == "OpenSource") { - if (platform() != WINDOWS_RT - && (platform() != ANDROID || dictionary["ANDROID_STYLE_ASSETS"] == "no")) { - theLicense = "GNU Lesser General Public License (LGPL) version 3\n" - "or the GNU General Public License (GPL) version 2"; - } else { - theLicense = "GNU Lesser General Public License (LGPL) version 3"; - showGpl2 = false; - } - } else { - // the first line of the license file tells us which license it is - QFile file(licenseFile); - if (!file.open(QFile::ReadOnly)) { - cout << "Failed to load LICENSE file" << endl; - return false; - } - theLicense = file.readLine().trimmed(); - } - - forever { - char accept = '?'; - cout << "You are licensed to use this software under the terms of" << endl - << "the " << theLicense << "." << endl - << endl; - if (dictionary["EDITION"] == "OpenSource") { - cout << "Type 'L' to view the GNU Lesser General Public License version 3 (LGPLv3)." << endl; - if (showGpl2) - cout << "Type 'G' to view the GNU General Public License version 2 (GPLv2)." << endl; - } else { - cout << "Type '?' to view the " << theLicense << "." << endl; - } - cout << "Type 'y' to accept this license offer." << endl - << "Type 'n' to decline this license offer." << endl - << endl - << "Do you accept the terms of the license?" << endl; - cin >> accept; - accept = tolower(accept); - - if (accept == 'y') { - configCmdLine << "-confirm-license"; - return true; - } else if (accept == 'n') { - return false; - } else { - if (dictionary["EDITION"] == "OpenSource") { - if (accept == 'l') - licenseFile = orgLicenseFile + "/LICENSE.LGPL3"; - else - licenseFile = orgLicenseFile + "/LICENSE.GPL2"; - } - // Get console line height, to fill the screen properly - int i = 0, screenHeight = 25; // default - CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE); - if (GetConsoleScreenBufferInfo(stdOut, &consoleInfo)) - screenHeight = consoleInfo.srWindow.Bottom - - consoleInfo.srWindow.Top - - 1; // Some overlap for context - - // Prompt the license content to the user - QFile file(licenseFile); - if (!file.open(QFile::ReadOnly)) { - cout << "Failed to load LICENSE file" << licenseFile << endl; - return false; - } - QStringList licenseContent = QString(file.readAll()).split('\n'); - while (i < licenseContent.size()) { - cout << licenseContent.at(i) << endl; - if (++i % screenHeight == 0) { - promptKeyPress(); - cout << "\r"; // Overwrite text above - } - } - } - } -} - -void Configure::readLicense() -{ - dictionary["PLATFORM NAME"] = platformName(); - dictionary["LICENSE FILE"] = sourcePath; - - bool openSource = false; - bool hasOpenSource = QFile::exists(dictionary["LICENSE FILE"] + "/LICENSE.LGPL3") || QFile::exists(dictionary["LICENSE FILE"] + "/LICENSE.GPL2"); - if (dictionary["BUILDTYPE"] == "commercial") { - openSource = false; - } else if (dictionary["BUILDTYPE"] == "opensource") { - openSource = true; - } else if (hasOpenSource) { // No Open Source? Just display the commercial license right away - forever { - char accept = '?'; - cout << "Which edition of Qt do you want to use ?" << endl; - cout << "Type 'c' if you want to use the Commercial Edition." << endl; - cout << "Type 'o' if you want to use the Open Source Edition." << endl; - cin >> accept; - accept = tolower(accept); - - if (accept == 'c') { - openSource = false; - break; - } else if (accept == 'o') { - openSource = true; - break; - } - } - } - if (hasOpenSource && openSource) { - cout << endl << "This is the " << dictionary["PLATFORM NAME"] << " Open Source Edition." << endl << endl; - dictionary["LICENSEE"] = "Open Source"; - dictionary["EDITION"] = "OpenSource"; - } else if (openSource) { - cout << endl << "Cannot find the GPL license files! Please download the Open Source version of the library." << endl; - dictionary["DONE"] = "error"; - return; - } else { - QString tpLicense = sourcePath + "/LICENSE.PREVIEW.COMMERCIAL"; - if (QFile::exists(tpLicense)) { - cout << endl << "This is the Qt Preview Edition." << endl << endl; - - dictionary["EDITION"] = "Preview"; - dictionary["LICENSE FILE"] = tpLicense; - } else { - Tools::checkLicense(dictionary, sourcePath, buildPath); - } - } - - if (dictionary["LICENSE_CONFIRMED"] != "yes") { - if (!showLicense(dictionary["LICENSE FILE"])) { - cout << "Configuration aborted since license was not accepted" << endl; - dictionary["DONE"] = "error"; - return; - } - } else if (dictionary["LICHECK"].isEmpty()) { // licheck executable shows license - cout << "You have already accepted the terms of the license." << endl << endl; - } - - if (dictionary["BUILDTYPE"] == "none") { - if (openSource) - configCmdLine << "-opensource"; - else - configCmdLine << "-commercial"; - } -} - bool Configure::reloadCmdLine(int idx) { QFile inFile(buildPathMangled + "/config.opt"); @@ -1112,6 +927,20 @@ bool Configure::reloadCmdLine(int idx) void Configure::saveCmdLine() { if (dictionary[ "REDO" ] != "yes") { + if (dictionary["BUILDTYPE"] == "none") { + bool openSource = false; + QFile inFile(buildPath + "/mkspecs/qconfig.pri"); + if (inFile.open(QFile::ReadOnly | QFile::Text)) { + QTextStream inStream(&inFile); + while (!inStream.atEnd()) { + if (inStream.readLine() == "QT_EDITION = OpenSource") + openSource = true; + } + } + configCmdLine.append(openSource ? "-opensource" : "-commercial"); + } + if (dictionary["LICENSE_CONFIRMED"] != "yes") + configCmdLine.append("-confirm-license"); QFile outFile(buildPathMangled + "/config.opt"); if (outFile.open(QFile::WriteOnly | QFile::Text)) { QTextStream outStream(&outFile); @@ -1134,23 +963,6 @@ bool Configure::isOk() return (dictionary[ "DONE" ] != "error"); } -QString Configure::platformName() const -{ - switch (platform()) { - default: - case WINDOWS: - return QStringLiteral("Qt for Windows"); - case WINDOWS_RT: - return QStringLiteral("Qt for Windows Runtime"); - case QNX: - return QStringLiteral("Qt for QNX"); - case ANDROID: - return QStringLiteral("Qt for Android"); - case OTHER: - return QStringLiteral("Qt for ???"); - } -} - int Configure::platform() const { const QString xQMakeSpec = dictionary.value("XQMAKESPEC"); diff --git a/tools/configure/configureapp.h b/tools/configure/configureapp.h index c8d4d3df53..b007f3c487 100644 --- a/tools/configure/configureapp.h +++ b/tools/configure/configureapp.h @@ -54,14 +54,10 @@ public: void generateQDevicePri(); void prepareConfigTests(); - bool showLicense(QString licenseFile); - void readLicense(); - bool isDone(); bool isOk(); int platform() const; - QString platformName() const; private: int verbose; @@ -86,8 +82,6 @@ private: bool reloadCmdLine(int idx); void saveCmdLine(); - - void applySpecSpecifics(); }; class FileWriter : public QTextStream diff --git a/tools/configure/environment.cpp b/tools/configure/environment.cpp index e585b16ea7..260af276fa 100644 --- a/tools/configure/environment.cpp +++ b/tools/configure/environment.cpp @@ -378,29 +378,4 @@ int Environment::execute(QStringList arguments, const QStringList &additionalEnv return exitCode; } -/*! - Executes \a command with _popen() and returns the stdout of the command. - - Taken from qmake's system() command. -*/ -QString Environment::execute(const QString &command, int *returnCode) -{ - QString output; - FILE *proc = _popen(command.toLatin1().constData(), "r"); - char buff[256]; - while (proc && !feof(proc)) { - int read_in = int(fread(buff, 1, 255, proc)); - if (!read_in) - break; - buff[read_in] = '\0'; - output += buff; - } - if (proc) { - int r = _pclose(proc); - if (returnCode) - *returnCode = r; - } - return output; -} - QT_END_NAMESPACE diff --git a/tools/configure/environment.h b/tools/configure/environment.h index aa8e7fd8bc..8415fa10a6 100644 --- a/tools/configure/environment.h +++ b/tools/configure/environment.h @@ -52,7 +52,6 @@ public: static QString detectQMakeSpec(); static int execute(QStringList arguments, const QStringList &additionalEnv, const QStringList &removeEnv); - static QString execute(const QString &command, int *returnCode = 0); private: static Compiler detectedCompiler; diff --git a/tools/configure/main.cpp b/tools/configure/main.cpp index 91a99c16c2..f6c2722529 100644 --- a/tools/configure/main.cpp +++ b/tools/configure/main.cpp @@ -45,13 +45,6 @@ int runConfigure( int argc, char** argv ) if (!app.isOk()) return 3; - // Read license now, and exit if it doesn't pass. - // This lets the user see the command-line options of configure - // without having to load and parse the license file. - app.readLicense(); - if (!app.isOk()) - return 3; - // Source file with path settings. Needed by qmake. app.generateQConfigCpp(); diff --git a/tools/configure/tools.cpp b/tools/configure/tools.cpp deleted file mode 100644 index 5ba7125975..0000000000 --- a/tools/configure/tools.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** 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 "tools.h" -#include "environment.h" - -#include -#include -#include -#include - -#include - -std::ostream &operator<<(std::ostream &s, const QString &val); -using namespace std; - -void Tools::checkLicense(QMap &dictionary, - const QString &sourcePath, const QString &buildPath) -{ - dictionary["LICHECK"] = "licheck.exe"; - - const QString licenseChecker = - QDir::toNativeSeparators(sourcePath + "/bin/licheck.exe"); - - if (QFile::exists(licenseChecker)) { - const QString qMakeSpec = - QDir::toNativeSeparators(dictionary.value("QMAKESPEC")); - const QString xQMakeSpec = - QDir::toNativeSeparators(dictionary.value("XQMAKESPEC")); - - QString command = QString("%1 %2 %3 %4 %5 %6") - .arg(licenseChecker, - dictionary.value("LICENSE_CONFIRMED", "no"), - QDir::toNativeSeparators(sourcePath), - QDir::toNativeSeparators(buildPath), - qMakeSpec, xQMakeSpec); - - int returnValue = 0; - QString licheckOutput = Environment::execute(command, &returnValue); - - if (returnValue) { - dictionary["DONE"] = "error"; - } else { - foreach (const QString &var, licheckOutput.split('\n')) - dictionary[var.section('=', 0, 0).toUpper()] = var.section('=', 1, 1); - dictionary["LICENSE_CONFIRMED"] = "yes"; - } - } else { - cout << endl << "Error: Could not find licheck.exe" << endl - << "Try re-installing." << endl << endl; - dictionary["DONE"] = "error"; - } -} - diff --git a/tools/configure/tools.h b/tools/configure/tools.h deleted file mode 100644 index 17dcc88518..0000000000 --- a/tools/configure/tools.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** 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$ -** -****************************************************************************/ - -#ifndef _TOOLS_H_ -#define _TOOLS_H_ - -#include -#include - -class Tools -{ -public: - static void checkLicense(QMap &dictionary, - const QString &sourcePath, const QString &buildPath); -}; - -#endif // _TOOLS_H_ - -- cgit v1.2.3