Skip to content

Commit 421531b

Browse files
committed
Move swiftpm to swift_build_support infra
This will allow cleaning up most of the hacks in SwiftPM's build script. <rdar://problem/56220087>
1 parent 3671cab commit 421531b

File tree

4 files changed

+78
-7
lines changed

4 files changed

+78
-7
lines changed

utils/build-script

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ class BuildScriptInvocation(object):
337337
"--libdispatch-build-type", args.libdispatch_build_variant,
338338
"--libicu-build-type", args.libicu_build_variant,
339339
"--xctest-build-type", args.build_variant,
340-
"--swiftpm-build-type", args.build_variant,
341340
"--llbuild-build-type", args.build_variant,
342341
"--swift-enable-assertions", str(args.swift_assertions).lower(),
343342
"--swift-stdlib-enable-assertions", str(
@@ -464,8 +463,6 @@ class BuildScriptInvocation(object):
464463
impl_args += ["--skip-build-libdispatch"]
465464
if not args.build_libicu:
466465
impl_args += ["--skip-build-libicu"]
467-
if not args.build_swiftpm:
468-
impl_args += ["--skip-build-swiftpm"]
469466
if not args.build_playgroundsupport:
470467
impl_args += ["--skip-build-playgroundsupport"]
471468
if args.build_swift_dynamic_stdlib:
@@ -508,7 +505,6 @@ class BuildScriptInvocation(object):
508505
impl_args += ["--skip-test-cmark",
509506
"--skip-test-lldb",
510507
"--skip-test-llbuild",
511-
"--skip-test-swiftpm",
512508
"--skip-test-xctest",
513509
"--skip-test-foundation",
514510
"--skip-test-libdispatch",

utils/build_swift/driver_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def _apply_default_arguments(args):
203203
args.test_tvos = False
204204
args.test_watchos = False
205205
args.test_android = False
206+
args.test_swiftpm = False
206207
args.test_swiftsyntax = False
207208
args.test_indexstoredb = False
208209
args.test_sourcekitlsp = False
@@ -557,6 +558,9 @@ def create_argument_parser():
557558
option(['-p', '--swiftpm'], store_true('build_swiftpm'),
558559
help='build swiftpm')
559560

561+
option(['--install-swiftpm'], store_true('install_swiftpm'),
562+
help='install swiftpm')
563+
560564
option(['--swiftsyntax'], store_true('build_swiftsyntax'),
561565
help='build swiftSyntax')
562566

@@ -968,6 +972,8 @@ def create_argument_parser():
968972
help='skip testing Android device targets on the host machine (the '
969973
'phone itself)')
970974

975+
option('--skip-test-swiftpm', toggle_false('test_swiftpm'),
976+
help='skip testing swiftpm')
971977
option('--skip-test-swiftsyntax', toggle_false('test_swiftsyntax'),
972978
help='skip testing SwiftSyntax')
973979
option('--skip-test-indexstore-db', toggle_false('test_indexstoredb'),

utils/build_swift/tests/expected_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
'build_swiftevolve': False,
8989
'build_indexstoredb': False,
9090
'build_sourcekitlsp': False,
91+
'install_swiftpm': False,
9192
'install_swiftsyntax': False,
9293
'skip_install_swiftsyntax_module': False,
9394
'swiftsyntax_verify_generated_files': False,
@@ -208,6 +209,7 @@
208209
'test_watchos': False,
209210
'test_watchos_host': False,
210211
'test_watchos_simulator': False,
212+
'test_swiftpm': False,
211213
'test_swiftsyntax': False,
212214
'test_indexstoredb': False,
213215
'test_sourcekitlsp': False,
@@ -485,6 +487,7 @@ class BuildScriptImplOption(_BaseOption):
485487
dest='skip_install_swiftsyntax_module'),
486488
EnableOption('--swiftsyntax-verify-generated-files',
487489
dest='swiftsyntax_verify_generated_files'),
490+
EnableOption('--install-swiftpm', dest='install_swiftpm'),
488491
EnableOption('--install-sourcekit-lsp', dest='install_sourcekitlsp'),
489492
EnableOption('--install-skstresstester', dest='install_skstresstester'),
490493
EnableOption('--install-swiftevolve', dest='install_swiftevolve'),
@@ -542,6 +545,7 @@ class BuildScriptImplOption(_BaseOption):
542545
DisableOption('--skip-test-watchos-host', dest='test_watchos_host'),
543546
DisableOption('--skip-test-watchos-simulator',
544547
dest='test_watchos_simulator'),
548+
DisableOption('--skip-test-swiftpm', dest='test_swiftpm'),
545549
DisableOption('--skip-test-swiftsyntax', dest='test_swiftsyntax'),
546550
DisableOption('--skip-test-indexstore-db', dest='test_indexstoredb'),
547551
DisableOption('--skip-test-sourcekit-lsp', dest='test_sourcekitlsp'),

utils/swift_build_support/swift_build_support/products/swiftpm.py

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,81 @@
22
#
33
# This source file is part of the Swift.org open source project
44
#
5-
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
66
# Licensed under Apache License v2.0 with Runtime Library Exception
77
#
88
# See https://swift.org/LICENSE.txt for license information
99
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
#
1111
# ----------------------------------------------------------------------------
1212

13-
from . import product
13+
import os
14+
import platform
1415

16+
from . import product
17+
from .. import shell
1518

1619
class SwiftPM(product.Product):
17-
pass
20+
@classmethod
21+
def product_source_name(cls):
22+
return "swiftpm"
23+
24+
@classmethod
25+
def is_build_script_impl_product(cls):
26+
return False
27+
28+
def should_build(self, host_target):
29+
return True
30+
31+
def run_build_script_helper(self, action, host_target, additional_params=[]):
32+
script_path = os.path.join(
33+
self.source_dir, 'Utilities', 'bootstrap')
34+
toolchain_path = self.install_toolchain_path()
35+
swiftc = os.path.join(toolchain_path, "usr", "bin", "swiftc")
36+
sbt = os.path.join(toolchain_path, "usr", "bin", "swift-build-tool")
37+
38+
llbuild_src = os.path.join(
39+
os.path.dirname(self.source_dir), "llbuild")
40+
41+
# FIXME: We require llbuild build directory in order to build. Is
42+
# there a better way to get this?
43+
build_root = os.path.dirname(self.build_dir)
44+
llbuild_build_dir = os.path.join(
45+
build_root, '%s-%s' % ("llbuild", host_target))
46+
47+
helper_cmd = [script_path]
48+
49+
if action != "build":
50+
helper_cmd.append(action)
51+
52+
if self.is_release():
53+
helper_cmd.append("--release")
54+
55+
helper_cmd += [
56+
"--swiftc=" + swiftc,
57+
"--sbt=" + sbt,
58+
"--build", self.build_dir,
59+
"--llbuild-source-dir=" + llbuild_src,
60+
"--llbuild-build-dir=" + llbuild_build_dir,
61+
]
62+
helper_cmd.extend(additional_params)
63+
64+
shell.call(helper_cmd)
65+
66+
def build(self, host_target):
67+
self.run_build_script_helper('build', host_target)
68+
69+
def should_test(self, host_target):
70+
return self.args.test_swiftpm
71+
72+
def test(self, host_target):
73+
self.run_build_script_helper('test', host_target)
74+
75+
def should_install(self, host_target):
76+
return self.args.install_swiftpm
77+
78+
def install(self, host_target):
79+
install_prefix = self.args.install_destdir + self.args.install_prefix
80+
self.run_build_script_helper('install', host_target, [
81+
'--prefix', install_prefix
82+
])

0 commit comments

Comments
 (0)