Skip to content

Commit 5c8ed58

Browse files
authored
Merge pull request swiftlang#142 from benlangmuir/install
[build-script] Add installation support for sourcekit-lsp
2 parents 697d02a + 9e8e088 commit 5c8ed58

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

Utilities/build-script-helper.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def swiftpm(action, swift_exec, swiftpm_args, env=None):
1515
subprocess.check_call(cmd, env=env)
1616

1717
def swiftpm_bin_path(swift_exec, swiftpm_args, env=None):
18+
swiftpm_args = filter(lambda arg: arg != '-v' and arg != '--verbose', swiftpm_args)
1819
cmd = [swift_exec, 'build', '--show-bin-path'] + swiftpm_args
1920
print(' '.join(cmd))
2021
return subprocess.check_output(cmd, env=env).strip()
@@ -29,18 +30,46 @@ def get_swiftpm_options(args):
2930
if args.verbose:
3031
swiftpm_args += ['--verbose']
3132

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:
3340
swiftpm_args += [
3441
# Dispatch headers
3542
'-Xcxx', '-I', '-Xcxx',
3643
os.path.join(args.toolchain, 'usr', 'lib', 'swift'),
3744
# For <Block.h>
3845
'-Xcxx', '-I', '-Xcxx',
3946
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',
4049
]
4150

4251
return swiftpm_args
4352

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+
4473
def main():
4574
parser = argparse.ArgumentParser(description='Build along with the Swift build-script.')
4675
def add_common_args(parser):
@@ -49,6 +78,7 @@ def add_common_args(parser):
4978
parser.add_argument('--ninja-bin', metavar='PATH', help='ninja binary to use for testing')
5079
parser.add_argument('--build-path', metavar='PATH', default='.build', help='build in the given path')
5180
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')
5282
parser.add_argument('--verbose', '-v', action='store_true', help='enable verbose output')
5383

5484
subparsers = parser.add_subparsers(title='subcommands', dest='action', metavar='action')
@@ -58,6 +88,9 @@ def add_common_args(parser):
5888
test_parser = subparsers.add_parser('test', help='test the package')
5989
add_common_args(test_parser)
6090

91+
install_parser = subparsers.add_parser('install', help='build the package')
92+
add_common_args(install_parser)
93+
6194
args = parser.parse_args(sys.argv[1:])
6295

6396
# Canonicalize paths
@@ -76,7 +109,8 @@ def add_common_args(parser):
76109
# Set the toolchain used in tests at runtime
77110
env['SOURCEKIT_TOOLCHAIN_PATH'] = args.toolchain
78111
# 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"
80114

81115
if args.ninja_bin:
82116
env['NINJA_BIN'] = args.ninja_bin
@@ -89,6 +123,10 @@ def add_common_args(parser):
89123
print('Cleaning ' + tests)
90124
shutil.rmtree(tests, ignore_errors=True)
91125
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)
92130
else:
93131
assert False, 'unknown action \'{}\''.format(args.action)
94132

0 commit comments

Comments
 (0)