Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion swift/extractor/trap/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,5 @@ swift_cc_library(
deps = [
"//swift/extractor/infra/file",
"//swift/logging",
"@absl//absl/numeric:bits",
],
)
4 changes: 2 additions & 2 deletions swift/extractor/trap/TrapLabel.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include <bit>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include "absl/numeric/bits.h"
#include <binlog/binlog.hpp>
#include <cmath>
#include <charconv>
Expand Down Expand Up @@ -52,7 +52,7 @@ class UntypedTrapLabel {
size_t strSize() const {
if (id_ == 0) return 2; // #0
// Number of hex digits is ceil(bit_width(id) / 4), but C++ integer division can only do floor.
return /* # */ 1 + /* hex digits */ 1 + (absl::bit_width(id_) - 1) / 4;
return /* # */ 1 + /* hex digits */ 1 + (std::bit_width(id_) - 1) / 4;
}

friend bool operator!=(UntypedTrapLabel lhs, UntypedTrapLabel rhs) { return lhs.id_ != rhs.id_; }
Expand Down
37 changes: 10 additions & 27 deletions swift/logging/SwiftDiagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ struct SwiftDiagnostic {

std::optional<SwiftDiagnosticsLocation> location{};

// optional arguments can be either Severity or Visibility to set the corresponding field.
// TODO(C++20) this constructor won't really be necessary anymore with designated initializers
template <typename... OptionalArgs>
constexpr SwiftDiagnostic(std::string_view id,
std::string_view name,
std::string_view action,
OptionalArgs... optionalArgs)
: id{id}, name{name}, action{action} {
(setOptionalArg(optionalArgs), ...);
}

// create a JSON diagnostics for this source with the given `timestamp` and Markdown `message`
// A markdownMessage is emitted that includes both the message and the action to take. The id is
// used to construct the source id in the form `swift/<prog name>/<id>`
Expand All @@ -94,13 +83,6 @@ struct SwiftDiagnostic {

private:
bool has(Visibility v) const;

constexpr void setOptionalArg(Visibility v) { visibility = v; }
constexpr void setOptionalArg(Severity s) { severity = s; }

// intentionally left undefined
template <typename T>
constexpr void setOptionalArg(T);
};

inline constexpr SwiftDiagnostic::Visibility operator|(SwiftDiagnostic::Visibility lhs,
Expand All @@ -116,14 +98,15 @@ inline constexpr SwiftDiagnostic::Visibility operator&(SwiftDiagnostic::Visibili
}

constexpr SwiftDiagnostic internalError{
"internal-error",
"Internal error",
"Some or all of the Swift analysis may have failed.\n"
"\n"
"If the error persists, contact support, quoting the error message and describing what "
"happened, or [open an issue in our open source repository][1].\n"
"\n"
"[1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md",
SwiftDiagnostic::Severity::warning,
.id = "internal-error",
.name = "Internal error",
.action =
"Some or all of the Swift analysis may have failed.\n"
"\n"
"If the error persists, contact support, quoting the error message and describing what "
"happened, or [open an issue in our open source repository][1].\n"
"\n"
"[1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md",
.severity = SwiftDiagnostic::Severity::warning,
};
} // namespace codeql
5 changes: 2 additions & 3 deletions swift/logging/SwiftLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@
#define DIAGNOSE_CRITICAL(ID, ...) DIAGNOSE_WITH_LEVEL(critical, ID, __VA_ARGS__)

#define CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX "[{}] "
// TODO(C++20) replace non-standard , ##__VA_ARGS__ with __VA_OPT__(,) __VA_ARGS__
#define DIAGNOSE_WITH_LEVEL(LEVEL, ID, FORMAT, ...) \
do { \
auto _now = ::binlog::clockNow(); \
const ::codeql::SwiftDiagnostic& _id = ID; \
::codeql::Log::diagnose(_id, std::chrono::nanoseconds{_now}, \
fmt::format(FORMAT, ##__VA_ARGS__)); \
fmt::format(FORMAT __VA_OPT__(, ) __VA_ARGS__)); \
LOG_WITH_LEVEL_AND_TIME(LEVEL, _now, CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX FORMAT, \
_id.abbreviation(), ##__VA_ARGS__); \
_id.abbreviation() __VA_OPT__(, ) __VA_ARGS__); \
} while (false)

// avoid calling into binlog's original macros
Expand Down
29 changes: 15 additions & 14 deletions swift/tools/autobuilder-diagnostics/IncompatibleOs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
const std::string_view codeql::programName = "autobuilder";

constexpr codeql::SwiftDiagnostic incompatibleOs{
"incompatible-os",
"Incompatible operating system (expected macOS)",
"[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",
.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() {
Expand Down
7 changes: 4 additions & 3 deletions swift/xcode-autobuilder/XcodeBuildRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#include "swift/xcode-autobuilder/CustomizingBuildLink.h"

constexpr codeql::SwiftDiagnostic buildCommandFailed{
"build-command-failed", "Detected build command failed",
"Set up a [manual build command][1] or [check the logs of the autobuild step][2].\n"
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK "\n[2]: " CHECK_LOGS_HELP_LINK};
.id = "build-command-failed",
.name = "Detected build command failed",
.action = "Set up a [manual build command][1] or [check the logs of the autobuild step][2].\n"
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK "\n[2]: " CHECK_LOGS_HELP_LINK};

static codeql::Logger& logger() {
static codeql::Logger ret{"build"};
Expand Down
23 changes: 12 additions & 11 deletions swift/xcode-autobuilder/xcode-autobuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ static constexpr std::string_view unknownType = "<unknown_target_type>";

const std::string_view codeql::programName = "autobuilder";

constexpr codeql::SwiftDiagnostic noProjectFound{"no-project-found",
"No Xcode project or workspace found",
"Set up a [manual build command][1].\n"
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
constexpr codeql::SwiftDiagnostic noProjectFound{
.id = "no-project-found",
.name = "No Xcode project or workspace found",
.action = "Set up a [manual build command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};

constexpr codeql::SwiftDiagnostic noSwiftTarget{
"no-swift-target", "No Swift compilation target found",
"To analyze a custom set of source files, set up a [manual build command][1].\n"
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
.id = "no-swift-target",
.name = "No Swift compilation target found",
.action = "To analyze a custom set of source files, set up a [manual build "
"command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};

constexpr codeql::SwiftDiagnostic spmNotSupported{
"spm-not-supported", "Swift Package Manager is not supported",
"Swift Package Manager builds are not currently supported by `autobuild`. Set up a [manual "
"build command][1].\n"
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
.id = "spm-not-supported",
.name = "Swift Package Manager is not supported",
.action = "Swift Package Manager builds are not currently supported by `autobuild`. Set up a "
"[manual build command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};

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