|
1 |
| -#!/bin/bash |
2 |
| -##===----------------------------------------------------------------------===## |
3 |
| -## |
4 |
| -## This source file is part of the Swift open source project |
5 |
| -## |
6 |
| -## Copyright (c) 2014-2022 Apple Inc. and the Swift project authors |
7 |
| -## Licensed under Apache License v2.0 with Runtime Library Exception |
8 |
| -## |
9 |
| -## See http://swift.org/LICENSE.txt for license information |
10 |
| -## See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
11 |
| -## |
12 |
| -##===----------------------------------------------------------------------===## |
13 |
| - |
14 |
| -set -eu |
15 |
| - |
16 |
| -__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
17 |
| -root_dir="$(cd ${__dir}/.. && pwd)" |
18 |
| - |
19 |
| -cd "${root_dir}/" |
20 |
| -echo "Current directory is ${PWD}" |
21 |
| - |
22 |
| -CONFIGURATION=debug |
23 |
| -export SWIFTCI_IS_SELF_HOSTED=1 |
24 |
| - |
25 |
| -# Ensure SDKROOT is configured |
26 |
| -host=$(uname) |
27 |
| -if [ "${host}" == "Darwin" ]; then |
28 |
| - export SDKROOT=$(xcrun --show-sdk-path --sdk macosx) |
29 |
| -fi |
30 |
| - |
31 |
| -set -x |
32 |
| - |
33 |
| -env | sort |
34 |
| - |
35 |
| -# Display toolchain version |
36 |
| -swift --version |
37 |
| - |
38 |
| -# Perform package update in order to get the latest commits for the dependencies. |
39 |
| -swift package update |
40 |
| -swift build -c $CONFIGURATION |
41 |
| -swift test -c $CONFIGURATION --parallel |
42 |
| - |
43 |
| -# Run the integration tests with just built SwiftPM. |
44 |
| -export SWIFTPM_BIN_DIR=$(swift build -c $CONFIGURATION --show-bin-path) |
45 |
| -( |
46 |
| - cd ${root_dir}/IntegrationTests |
47 |
| - # Perform package update in order to get the latest commits for the dependencies. |
48 |
| - swift package update |
49 |
| - $SWIFTPM_BIN_DIR/swift-test --parallel |
| 1 | +#!/usr/bin/env python3 |
| 2 | +# ===----------------------------------------------------------------------===## |
| 3 | +# |
| 4 | +# This source file is part of the Swift open source project |
| 5 | +# |
| 6 | +# Copyright (c) 2025 Apple Inc. and the Swift project authors |
| 7 | +# Licensed under Apache License v2.0 with Runtime Library Exception |
| 8 | +# |
| 9 | +# See http://swift.org/LICENSE.txt for license information |
| 10 | +# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 11 | +# |
| 12 | +# ===----------------------------------------------------------------------===## |
| 13 | + |
| 14 | +import argparse |
| 15 | +import contextlib |
| 16 | +import enum |
| 17 | +import logging |
| 18 | +import os |
| 19 | +import pathlib |
| 20 | +import platform |
| 21 | +import sys |
| 22 | +import typing as t |
| 23 | + |
| 24 | +from helpers import call, call_output |
| 25 | + |
| 26 | +logging.basicConfig( |
| 27 | + format=" | ".join( |
| 28 | + [ |
| 29 | + # Prefix script name to the log in an attempt to avoid confusion when parsing logs |
| 30 | + f"{pathlib.Path(sys.argv[0]).name}", |
| 31 | + "%(asctime)s", |
| 32 | + "%(levelname)-8s", |
| 33 | + "%(module)s", |
| 34 | + "%(funcName)s", |
| 35 | + "Line:%(lineno)d", |
| 36 | + "%(message)s", |
| 37 | + ] |
| 38 | + ), |
| 39 | + level=logging.INFO, |
50 | 40 | )
|
51 | 41 |
|
52 |
| -if [ "${host}" == "Darwin" ]; then |
53 |
| - echo "Current working directory is ${PWD}" |
54 |
| - echo "Bootstrapping with the XCBuild codepath..." |
55 |
| - ${root_dir}/Utilities/bootstrap \ |
56 |
| - build \ |
57 |
| - --release \ |
58 |
| - --verbose \ |
59 |
| - --cross-compile-hosts macosx-arm64 \ |
60 |
| - --skip-cmake-bootstrap \ |
61 |
| - --swift-build-path "${SWIFTPM_BIN_DIR}/swift-build" |
62 |
| -fi |
| 42 | + |
| 43 | +REPO_ROOT_PATH = pathlib.Path(__file__).parent.parent.resolve() |
| 44 | + |
| 45 | + |
| 46 | +@contextlib.contextmanager |
| 47 | +def change_directory(directory: pathlib.Path) -> t.Iterator[pathlib.Path]: |
| 48 | + current_directory = pathlib.Path.cwd() |
| 49 | + logging.info("Current directory is %s", current_directory) |
| 50 | + logging.info("Changing directory to: %s", directory) |
| 51 | + os.chdir(directory) |
| 52 | + |
| 53 | + try: |
| 54 | + yield directory |
| 55 | + finally: |
| 56 | + logging.debug("Chaning directory back to %s", current_directory) |
| 57 | + os.chdir(current_directory) |
| 58 | + |
| 59 | + |
| 60 | +class Configuration(str, enum.Enum): |
| 61 | + DEBUG = "debug" |
| 62 | + RELEASE = "release" |
| 63 | + |
| 64 | + |
| 65 | +def get_arguments() -> argparse.Namespace: |
| 66 | + parser = argparse.ArgumentParser( |
| 67 | + formatter_class=argparse.ArgumentDefaultsHelpFormatter |
| 68 | + ) |
| 69 | + |
| 70 | + parser.add_argument( |
| 71 | + "-v", |
| 72 | + "--verbose", |
| 73 | + dest="is_verbose", |
| 74 | + action="store_true", |
| 75 | + help="When set, prints verbose information.", |
| 76 | + ) |
| 77 | + parser.add_argument( |
| 78 | + "-c", |
| 79 | + "--configuration", |
| 80 | + type=Configuration, |
| 81 | + dest="config", |
| 82 | + default="debug", |
| 83 | + choices=[e.value for e in Configuration], |
| 84 | + help="The configuraiton to use.", |
| 85 | + ) |
| 86 | + |
| 87 | + args = parser.parse_args() |
| 88 | + return args |
| 89 | + |
| 90 | + |
| 91 | +def log_environment() -> None: |
| 92 | + logging.info("Environment Variables") |
| 93 | + for key, value in sorted(os.environ.items()): |
| 94 | + logging.info(" --> %s=%r", key, value) |
| 95 | + |
| 96 | + |
| 97 | +def get_swiftpm_bin_dir(config: Configuration) -> pathlib.Path: |
| 98 | + swiftpm_bin_dir = pathlib.Path( |
| 99 | + call_output(["swift", "build", "--configuration", config, "--show-bin-path"]) |
| 100 | + ) |
| 101 | + logging.info("SwiftPM BIN DIR: %s", swiftpm_bin_dir) |
| 102 | + return swiftpm_bin_dir |
| 103 | + |
| 104 | + |
| 105 | +def is_on_darwin() -> bool: |
| 106 | + return platform.uname().system == "Darwin" |
| 107 | + |
| 108 | + |
| 109 | +def set_environment(*, config: Configuration) -> None: |
| 110 | + os.environ["SWIFTCI_IS_SELF_HOSTED"] = "1" |
| 111 | + |
| 112 | + # Set the SWIFTPM_BIN_DIR path |
| 113 | + os.environ["SWIFTPM_BIN_DIR"] = str(get_swiftpm_bin_dir(config=config)) |
| 114 | + |
| 115 | + # Ensure SDKROOT is configure |
| 116 | + if is_on_darwin(): |
| 117 | + sdk_root = call_output(["xcrun", "--show-sdk-path", "--sdk", "macosx"]) |
| 118 | + logging.debug("macos sdk root = %r", sdk_root) |
| 119 | + os.environ["SDKROOT"] = sdk_root |
| 120 | + log_environment() |
| 121 | + |
| 122 | + |
| 123 | +def run_bootstrap(swiftpm_bin_dir: pathlib.Path) -> None: |
| 124 | + if is_on_darwin(): |
| 125 | + logging.info("Current working directory is %s", pathlib.Path.cwd()) |
| 126 | + logging.info("Bootstrapping with the XCBuild codepath...") |
| 127 | + call( |
| 128 | + [ |
| 129 | + REPO_ROOT_PATH / "Utilities" / "bootstrap", |
| 130 | + "build", |
| 131 | + "--release", |
| 132 | + "--verbose", |
| 133 | + "--cross-compile-hosts", |
| 134 | + "macosx-arm64", |
| 135 | + "--skip-cmake-bootstrap", |
| 136 | + "--swift-build-path", |
| 137 | + (swiftpm_bin_dir / "swift-build").resolve(), |
| 138 | + ], |
| 139 | + ) |
| 140 | + |
| 141 | + |
| 142 | +def main() -> None: |
| 143 | + args = get_arguments() |
| 144 | + logging.getLogger().setLevel(logging.DEBUG if args.is_verbose else logging.INFO) |
| 145 | + logging.debug("Args: %r", args) |
| 146 | + |
| 147 | + with change_directory(REPO_ROOT_PATH): |
| 148 | + set_environment(config=args.config) |
| 149 | + |
| 150 | + call( |
| 151 | + ["swift", "--version"], |
| 152 | + ) |
| 153 | + call( |
| 154 | + ["swift", "package", "update"], |
| 155 | + ) |
| 156 | + call( |
| 157 | + ["swift", "build", "--configuration", args.config], |
| 158 | + ) |
| 159 | + call( |
| 160 | + ["swift", "test", "--configuration", args.config, "--parallel"], |
| 161 | + ) |
| 162 | + |
| 163 | + with change_directory(REPO_ROOT_PATH / "IntegrationTests"): |
| 164 | + swiftpm_bin_dir = get_swiftpm_bin_dir(config=args.config) |
| 165 | + call( |
| 166 | + ["swift", "package", "update"], |
| 167 | + ) |
| 168 | + call( |
| 169 | + [ |
| 170 | + str(swiftpm_bin_dir / "swift-test"), |
| 171 | + "--parallel", |
| 172 | + ], |
| 173 | + ) |
| 174 | + |
| 175 | + run_bootstrap(swiftpm_bin_dir=swiftpm_bin_dir) |
| 176 | + |
| 177 | + |
| 178 | +if __name__ == "__main__": |
| 179 | + main() |
0 commit comments