53
53
class BinaryNotFound (BaseException ):
54
54
55
55
def __init__ (self , * , tool : str , path : pathlib .Path ):
56
- super ().__init__ ("Unable to find {tool} source directory at {path}" )
56
+ super ().__init__ (f "Unable to find { tool } source directory at { path } " )
57
57
58
+ def log_entry_exit (func ):
59
+ def wrapper (* args , ** kwargs ):
60
+ logging .debug ("Starting call to %s ..." , func .__name__ )
61
+ try :
62
+ return func (* args , ** kwargs )
63
+ finally :
64
+ logging .debug ("Done call to %s ..." , func .__name__ )
58
65
66
+ return wrapper
67
+
68
+ @log_entry_exit
59
69
def main ():
60
70
parser = argparse .ArgumentParser (description = """
61
71
This script will build a bootstrapped copy of the Swift Package Manager, and optionally perform extra
@@ -95,6 +105,7 @@ def main():
95
105
# Argument parsing
96
106
# -----------------------------------------------------------
97
107
108
+ @log_entry_exit
98
109
def add_global_args (parser ):
99
110
"""Configures the parser with the arguments necessary for all actions."""
100
111
parser .add_argument (
@@ -111,6 +122,7 @@ def add_global_args(parser):
111
122
action = "store_true" ,
112
123
help = "whether to always reconfigure cmake" )
113
124
125
+ @log_entry_exit
114
126
def add_build_args (parser ):
115
127
"""Configures the parser with the arguments necessary for build-related actions."""
116
128
add_global_args (parser )
@@ -187,6 +199,7 @@ def add_build_args(parser):
187
199
"--cross-compile-config" ,
188
200
help = "Swift flags to cross-compile SwiftPM with itself" )
189
201
202
+ @log_entry_exit
190
203
def add_test_args (parser ):
191
204
"""Configures the parser with the arguments necessary for the test action."""
192
205
add_build_args (parser )
@@ -206,6 +219,7 @@ def add_test_args(parser):
206
219
help = "whether to skip tests with the integrated driver" ,
207
220
default = True )
208
221
222
+ @log_entry_exit
209
223
def parse_global_args (args ):
210
224
"""Parses and cleans arguments necessary for all actions."""
211
225
# Test if 'build_dirs' and 'source_dirs' exist, and initialise them only if not.
@@ -236,6 +250,7 @@ def parse_global_args(args):
236
250
else :
237
251
args .sysroot = None
238
252
253
+ @log_entry_exit
239
254
def parse_build_args (args ):
240
255
"""Parses and cleans arguments necessary for build-related actions."""
241
256
parse_global_args (args )
@@ -250,6 +265,8 @@ def parse_build_args(args):
250
265
args .build_dirs ["llbuild" ] = os .path .abspath (args .llbuild_build_dir )
251
266
252
267
args .swiftc_path = get_swiftc_path (args )
268
+ logging .debug ("Returned value of get_swiftc_path(args): %r" , get_swiftc_path (args ))
269
+ logging .debug ("Settings args.swiftc_path to %r" , args .swiftc_path )
253
270
args .clang_path = get_tool_path (args , "clang" )
254
271
args .clangxx_path = get_tool_path (args , "clang++" )
255
272
if not args .skip_cmake_bootstrap :
@@ -276,10 +293,12 @@ def parse_build_args(args):
276
293
args .bootstrap = not args .skip_cmake_bootstrap or \
277
294
not os .path .exists (os .path .join (os .path .split (args .swiftc_path )[0 ], "swift-build" ))
278
295
296
+ @log_entry_exit
279
297
def parse_test_args (args ):
280
298
"""Parses and cleans arguments necessary for the test action."""
281
299
parse_build_args (args )
282
300
301
+ @log_entry_exit
283
302
def get_swiftc_path (args ):
284
303
"""Returns the path to the Swift compiler."""
285
304
logging .debug ("Getting path to swiftc..." )
@@ -307,11 +326,12 @@ def get_swiftc_path(args):
307
326
308
327
logging .debug ("swiftc_path set to %r" , swiftc_path )
309
328
if os .path .exists (swiftc_path ):
310
- logging .debug ("swiftc_path exists.. returning..." )
329
+ logging .debug ("swiftc_path exists.. returning %r ..." , swiftc_path )
311
330
return swiftc_path
312
331
logging .error ("unable to find swiftc at %s" , swiftc_path )
313
332
raise BinaryNotFound (tool = "swiftc" , path = swiftc_path )
314
333
334
+ @log_entry_exit
315
335
def get_tool_path (args , tool ):
316
336
"""Returns the path to the specified tool."""
317
337
logging .debug ("Searching for %s tool" , tool )
@@ -327,6 +347,7 @@ def get_tool_path(args, tool):
327
347
else :
328
348
return call_output (["which" , tool ], verbose = args .verbose )
329
349
350
+ @log_entry_exit
330
351
def get_build_target (args , cross_compile = False ):
331
352
"""Returns the target-triple of the current machine or for cross-compilation."""
332
353
try :
@@ -379,13 +400,15 @@ def get_unversioned_build_target(args, cross_compile=False):
379
400
# Actions
380
401
# -----------------------------------------------------------
381
402
403
+ @log_entry_exit
382
404
def clean (args ):
383
405
"""Cleans the build artifacts."""
384
406
logging .info ("Cleaning" )
385
407
parse_global_args (args )
386
408
387
409
call (["rm" , "-rf" , args .build_dir ], verbose = args .verbose )
388
410
411
+ @log_entry_exit
389
412
def build (args ):
390
413
"""Builds SwiftPM using a two-step process: first using CMake, then with itself."""
391
414
parse_build_args (args )
@@ -423,6 +446,7 @@ def build(args):
423
446
424
447
build_swiftpm_with_swiftpm (args ,integrated_swift_driver = False )
425
448
449
+ @log_entry_exit
426
450
def test (args ):
427
451
"""Builds SwiftPM, then tests itself."""
428
452
build (args )
@@ -456,6 +480,7 @@ def test(args):
456
480
integratedDriverCmd .append ("BuildTests;FunctionalTests" )
457
481
call_swiftpm (args , integratedDriverCmd )
458
482
483
+ @log_entry_exit
459
484
def install (args ):
460
485
"""Builds SwiftPM, then installs its build products."""
461
486
build (args )
@@ -493,6 +518,7 @@ def install(args):
493
518
install_dylib (args , "SwiftPMDataModel" , args .libswiftpmdatamodel_install_dir , libswiftpmdatamodel_modules )
494
519
495
520
# Installs the SwiftPM tools and runtime support libraries.
521
+ @log_entry_exit
496
522
def install_swiftpm (prefix , args ):
497
523
# Install the swift-package-manager tool and create symlinks to it.
498
524
cli_tool_dest = os .path .join (prefix , "bin" )
@@ -520,6 +546,7 @@ def install_swiftpm(prefix, args):
520
546
521
547
522
548
# Helper function that installs a dynamic library and a set of modules to a particular directory.
549
+ @log_entry_exit
523
550
def install_dylib (args , library_name , install_dir , module_names ):
524
551
# Install the dynamic library itself.
525
552
install_binary (args , g_shared_lib_prefix + library_name + g_shared_lib_suffix , install_dir )
@@ -541,6 +568,7 @@ def install_dylib(args, library_name, install_dir, module_names):
541
568
542
569
543
570
# Helper function that installs a single built artifact to a particular directory. The source may be either a file or a directory.
571
+ @log_entry_exit
544
572
def install_binary (args , binary , destination , destination_is_directory = True , ignored_patterns = [], subpath = None ):
545
573
if subpath :
546
574
basepath = os .path .join (args .bin_dir , subpath )
@@ -549,6 +577,7 @@ def install_binary(args, binary, destination, destination_is_directory=True, ign
549
577
src = os .path .join (basepath , binary )
550
578
install_file (args , src , destination , destination_is_directory = destination_is_directory , ignored_patterns = ignored_patterns )
551
579
580
+ @log_entry_exit
552
581
def install_file (args , src , destination , destination_is_directory = True , ignored_patterns = []):
553
582
if destination_is_directory :
554
583
dest = os .path .join (destination , os .path .basename (src ))
@@ -566,6 +595,7 @@ def install_file(args, src, destination, destination_is_directory=True, ignored_
566
595
# Build functions
567
596
# -----------------------------------------------------------
568
597
598
+ @log_entry_exit
569
599
def build_with_cmake (args , cmake_args , ninja_args , source_path , build_dir , cmake_env = []):
570
600
"""Runs CMake if needed, then builds with Ninja."""
571
601
cache_path = os .path .join (build_dir , "CMakeCache.txt" )
@@ -605,6 +635,7 @@ def build_with_cmake(args, cmake_args, ninja_args, source_path, build_dir, cmake
605
635
606
636
call (ninja_cmd + ninja_args , cwd = build_dir , verbose = args .verbose )
607
637
638
+ @log_entry_exit
608
639
def build_llbuild (args ):
609
640
"""Builds LLBuild using CMake."""
610
641
logging .info ("Building llbuild" )
@@ -637,6 +668,7 @@ def build_llbuild(args):
637
668
args .source_dirs ["llbuild" ] = get_llbuild_source_path (args )
638
669
build_with_cmake (args , flags , [], args .source_dirs ["llbuild" ], args .build_dirs ["llbuild" ], cmake_env = cmake_env )
639
670
671
+ @log_entry_exit
640
672
def build_dependency (args , target_name , common_cmake_flags = [], non_darwin_cmake_flags = []):
641
673
logging .info ("Building dependency %s" , target_name )
642
674
args .build_dirs [target_name ] = os .path .join (args .target_dir , target_name )
@@ -650,19 +682,22 @@ def build_dependency(args, target_name, common_cmake_flags = [], non_darwin_cmak
650
682
651
683
build_with_cmake (args , cmake_flags , [], args .source_dirs [target_name ], args .build_dirs [target_name ])
652
684
685
+ @log_entry_exit
653
686
def add_rpath_for_cmake_build (args , rpath ):
654
687
"Adds the given rpath to the CMake-built swift-bootstrap"
655
688
swift_build = os .path .join (args .bootstrap_dir , "bin/swift-bootstrap" )
656
689
add_rpath_cmd = ["install_name_tool" , "-add_rpath" , rpath , swift_build ]
657
690
logging .info (' ' .join (add_rpath_cmd ))
658
691
subprocess .call (add_rpath_cmd , stderr = subprocess .PIPE , env = os .environ )
659
692
693
+ @log_entry_exit
660
694
def get_swift_backdeploy_library_paths (args ):
661
695
if platform .system () == 'Darwin' :
662
696
return ['/usr/lib/swift' ]
663
697
else :
664
698
return []
665
699
700
+ @log_entry_exit
666
701
def build_swiftpm_with_cmake (args ):
667
702
"""Builds SwiftPM using CMake."""
668
703
logging .info ("Building SwiftPM (with CMake)" )
@@ -702,6 +737,7 @@ def build_swiftpm_with_cmake(args):
702
737
for lib_path in get_swift_backdeploy_library_paths (args ):
703
738
add_rpath_for_cmake_build (args , lib_path )
704
739
740
+ @log_entry_exit
705
741
def build_swiftpm_with_swiftpm (args , integrated_swift_driver ):
706
742
"""Builds SwiftPM using the version of SwiftPM built with CMake."""
707
743
@@ -745,6 +781,7 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
745
781
746
782
symlink_force (os .path .join (args .bootstrap_dir , "pm" ), os .path .join (lib_dir , "pm" ))
747
783
784
+ @log_entry_exit
748
785
def call_swiftpm (args , cmd , cwd = None ):
749
786
"""Calls a SwiftPM binary with the necessary environment variables and flags."""
750
787
logging .info ("function args: %r, cmd: %r, cwd: %r" , args , cmd , cwd )
@@ -773,16 +810,19 @@ def call_swiftpm(args, cmd, cwd=None):
773
810
# Build-related helper functions
774
811
# -----------------------------------------------------------
775
812
813
+ @log_entry_exit
776
814
def get_dispatch_cmake_arg (args ):
777
815
"""Returns the CMake argument to the Dispatch configuration to use for building SwiftPM."""
778
816
dispatch_dir = os .path .join (args .dispatch_build_dir , "cmake/modules" )
779
817
return "-Ddispatch_DIR=" + dispatch_dir
780
818
819
+ @log_entry_exit
781
820
def get_foundation_cmake_arg (args ):
782
821
"""Returns the CMake argument to the Foundation configuration to use for building SwiftPM."""
783
822
foundation_dir = os .path .join (args .foundation_build_dir , "cmake/modules" )
784
823
return "-DFoundation_DIR=" + foundation_dir
785
824
825
+ @log_entry_exit
786
826
def get_llbuild_cmake_arg (args ):
787
827
"""Returns the CMake argument to the LLBuild framework/binary to use for building SwiftPM."""
788
828
if args .llbuild_link_framework :
@@ -791,6 +831,7 @@ def get_llbuild_cmake_arg(args):
791
831
llbuild_dir = os .path .join (args .build_dirs ["llbuild" ], "cmake/modules" )
792
832
return "-DLLBuild_DIR=" + llbuild_dir
793
833
834
+ @log_entry_exit
794
835
def get_llbuild_source_path (args ):
795
836
"""Returns the path to the LLBuild source folder."""
796
837
llbuild_path = os .path .join (args .project_root , ".." , "llbuild" )
@@ -800,6 +841,7 @@ def get_llbuild_source_path(args):
800
841
logging .error ("unable to find llbuild source directory at %s" , llbuild_path )
801
842
raise BinaryNotFound (tool = "llbuild" , path = llbuild_path )
802
843
844
+ @log_entry_exit
803
845
def get_swiftpm_env_cmd (args ):
804
846
"""Returns the environment variable command to run SwiftPM binaries."""
805
847
env_cmd = ["env" ]
@@ -846,6 +888,7 @@ def get_swiftpm_env_cmd(args):
846
888
]
847
889
return env_cmd
848
890
891
+ @log_entry_exit
849
892
def get_swiftpm_flags (args ):
850
893
"""Returns the flags to run SwiftPM binaries."""
851
894
build_flags = [
0 commit comments