Skip to content

Commit 8efd127

Browse files
author
Paolo Tranquilli
committed
Swift: improve diagnostics for OS incompatibility
* do not mention any more that one might make analysis happen on Linux with advanced setup * say that outright Swift analysis is only supported on macOS, not just autobuild. * emit the error diagnostics even for traced builds, not only for autobuilds (by using a dummy `extractor` executable).
1 parent 7ab06fc commit 8efd127

File tree

9 files changed

+63
-50
lines changed

9 files changed

+63
-50
lines changed

swift/BUILD.bazel

+17-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ filegroup(
2626
)
2727

2828
codeql_pkg_files(
29-
name = "autobuilder-incompatible-os",
30-
exes = ["//swift/tools/diagnostics:autobuilder-incompatible-os"],
29+
name = "incompatible-os",
30+
exes = ["//swift/tools/incompatible-os"],
31+
renames = select_os(
32+
otherwise = {},
33+
windows = {
34+
"//swift/tools/incompatible-os": "extractor.exe",
35+
},
36+
),
3137
)
3238

3339
codeql_pkg_runfiles(
@@ -42,7 +48,7 @@ pkg_filegroup(
4248
":autobuilder-files",
4349
],
4450
otherwise = [
45-
":autobuilder-incompatible-os",
51+
":incompatible-os",
4652
],
4753
),
4854
prefix = "tools/{CODEQL_PLATFORM}",
@@ -64,6 +70,13 @@ pkg_filegroup(
6470
prefix = "tools/{CODEQL_PLATFORM}",
6571
)
6672

73+
pkg_filegroup(
74+
name = "incompatible-linux-extractor",
75+
srcs = ["//swift/extractor:incompatible"],
76+
prefix = "tools/{CODEQL_PLATFORM}",
77+
target_compatible_with = ["@platforms//os:linux"],
78+
)
79+
6780
codeql_pkg_files(
6881
name = "root-files",
6982
srcs = [
@@ -86,7 +99,7 @@ zip_map = {
8699
":tools",
87100
"//swift/downgrades",
88101
] + select_os(
89-
linux = [":extractor"] if linux_included else [],
102+
linux = [":extractor"] if linux_included else [":incompatible-linux-extractor"],
90103
macos = [":extractor"],
91104
windows = [],
92105
),

swift/extractor/BUILD.bazel

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
2-
load("//misc/bazel:pkg.bzl", "codeql_pkg_runfiles")
2+
load("//misc/bazel:pkg.bzl", "codeql_pkg_files", "codeql_pkg_runfiles")
33
load("//swift:rules.bzl", "swift_cc_binary")
44

55
swift_cc_binary(
@@ -36,3 +36,11 @@ codeql_pkg_runfiles(
3636
exes = [":extractor"],
3737
visibility = ["//swift:__pkg__"],
3838
)
39+
40+
codeql_pkg_files(
41+
name = "incompatible",
42+
exes = ["incompatible-extractor.sh"],
43+
renames = {"incompatible-extractor.sh": "extractor"},
44+
target_compatible_with = ["@platforms//os:linux"],
45+
visibility = ["//swift:__pkg__"],
46+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
exec -a "$0" "$(dirname $0)/incompatible-os"

swift/ql/integration-tests/autobuilder/unsupported-os/diagnostics.expected

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"markdownMessage": "Currently, `autobuild` for Swift analysis is only supported on macOS.\n\n[Change the Actions runner][1] to run on macOS.\n\nYou may be able to run analysis on Linux by setting up a [manual build command][2].\n\n[1]: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on\n[2]: https://docs.github.com/en/enterprise-server/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-language",
2+
"markdownMessage": "Currently, Swift analysis is only supported on macOS.\n\n[Change the Actions runner][1] to run on macOS.\n\n[1]: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on",
33
"severity": "error",
44
"source": {
55
"extractorName": "swift",
6-
"id": "swift/autobuilder/incompatible-os",
6+
"id": "swift/extractor/incompatible-os",
77
"name": "Incompatible operating system (expected macOS)"
88
},
99
"visibility": {

swift/tools/autobuild.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"%CODEQL_EXTRACTOR_SWIFT_ROOT%/tools/%CODEQL_PLATFORM%/autobuilder-incompatible-os.exe"
1+
"%CODEQL_EXTRACTOR_SWIFT_ROOT%/tools/%CODEQL_PLATFORM%/exctractor.exe"

swift/tools/autobuild.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
55
export CODEQL_SWIFT_POD_EXEC=`which pod`
66
exec "${CODEQL_EXTRACTOR_SWIFT_ROOT}/tools/${CODEQL_PLATFORM}/swift-autobuilder"
77
else
8-
exec "${CODEQL_EXTRACTOR_SWIFT_ROOT}/tools/${CODEQL_PLATFORM}/autobuilder-incompatible-os"
8+
exec "${CODEQL_EXTRACTOR_SWIFT_ROOT}/tools/${CODEQL_PLATFORM}/incompatible-os"
99
fi

swift/tools/diagnostics/AutobuilderIncompatibleOs.cpp

-39
This file was deleted.

swift/tools/diagnostics/BUILD.bazel swift/tools/incompatible-os/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
load("//swift:rules.bzl", "swift_cc_binary")
22

33
swift_cc_binary(
4-
name = "autobuilder-incompatible-os",
5-
srcs = ["AutobuilderIncompatibleOs.cpp"],
4+
name = "incompatible-os",
5+
srcs = ["IncompatibleOs.cpp"],
66
# No restrictions (Windows allowed)
77
target_compatible_with = [],
88
visibility = ["//swift:__subpackages__"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Unconditionally emits a diagnostic about running the autobuilder on an incompatible, non-macOS OS
2+
// and exits with an error code.
3+
//
4+
// This is implemented as a C++ binary instead of a hardcoded JSON file so we can leverage existing
5+
// diagnostic machinery for emitting correct timestamps, generating correct file names, etc.
6+
7+
#include "swift/logging/SwiftLogging.h"
8+
9+
const std::string_view codeql::programName = "extractor";
10+
const std::string_view codeql::extractorName = "swift";
11+
12+
constexpr codeql::Diagnostic incompatibleOs{
13+
.id = "incompatible-os",
14+
.name = "Incompatible operating system (expected macOS)",
15+
.action = "[Change the Actions runner][1] to run on macOS.\n\n"
16+
"[1]: "
17+
"https://docs.github.com/en/actions/using-workflows/"
18+
"workflow-syntax-for-github-actions#jobsjob_idruns-on"};
19+
20+
static codeql::Logger& logger() {
21+
static codeql::Logger ret{"main"};
22+
return ret;
23+
}
24+
25+
int main() {
26+
DIAGNOSE_ERROR(incompatibleOs, "Currently, Swift analysis is only supported on macOS.");
27+
return 1;
28+
}

0 commit comments

Comments
 (0)