Skip to content

Commit 957c777

Browse files
committed
Build all examples in build script
1 parent c56cf30 commit 957c777

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

build-script.py

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
PACKAGE_DIR = os.path.dirname(os.path.realpath(__file__))
1717
WORKSPACE_DIR = os.path.dirname(PACKAGE_DIR)
18+
EXAMPLES_DIR = os.path.join(PACKAGE_DIR, "Examples")
1819
SOURCES_DIR = os.path.join(PACKAGE_DIR, "Sources")
1920
SWIFTSYNTAX_DIR = os.path.join(SOURCES_DIR, "SwiftSyntax")
2021
SWIFTSYNTAX_DOCUMENTATION_DIR = \
@@ -401,13 +402,13 @@ def clear_gyb_files_from_previous_run(
401402

402403

403404
def get_swiftpm_invocation(
404-
toolchain: str, action: str, build_dir: Optional[str],
405+
toolchain: str, action: str, package_dir: str, build_dir: Optional[str],
405406
multiroot_data_file: Optional[str], release: bool
406407
) -> List[str]:
407408
swift_exec = os.path.join(toolchain, "bin", "swift")
408409

409410
swiftpm_call = [swift_exec, action]
410-
swiftpm_call.extend(["--package-path", PACKAGE_DIR])
411+
swiftpm_call.extend(["--package-path", package_dir])
411412
if platform.system() != "Darwin":
412413
swiftpm_call.extend(["--enable-test-discovery"])
413414
if release:
@@ -421,9 +422,12 @@ def get_swiftpm_invocation(
421422

422423

423424
class Builder(object):
424-
swiftpm_call: List[str]
425425
verbose: bool
426426
toolchain: str
427+
build_dir: Optional[str]
428+
multiroot_data_file: Optional[str]
429+
release: bool
430+
disable_sandbox: bool
427431

428432
def __init__(
429433
self,
@@ -434,23 +438,38 @@ def __init__(
434438
verbose: bool,
435439
disable_sandbox: bool = False,
436440
) -> None:
437-
self.swiftpm_call = get_swiftpm_invocation(
438-
toolchain=toolchain,
439-
action="build",
440-
build_dir=build_dir,
441-
multiroot_data_file=multiroot_data_file,
442-
release=release,
443-
)
444-
if disable_sandbox:
445-
self.swiftpm_call.append("--disable-sandbox")
446-
if verbose:
447-
self.swiftpm_call.extend(["--verbose"])
441+
self.build_dir = build_dir
442+
self.multiroot_data_file = multiroot_data_file
443+
self.release = release
444+
self.disable_sandbox = disable_sandbox
448445
self.verbose = verbose
449446
self.toolchain = toolchain
450447

451-
def build(self, product_name: str) -> None:
452-
print("** Building " + product_name + " **")
453-
command = list(self.swiftpm_call)
448+
def __get_swiftpm_invocation(self, package_dir: str) -> List[str]:
449+
invocation = get_swiftpm_invocation(
450+
self.toolchain,
451+
"build",
452+
package_dir,
453+
self.build_dir,
454+
self.multiroot_data_file,
455+
self.release
456+
)
457+
if self.disable_sandbox:
458+
invocation.append("--disable-sandbox")
459+
if self.verbose:
460+
invocation.append("--verbose")
461+
return invocation
462+
463+
def buildProduct(self, product_name: str) -> None:
464+
print("** Building product " + product_name + " **")
465+
self.__build(PACKAGE_DIR, product_name)
466+
467+
def buildExample(self, example_name: str) -> None:
468+
print("** Building example " + example_name + " **")
469+
self.__build(EXAMPLES_DIR, example_name)
470+
471+
def __build(self, package_dir: str, product_name: str) -> None:
472+
command = list(self.__get_swiftpm_invocation(package_dir))
454473
command.extend(["--product", product_name])
455474

456475
env = dict(os.environ)
@@ -599,6 +618,7 @@ def find_lit_test_helper_exec(
599618
swiftpm_call = get_swiftpm_invocation(
600619
toolchain=toolchain,
601620
action="build",
621+
package_dir=PACKAGE_DIR,
602622
build_dir=build_dir,
603623
multiroot_data_file=None,
604624
release=release,
@@ -651,6 +671,7 @@ def run_xctests(toolchain: str, build_dir: Optional[str],
651671
swiftpm_call = get_swiftpm_invocation(
652672
toolchain=toolchain,
653673
action="test",
674+
package_dir=PACKAGE_DIR,
654675
build_dir=build_dir,
655676
multiroot_data_file=multiroot_data_file,
656677
release=release,
@@ -738,9 +759,14 @@ def build_command(args: argparse.Namespace) -> None:
738759
)
739760
# Until rdar://53881101 is implemented, we cannot request a build of multiple
740761
# targets simultaneously. For now, just build one product after the other.
741-
builder.build("SwiftSyntax")
742-
builder.build("SwiftSyntaxParser")
743-
builder.build("SwiftSyntaxBuilder")
762+
builder.buildProduct("SwiftSyntax")
763+
builder.buildProduct("SwiftSyntaxParser")
764+
builder.buildProduct("SwiftSyntaxBuilder")
765+
766+
# Build examples
767+
builder.buildExample("AddOneToIntegerLiterals")
768+
builder.buildExample("CodeGenerationUsingSwiftSyntaxBuilder")
769+
builder.buildExample("MigrateToNewIfLetSyntax")
744770
except subprocess.CalledProcessError as e:
745771
fail_for_called_process_error("Building SwiftSyntax failed", e)
746772

@@ -756,7 +782,7 @@ def test_command(args: argparse.Namespace) -> None:
756782
disable_sandbox=args.disable_sandbox,
757783
)
758784

759-
builder.build("lit-test-helper")
785+
builder.buildProduct("lit-test-helper")
760786

761787
run_tests(
762788
toolchain=args.toolchain,

0 commit comments

Comments
 (0)