Skip to content

Commit

Permalink
Swift: improve diagnostics for OS incompatibility
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
Paolo Tranquilli committed Dec 16, 2024
1 parent 7ab06fc commit 8efd127
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 50 deletions.
21 changes: 17 additions & 4 deletions swift/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ filegroup(
)

codeql_pkg_files(
name = "autobuilder-incompatible-os",
exes = ["//swift/tools/diagnostics:autobuilder-incompatible-os"],
name = "incompatible-os",
exes = ["//swift/tools/incompatible-os"],
renames = select_os(
otherwise = {},
windows = {
"//swift/tools/incompatible-os": "extractor.exe",
},
),
)

codeql_pkg_runfiles(
Expand All @@ -42,7 +48,7 @@ pkg_filegroup(
":autobuilder-files",
],
otherwise = [
":autobuilder-incompatible-os",
":incompatible-os",
],
),
prefix = "tools/{CODEQL_PLATFORM}",
Expand All @@ -64,6 +70,13 @@ pkg_filegroup(
prefix = "tools/{CODEQL_PLATFORM}",
)

pkg_filegroup(
name = "incompatible-linux-extractor",
srcs = ["//swift/extractor:incompatible"],
prefix = "tools/{CODEQL_PLATFORM}",
target_compatible_with = ["@platforms//os:linux"],
)

codeql_pkg_files(
name = "root-files",
srcs = [
Expand All @@ -86,7 +99,7 @@ zip_map = {
":tools",
"//swift/downgrades",
] + select_os(
linux = [":extractor"] if linux_included else [],
linux = [":extractor"] if linux_included else [":incompatible-linux-extractor"],
macos = [":extractor"],
windows = [],
),
Expand Down
10 changes: 9 additions & 1 deletion swift/extractor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("//misc/bazel:pkg.bzl", "codeql_pkg_runfiles")
load("//misc/bazel:pkg.bzl", "codeql_pkg_files", "codeql_pkg_runfiles")
load("//swift:rules.bzl", "swift_cc_binary")

swift_cc_binary(
Expand Down Expand Up @@ -36,3 +36,11 @@ codeql_pkg_runfiles(
exes = [":extractor"],
visibility = ["//swift:__pkg__"],
)

codeql_pkg_files(
name = "incompatible",
exes = ["incompatible-extractor.sh"],
renames = {"incompatible-extractor.sh": "extractor"},
target_compatible_with = ["@platforms//os:linux"],
visibility = ["//swift:__pkg__"],
)
3 changes: 3 additions & 0 deletions swift/extractor/incompatible-extractor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exec -a "$0" "$(dirname $0)/incompatible-os"
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"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",
"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",
"severity": "error",
"source": {
"extractorName": "swift",
"id": "swift/autobuilder/incompatible-os",
"id": "swift/extractor/incompatible-os",
"name": "Incompatible operating system (expected macOS)"
},
"visibility": {
Expand Down
2 changes: 1 addition & 1 deletion swift/tools/autobuild.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"%CODEQL_EXTRACTOR_SWIFT_ROOT%/tools/%CODEQL_PLATFORM%/autobuilder-incompatible-os.exe"
"%CODEQL_EXTRACTOR_SWIFT_ROOT%/tools/%CODEQL_PLATFORM%/exctractor.exe"
2 changes: 1 addition & 1 deletion swift/tools/autobuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
export CODEQL_SWIFT_POD_EXEC=`which pod`
exec "${CODEQL_EXTRACTOR_SWIFT_ROOT}/tools/${CODEQL_PLATFORM}/swift-autobuilder"
else
exec "${CODEQL_EXTRACTOR_SWIFT_ROOT}/tools/${CODEQL_PLATFORM}/autobuilder-incompatible-os"
exec "${CODEQL_EXTRACTOR_SWIFT_ROOT}/tools/${CODEQL_PLATFORM}/incompatible-os"
fi
39 changes: 0 additions & 39 deletions swift/tools/diagnostics/AutobuilderIncompatibleOs.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("//swift:rules.bzl", "swift_cc_binary")

swift_cc_binary(
name = "autobuilder-incompatible-os",
srcs = ["AutobuilderIncompatibleOs.cpp"],
name = "incompatible-os",
srcs = ["IncompatibleOs.cpp"],
# No restrictions (Windows allowed)
target_compatible_with = [],
visibility = ["//swift:__subpackages__"],
Expand Down
28 changes: 28 additions & 0 deletions swift/tools/incompatible-os/IncompatibleOs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Unconditionally emits a diagnostic about running the autobuilder on an incompatible, non-macOS OS
// and exits with an error code.
//
// This is implemented as a C++ binary instead of a hardcoded JSON file so we can leverage existing
// diagnostic machinery for emitting correct timestamps, generating correct file names, etc.

#include "swift/logging/SwiftLogging.h"

const std::string_view codeql::programName = "extractor";
const std::string_view codeql::extractorName = "swift";

constexpr codeql::Diagnostic incompatibleOs{
.id = "incompatible-os",
.name = "Incompatible operating system (expected macOS)",
.action = "[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"};

static codeql::Logger& logger() {
static codeql::Logger ret{"main"};
return ret;
}

int main() {
DIAGNOSE_ERROR(incompatibleOs, "Currently, Swift analysis is only supported on macOS.");
return 1;
}

0 comments on commit 8efd127

Please sign in to comment.