Skip to content

Commit b214003

Browse files
authored
Merge pull request github#13131 from github/sashabu/tsp-incompatible-os
Swift: Emit a diagnostic when attempting to use the autobuilder on Linux.
2 parents 202037e + 95cd948 commit b214003

File tree

7 files changed

+89
-3
lines changed

7 files changed

+89
-3
lines changed

swift/BUILD.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ pkg_runfiles(
5757
prefix = "tools/" + codeql_platform,
5858
)
5959

60+
pkg_runfiles(
61+
name = "incompatible-os",
62+
srcs = ["//swift/tools/autobuilder-diagnostics:incompatible-os"],
63+
prefix = "tools/" + codeql_platform,
64+
)
65+
6066
pkg_files(
6167
name = "swift-test-sdk-arch",
6268
srcs = ["//swift/third_party/swift-llvm-support:swift-test-sdk"],
@@ -70,7 +76,9 @@ pkg_filegroup(
7076
":extractor",
7177
":swift-test-sdk-arch",
7278
] + select({
73-
"@platforms//os:linux": [],
79+
"@platforms//os:linux": [
80+
":incompatible-os",
81+
],
7482
"@platforms//os:macos": [
7583
":xcode-autobuilder",
7684
],

swift/integration-tests/diagnostics_test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def _load_concatenated_json(text):
4040

4141

4242
def _normalize_json(data):
43+
# at the moment helpLinks are a set within the codeql cli
44+
for e in data:
45+
e.get("helpLinks", []).sort()
4346
entries = [json.dumps(e, sort_keys=True, indent=2) for e in data]
4447
entries.sort()
4548
entries.append("")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"helpLinks": [
3+
"https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on",
4+
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning",
5+
"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"
6+
],
7+
"plaintextMessage": "CodeQL Swift analysis is currently only officially supported on macOS.\n\nChange the action runner to a macOS one. Analysis on Linux might work, but requires setting up a custom build command.",
8+
"severity": "error",
9+
"source": {
10+
"extractorName": "swift",
11+
"id": "swift/autobuilder/incompatible-os",
12+
"name": "Incompatible operating system for autobuild (expected macOS)"
13+
},
14+
"visibility": {
15+
"cliSummaryTable": true,
16+
"statusPage": true,
17+
"telemetry": true
18+
}
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from create_database_utils import *
2+
from diagnostics_test_utils import *
3+
4+
run_codeql_database_create([], lang='swift', keep_trap=True, db=None, runFunction=runUnsuccessfully)
5+
check_diagnostics()

swift/tools/autobuild.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
if [[ "$OSTYPE" == "darwin"* ]]; then
44
exec "${CODEQL_EXTRACTOR_SWIFT_ROOT}/tools/${CODEQL_PLATFORM}/xcode-autobuilder"
55
else
6-
echo "Not implemented yet"
7-
exit 1
6+
exec "${CODEQL_EXTRACTOR_SWIFT_ROOT}/tools/${CODEQL_PLATFORM}/incompatible-os"
87
fi
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("//swift:rules.bzl", "swift_cc_binary")
2+
load("//misc/bazel/cmake:cmake.bzl", "generate_cmake")
3+
4+
swift_cc_binary(
5+
name = "incompatible-os",
6+
srcs = ["IncompatibleOs.cpp"],
7+
visibility = ["//swift:__subpackages__"],
8+
deps = [
9+
"//swift/logging",
10+
],
11+
)
12+
13+
generate_cmake(
14+
name = "cmake",
15+
targets = [":incompatible-os"],
16+
visibility = ["//visibility:public"],
17+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 = "autobuilder";
10+
11+
namespace codeql_diagnostics {
12+
constexpr codeql::SwiftDiagnosticsSource incompatible_os{
13+
"incompatible_os", "Incompatible operating system for autobuild (expected macOS)",
14+
"Change the action runner to a macOS one. Analysis on Linux might work, but requires setting "
15+
"up a custom build command",
16+
"https://docs.github.com/en/actions/using-workflows/"
17+
"workflow-syntax-for-github-actions#jobsjob_idruns-on "
18+
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
19+
"automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning "
20+
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
21+
"automatically-scanning-your-code-for-vulnerabilities-and-errors/"
22+
"configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-"
23+
"language"};
24+
} // namespace codeql_diagnostics
25+
26+
static codeql::Logger& logger() {
27+
static codeql::Logger ret{"main"};
28+
return ret;
29+
}
30+
31+
int main() {
32+
DIAGNOSE_ERROR(incompatible_os,
33+
"CodeQL Swift analysis is currently only officially supported on macOS");
34+
return 1;
35+
}

0 commit comments

Comments
 (0)