Skip to content

Commit 4a5e0da

Browse files
committed
build: Unhardcode Swift source directory name
This is useful if you maintain several swift worktrees that reside in the source root directory.
1 parent ddfb26b commit 4a5e0da

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

utils/build-script-impl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ KNOWN_SETTINGS=(
203203
llvm-ninja-targets-for-cross-compile-hosts "" "list of ninja targets to build for LLVM for hosts that are cross-compiled"
204204

205205
## Swift Options
206+
swift-source-dirname "" "The name of the Swift source directory"
206207
swift-analyze-code-coverage "not-merged" "Code coverage analysis mode for Swift (false, not-merged, merged). Defaults to false if the argument is not present, and not-merged if the argument is present without a modifier."
207208
swift-enable-assertions "1" "enable assertions in Swift"
208209
swift-enable-ast-verifier "1" "If enabled, and the assertions are enabled, the built Swift compiler will run the AST verifier every time it is invoked"
@@ -1233,7 +1234,7 @@ function host_has_darwin_symbols() {
12331234
# Calculate source directories for each product.
12341235
#
12351236
NINJA_SOURCE_DIR="${WORKSPACE}/ninja"
1236-
SWIFT_SOURCE_DIR="${WORKSPACE}/swift"
1237+
SWIFT_SOURCE_DIR="${WORKSPACE}/${SWIFT_SOURCE_DIRNAME}"
12371238
LLVM_SOURCE_DIR="${WORKSPACE}/llvm-project/llvm"
12381239
CMARK_SOURCE_DIR="${WORKSPACE}/cmark"
12391240
LLDB_SOURCE_DIR="${WORKSPACE}/llvm-project/lldb"

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def convert_to_impl_arguments(self):
138138
'--build-swift-clang-overlays', str(
139139
args.build_swift_clang_overlays).lower(),
140140
'--build-swift-remote-mirror', str(args.build_swift_remote_mirror).lower(),
141+
"--swift-source-dirname", products.Swift.product_source_name(),
141142
]
142143

143144
# Compute any product specific cmake arguments.

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13+
from build_swift.build_swift.constants import SWIFT_REPO_NAME
14+
1315
from . import cmark
1416
from . import earlyswiftdriver
1517
from . import libcxx
@@ -99,6 +101,14 @@ def __init__(self, args, toolchain, source_dir, build_dir):
99101

100102
self._handle_swift_debuginfo_non_lto_args()
101103

104+
@classmethod
105+
def product_source_name(cls):
106+
"""product_source_name() -> str
107+
108+
The name of the source code directory of this product.
109+
"""
110+
return SWIFT_REPO_NAME
111+
102112
@classmethod
103113
def is_build_script_impl_product(cls):
104114
"""is_build_script_impl_product -> bool
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# REQUIRES: OS=macosx
2+
# REQUIRES: standalone_build
3+
# REQUIRES: target-same-as-host
4+
5+
# RUN: %empty-directory(%t)
6+
# RUN: %empty-directory(%t/build)
7+
8+
# Set up a local clone of swift in a temporary workspace and add a sibling
9+
# linked worktree to the clone.
10+
# RUN: git clone --depth 1 file://%swift_src_root %t/swift
11+
# RUN: git -C %t/swift worktree add --detach %t/swift-worktree
12+
13+
# Invoke the build script from the worktree.
14+
# RUN: %t/swift-worktree/utils/build-script --dry-run | %FileCheck -DARCH=%target-arch %s
15+
16+
# We should generate a build system for the linked worktree, not the main
17+
# worktree.
18+
# CHECK: {{^}}+ mkdir -p {{.*}}/swift-macosx-[[ARCH]]{{$}}
19+
# CHECK: {{^}}+ env {{.+}}/cmake -G Ninja {{.*}}/swift-worktree{{$}}

0 commit comments

Comments
 (0)