mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Swift: package resource dir from precomiled toolchain
This commit is contained in:
@@ -64,6 +64,13 @@ pkg_runfiles(
|
||||
prefix = "tools/" + codeql_platform,
|
||||
)
|
||||
|
||||
pkg_filegroup(
|
||||
name = "resource-dir-arch",
|
||||
srcs = ["//swift/third_party/swift-llvm-support:swift-resource-dir"],
|
||||
prefix = "resource-dir/" + codeql_platform,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
pkg_files(
|
||||
name = "swift-test-sdk-arch",
|
||||
srcs = ["//swift/third_party/swift-llvm-support:swift-test-sdk"],
|
||||
@@ -76,6 +83,7 @@ pkg_filegroup(
|
||||
srcs = [
|
||||
":extractor",
|
||||
":swift-test-sdk-arch",
|
||||
":resource-dir-arch",
|
||||
] + select({
|
||||
"@platforms//os:linux": [
|
||||
":incompatible-os",
|
||||
|
||||
@@ -174,7 +174,9 @@ codeql::TrapDomain invocationTrapDomain(codeql::SwiftExtractorState& state) {
|
||||
return std::move(maybeDomain.value());
|
||||
}
|
||||
|
||||
codeql::SwiftExtractorConfiguration configure(int argc, char** argv) {
|
||||
codeql::SwiftExtractorConfiguration configure(int argc,
|
||||
char** argv,
|
||||
const std::string& resourceDir) {
|
||||
codeql::SwiftExtractorConfiguration configuration{};
|
||||
configuration.trapDir = getenv_or("CODEQL_EXTRACTOR_SWIFT_TRAP_DIR", "extractor-out/trap/swift");
|
||||
configuration.sourceArchiveDir =
|
||||
@@ -182,6 +184,13 @@ codeql::SwiftExtractorConfiguration configure(int argc, char** argv) {
|
||||
configuration.scratchDir =
|
||||
getenv_or("CODEQL_EXTRACTOR_SWIFT_SCRATCH_DIR", "extractor-out/working");
|
||||
configuration.frontendOptions.assign(argv + 1, argv + argc);
|
||||
// TODO: Should be moved to the tracer config
|
||||
for (int i = 0; i < argc - 1; i++) {
|
||||
if (std::string("-resource-dir") == configuration.frontendOptions[i]) {
|
||||
configuration.frontendOptions[i + 1] = resourceDir.c_str();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@@ -214,7 +223,9 @@ int main(int argc, char** argv, char** envp) {
|
||||
INITIALIZE_LLVM();
|
||||
initializeSwiftModules();
|
||||
|
||||
const auto configuration = configure(argc, argv);
|
||||
std::string resourceDir = getenv_or("CODEQL_EXTRACTOR_SWIFT_ROOT", ".") + "/resource-dir/" +
|
||||
getenv_or("CODEQL_PLATFORM", ".");
|
||||
const auto configuration = configure(argc, argv, resourceDir);
|
||||
LOG_INFO("calling extractor with arguments \"{}\"", argDump(argc, argv));
|
||||
LOG_DEBUG("environment:\n{}\n", envDump(envp));
|
||||
|
||||
|
||||
@@ -31,3 +31,12 @@ pkg_files(
|
||||
strip_prefix = strip_prefix.from_pkg(),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
pkg_files(
|
||||
name = "swift-resource-dir",
|
||||
srcs = glob([
|
||||
"toolchain/lib/swift/**/*",
|
||||
]),
|
||||
strip_prefix = "toolchain/lib/swift",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
@@ -17,5 +17,5 @@ _arch_override = {
|
||||
for arch in ("linux", "darwin_x86_64", "darwin_arm64")
|
||||
}),
|
||||
)
|
||||
for name in ("swift-llvm-support", "swift-test-sdk")
|
||||
for name in ("swift-llvm-support", "swift-test-sdk", "swift-resource-dir")
|
||||
]
|
||||
|
||||
@@ -6,11 +6,11 @@ QLTEST_LOG="$CODEQL_EXTRACTOR_SWIFT_LOG_DIR"/qltest.log
|
||||
|
||||
EXTRACTOR="$CODEQL_EXTRACTOR_SWIFT_ROOT/tools/$CODEQL_PLATFORM/extractor"
|
||||
SDK="$CODEQL_EXTRACTOR_SWIFT_ROOT/qltest/$CODEQL_PLATFORM/sdk"
|
||||
RESOURCE_DIR="$CODEQL_EXTRACTOR_SWIFT_ROOT/resource-dir/$CODEQL_PLATFORM"
|
||||
export CODEQL_EXTRACTOR_SWIFT_LOG_LEVELS=${CODEQL_EXTRACTOR_SWIFT_LOG_LEVELS:-out:text:no_logs,out:console:info}
|
||||
|
||||
for src in *.swift; do
|
||||
env=()
|
||||
opts=(-sdk "$SDK" -c -primary-file "$src")
|
||||
opts=(-sdk "$SDK" -resource-dir "$RESOURCE_DIR" -c -primary-file "$src")
|
||||
opts+=($(sed -n '1 s=//codeql-extractor-options:==p' $src))
|
||||
expected_status=$(sed -n 's=//codeql-extractor-expected-status:[[:space:]]*==p' $src)
|
||||
expected_status=${expected_status:-0}
|
||||
|
||||
@@ -60,7 +60,7 @@ def assert_extractor_executed_with(*flags):
|
||||
for actual, expected in itertools.zip_longest(execution, flags):
|
||||
if actual:
|
||||
actual = actual.strip()
|
||||
expected_prefix = f"-sdk {swift_root}/qltest/{platform}/sdk -c -primary-file "
|
||||
expected_prefix = f"-sdk {swift_root}/qltest/{platform}/sdk -resource-dir {swift_root}/resource-dir/{platform} -c -primary-file "
|
||||
assert actual.startswith(expected_prefix), f"correct sdk option not found in\n{actual}"
|
||||
actual = actual[len(expected_prefix):]
|
||||
assert actual, f"\nnot encountered: {expected}"
|
||||
|
||||
Reference in New Issue
Block a user