diff --git a/bin/CraftSetupHelper.py b/bin/CraftSetupHelper.py index 62bc067bf..1f15a7d68 100644 --- a/bin/CraftSetupHelper.py +++ b/bin/CraftSetupHelper.py @@ -1,422 +1,422 @@ # -*- coding: utf-8 -*- # Copyright Hannah von Reth # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. import argparse import collections import os import platform import shutil import subprocess import sys from CraftCore import CraftCore from CraftOS.osutils import OsUtils from Utils.CaseInsensitiveDict import CaseInsensitiveDict # The minimum python version for craft please edit here # if you add code that changes this requirement MIN_PY_VERSION = (3, 6, 0) def log(msg, critical=False): if critical or not CraftCore.settings.getboolean("ContinuousIntegration", "Enabled", False): CraftCore.debug.print(msg, sys.stderr) else: CraftCore.log.debug(msg) if critical: exit(1) if sys.version_info[0:3] < MIN_PY_VERSION: log("Error: Python too old!\n" "Craft needs at least Python Version %s.%s.%s\n" "Please install it and adapt your CraftSettings.ini" % MIN_PY_VERSION, critical=True) if not platform.machine().endswith("64"): log(f"Craft requires a 64bit operating system. Your are using: {platform.machine()}", critical=True) class SetupHelper(object): CraftVersion = "master" NeedsSetup = "KDEROOT" not in os.environ def __init__(self, args=None): self.args = args if CraftCore.settings.getboolean("General", "AllowAnsiColor", False): OsUtils.enableAnsiColors() if SetupHelper.NeedsSetup: SetupHelper.NeedsSetup = False self.checkForEvilApplication() self.setupEnvironment() @staticmethod def _getOutput(command, shell=False): CraftCore.log.debug(f"SetupHelper._getOutput: {command}") p = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell, universal_newlines=True, errors="backslashreplace") out = p.stdout.strip() CraftCore.log.debug(f"SetupHelper._getOutput: return {p.returncode} {out}") return p.returncode, out def run(self): parser = argparse.ArgumentParser() parser.add_argument("--get", action="store_true") parser.add_argument("--print-banner", action="store_true") parser.add_argument("--getenv", action="store_true") parser.add_argument("--setup", action="store_true") parser.add_argument("rest", nargs=argparse.REMAINDER) args = parser.parse_args() if args.get: default = "" if len(args.rest) == 3: default = args.rest[2] CraftCore.log.info(CraftCore.settings.get(args.rest[0], args.rest[1], default)) elif args.print_banner: self.printBanner() elif args.getenv: self.printEnv() elif args.setup: self.printEnv() self.printBanner() def checkForEvilApplication(self): blackList = [] if OsUtils.isWin(): blackList += ["sh", "gcc", "g++", "cpp"] for app in blackList: location = shutil.which(app) if location: location = os.path.dirname(location) if not CraftCore.settings.getboolean("ContinuousIntegration", "Enabled", False): log( f"Found \"{app}\" in your PATH: \"{location}\"\n" f"This application is known to cause problems with your configuration of Craft.\n" f"Please remove it from PATH or manually set a value for PATH in your CraftSettings.ini:\n" f"\n" f"[Environment]\n" f"PATH=" f"\n") else: path = collections.OrderedDict.fromkeys(os.environ["Path"].split(os.path.pathsep)) del path[location] self.addEnvVar("Path", os.path.pathsep.join(path)) @staticmethod def printBanner(): def printRow(name, value): log(f"{name:20}: {value}") printRow("Craft", CraftCore.standardDirs.craftRoot()) printRow("Version", SetupHelper.CraftVersion) printRow("ABI", CraftCore.compiler) printRow("Download directory", CraftCore.standardDirs.downloadDir()) def addEnvVar(self, key, val): os.environ[key] = val def prependEnvVar(self, key : str, var : str, sep : str=os.path.pathsep) -> None: if not type(var) == list: var = [var] if key in os.environ: env = var + os.environ[key].split(sep) var = list(collections.OrderedDict.fromkeys(env)) val = sep.join(var) CraftCore.log.debug(f"Setting {key}={val}") os.environ[key] = val @staticmethod def stringToEnv(string : str): for line in string.strip().split("\n"): kv = line.strip().split("=", 1) if len(kv) != 2: log(f"Failed to parse environment variable: {line}\n{string}") continue # TODO: why? if kv[0] == "Path": kv[0] = "PATH" os.environ[kv[0]] = kv[1] return os.environ @staticmethod - def _callVCVER(version : int, args : []=None, native : bool=True, Prerelease : bool = False) -> str: + def _callVCVER(version : int, args : []=None, native : bool=True, prerelease : bool=False) -> str: if not args: args = [] vswhere = os.path.join(CraftCore.standardDirs.craftBin(), "3rdparty", "vswhere", "vswhere.exe") command = [vswhere, "-property", "installationPath", "-nologo", "-latest"] - if Prerelease: + if prerelease: command += ["-prerelease"] if version: command += ["-version", f"[{version},{version+1})"] if version < 15: command.append("-legacy") else: if not args: args = ["-products", "*"] if native: # this fails with express versions args += ["-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"] return SetupHelper._getOutput(command + args)[1] @staticmethod def getMSVCEnv(version=None, architecture="x86", toolset=None, native=True) -> str: if native: architectures = {"x86": "amd64_x86", "x64": "amd64"} else: architectures = {"x86": "x86", "x64": "x86_amd64"} args = architectures[architecture] path = "" if version == 14: # are we using msvc2017 with "VC++ 2015.3 v14.00 (v140) toolset for desktop" path = SetupHelper._callVCVER(15, args=["-products", "*", "-requires", "Microsoft.VisualStudio.Component.VC.140"], native=native) if path and not toolset: toolset = "14.0" if toolset: args += f" -vcvars_ver={toolset}" if not path: path = SetupHelper._callVCVER(version, native=native) if not path: - path = SetupHelper._callVCVER(version, native=native, Prerelease=True) + path = SetupHelper._callVCVER(version, native=native, prerelease=True) if path: log("Found MSVS only in a prerelease version. I will use that.") if not path: log("Unable to locate Visual Studio. Please install it with the C++ component. Aborting.", critical=True) path = os.path.join(path, "VC") if not os.path.exists(os.path.join(path, "vcvarsall.bat")): path = os.path.join(path, "Auxiliary", "Build") path = os.path.join(path, "vcvarsall.bat") if not os.path.isfile(path): log(f"Failed to setup msvc compiler.\n" f"{path} does not exist.", critical=True) status, result = SetupHelper._getOutput(f"\"{path}\" {args} > NUL && set", shell=True) if status != 0: log(f"Failed to setup msvc compiler.\n" f"Command: {result} ", critical=True) return SetupHelper.stringToEnv(result) def getEnv(self): if CraftCore.compiler.isMSVC(): return SetupHelper.getMSVCEnv(CraftCore.compiler.getInternalVersion(), CraftCore.compiler.architecture, CraftCore.compiler.msvcToolset, CraftCore.compiler.isNative()) elif CraftCore.compiler.isIntel(): architectures = {"x86": "ia32", "x64": "intel64"} programFiles = os.getenv("ProgramFiles(x86)") or os.getenv("ProgramFiles") status, result = SetupHelper._getOutput( "\"%s\\Intel\\Composer XE\\bin\\compilervars.bat\" %s > NUL && set" % ( programFiles, architectures[CraftCore.compiler.architecture]), shell=True) if status != 0: log("Failed to setup intel compiler", critical=True) return SetupHelper.stringToEnv(result) return os.environ def setXDG(self): self.prependEnvVar("XDG_DATA_DIRS", [os.path.join(CraftCore.standardDirs.craftRoot(), "share")]) if OsUtils.isUnix(): self.prependEnvVar("XDG_CONFIG_DIRS", [os.path.join(CraftCore.standardDirs.craftRoot(), "etc", "xdg")]) self.addEnvVar("XDG_DATA_HOME", os.path.join(CraftCore.standardDirs.craftRoot(), "home", os.getenv("USER"), ".local5", "share")) self.addEnvVar("XDG_CONFIG_HOME", os.path.join(CraftCore.standardDirs.craftRoot(), "home", os.getenv("USER"), ".config")) self.addEnvVar("XDG_CACHE_HOME", os.path.join(CraftCore.standardDirs.craftRoot(), "home", os.getenv("USER"), ".cache")) def _setupUnix(self): if CraftCore.compiler.isLinux: self.prependEnvVar("LDFLAGS", "-Wl,-rpath,'$ORIGIN/../lib'", sep=" ") self.prependEnvVar("LD_LIBRARY_PATH", [os.path.join(CraftCore.standardDirs.craftRoot(), "lib"), os.path.join(CraftCore.standardDirs.craftRoot(), "lib", "x86_64-linux-gnu")]) self.prependEnvVar("BISON_PKGDATADIR", os.path.join(CraftCore.standardDirs.craftRoot(), "share", "bison")) self.prependEnvVar("M4", os.path.join(CraftCore.standardDirs.craftRoot(), "dev-utils", "bin", "m4")) def _setupWin(self): if not "HOME" in os.environ: self.addEnvVar("HOME", os.getenv("USERPROFILE")) if CraftCore.compiler.isMinGW(): if not CraftCore.settings.getboolean("QtSDK", "Enabled", "false"): if CraftCore.compiler.isX86(): self.prependEnvVar("PATH", os.path.join(CraftCore.standardDirs.craftRoot(), "mingw", "bin")) else: self.prependEnvVar("PATH", os.path.join(CraftCore.standardDirs.craftRoot(), "mingw64", "bin")) else: compilerName = CraftCore.settings.get("QtSDK", "Compiler") compilerMap = {"mingw53_32": "mingw530_32"} self.prependEnvVar("PATH", os.path.join(CraftCore.settings.get("QtSDK", "Path"), "Tools", compilerMap.get(compilerName, compilerName), "bin")) if CraftCore.settings.getboolean("QtSDK", "Enabled", "false"): self.prependEnvVar("PATH", os.path.join(CraftCore.settings.get("QtSDK", "Path"), CraftCore.settings.get("QtSDK", "Version"), CraftCore.settings.get("QtSDK", "Compiler"), "bin")) if CraftCore.compiler.isMinGW(): if not CraftCore.settings.getboolean("QtSDK", "Enabled", "false"): if CraftCore.compiler.isX86(): self.prependEnvVar("PATH", os.path.join(CraftCore.standardDirs.craftRoot(), "mingw", "bin")) else: self.prependEnvVar("PATH", os.path.join(CraftCore.standardDirs.craftRoot(), "mingw64", "bin")) else: compilerName = CraftCore.settings.get("QtSDK", "Compiler") compilerMap = {"mingw53_32": "mingw530_32"} self.prependEnvVar("PATH", os.path.join(CraftCore.settings.get("QtSDK", "Path"), "Tools", compilerMap.get(compilerName, compilerName), "bin")) def setupEnvironment(self): originaleEnv = CaseInsensitiveDict(os.environ) for var, value in CraftCore.settings.getSection("Environment"): # set and override existing values # the ini is case insensitive so sections are lowercase.... self.addEnvVar(var.upper(), value) self.prependEnvVar("PATH", os.path.dirname(sys.executable)) os.environ = self.getEnv() self.addEnvVar("KDEROOT", CraftCore.standardDirs.craftRoot()) self.addEnvVar("SSL_CERT_FILE", os.path.join(CraftCore.standardDirs.etcDir(), "cacert.pem")) self.addEnvVar("REQUESTS_CA_BUNDLE", os.path.join(CraftCore.standardDirs.etcDir(), "cacert.pem")) if CraftCore.settings.getboolean("Compile", "UseCCache", False): self.addEnvVar("CCACHE_DIR", CraftCore.settings.get("Paths", "CCACHE_DIR", os.path.join(CraftCore.standardDirs.craftRoot(), "build", "CCACHE"))) if CraftCore.settings.getboolean("QtSDK", "Enabled", "false"): sdkPath = os.path.join(CraftCore.settings.get("QtSDK", "Path"), CraftCore.settings.get("QtSDK", "Version"), CraftCore.settings.get("QtSDK", "Compiler"), "bin") if not os.path.exists(sdkPath): log(f"Please ensure that you have installed the Qt SDK in {sdkPath}", critical=True) self.prependEnvVar("PATH", sdkPath) if OsUtils.isWin(): self._setupWin() else: self._setupUnix() PKG_CONFIG_PATH = collections.OrderedDict.fromkeys([os.path.join(CraftCore.standardDirs.craftRoot(), "lib", "pkgconfig")]) if "PKG_CONFIG_PATH" in originaleEnv: PKG_CONFIG_PATH.update(collections.OrderedDict.fromkeys(originaleEnv["PKG_CONFIG_PATH"].split(os.path.pathsep))) else: pkgCOnfig = shutil.which("pkg-config", path=originaleEnv["PATH"]) if pkgCOnfig: out = self._getOutput("pkg-config --variable pc_path pkg-config", shell=True) if out[0] == 0: PKG_CONFIG_PATH.update(collections.OrderedDict.fromkeys(out[1].split(os.path.pathsep))) self.prependEnvVar("PKG_CONFIG_PATH", os.path.pathsep.join(PKG_CONFIG_PATH.keys())) self.prependEnvVar("QT_PLUGIN_PATH", [os.path.join(CraftCore.standardDirs.craftRoot(), "plugins"), os.path.join(CraftCore.standardDirs.craftRoot(), "lib", "plugins"), os.path.join(CraftCore.standardDirs.craftRoot(), "lib64", "plugins"), os.path.join(CraftCore.standardDirs.craftRoot(), "lib", "x86_64-linux-gnu", "plugins"), os.path.join(CraftCore.standardDirs.craftRoot(), "lib", "plugin") ]) self.prependEnvVar("QML2_IMPORT_PATH", [os.path.join(CraftCore.standardDirs.craftRoot(), "qml"), os.path.join(CraftCore.standardDirs.craftRoot(), "lib", "qml"), os.path.join(CraftCore.standardDirs.craftRoot(), "lib64", "qml"), os.path.join(CraftCore.standardDirs.craftRoot(), "lib", "x86_64-linux-gnu", "qml") ]) self.prependEnvVar("QML_IMPORT_PATH", os.environ["QML2_IMPORT_PATH"]) self.prependEnvVar("QT_DATA_DIRS", CraftCore.standardDirs.locations.data) self.setXDG() self.prependEnvVar("PATH", CraftCore.standardDirs.craftBin()) # make sure that craftroot bin is the first to look for dlls etc self.prependEnvVar("PATH", os.path.join(CraftCore.standardDirs.craftRoot(), "bin")) self.prependEnvVar("PATH", os.path.join(CraftCore.standardDirs.craftRoot(), "dev-utils", "bin")) # add python site packages to pythonpath self.prependEnvVar("PYTHONPATH", os.path.join(CraftCore.standardDirs.craftRoot(), "lib", "site-packages")) if CraftCore.compiler.isClang(): if OsUtils.isUnix(): self.addEnvVar("CC", "/usr/bin/clang") self.addEnvVar("CXX", "/usr/bin/clang++") else: if CraftCore.compiler.isMSVC(): self.addEnvVar("CC", "clang-cl") self.addEnvVar("CXX", "clang-cl") else: self.addEnvVar("CC", "clang") self.addEnvVar("CXX", "clang") elif CraftCore.compiler.isGCC(): if not CraftCore.compiler.isNative() and CraftCore.compiler.isX86(): self.addEnvVar("CC", "gcc -m32") self.addEnvVar("CXX", "g++ -m32") self.addEnvVar("AS", "gcc -c -m32") else: self.addEnvVar("CC", "gcc") self.addEnvVar("CXX", "g++") if CraftCore.settings.getboolean("General", "AllowAnsiColor", False): # different non standard env switches self.addEnvVar("CLICOLOR_FORCE", "1") self.addEnvVar("CLICOLOR", "1") self.addEnvVar("ANSICON", "1") if CraftCore.compiler.isClang() and CraftCore.compiler.isMSVC(): self.prependEnvVar("CFLAGS", "-fcolor-diagnostics -fansi-escape-codes", sep=" ") self.prependEnvVar("CXXFLAGS", "-fcolor-diagnostics -fansi-escape-codes", sep=" ") elif CraftCore.compiler.isGCCLike(): self.prependEnvVar("CFLAGS", "-fdiagnostics-color=always", sep=" ") self.prependEnvVar("CXXFLAGS", "-fdiagnostics-color=always", sep=" ") if OsUtils.isWin(): os.environ["TERM"] = "xterm-color" # pretend to be a common smart terminal def printEnv(self): self.setupEnvironment() for key, val in os.environ.items(): if "\n" in val: log(f"Not adding ${key} to environment since it contains " "a newline character and that breaks craftenv.sh") continue if key.startswith("BASH_FUNC_"): continue # weird protected env vars if key in {"PROFILEREAD"}: continue CraftCore.log.info(f"{key}={val}") @property def version(self): return CraftCore.settings.version helper = SetupHelper() if __name__ == '__main__': helper.run() diff --git a/blueprints/libs/runtime/runtime.py b/blueprints/libs/runtime/runtime.py index 3047eab83..6ccf01ee1 100644 --- a/blueprints/libs/runtime/runtime.py +++ b/blueprints/libs/runtime/runtime.py @@ -1,84 +1,86 @@ import info import glob class subinfo(info.infoclass): def registerOptions(self): self.parent.package.categoryInfo.platforms = CraftCore.compiler.Platforms.Windows def setTargets(self): # not used yet only for reference ver = str(CraftCore.compiler.getVersion()) self.patchLevel[ver] = 1 self.targets[ver] = "" self.description = "The compiler runtime package" self.defaultTarget = ver def setDependencies(self): self.buildDependencies["virtual/base"] = None if CraftCore.compiler.isMinGW(): self.buildDependencies["dev-utils/mingw-w64"] = None from Package.BinaryPackageBase import * class PackageWin(BinaryPackageBase): def __init__(self): BinaryPackageBase.__init__(self) self.subinfo.options.package.disableBinaryCache = CraftCore.compiler.isMSVC() def fetch(self): return True def unpack(self): return True def install(self): destdir = os.path.join(self.installDir(), "bin") utils.createDir(destdir) files = [] if CraftCore.compiler.isMinGW(): files = ['libgomp-1.dll', 'libstdc++-6.dll', 'libwinpthread-1.dll'] if CraftCore.compiler.isMinGW_W32(): files.append('libgcc_s_sjlj-1.dll') srcdir = os.path.join(self.rootdir, "mingw", "bin") elif CraftCore.compiler.isMinGW_W64(): files.append('libgcc_s_seh-1.dll') srcdir = os.path.join(self.rootdir, "mingw64", "bin") elif CraftCore.compiler.isMSVC(): if self.buildType() != "Debug": - if CraftCore.compiler.isMSVC2019() or CraftCore.compiler.isMSVC2017(): - if CraftCore.compiler.isMSVC2019: + if CraftCore.compiler.getInternalVersion() >= 15: + if CraftCore.compiler.isMSVC2019(): flavor="2019" - else: + elif CraftCore.compiler.isMSVC2017(): flavor="2017" + else: + raise Exception("Unknown compiler") if "VCTOOLSREDISTDIR" in os.environ: redistDir = os.environ["VCTOOLSREDISTDIR"] else: CraftCore.log.error((r"Could not find Microsoft Visual Studio {0}.\n" + r"VCTOOLSREDISTDIR does not exist, and likely should point to '*\Microsoft Visual Studio\{0}\Community\VC\Redist\MSVC\xx.xx.xxxxx'.").format(flavor)) elif CraftCore.compiler.isMSVC2015(): if "VCINSTALLDIR" in os.environ: redistDir = os.path.join(os.environ["VCINSTALLDIR"], "redist") else: CraftCore.log.error("Could not find Microsoft Visual Studio 2015.\n" + r"VCINSTALLDIR does not exist, and should point to '*\Microsoft Visual Studio\2015\Community\VC\'.") if redistDir: files = glob.glob(os.path.join(redistDir, CraftCore.compiler.architecture, "**/*.dll"), recursive=True) else: CraftCore.log.error("Unsupported Compiler") return False for f in files: if not os.path.isabs(f): f = os.path.join(srcdir, f) utils.copyFile(f, os.path.join(destdir, os.path.basename(f)), linkOnly=False) return True from Package.Qt5CorePackageBase import * class Package(Qt5CoreSdkPackageBase): def __init__(self): Qt5CoreSdkPackageBase.__init__(self, condition=OsUtils.isWin(), classA=PackageWin) diff --git a/etc/CraftCoreSettings.ini b/etc/CraftCoreSettings.ini index 21e6106f4..6e23c7964 100644 --- a/etc/CraftCoreSettings.ini +++ b/etc/CraftCoreSettings.ini @@ -1,6 +1,6 @@ # Don't modify this file, rather set the values in your # etc/CraftSettings.ini [Packager] RepositoryUrl = https://files.kde.org/craft/master/ -CacheVersion = Qt_5.12.0 +CacheVersion = Qt_5.12.2 diff --git a/setup/CraftBootstrap.py b/setup/CraftBootstrap.py index 0abd6c268..5db70dbf9 100644 --- a/setup/CraftBootstrap.py +++ b/setup/CraftBootstrap.py @@ -1,277 +1,277 @@ import argparse import configparser import os import platform import re import shutil import subprocess import sys import urllib.parse import urllib.request if not platform.machine().endswith("64"): print(f"Craft requires a 64bit operating system. You are using: {platform.machine()}") exit(1) class CraftBootstrap(object): def __init__(self, craftRoot, branch, dryRun): self.craftRoot = craftRoot self.branch = branch self.dryRun = dryRun if not dryRun: with open(os.path.join(craftRoot, f"craft-{branch}", "CraftSettings.ini.template"), "rt", encoding="UTF-8") as ini: self.settings = ini.read().splitlines() else: with open(dryRun, "rt", encoding="UTF-8") as ini: self.settings = ini.read().splitlines() @staticmethod def isWin(): return os.name == 'nt' @staticmethod def isUnix(): return os.name == 'posix' @staticmethod def isFreeBSD(): return CraftBootstrap.isUnix() and platform.system() == 'FreeBSD' @staticmethod def isMac(): return CraftBootstrap.isUnix() and platform.system() == 'Darwin' @staticmethod def isLinux(): return CraftBootstrap.isUnix() and platform.system() == 'Linux' @staticmethod def printProgress(percent): width, _ = shutil.get_terminal_size((80, 20)) width -= 20 # margin times = int(width / 100 * percent) sys.stdout.write("\r[{progress}{space}]{percent}%".format(progress="#" * times, space=" " * (width - times), percent=percent)) sys.stdout.flush() @staticmethod def promptForChoice(title, choices, default=None): if not default: if isinstance(choices[0], tuple): default, _ = choices[0] else: default = choices[0] selection = ", ".join(["[{index}] {value}".format(index=index, value=value[0] if isinstance(value, tuple) else value) for index, value in enumerate(choices)]) promp = "{selection} (Default is {default}): ".format(selection=selection, default=default[0] if isinstance(default, tuple) else default) print() while (True): print(title) choice = input(promp) try: choiceInt = int(choice) except: choiceInt = -1 if choice == "": for choice in choices: if isinstance(choice, tuple): key, val = choice else: key = val = choice if key == default: return val elif choiceInt in range(len(choices)): if isinstance(choices[choiceInt], tuple): return choices[choiceInt][1] else: return choices[choiceInt] def setSettignsValue(self, section, key, value): reKey = re.compile(r"^[\#;]?\s*{key}\s*=.*$".format(key=key), re.IGNORECASE) reSection = re.compile(r"^\[(.*)\]$".format(section=section)) inSection = False for i, line in enumerate(self.settings): sectionMatch = reSection.match(line) if sectionMatch: inSection = sectionMatch.group(1) == section elif inSection and reKey.match(line): self.settings[i] = f"{key} = {value}" return print(f"Unable to locate\n" f"\t[{section}]\n" f"\t{key}") exit(1) def writeSettings(self): if not os.path.isdir(os.path.join(self.craftRoot, "etc")): os.makedirs(os.path.join(self.craftRoot, "etc"), exist_ok=True) if not self.dryRun: with open(os.path.join(self.craftRoot, "etc", "CraftSettings.ini"), "wt+") as out: out.write("\n".join(self.settings)) else: with open(self.dryRun + ".dry_run", "wt+") as out: out.write("\n".join(self.settings)) @staticmethod def downloadFile(url, destdir, filename=None): if not os.path.exists(destdir): os.makedirs(destdir) if not filename: _, _, path, _, _, _ = urllib.parse.urlparse(url) filename = os.path.basename(path) print("Starting to download %s to %s" % (url, os.path.join(destdir, filename))) if os.path.exists(os.path.join(destdir, filename)): return True def dlProgress(count, blockSize, totalSize): if totalSize != -1: percent = int(count * blockSize * 100 / totalSize) CraftBootstrap.printProgress(percent) else: sys.stdout.write(("\r%s bytes downloaded" % (count * blockSize))) sys.stdout.flush() urllib.request.urlretrieve(url, filename=os.path.join(destdir, filename), reporthook=dlProgress) print() return os.path.exists(os.path.join(destdir, filename)) def run(args, command): root = os.path.join(args.prefix, "craft") if not os.path.isdir(root): root = os.path.join(args.prefix, f"craft-{args.branch}") script = os.path.join(root, "bin", "craft.py") command = [sys.executable, script] + command commandStr = " ".join(command) print(f"Execute: {commandStr}") if not args.dry_run: if not subprocess.run(command).returncode == 0: exit(1) def getArchitecture(): if CraftBootstrap.isWin(): return CraftBootstrap.promptForChoice("Select architecture", [("x86", "32"), ("x64", "64")], "x64") else: return 64 if sys.maxsize > 2**32 else 32 def getABI(): if CraftBootstrap.isWin(): platform = "windows" abi, compiler = CraftBootstrap.promptForChoice("Select compiler", [("Mingw-w64", ("mingw", "gcc")), ("Microsoft Visual Studio 2015", ("msvc2015", "cl")), ("Microsoft Visual Studio 2017", ("msvc2017", "cl")), - ("Microsoft Visual Studio 2019", ("msvc2019", "cl"))], - "Microsoft Visual Studio 2017") + # ("Microsoft Visual Studio 2019", ("msvc2019", "cl")) + ], "Microsoft Visual Studio 2017") abi += f"_{getArchitecture()}" elif CraftBootstrap.isUnix(): if CraftBootstrap.isMac(): platform = "macos" compiler = "clang" else: if CraftBootstrap.isLinux(): platform = "linux" elif CraftBootstrap.isFreeBSD(): platform = "freebsd" compiler = CraftBootstrap.promptForChoice("Select compiler", ["gcc", "clang"]) abi = getArchitecture() return f"{platform}-{abi}-{compiler}" def setUp(args): if not args.dry_run and not os.path.exists(args.prefix): os.makedirs(args.prefix) for d in os.listdir(args.prefix): if d != "downloads":#generated by the windows script print("Error: you are trying to install Craft into an non empty directory") exit(1) print("Welcome to the Craft setup wizard!") abi = getABI() installShortCut = False if CraftBootstrap.isWin(): installShortCut = CraftBootstrap.promptForChoice("Do you want to install a StartMenu entry", [("Yes", True), ("No", False)], default="Yes") if not args.dry_run: if args.localDev: shutil.copytree(args.localDev, os.path.join(args.prefix, f"craft-{args.branch}"), ignore=shutil.ignore_patterns(".git")) print("Getting code from local {}".format(args.localDev)) else: CraftBootstrap.downloadFile(f"https://github.com/KDE/craft/archive/{args.branch}.zip", os.path.join(args.prefix, "download"), f"craft-{args.branch}.zip") shutil.unpack_archive(os.path.join(args.prefix, "download", f"craft-{args.branch}.zip"), args.prefix) boot = CraftBootstrap(args.prefix, args.branch, args.dry_run) boot.setSettignsValue("Paths", "Python", os.path.dirname(sys.executable)) boot.setSettignsValue("General", "ABI", abi) py = shutil.which("py") if py: py2 = subprocess.getoutput(f"""{py} -2 -c "import sys; print(sys.executable)" """) if os.path.isfile(py2): boot.setSettignsValue("Paths", "Python27", os.path.dirname(py2)) if CraftBootstrap.isWin(): boot.setSettignsValue("Compile", "MakeProgram", "mingw32-make" if "mingw" in abi else "jom") else: boot.setSettignsValue("Compile", "MakeProgram", "make") boot.writeSettings() cmd = [] if args.verbose: cmd.append("-vvv") cmd += ["craft"] run(args, cmd) if not args.dry_run: shutil.rmtree(os.path.join(args.prefix, f"craft-{args.branch}")) if installShortCut: run(args, ["craft-startmenu-entry"]) # install toast notifications run(args, ["dev-utils/snoretoast"]) print("Setup complete") print() print("Please run the following command to get started:") path = os.path.join(args.prefix, "craft", "craftenv") if CraftBootstrap.isWin(): print(f" {path}.ps1") else: print(f" source {path}.sh") if __name__ == "__main__": parser = argparse.ArgumentParser(prog="CraftSetupHelper") parser.add_argument("--root", action="store", help="Deprecated: use prefix instead.") parser.add_argument("--prefix", action="store", default=os.getcwd(), help="The installation directory.") parser.add_argument("--branch", action="store", default="master", help="The branch to install") parser.add_argument("--verbose", action="store_true", help="The verbosity.") parser.add_argument("--dry-run", action="store", help="Configure the passed CraftSettings.ini and exit.") parser.add_argument("--version", action="version", version="%(prog)s master") parser.add_argument("--localDev", action="store", help="Path to a local directory to use instead of fetching from github") args = parser.parse_args() if args.root: args.prefix = args.root setUp(args)