Changeset View
Changeset View
Standalone View
Standalone View
bin/CraftSetupHelper.py
1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- | ||
---|---|---|---|---|---|
2 | # Helper script for substitution of paths, independent of cmd or powershell | 2 | # Helper script for substitution of paths, independent of cmd or powershell | ||
3 | # copyright: | 3 | # copyright: | ||
4 | # Hannah von Reth <vonreth [AT] kde [DOT] org> | 4 | # Hannah von Reth <vonreth [AT] kde [DOT] org> | ||
5 | 5 | | |||
6 | import subprocess | 6 | import subprocess | ||
7 | import argparse | 7 | import argparse | ||
8 | import collections | 8 | import collections | ||
9 | 9 | | |||
10 | import shutil | 10 | import shutil | ||
11 | 11 | | |||
12 | from CraftConfig import * | 12 | from CraftConfig import * | ||
13 | from CraftOS.osutils import OsUtils | 13 | from CraftOS.osutils import OsUtils | ||
14 | import compiler | 14 | from compiler import craftCompiler | ||
15 | 15 | | |||
16 | 16 | | |||
17 | # The minimum python version for craft please edit here | 17 | # The minimum python version for craft please edit here | ||
18 | # if you add code that changes this requirement | 18 | # if you add code that changes this requirement | ||
19 | MIN_PY_VERSION = (3, 6, 0) | 19 | MIN_PY_VERSION = (3, 6, 0) | ||
20 | 20 | | |||
21 | if sys.version_info[ 0:3 ] < MIN_PY_VERSION: | 21 | if sys.version_info[ 0:3 ] < MIN_PY_VERSION: | ||
22 | print( "Error: Python too old!", file= sys.stderr ) | 22 | print( "Error: Python too old!", file= sys.stderr ) | ||
Show All 31 Lines | 52 | elif args.setup: | |||
54 | self.printEnv() | 54 | self.printEnv() | ||
55 | self.printBanner( ) | 55 | self.printBanner( ) | ||
56 | 56 | | |||
57 | 57 | | |||
58 | def checkForEvilApplication(self): | 58 | def checkForEvilApplication(self): | ||
59 | blackList = [] | 59 | blackList = [] | ||
60 | if OsUtils.isWin(): | 60 | if OsUtils.isWin(): | ||
61 | blackList += ["sh"] | 61 | blackList += ["sh"] | ||
62 | if compiler.isMSVC(): | 62 | if craftCompiler.isMSVC(): | ||
63 | blackList += ["gcc", "g++"] | 63 | blackList += ["gcc", "g++"] | ||
64 | for app in blackList: | 64 | for app in blackList: | ||
65 | location = shutil.which(app) | 65 | location = shutil.which(app) | ||
66 | if location: | 66 | if location: | ||
67 | location = os.path.dirname(location) | 67 | location = os.path.dirname(location) | ||
68 | if not craftSettings.getboolean("ContinuousIntegration", "Enabled", False): | 68 | if not craftSettings.getboolean("ContinuousIntegration", "Enabled", False): | ||
69 | print(f"Found \"{app}\" in your PATH: \"{location}\"\n" | 69 | print(f"Found \"{app}\" in your PATH: \"{location}\"\n" | ||
70 | f"This application is known to cause problems with your configuration of Craft.\n" | 70 | f"This application is known to cause problems with your configuration of Craft.\n" | ||
Show All 28 Lines | 97 | def printBanner( self ): | |||
99 | if craftSettings.getboolean("ContinuousIntegration", "Enabled", False): | 99 | if craftSettings.getboolean("ContinuousIntegration", "Enabled", False): | ||
100 | stream = sys.stdout | 100 | stream = sys.stdout | ||
101 | def printRow(name, value): | 101 | def printRow(name, value): | ||
102 | print(f"{name:20}: {value}", file=stream) | 102 | print(f"{name:20}: {value}", file=stream) | ||
103 | if CraftStandardDirs.isShortPathEnabled(): | 103 | if CraftStandardDirs.isShortPathEnabled(): | ||
104 | with TemporaryUseShortpath(False): | 104 | with TemporaryUseShortpath(False): | ||
105 | printRow("Craft Root", CraftStandardDirs.craftRoot()) | 105 | printRow("Craft Root", CraftStandardDirs.craftRoot()) | ||
106 | printRow("Craft", CraftStandardDirs.craftRoot( )) | 106 | printRow("Craft", CraftStandardDirs.craftRoot( )) | ||
107 | printRow("Compiler", compiler.getCompilerName( )) | 107 | printRow("ABI", craftCompiler) | ||
108 | printRow("Svn directory", CraftStandardDirs.svnDir( )) | 108 | printRow("Svn directory", CraftStandardDirs.svnDir( )) | ||
109 | printRow("Git directory", CraftStandardDirs.gitDir( )) | 109 | printRow("Git directory", CraftStandardDirs.gitDir( )) | ||
110 | printRow("Download directory", CraftStandardDirs.downloadDir( )) | 110 | printRow("Download directory", CraftStandardDirs.downloadDir( )) | ||
111 | if "CraftDeprecatedEntryScript" in os.environ: | 111 | if "CraftDeprecatedEntryScript" in os.environ: | ||
112 | oldScript = os.environ["CraftDeprecatedEntryScript"] | 112 | oldScript = os.environ["CraftDeprecatedEntryScript"] | ||
113 | ext = ".ps1" if OsUtils.isWin() else ".sh" | 113 | ext = ".ps1" if OsUtils.isWin() else ".sh" | ||
114 | print(f"You used the deprecated script {oldScript}\n" | 114 | print(f"You used the deprecated script {oldScript}\n" | ||
115 | f"Please use craftenv{ext} instead", file=sys.stderr) | 115 | f"Please use craftenv{ext} instead", file=sys.stderr) | ||
Show All 11 Lines | 121 | def prependPath( self, key, var ): | |||
127 | os.environ[ key ] = os.path.pathsep.join( var ) | 127 | os.environ[ key ] = os.path.pathsep.join( var ) | ||
128 | 128 | | |||
129 | def stringToEnv( self, string ): | 129 | def stringToEnv( self, string ): | ||
130 | for line in string.split( "\n" ): | 130 | for line in string.split( "\n" ): | ||
131 | key, value = line.strip( ).split( "=", 1 ) | 131 | key, value = line.strip( ).split( "=", 1 ) | ||
132 | os.environ[ key ] = value | 132 | os.environ[ key ] = value | ||
133 | 133 | | |||
134 | def getEnv( self ): | 134 | def getEnv( self ): | ||
135 | if compiler.isMSVC( ): | 135 | if craftCompiler.isMSVC(): | ||
136 | architectures = { "x86": "x86", "x64": "amd64", "x64_cross": "x86_amd64" } | 136 | architectures = { "x86": "x86", "x64": "amd64", "x64_cross": "x86_amd64" } | ||
137 | version = compiler.internalVerison() | 137 | version = craftCompiler.internalVerison() | ||
138 | vswhere = os.path.join(CraftStandardDirs.craftBin(), "3rdparty", "vswhere", "vswhere.exe") | 138 | vswhere = os.path.join(CraftStandardDirs.craftBin(), "3rdparty", "vswhere", "vswhere.exe") | ||
139 | path = subprocess.getoutput(f"\"{vswhere}\"" | 139 | path = subprocess.getoutput(f"\"{vswhere}\"" | ||
140 | f" -version \"[{version},{version+1})\" -property installationPath -legacy -nologo -latest") | 140 | f" -version \"[{version},{version+1})\" -property installationPath -legacy -nologo -latest") | ||
141 | arg = architectures[ compiler.architecture() ] + ("_cross" if not compiler.isNative() else "") | 141 | arg = architectures[ craftCompiler.architecture] + ("_cross" if not craftCompiler.isNative() else "") | ||
142 | path = os.path.join(path, "VC") | 142 | path = os.path.join(path, "VC") | ||
143 | if version >= 15: | 143 | if version >= 15: | ||
144 | path = os.path.join(path, "Auxiliary","Build") | 144 | path = os.path.join(path, "Auxiliary","Build") | ||
145 | path = os.path.join(path, "vcvarsall.bat") | 145 | path = os.path.join(path, "vcvarsall.bat") | ||
146 | status, result = subprocess.getstatusoutput(f"\"{path}\" {arg} > NUL && set") | 146 | status, result = subprocess.getstatusoutput(f"\"{path}\" {arg} > NUL && set") | ||
147 | if status != 0: | 147 | if status != 0: | ||
148 | print( "Failed to setup msvc compiler", file = sys.stderr ) | 148 | print( "Failed to setup msvc compiler", file = sys.stderr ) | ||
149 | exit(1) | 149 | exit(1) | ||
150 | return self.stringToEnv( result ) | 150 | return self.stringToEnv( result ) | ||
151 | 151 | | |||
152 | elif compiler.isIntel( ): | 152 | elif craftCompiler.isIntel(): | ||
153 | architectures = { "x86": "ia32", "x64": "intel64" } | 153 | architectures = { "x86": "ia32", "x64": "intel64" } | ||
154 | programFiles = os.getenv( "ProgramFiles(x86)" ) or os.getenv( "ProgramFiles" ) | 154 | programFiles = os.getenv( "ProgramFiles(x86)" ) or os.getenv( "ProgramFiles" ) | ||
155 | status, result = subprocess.getstatusoutput( | 155 | status, result = subprocess.getstatusoutput( | ||
156 | "\"%s\\Intel\\Composer XE\\bin\\compilervars.bat\" %s > NUL && set" % ( | 156 | "\"%s\\Intel\\Composer XE\\bin\\compilervars.bat\" %s > NUL && set" % ( | ||
157 | programFiles, architectures[ compiler.architecture( ) ]) ) | 157 | programFiles, architectures[ craftCompiler.architecture]) ) | ||
158 | if status != 0: | 158 | if status != 0: | ||
159 | print( "Failed to setup intel compiler", file = sys.stderr ) | 159 | print( "Failed to setup intel compiler", file = sys.stderr ) | ||
160 | exit(1) | 160 | exit(1) | ||
161 | return self.stringToEnv( result ) | 161 | return self.stringToEnv( result ) | ||
162 | 162 | | |||
163 | 163 | | |||
164 | def setXDG(self): | 164 | def setXDG(self): | ||
165 | self.prependPath( "XDG_DATA_DIRS", [os.path.join( CraftStandardDirs.craftRoot( ), "share" )]) | 165 | self.prependPath( "XDG_DATA_DIRS", [os.path.join( CraftStandardDirs.craftRoot( ), "share" )]) | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 212 | if OsUtils.isUnix(): | |||
213 | self.prependPath("LD_LIBRARY_PATH", [ os.path.join(CraftStandardDirs.craftRoot(), "lib"), | 213 | self.prependPath("LD_LIBRARY_PATH", [ os.path.join(CraftStandardDirs.craftRoot(), "lib"), | ||
214 | os.path.join(CraftStandardDirs.craftRoot(), "lib", "x86_64-linux-gnu") ]) | 214 | os.path.join(CraftStandardDirs.craftRoot(), "lib", "x86_64-linux-gnu") ]) | ||
215 | 215 | | |||
216 | self.setXDG() | 216 | self.setXDG() | ||
217 | 217 | | |||
218 | if craftSettings.getboolean("QtSDK", "Enabled", "false"): | 218 | if craftSettings.getboolean("QtSDK", "Enabled", "false"): | ||
219 | self.prependPath( "PATH", os.path.join( craftSettings.get("QtSDK", "Path") , craftSettings.get("QtSDK", "Version"), craftSettings.get("QtSDK", "Compiler"), "bin")) | 219 | self.prependPath( "PATH", os.path.join( craftSettings.get("QtSDK", "Path") , craftSettings.get("QtSDK", "Version"), craftSettings.get("QtSDK", "Compiler"), "bin")) | ||
220 | 220 | | |||
221 | if compiler.isMinGW( ): | 221 | if craftCompiler.isMinGW(): | ||
222 | if not craftSettings.getboolean("QtSDK", "Enabled", "false"): | 222 | if not craftSettings.getboolean("QtSDK", "Enabled", "false"): | ||
223 | if compiler.isX86( ): | 223 | if craftCompiler.isX86(): | ||
224 | self.prependPath( "PATH", os.path.join( CraftStandardDirs.craftRoot( ), "mingw", "bin" ) ) | 224 | self.prependPath( "PATH", os.path.join( CraftStandardDirs.craftRoot( ), "mingw", "bin" ) ) | ||
225 | else: | 225 | else: | ||
226 | self.prependPath( "PATH", os.path.join( CraftStandardDirs.craftRoot( ), "mingw64", "bin" ) ) | 226 | self.prependPath( "PATH", os.path.join( CraftStandardDirs.craftRoot( ), "mingw64", "bin" ) ) | ||
227 | else: | 227 | else: | ||
228 | compilerName = craftSettings.get("QtSDK", "Compiler") | 228 | compilerName = craftSettings.get("QtSDK", "Compiler") | ||
229 | compilerMap = {"mingw53_32":"mingw530_32"} | 229 | compilerMap = {"mingw53_32":"mingw530_32"} | ||
230 | self.prependPath( "PATH", os.path.join( craftSettings.get("QtSDK", "Path") ,"Tools", compilerMap.get(compilerName, compilerName), "bin" )) | 230 | self.prependPath( "PATH", os.path.join( craftSettings.get("QtSDK", "Path") ,"Tools", compilerMap.get(compilerName, compilerName), "bin" )) | ||
231 | 231 | | |||
Show All 22 Lines |