From 8efd1270109794872b1a9e5015120ba57fb85c7a Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 16 Dec 2024 10:12:31 +0100 Subject: [PATCH 1/2] 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). --- swift/BUILD.bazel | 21 ++++++++-- swift/extractor/BUILD.bazel | 10 ++++- swift/extractor/incompatible-extractor.sh | 3 ++ .../unsupported-os/diagnostics.expected | 4 +- swift/tools/autobuild.cmd | 2 +- swift/tools/autobuild.sh | 2 +- .../diagnostics/AutobuilderIncompatibleOs.cpp | 39 ------------------- .../BUILD.bazel | 4 +- .../tools/incompatible-os/IncompatibleOs.cpp | 28 +++++++++++++ 9 files changed, 63 insertions(+), 50 deletions(-) create mode 100755 swift/extractor/incompatible-extractor.sh delete mode 100644 swift/tools/diagnostics/AutobuilderIncompatibleOs.cpp rename swift/tools/{diagnostics => incompatible-os}/BUILD.bazel (72%) create mode 100644 swift/tools/incompatible-os/IncompatibleOs.cpp diff --git a/swift/BUILD.bazel b/swift/BUILD.bazel index 45b0f6687cbd..d9a5e912668f 100644 --- a/swift/BUILD.bazel +++ b/swift/BUILD.bazel @@ -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( @@ -42,7 +48,7 @@ pkg_filegroup( ":autobuilder-files", ], otherwise = [ - ":autobuilder-incompatible-os", + ":incompatible-os", ], ), prefix = "tools/{CODEQL_PLATFORM}", @@ -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 = [ @@ -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 = [], ), diff --git a/swift/extractor/BUILD.bazel b/swift/extractor/BUILD.bazel index c96552728328..425d72146527 100644 --- a/swift/extractor/BUILD.bazel +++ b/swift/extractor/BUILD.bazel @@ -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( @@ -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__"], +) diff --git a/swift/extractor/incompatible-extractor.sh b/swift/extractor/incompatible-extractor.sh new file mode 100755 index 000000000000..2e5b31906961 --- /dev/null +++ b/swift/extractor/incompatible-extractor.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +exec -a "$0" "$(dirname $0)/incompatible-os" diff --git a/swift/ql/integration-tests/autobuilder/unsupported-os/diagnostics.expected b/swift/ql/integration-tests/autobuilder/unsupported-os/diagnostics.expected index 72b2d9f081f2..19c8a6b0752d 100644 --- a/swift/ql/integration-tests/autobuilder/unsupported-os/diagnostics.expected +++ b/swift/ql/integration-tests/autobuilder/unsupported-os/diagnostics.expected @@ -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": { diff --git a/swift/tools/autobuild.cmd b/swift/tools/autobuild.cmd index fc90f9f2f052..7895599f811e 100644 --- a/swift/tools/autobuild.cmd +++ b/swift/tools/autobuild.cmd @@ -1 +1 @@ -"%CODEQL_EXTRACTOR_SWIFT_ROOT%/tools/%CODEQL_PLATFORM%/autobuilder-incompatible-os.exe" +"%CODEQL_EXTRACTOR_SWIFT_ROOT%/tools/%CODEQL_PLATFORM%/exctractor.exe" diff --git a/swift/tools/autobuild.sh b/swift/tools/autobuild.sh index 89bf3c12435b..aa2afcf57e91 100755 --- a/swift/tools/autobuild.sh +++ b/swift/tools/autobuild.sh @@ -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 diff --git a/swift/tools/diagnostics/AutobuilderIncompatibleOs.cpp b/swift/tools/diagnostics/AutobuilderIncompatibleOs.cpp deleted file mode 100644 index c9ee7fa1ab26..000000000000 --- a/swift/tools/diagnostics/AutobuilderIncompatibleOs.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// 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 = "autobuilder"; -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" - "You 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"}; - -static codeql::Logger& logger() { - static codeql::Logger ret{"main"}; - return ret; -} - -int main() { - DIAGNOSE_ERROR(incompatibleOs, - "Currently, `autobuild` for Swift analysis is only supported on macOS."); - return 1; -} diff --git a/swift/tools/diagnostics/BUILD.bazel b/swift/tools/incompatible-os/BUILD.bazel similarity index 72% rename from swift/tools/diagnostics/BUILD.bazel rename to swift/tools/incompatible-os/BUILD.bazel index e02d6aed13b0..a834415ed9f5 100644 --- a/swift/tools/diagnostics/BUILD.bazel +++ b/swift/tools/incompatible-os/BUILD.bazel @@ -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__"], diff --git a/swift/tools/incompatible-os/IncompatibleOs.cpp b/swift/tools/incompatible-os/IncompatibleOs.cpp new file mode 100644 index 000000000000..4aecccef564f --- /dev/null +++ b/swift/tools/incompatible-os/IncompatibleOs.cpp @@ -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; +} From e4eb2697eb4987054aae7bc8ae5bdfb3f91aec0b Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 16 Dec 2024 13:44:33 +0100 Subject: [PATCH 2/2] Swift: fix typo in `autobuild.cmd` --- swift/tools/autobuild.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swift/tools/autobuild.cmd b/swift/tools/autobuild.cmd index 7895599f811e..6ca5d4c4d15f 100644 --- a/swift/tools/autobuild.cmd +++ b/swift/tools/autobuild.cmd @@ -1 +1 @@ -"%CODEQL_EXTRACTOR_SWIFT_ROOT%/tools/%CODEQL_PLATFORM%/exctractor.exe" +"%CODEQL_EXTRACTOR_SWIFT_ROOT%/tools/%CODEQL_PLATFORM%/extractor.exe"