Skip to content

Commit 966bbcc

Browse files
committed
[build-script] Simpified code
1 parent b3dc7b7 commit 966bbcc

File tree

2 files changed

+18
-58
lines changed

2 files changed

+18
-58
lines changed

utils/build-script

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,7 @@ details of the setups of other systems or automated environments.""")
13081308
build_script_impl_args += [
13091309
"--foundation-build-type", args.foundation_build_variant
13101310
]
1311-
if (args.cmake_generator == 'Ninja' and
1312-
toolchain.ninja is None):
1311+
if args.cmake_generator == 'Ninja' and toolchain.ninja is None:
13131312
build_script_impl_args += ["--build-ninja"]
13141313

13151314
if args.skip_build_linux:

utils/swift_build_support/swift_build_support/toolchain.py

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -32,62 +32,25 @@ class Toolchain(object):
3232
"""Represents native host toolchain
3333
"""
3434

35-
def find_tool(self, tool, versioned=False):
35+
def find_tool(self, *names):
3636
raise NotImplementedError('Subclasses must implement this method')
3737

38-
# NOTE: We are declaring attribute for each tools because we need
39-
# them be assignable. For example, `toolchain.cc` can be
40-
# overriden by user supplied argument: --host-cc=/path/to/clang
41-
# And we don't want to override __getattr__ because that would need
42-
# heuristic command name inference. e.g. llvm_cov -> llvm-cov
43-
44-
@cache_util.reify
45-
def cc(self):
46-
'''Return Clang host tool path if found. `None` otherwise.
47-
'''
48-
return self.find_tool('clang')
49-
50-
@cache_util.reify
51-
def cxx(self):
52-
'''Return Clang host tool path if found. `None` otherwise.
53-
'''
54-
return self.find_tool('clang++')
55-
56-
@cache_util.reify
57-
def cmake(self):
58-
'''Return CMake host tool path if found. `None` otherwise.
59-
'''
60-
return self.find_tool('cmake')
61-
62-
@cache_util.reify
63-
def ninja(self):
64-
'''Return Ninja host tool path if found. `None` otherwise.
65-
'''
66-
return self.find_tool('ninja', 'ninja-build')
67-
68-
@cache_util.reify
69-
def distcc(self):
70-
'''Return distcc host tool path if found. `None` otherwise.
71-
'''
72-
return self.find_tool('distcc')
73-
74-
@cache_util.reify
75-
def distcc_pump(self):
76-
'''Return distcc-pump host tool path if found. `None` otherwise.
77-
'''
78-
return self.find_tool('distcc-pump', 'pump')
79-
80-
@cache_util.reify
81-
def llvm_profdata(self):
82-
'''Return llvm-profdata host tool path if found. `None` otherwise.
83-
'''
84-
return self.find_tool('llvm-profdata')
8538

86-
@cache_util.reify
87-
def llvm_cov(self):
88-
'''Return llvm-cov host tool path if found. `None` otherwise.
89-
'''
90-
return self.find_tool('llvm-cov')
39+
# Declare properties for each tools.
40+
# These properties are loaded lazily and assignable.
41+
def _register(name, *tool):
42+
def _getter(self):
43+
return self.find_tool(*tool)
44+
_getter.__name__ = name
45+
setattr(Toolchain, name, cache_util.reify(_getter))
46+
_register("cc", "clang")
47+
_register("cxx", "clang++")
48+
_register("ninja", "ninja", "ninja-build")
49+
_register("cmake", "cmake")
50+
_register("distcc", "distcc")
51+
_register("distcc_pump", "distcc-pump", "pump")
52+
_register("llvm_profdata", "llvm-profdata")
53+
_register("llvm_cov", "llvm-cov")
9154

9255

9356
class Darwin(Toolchain):
@@ -198,9 +161,7 @@ def _release_date():
198161

199162

200163
class Cygwin(Linux):
201-
# FIXME: Currently, Cygwin is considered as the same as Linux.
202-
# I'm not sure it's correct or not.
203-
# Please some Cygwin user could confirm this or fix it.
164+
# Currently, Cygwin is considered as the same as Linux.
204165
pass
205166

206167

0 commit comments

Comments
 (0)