Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit 5d48d44

Browse files
author
Pascal Thomet
committed
install_clcache_msbuild.py : more robust cl.exe detection
(+ some linting)
1 parent 9001bb0 commit 5d48d44

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

install_for_msbuild/install_clcache_msbuild.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
import sys
33
import argparse
4+
import winshell
45
import env_utils
56
import locate_cl_exe
6-
import winshell
77

88

99
THIS_DIR = env_utils.fileDirNameAbsolute(__file__)
@@ -95,7 +95,7 @@ def showStatus():
9595
print("clcache is *ENABLED* in " + MSBUILD_USER_SETTINGS_DIR)
9696
else:
9797
print("clcache is *NOT ENABLED* in " + MSBUILD_USER_SETTINGS_DIR)
98-
98+
9999
cl = env_utils.readEnvVariableFromRegistry("CLCACHE_CL")
100100
print("CLCACHE_CL (real compiler) is :" + cl)
101101
print("call clcache -s for statistics")
@@ -150,10 +150,10 @@ def selectCl():
150150
def fullClcacheSetup():
151151
if not installClcache():
152152
return False
153-
if not copyMsvcPrefClcache():
154-
return False
155153
if not selectCl():
156154
return False
155+
if not copyMsvcPrefClcache():
156+
return False
157157
if not showClCacheUsage():
158158
return False
159159
return True
@@ -244,11 +244,11 @@ def main():
244244
epilog=epilog,
245245
formatter_class=argparse.RawDescriptionHelpFormatter
246246
)
247-
choices = [ "status", "install",
248-
"enable", "disable",
249-
'enable_server', "disable_server"
250-
"enable_logs", "disable_logs",
251-
"show_cl_list", "select_cl"]
247+
choices = ["status", "install",
248+
"enable", "disable",
249+
"enable_server", "disable_server"
250+
"enable_logs", "disable_logs",
251+
"show_cl_list", "select_cl"]
252252
parser.add_argument("action", choices=choices, help="action")
253253
parser.add_argument("--cachedir", help="clcache directory")
254254
parser.add_argument("--cache_size", help="clcache size in Go", type=int, default=0)

install_for_msbuild/locate_cl_exe.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def implFindMsvcUpTo2015() -> typing.List[MsvcInstall]:
4545
valueName = "InstallDir"
4646
key = keyTemplate.replace("__VERSION__", version)
4747
installDir = env_utils.readRegistryValueLocalMachine(key, valueName)
48-
if installDir is not None:
48+
if installDir is not None and os.path.isdir(installDir):
4949
result.append(MsvcInstall(version, installDir))
5050
return result
5151

@@ -67,10 +67,12 @@ def findMsvc() -> typing.List[MsvcInstall]:
6767
def implfindClExesForOldMsvc(msvcInstall: MsvcInstall) -> typing.List[ClInfo]:
6868
result = []
6969
mainClPath = env_utils.dirNameAbsolute(msvcInstall.installDir + "\\..\\..\\vc\\bin")
70+
if not os.path.isdir(mainClPath):
71+
return []
7072
subDirs = env_utils.listSubdirs(mainClPath, appendFolder=False) + ["."]
7173
def hasClExe(subdir):
7274
return os.path.isfile(mainClPath + "\\" + subdir + "\\cl.exe")
73-
dirsWithCl = [ dir for dir in subDirs if hasClExe(dir)]
75+
dirsWithCl = [dir for dir in subDirs if hasClExe(dir)]
7476
# dirWithCl is something like
7577
# ['amd64', 'amd64_arm', 'amd64_x86', 'x86_amd64', 'x86_arm', '.']
7678
# in this ist : "." = x86_x86 and amd64 = amd64_amd64
@@ -86,14 +88,14 @@ def hasClExe(subdir):
8688
tokens = dirWithCl.split("_")
8789
hostArch = tokens[0]
8890
targetArch = tokens[1]
89-
result.append( ClInfo(msvcInstall, fullDir, hostArch, targetArch ) )
91+
result.append(ClInfo(msvcInstall, fullDir, hostArch, targetArch))
9092
return result
9193

9294

9395
def implfindClExesForMsvc2017(msvcInstall: MsvcInstall) -> typing.List[ClInfo]:
9496
result = []
9597
topDir = msvcInstall.installDir + "\\VC\\Tools\\MSVC"
96-
for dirpath, dirnames, filenames in os.walk(topDir):
98+
for dirpath, _, filenames in os.walk(topDir):
9799
for file in filenames:
98100
if file == "cl.exe":
99101
# dirpath looks like
@@ -120,14 +122,14 @@ def findClExesList() -> typing.List[ClInfo]:
120122

121123
def printClList(clInfoList: typing.List[ClInfo]) -> str:
122124
def clInfoToData(clInfo: ClInfo):
123-
return [clInfo.msvcInstall.version, clInfo.targetArch,
125+
return [clInfo.msvcInstall.version, clInfo.targetArch,
124126
clInfo.hostArch, env_utils.shortDirectoryName(clInfo.installDir)]
125127
headers = ["#", "version", "targetArch", "hostArch", "folder (shortened)"]
126128
data = [clInfoToData(clInfo) for clInfo in clInfoList]
127129
rowFormat = "{:>4}{:>18}{:>11}{:>11}{:>80}"
128130

129131
print(rowFormat.format(*headers))
130-
id = 1
132+
rowId = 1
131133
for version in data:
132-
print(rowFormat.format(id, *version))
133-
id = id + 1
134+
print(rowFormat.format(rowId, *version))
135+
rowId = rowId + 1

0 commit comments

Comments
 (0)