Skip to content

Commit 1561e76

Browse files
committed
Fix path resoltion in lit testing
1 parent 171487c commit 1561e76

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

build-script.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -524,22 +524,33 @@ def check_incr_transfer_roundtrip_exec() -> None:
524524
)
525525

526526

527-
def find_lit_test_helper_exec(
528-
toolchain: str, build_dir: Optional[str], release: bool
527+
def find_swiftpm_bin_path(
528+
package_dir: str, toolchain: str, build_dir: Optional[str], release: bool
529529
) -> str:
530530
swiftpm_call = get_swiftpm_invocation(
531531
toolchain=toolchain,
532532
action="build",
533-
package_dir=PACKAGE_DIR,
533+
package_dir=package_dir,
534534
build_dir=build_dir,
535535
multiroot_data_file=None,
536536
release=release,
537537
)
538-
swiftpm_call.extend(["--product", "lit-test-helper"])
539538
swiftpm_call.extend(["--show-bin-path"])
540539

541540
bin_dir = subprocess.check_output(swiftpm_call)
542-
return os.path.join(bin_dir.strip().decode('utf-8'), "lit-test-helper")
541+
return bin_dir.strip().decode('utf-8')
542+
543+
544+
def find_product_bin_path(
545+
toolchain: str, build_dir: Optional[str], release: bool
546+
) -> str:
547+
return find_swiftpm_bin_path(PACKAGE_DIR, toolchain, build_dir, release)
548+
549+
550+
def find_examples_bin_path(
551+
toolchain: str, build_dir: Optional[str], release: bool
552+
) -> str:
553+
return find_swiftpm_bin_path(EXAMPLES_DIR, toolchain, build_dir, release)
543554

544555

545556
def run_lit_tests(toolchain: str, build_dir: Optional[str], release: bool,
@@ -549,9 +560,12 @@ def run_lit_tests(toolchain: str, build_dir: Optional[str], release: bool,
549560
check_lit_exec()
550561
check_incr_transfer_roundtrip_exec()
551562

552-
lit_test_helper_exec = find_lit_test_helper_exec(
553-
toolchain=toolchain, build_dir=build_dir, release=release
554-
)
563+
product_bin_path = find_product_bin_path(
564+
toolchain=toolchain, build_dir=build_dir, release=release)
565+
examples_bin_path = find_examples_bin_path(
566+
toolchain=toolchain, build_dir=build_dir, release=release)
567+
568+
lit_test_helper_exec = os.path.join(product_bin_path, "lit-test-helper")
555569

556570
lit_call = ["python3", LIT_EXEC]
557571
lit_call.append(os.path.join(PACKAGE_DIR, "lit_tests"))
@@ -563,11 +577,7 @@ def run_lit_tests(toolchain: str, build_dir: Optional[str], release: bool,
563577
lit_call.extend(
564578
["--param", "INCR_TRANSFER_ROUND_TRIP.PY=" + INCR_TRANSFER_ROUNDTRIP_EXEC]
565579
)
566-
567-
build_subdir = 'release' if release else 'debug'
568-
package_build_dir = build_dir + '/' + build_subdir
569-
570-
lit_call.extend(["--param", "BUILD_DIR=" + package_build_dir])
580+
lit_call.extend(["--param", "EXAMPLES_BIN_PATH=" + examples_bin_path])
571581
lit_call.extend(["--param", "TOOLCHAIN=" + toolchain])
572582

573583
# Print all failures
@@ -663,7 +673,7 @@ def verify_source_code_command(args: argparse.Namespace) -> None:
663673
def build_command(args: argparse.Namespace) -> None:
664674
try:
665675
builder = Builder(
666-
toolchain=args.toolchain,
676+
toolchain=realpath(args.toolchain),
667677
build_dir=realpath(args.build_dir),
668678
multiroot_data_file=args.multiroot_data_file,
669679
release=args.release,
@@ -686,7 +696,7 @@ def build_command(args: argparse.Namespace) -> None:
686696
def test_command(args: argparse.Namespace) -> None:
687697
try:
688698
builder = Builder(
689-
toolchain=args.toolchain,
699+
toolchain=realpath(args.toolchain),
690700
build_dir=realpath(args.build_dir),
691701
multiroot_data_file=args.multiroot_data_file,
692702
release=args.release,
@@ -698,7 +708,7 @@ def test_command(args: argparse.Namespace) -> None:
698708
builder.buildExample("ExamplePlugin")
699709

700710
run_tests(
701-
toolchain=args.toolchain,
711+
toolchain=realpath(args.toolchain),
702712
build_dir=realpath(args.build_dir),
703713
multiroot_data_file=args.multiroot_data_file,
704714
release=args.release,

lit_tests/compiler_plugin_basic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: %swift-frontend -typecheck -swift-version 5 \
66
// RUN: -enable-experimental-feature Macros \
77
// RUN: -dump-macro-expansions \
8-
// RUN: -load-plugin-executable %build_dir/ExamplePlugin#ExamplePlugin \
8+
// RUN: -load-plugin-executable %examples_bin_path/ExamplePlugin#ExamplePlugin \
99
// RUN -module-name MyApp \
1010
// RUN: %s > %t/expansions-dump.txt 2>&1
1111
//

lit_tests/lit.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ config.suffixes = [".swift"]
5959
config.test_format = lit.formats.ShTest(execute_external=True)
6060
config.test_exec_root = tempfile.gettempdir()
6161

62-
config.build_dir = lit_config.params.get("BUILD_DIR")
62+
config.examples_bin_path = lit_config.params.get("EXAMPLES_BIN_PATH")
6363
config.filecheck = inferSwiftBinary("FileCheck")
6464
config.incr_transfer_round_trip = inferSwiftBinary("incr_transfer_round_trip.py")
6565
config.lit_test_helper = inferSwiftBinary("lit-test-helper")
@@ -71,9 +71,9 @@ config.swift_frontend = inferSwiftBinary("swift-frontend")
7171
# // REQUIRES: platform=<platform>
7272
# where <platform> is Linux or Darwin
7373
# Add a platform feature.
74-
config.available_features.add("platform="+platform.system())
74+
config.available_features.add("platform=" + platform.system())
7575

76-
config.substitutions.append(("%build_dir", config.build_dir))
76+
config.substitutions.append(("%examples_bin_path", config.examples_bin_path))
7777
config.substitutions.append(
7878
("%empty-directory\(([^)]+)\)", 'rm -rf "\\1" && mkdir -p "\\1"')
7979
)

0 commit comments

Comments
 (0)