Skip to content

Commit 10e0e56

Browse files
committed
Emit debugging and running information hints when building TestFoundation
1 parent 5546e0e commit 10e0e56

File tree

5 files changed

+55
-18
lines changed

5 files changed

+55
-18
lines changed

build.py

+40-7
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
foundation.CFLAGS = '-DDEPLOYMENT_TARGET_MACOSX '
2121
foundation.LDFLAGS = '-licucore -twolevel_namespace -Wl,-alias_list,CoreFoundation/Base.subproj/DarwinSymbolAliases -sectcreate __UNICODE __csbitmaps CoreFoundation/CharacterSets/CFCharacterSetBitmaps.bitmap -sectcreate __UNICODE __properties CoreFoundation/CharacterSets/CFUniCharPropertyDatabase.data -sectcreate __UNICODE __data CoreFoundation/CharacterSets/CFUnicodeData-L.mapping -segprot __UNICODE r r '
2222

23-
foundation.SWIFTCFLAGS = ''
24-
2523
# For now, we do not distinguish between public and private headers (they are all private to Foundation)
2624
# These are really part of CF, which should ultimately be a separate target
2725
foundation.ROOT_HEADERS_FOLDER_PATH = "/usr/lib/swift"
@@ -47,11 +45,21 @@
4745
'-I./'
4846
])
4947

50-
foundation.SWIFTCFLAGS += " ".join([
48+
swift_cflags = [
5149
'-I${BUILD_DIR}/Foundation/usr/lib/swift'
52-
])
50+
]
51+
52+
if "XCTEST_BUILD_DIR" in Configuration.current.variables:
53+
swift_cflags += [
54+
'-I${XCTEST_BUILD_DIR}',
55+
'-L${XCTEST_BUILD_DIR}',
56+
]
57+
foundation.SWIFTCFLAGS = " ".join(swift_cflags)
5358

54-
foundation.LDFLAGS += '-lpthread -ldl -lm -lswiftCore'
59+
foundation.LDFLAGS += '-lpthread -ldl -lm -lswiftCore '
60+
61+
if "XCTEST_BUILD_DIR" in Configuration.current.variables:
62+
foundation.LDFLAGS += '-L${XCTEST_BUILD_DIR}'
5563

5664
headers = CopyHeaders(
5765
module = 'CoreFoundation/Base.subproj/linux.modulemap',
@@ -360,7 +368,7 @@
360368

361369
script.add_product(foundation)
362370

363-
script.add_text("""
371+
extra_script = """
364372
rule InstallFoundation
365373
command = mkdir -p "${DSTROOT}/${PREFIX}/lib/swift/${OS}"; $
366374
cp "${BUILD_DIR}/Foundation/${DYLIB_PREFIX}Foundation${DYLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib/swift/${OS}"; $
@@ -373,6 +381,31 @@
373381
build ${BUILD_DIR}/.install: InstallFoundation ${BUILD_DIR}/Foundation/${DYLIB_PREFIX}Foundation${DYLIB_SUFFIX}
374382
375383
build install: phony | ${BUILD_DIR}/.install
376-
""")
384+
385+
"""
386+
if "XCTEST_BUILD_DIR" in Configuration.current.variables:
387+
extra_script += """
388+
rule RunTestFoundation
389+
command = echo "**** RUNNING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/Foundation/:${XCTEST_BUILD_DIR} ${BUILD_DIR}/TestFoundation/TestFoundation\\n**** DEBUGGING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/Foundation/:${XCTEST_BUILD_DIR} lldb ${BUILD_DIR}/TestFoundation/TestFoundation\\n"
390+
description = Building Tests
391+
392+
build ${BUILD_DIR}/.test: RunTestFoundation | TestFoundation
393+
394+
build test: phony | ${BUILD_DIR}/.test
395+
396+
"""
397+
else:
398+
extra_script += """
399+
rule RunTestFoundation
400+
command = echo "**** RUNNING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/Foundation/ ${BUILD_DIR}/TestFoundation/TestFoundation\\n**** DEBUGGING TESTS ****\\nexecute:\\nLD_LIBRARY_PATH=${BUILD_DIR}/Foundation/ lldb ${BUILD_DIR}/TestFoundation/TestFoundation\\n"
401+
description = Building Tests
402+
403+
build ${BUILD_DIR}/.test: RunTestFoundation | TestFoundation
404+
405+
build test: phony | ${BUILD_DIR}/.test
406+
407+
"""
408+
409+
script.add_text(extra_script)
377410

378411
script.generate()

configure

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ def main():
7373
parser.add_argument('-v', '--verbose', dest='verbose', action="store_true")
7474
args, extras = parser.parse_known_args()
7575

76-
if len(extras) > 0:
77-
mode = extras[0].lower()
78-
if mode == 'debug':
76+
config.build_mode = Configuration.Release # by default build a release mode
77+
78+
for arg in extras:
79+
if arg == 'debug':
7980
config.build_mode = Configuration.Debug
80-
elif mode == 'release':
81+
elif arg == 'release':
8182
config.build_mode = Configuration.Release
82-
if len(extras) > 1 or config.build_mode is None:
83-
pass # fail here
84-
else:
85-
config.build_mode = Configuration.Release
83+
elif arg.startswith('-D'): # accept -DNAME=value as extra parameters to the configuration of the build.ninja
84+
key, val = arg[2:].split("=", 1)
85+
config.variables[key] = val
8686

8787
config.command = [os.path.abspath(__file__)] + sys.argv[1:]
8888

lib/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ class Configuration:
3737
extra_swift_flags = None
3838
extra_ld_flags = None
3939
build_mode = None
40+
variables = {}
4041
def __init__(self):
4142
pass

lib/phases.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ def generate(self):
416416

417417
return """
418418
build """ + appName + """: SwiftExecutable """ + swiftSources + self.generate_dependencies() + """ """ + libDependencyName + """
419-
flags = -I""" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + self.product.ROOT_HEADERS_FOLDER_PATH + " -I" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + " -L" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + """
420-
419+
flags = -I""" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + self.product.ROOT_HEADERS_FOLDER_PATH + " -I" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + " -L" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + " " + TargetConditional.value(self.product.SWIFTCFLAGS) + """
421420
build """ + self.executableName + """: phony | """ + appName + """
422421
"""
423422

lib/script.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def add_text(self, text):
3030
self.extra += text + "\n\n"
3131

3232
def generate_products(self):
33+
variables = ""
34+
for key, val in Configuration.current.variables.iteritems():
35+
variables += key + "=" + val
36+
variables += "\n"
3337
verbose_flags = """
3438
VERBOSE_FLAGS = """
3539
if Configuration.current.verbose:
@@ -148,7 +152,7 @@ def generate_products(self):
148152
AR_FLAGS = rcs
149153
"""
150154

151-
flags = verbose_flags + base_flags + c_flags + swift_flags + cxx_flags + ld_flags + ar_flags
155+
flags = variables + verbose_flags + base_flags + c_flags + swift_flags + cxx_flags + ld_flags + ar_flags
152156

153157
cp_command = """
154158
rule Cp

0 commit comments

Comments
 (0)