@@ -15,6 +15,7 @@ def swiftpm(action, swift_exec, swiftpm_args, env=None):
15
15
subprocess .check_call (cmd , env = env )
16
16
17
17
def swiftpm_bin_path (swift_exec , swiftpm_args , env = None ):
18
+ swiftpm_args = filter (lambda arg : arg != '-v' and arg != '--verbose' , swiftpm_args )
18
19
cmd = [swift_exec , 'build' , '--show-bin-path' ] + swiftpm_args
19
20
print (' ' .join (cmd ))
20
21
return subprocess .check_output (cmd , env = env ).strip ()
@@ -29,18 +30,46 @@ def get_swiftpm_options(args):
29
30
if args .verbose :
30
31
swiftpm_args += ['--verbose' ]
31
32
32
- if platform .system () != 'Darwin' :
33
+ if platform .system () == 'Darwin' :
34
+ swiftpm_args += [
35
+ # Relative library rpath for swift; will only be used when /usr/lib/swift
36
+ # is not available.
37
+ '-Xlinker' , '-rpath' , '-Xlinker' , '@executable_path/../lib/swift/macosx' ,
38
+ ]
39
+ else :
33
40
swiftpm_args += [
34
41
# Dispatch headers
35
42
'-Xcxx' , '-I' , '-Xcxx' ,
36
43
os .path .join (args .toolchain , 'usr' , 'lib' , 'swift' ),
37
44
# For <Block.h>
38
45
'-Xcxx' , '-I' , '-Xcxx' ,
39
46
os .path .join (args .toolchain , 'usr' , 'lib' , 'swift' , 'Block' ),
47
+ # Library rpath for swift, dispatch, Foundation, etc. when installing
48
+ '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/linux' ,
40
49
]
41
50
42
51
return swiftpm_args
43
52
53
+ def install (swiftpm_bin_path , toolchain ):
54
+ toolchain_bin = os .path .join (toolchain , 'usr' , 'bin' )
55
+ for exe in ['sourcekit-lsp' ]:
56
+ install_binary (exe , swiftpm_bin_path , toolchain_bin , toolchain )
57
+
58
+ def install_binary (exe , source_dir , install_dir , toolchain ):
59
+ cmd = ['rsync' , '-a' , os .path .join (source_dir , exe ), install_dir ]
60
+ print (' ' .join (cmd ))
61
+ subprocess .check_call (cmd )
62
+
63
+ if platform .system () == 'Darwin' :
64
+ result_path = os .path .join (install_dir , exe )
65
+ stdlib_rpath = os .path .join (toolchain , 'usr' , 'lib' , 'swift' , 'macosx' )
66
+ delete_rpath (stdlib_rpath , result_path )
67
+
68
+ def delete_rpath (rpath , binary ):
69
+ cmd = ["install_name_tool" , "-delete_rpath" , rpath , binary ]
70
+ print (' ' .join (cmd ))
71
+ subprocess .check_call (cmd )
72
+
44
73
def main ():
45
74
parser = argparse .ArgumentParser (description = 'Build along with the Swift build-script.' )
46
75
def add_common_args (parser ):
@@ -49,6 +78,7 @@ def add_common_args(parser):
49
78
parser .add_argument ('--ninja-bin' , metavar = 'PATH' , help = 'ninja binary to use for testing' )
50
79
parser .add_argument ('--build-path' , metavar = 'PATH' , default = '.build' , help = 'build in the given path' )
51
80
parser .add_argument ('--configuration' , '-c' , default = 'debug' , help = 'build using configuration (release|debug)' )
81
+ parser .add_argument ('--no-local-deps' , action = 'store_true' , help = 'use normal remote dependencies when building' )
52
82
parser .add_argument ('--verbose' , '-v' , action = 'store_true' , help = 'enable verbose output' )
53
83
54
84
subparsers = parser .add_subparsers (title = 'subcommands' , dest = 'action' , metavar = 'action' )
@@ -58,6 +88,9 @@ def add_common_args(parser):
58
88
test_parser = subparsers .add_parser ('test' , help = 'test the package' )
59
89
add_common_args (test_parser )
60
90
91
+ install_parser = subparsers .add_parser ('install' , help = 'build the package' )
92
+ add_common_args (install_parser )
93
+
61
94
args = parser .parse_args (sys .argv [1 :])
62
95
63
96
# Canonicalize paths
@@ -76,7 +109,8 @@ def add_common_args(parser):
76
109
# Set the toolchain used in tests at runtime
77
110
env ['SOURCEKIT_TOOLCHAIN_PATH' ] = args .toolchain
78
111
# Use local dependencies (i.e. checked out next sourcekit-lsp).
79
- env ['SWIFTCI_USE_LOCAL_DEPS' ] = "1"
112
+ if not args .no_local_deps :
113
+ env ['SWIFTCI_USE_LOCAL_DEPS' ] = "1"
80
114
81
115
if args .ninja_bin :
82
116
env ['NINJA_BIN' ] = args .ninja_bin
@@ -89,6 +123,10 @@ def add_common_args(parser):
89
123
print ('Cleaning ' + tests )
90
124
shutil .rmtree (tests , ignore_errors = True )
91
125
swiftpm ('test' , swift_exec , swiftpm_args , env )
126
+ elif args .action == 'install' :
127
+ bin_path = swiftpm_bin_path (swift_exec , swiftpm_args , env )
128
+ swiftpm ('build' , swift_exec , swiftpm_args , env )
129
+ install (bin_path , args .toolchain )
92
130
else :
93
131
assert False , 'unknown action \' {}\' ' .format (args .action )
94
132
0 commit comments