@@ -27,10 +27,11 @@ from helpers import note, error, symlink_force, mkdir_p, call, call_output
2727
2828g_macos_deployment_target = '10.15'
2929
30+ g_shared_lib_prefix = "lib"
3031if platform .system () == 'Darwin' :
31- g_shared_lib_ext = ".dylib"
32+ g_shared_lib_suffix = ".dylib"
3233else :
33- g_shared_lib_ext = ".so"
34+ g_shared_lib_suffix = ".so"
3435
3536def main ():
3637 parser = argparse .ArgumentParser (description = """
@@ -366,7 +367,7 @@ def install(args):
366367 "PackageGraph" , "SPMBuildCore" , "Build" ,
367368 "Xcodeproj" , "Workspace"
368369 ]
369- install_libswiftpm_dylib (args , "SwiftPM" , args .libswiftpm_install_dir , libswiftpm_modules )
370+ install_dylib (args , "SwiftPM" , args .libswiftpm_install_dir , libswiftpm_modules )
370371
371372 # Install libSwiftPMDataModel if an install directory was provided.
372373 if args .libswiftpmdatamodel_install_dir :
@@ -377,10 +378,11 @@ def install(args):
377378 "PackageGraph" , "SPMBuildCore" ,
378379 "Xcodeproj" , "Workspace"
379380 ]
380- install_libswiftpm_dylib (args , "SwiftPMDataModel" , args .libswiftpmdatamodel_install_dir , libswiftpmdatamodel_modules )
381+ install_dylib (args , "SwiftPMDataModel" , args .libswiftpmdatamodel_install_dir , libswiftpmdatamodel_modules )
381382
383+ # Installs the SwiftPM tools and runtime support libraries.
382384def install_swiftpm (prefix , args ):
383- # Install swiftpm binary and create tool symlinks.
385+ # Install the swift-package tool and create symlinks to it .
384386 cli_tool_dest = os .path .join (prefix , "bin" )
385387 install_binary (args , "swift-package" , cli_tool_dest )
386388 for tool in ["swift-build" , "swift-test" , "swift-run" , "swift-package-collection" ]:
@@ -389,74 +391,50 @@ def install_swiftpm(prefix, args):
389391 note ("Creating tool symlink from %s to %s" % (src , dest ))
390392 symlink_force (src , dest )
391393
394+ # On Darwin, also install the swiftpm-xctest-helper tool.
392395 if platform .system () == 'Darwin' :
393396 dest = os .path .join (prefix , "libexec" , "swift" , "pm" )
394397 install_binary (args , "swiftpm-xctest-helper" , dest )
395398
396- # Install PackageDescription runtime libraries .
397- runtime_lib_dest = os .path .join (prefix , "lib" , "swift" , "pm" )
398- runtime_lib_src = os . path . join (args . bootstrap_dir , "pm" )
399+ # Install the PackageDescription library and associated modules .
400+ dest = os .path .join (prefix , "lib" , "swift" , "pm" , "ManifestAPI " )
401+ install_dylib (args , "PackageDescription" , dest , [ "PackageDescription" ] )
399402
400- files_to_install = ["libPackageDescription" + g_shared_lib_ext ]
401- if platform .system () == 'Darwin' :
402- files_to_install .append ("PackageDescription.swiftinterface" )
403- else :
404- files_to_install .append ("PackageDescription.swiftmodule" )
405- files_to_install .append ("PackageDescription.swiftdoc" )
406-
407- for file in files_to_install :
408- src = os .path .join (runtime_lib_src , "ManifestAPI" , file )
409- dest = os .path .join (runtime_lib_dest , "ManifestAPI" , file )
410- mkdir_p (os .path .dirname (dest ))
411-
412- note ("Installing %s to %s" % (src , dest ))
413-
414- file_util .copy_file (src , dest , update = 1 )
415-
416- files_to_install = ["libPackagePlugin" + g_shared_lib_ext ]
417- if platform .system () == 'Darwin' :
418- files_to_install .append ("PackagePlugin.swiftinterface" )
419- else :
420- files_to_install .append ("PackagePlugin.swiftmodule" )
421- files_to_install .append ("PackagePlugin.swiftdoc" )
422-
423- for file in files_to_install :
424- src = os .path .join (runtime_lib_src , "PluginAPI" , file )
425- dest = os .path .join (runtime_lib_dest , "PluginAPI" , file )
426- mkdir_p (os .path .dirname (dest ))
427-
428- note ("Installing %s to %s" % (src , dest ))
429-
430- file_util .copy_file (src , dest , update = 1 )
403+ # Install the PackagePlugin library and associated modules.
404+ dest = os .path .join (prefix , "lib" , "swift" , "pm" , "PluginAPI" )
405+ install_dylib (args , "PackagePlugin" , dest , ["PackagePlugin" ])
431406
432407
433- def install_libswiftpm_dylib (args , library_name , install_dir , module_names ):
434- # FIXME: Don't hardcode the prefix and suffix.
435- install_binary (args , "lib" + library_name + ".dylib" , install_dir )
408+ # Helper function that installs a dynamic library and a set of modules to a particular directory.
409+ def install_dylib (args , library_name , install_dir , module_names ):
410+ # Install the dynamic library itself.
411+ install_binary (args , g_shared_lib_prefix + library_name + g_shared_lib_suffix , install_dir )
436412
437- # Install the swiftmodule and swiftdoc files.
413+ # Install the swiftmodule/swiftinterface and swiftdoc files for all the modules .
438414 for module in module_names :
439- install_binary (args , module + ".swiftmodule" , install_dir )
440- if not args .cross_compile_hosts : # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
415+ # If we're cross-compiling, we expect the .swiftmodule to be a directory that contains everything.
416+ if args .cross_compile_hosts :
417+ install_binary (args , module + ".swiftmodule" , install_dir )
418+ else :
419+ # Otherwise we have either a .swiftinterface or a .swiftmodule, plus a .swiftdoc.
420+ if os .path .exists (os .path .join (args .bin_dir , module + ".swiftinterface" )):
421+ install_binary (args , module + ".swiftinterface" , install_dir )
422+ else :
423+ install_binary (args , module + ".swiftmodule" , install_dir )
441424 install_binary (args , module + ".swiftdoc" , install_dir )
442425
443- # Install the C headers.
444- tscclibc_include_dir = os .path .join (args .tsc_source_dir , "Sources/TSCclibc/include" )
445- tscclibc_include_dir_dest = os .path .join (install_dir , "TSCclibc" )
446- dir_util .copy_tree (tscclibc_include_dir , tscclibc_include_dir_dest )
447-
448426
427+ # Helper function that installs a single built artifact to a particular directory. The source may be either a file or a directory.
449428def install_binary (args , binary , dest_dir ):
450429 src = os .path .join (args .bin_dir , binary )
451430 dest = os .path .join (dest_dir , binary )
452431
453432 note ("Installing %s to %s" % (src , dest ))
454-
455433 mkdir_p (os .path .dirname (dest ))
456- if os .path .isdir (src ) and args . cross_compile_hosts : # Handle swiftmodule directories if compiling for multiple arches.
457- dir_util .copy_tree (src , dest )
434+ if os .path .isdir (src ):
435+ dir_util .copy_tree (src , dest , update = 1 , verbose = 1 )
458436 else :
459- file_util .copy_file (src , dest , update = 1 )
437+ file_util .copy_file (src , dest , update = 1 , verbose = 1 )
460438
461439# -----------------------------------------------------------
462440# Build functions
@@ -651,6 +629,7 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
651629 if integrated_swift_driver :
652630 swiftpm_args .append ("--use-integrated-swift-driver" )
653631
632+ # Build SwiftPM, including libSwiftPM, all the command line tools, and the current variant of PackageDescription.
654633 call_swiftpm (args , swiftpm_args )
655634
656635 # Setup symlinks that'll allow using swiftpm from the build directory.
0 commit comments