From af79bc2d3ffeddc3ddad49146e2f0acc67b8f3a8 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 4 Sep 2023 11:00:50 -0700 Subject: [PATCH] test: introduce a helper for building mock plugins Introduce a helper for mock plugins as `-rpath` is not a portable construct. This allows running more of the macro tests on Windows. --- test/Macros/lit.local.cfg | 24 ++++++++++++++++++++++ test/Macros/macro_plugin_basic.swift | 8 +------- test/Macros/macro_plugin_error.swift | 8 +------- test/Macros/macro_plugin_searchorder.swift | 8 +------- test/Macros/macro_swiftdeps.swift | 8 +------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/test/Macros/lit.local.cfg b/test/Macros/lit.local.cfg index 521ceea67705e..dd010ab88930a 100644 --- a/test/Macros/lit.local.cfg +++ b/test/Macros/lit.local.cfg @@ -1,3 +1,27 @@ # '-enable-experimental-feature Macros' requires an asserts build. if 'asserts' not in config.available_features: config.unsupported = True + +config.subsitutions = list(config.substitutions) + +def get_target_os(): + import re + (run_cpu, run_vendor, run_os, run_version) = re.match('([^-]+)-([^-]+)-([^0-9]+)(.*)', config.variant_triple).groups() + return run_os + +if get_target_os() in ['windows-msvc']: + config.substitutions.insert( + 0, + ( + '%swift-build-cxx-plugin', + '%clang -isysroot %host_sdk -I %swift_src_root/include -L %swift-lib-dir -l_swiftMockPlugin' + ) + ) +else: + config.substitutions.insert( + 0, + ( + '%swift-build-cxx-plugin', + '%clang -isysroot %host_sdk -I %swift_src_root/include -L %swift-lib-dir -l_swiftMockPlugin -Xlinker -rpath -Xlinker %swift-lib-dir' + ) + ) diff --git a/test/Macros/macro_plugin_basic.swift b/test/Macros/macro_plugin_basic.swift index 5aad4042143a2..191dc426b124f 100644 --- a/test/Macros/macro_plugin_basic.swift +++ b/test/Macros/macro_plugin_basic.swift @@ -3,13 +3,7 @@ // RUN: %empty-directory(%t) // RUN: split-file %s %t -// RUN: %clang \ -// RUN: -isysroot %host_sdk \ -// RUN: -I %swift_src_root/include \ -// RUN: -L %swift-lib-dir -l_swiftMockPlugin \ -// RUN: -Wl,-rpath,%swift-lib-dir \ -// RUN: -o %t/mock-plugin \ -// RUN: %t/plugin.c +// RUN: %swift-build-cxx-plugin -o %t/mock-plugin %t/plugin.c // RUN: env SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \ // RUN: -typecheck -verify \ diff --git a/test/Macros/macro_plugin_error.swift b/test/Macros/macro_plugin_error.swift index f0e3d719f842b..e50edef4dc89b 100644 --- a/test/Macros/macro_plugin_error.swift +++ b/test/Macros/macro_plugin_error.swift @@ -3,13 +3,7 @@ // RUN: %empty-directory(%t) // RUN: split-file %s %t -// RUN: %clang \ -// RUN: -isysroot %host_sdk \ -// RUN: -I %swift_src_root/include \ -// RUN: -L %swift-lib-dir -l_swiftMockPlugin \ -// RUN: -Wl,-rpath,%swift-lib-dir \ -// RUN: -o %t/mock-plugin \ -// RUN: %t/plugin.c +// RUN: %swift-build-cxx-plugin -o %t/mock-plugin %t/plugin.c // RUN: env SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \ // RUN: -typecheck -verify \ diff --git a/test/Macros/macro_plugin_searchorder.swift b/test/Macros/macro_plugin_searchorder.swift index 562144fa86b48..d99c9216cadf0 100644 --- a/test/Macros/macro_plugin_searchorder.swift +++ b/test/Macros/macro_plugin_searchorder.swift @@ -40,13 +40,7 @@ // RUN: -g -no-toolchain-stdlib-rpath //#-- For -load-plugin-executable -// RUN: %clang \ -// RUN: -isysroot %host_sdk \ -// RUN: -I %swift_src_root/include \ -// RUN: -L %swift-lib-dir -l_swiftMockPlugin \ -// RUN: -Wl,-rpath,%swift-lib-dir \ -// RUN: -o %t/libexec/MacroDefinitionPlugin \ -// RUN: %t/src/MacroDefinition.c +// RUN: %swift-build-cxx-plugin -o %t/libexec/MacroDefinitionPlugin %t/src/MacroDefinition.c //#-- Expect -load-plugin-library // RUN: %target-build-swift %t/src/test.swift \ diff --git a/test/Macros/macro_swiftdeps.swift b/test/Macros/macro_swiftdeps.swift index 07b45d73361b9..4c4f108eef35a 100644 --- a/test/Macros/macro_swiftdeps.swift +++ b/test/Macros/macro_swiftdeps.swift @@ -16,13 +16,7 @@ // RUN: -g -no-toolchain-stdlib-rpath //#-- Prepare the macro executable plugin. -// RUN: %clang \ -// RUN: -isysroot %host_sdk \ -// RUN: -I %swift_src_root/include \ -// RUN: -L %swift-lib-dir -l_swiftMockPlugin \ -// RUN: -Wl,-rpath,%swift-lib-dir \ -// RUN: -o %t/mock-plugin \ -// RUN: %t/src/plugin.c +// RUN: %swift-build-cxx-plugin -o %t/mock-plugin %t/src/plugin.c //#-- Prepare the macro library. // RUN: %target-swift-frontend \