mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Swift: turn internal error into a TSP warning
This commit is contained in:
@@ -8,6 +8,22 @@
|
|||||||
|
|
||||||
namespace codeql {
|
namespace codeql {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::string_view severityToString(SwiftDiagnostic::Severity severity) {
|
||||||
|
using S = SwiftDiagnostic::Severity;
|
||||||
|
switch (severity) {
|
||||||
|
case S::note:
|
||||||
|
return "note";
|
||||||
|
case S::warning:
|
||||||
|
return "warning";
|
||||||
|
case S::error:
|
||||||
|
return "error";
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
nlohmann::json SwiftDiagnostic::json(const std::chrono::system_clock::time_point& timestamp,
|
nlohmann::json SwiftDiagnostic::json(const std::chrono::system_clock::time_point& timestamp,
|
||||||
std::string_view message) const {
|
std::string_view message) const {
|
||||||
nlohmann::json ret{
|
nlohmann::json ret{
|
||||||
@@ -23,7 +39,7 @@ nlohmann::json SwiftDiagnostic::json(const std::chrono::system_clock::time_point
|
|||||||
{"cliSummaryTable", has(Visibility::cliSummaryTable)},
|
{"cliSummaryTable", has(Visibility::cliSummaryTable)},
|
||||||
{"telemetry", has(Visibility::telemetry)},
|
{"telemetry", has(Visibility::telemetry)},
|
||||||
}},
|
}},
|
||||||
{"severity", "error"},
|
{"severity", severityToString(severity)},
|
||||||
{"helpLinks", std::vector<std::string_view>(absl::StrSplit(helpLinks, ' '))},
|
{"helpLinks", std::vector<std::string_view>(absl::StrSplit(helpLinks, ' '))},
|
||||||
{format == Format::markdown ? "markdownMessage" : "plaintextMessage",
|
{format == Format::markdown ? "markdownMessage" : "plaintextMessage",
|
||||||
absl::StrCat(message, ".\n\n", action)},
|
absl::StrCat(message, ".\n\n", action)},
|
||||||
|
|||||||
@@ -46,34 +46,43 @@ struct SwiftDiagnostic {
|
|||||||
all = 0b111,
|
all = 0b111,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Notice that Tool Status Page severity is not necessarily the same as log severity, as the
|
||||||
|
// scope is different: TSP's scope is the whole analysis, log's scope is a single run
|
||||||
|
enum class Severity {
|
||||||
|
note,
|
||||||
|
warning,
|
||||||
|
error,
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr std::string_view extractorName = "swift";
|
||||||
|
|
||||||
std::string_view id;
|
std::string_view id;
|
||||||
std::string_view name;
|
std::string_view name;
|
||||||
static constexpr std::string_view extractorName = "swift";
|
|
||||||
Format format;
|
|
||||||
std::string_view action;
|
std::string_view action;
|
||||||
|
|
||||||
|
Format format{Format::markdown};
|
||||||
|
Visibility visibility{Visibility::all};
|
||||||
|
Severity severity{Severity::error};
|
||||||
|
|
||||||
// space separated if more than 1. Not a vector to allow constexpr
|
// space separated if more than 1. Not a vector to allow constexpr
|
||||||
// TODO(C++20) with vector going constexpr this can be turned to `std::vector<std::string_view>`
|
// TODO(C++20) with vector going constexpr this can be turned to `std::vector<std::string_view>`
|
||||||
std::string_view helpLinks;
|
std::string_view helpLinks{""};
|
||||||
// for the moment, we only output errors, so no need to store the severity
|
|
||||||
|
|
||||||
Visibility visibility{Visibility::all};
|
|
||||||
|
|
||||||
std::optional<SwiftDiagnosticsLocation> location{};
|
std::optional<SwiftDiagnosticsLocation> location{};
|
||||||
|
|
||||||
// notice help links are really required only for plaintext messages, otherwise they should be
|
// notice help links are really required only for plaintext messages, otherwise they should be
|
||||||
// directly embedded in the markdown message
|
// directly embedded in the markdown message
|
||||||
|
// optional arguments can be any of
|
||||||
|
// * std::string_view for setting helpLinks
|
||||||
|
// * Severity, Visibility or Format to set the corresponding field
|
||||||
|
template <typename... OptionalArgs>
|
||||||
constexpr SwiftDiagnostic(std::string_view id,
|
constexpr SwiftDiagnostic(std::string_view id,
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
Format format,
|
std::string_view action,
|
||||||
std::string_view action = "",
|
OptionalArgs... optionalArgs)
|
||||||
std::string_view helpLinks = "",
|
: id{id}, name{name}, action{action} {
|
||||||
Visibility visibility = Visibility::all)
|
(setOptionalArg(optionalArgs), ...);
|
||||||
: id{id},
|
}
|
||||||
name{name},
|
|
||||||
format{format},
|
|
||||||
action{action},
|
|
||||||
helpLinks{helpLinks},
|
|
||||||
visibility{visibility} {}
|
|
||||||
|
|
||||||
// create a JSON diagnostics for this source with the given `timestamp` and `message`
|
// create a JSON diagnostics for this source with the given `timestamp` and `message`
|
||||||
// Depending on format, either a plaintextMessage or markdownMessage is used that includes both
|
// Depending on format, either a plaintextMessage or markdownMessage is used that includes both
|
||||||
@@ -97,6 +106,11 @@ struct SwiftDiagnostic {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool has(Visibility v) const;
|
bool has(Visibility v) const;
|
||||||
|
|
||||||
|
constexpr void setOptionalArg(std::string_view h) { helpLinks = h; }
|
||||||
|
constexpr void setOptionalArg(Format f) { format = f; }
|
||||||
|
constexpr void setOptionalArg(Visibility v) { visibility = v; }
|
||||||
|
constexpr void setOptionalArg(Severity s) { severity = s; }
|
||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr SwiftDiagnostic::Visibility operator|(SwiftDiagnostic::Visibility lhs,
|
inline constexpr SwiftDiagnostic::Visibility operator|(SwiftDiagnostic::Visibility lhs,
|
||||||
@@ -114,9 +128,12 @@ inline constexpr SwiftDiagnostic::Visibility operator&(SwiftDiagnostic::Visibili
|
|||||||
constexpr SwiftDiagnostic internalError{
|
constexpr SwiftDiagnostic internalError{
|
||||||
"internal-error",
|
"internal-error",
|
||||||
"Internal error",
|
"Internal error",
|
||||||
SwiftDiagnostic::Format::plaintext,
|
"Some or all of the Swift analysis may have failed.\n"
|
||||||
/* action=*/"",
|
"\n"
|
||||||
/* helpLinks=*/"",
|
"If the error persists, contact support, quoting the error message and describing what "
|
||||||
SwiftDiagnostic::Visibility::telemetry,
|
"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,
|
||||||
};
|
};
|
||||||
} // namespace codeql
|
} // namespace codeql
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
const std::string_view codeql::programName = "autobuilder";
|
const std::string_view codeql::programName = "autobuilder";
|
||||||
|
|
||||||
constexpr codeql::SwiftDiagnostic incompatibleOs{
|
constexpr codeql::SwiftDiagnostic incompatibleOs{
|
||||||
"incompatible-os", "Incompatible operating system (expected macOS)",
|
"incompatible-os",
|
||||||
codeql::SwiftDiagnostic::Format::markdown,
|
"Incompatible operating system (expected macOS)",
|
||||||
"[Change the Actions runner][1] to run on macOS.\n"
|
"[Change the Actions runner][1] to run on macOS.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"You may be able to run analysis on Linux by setting up a [manual build command][2].\n"
|
"You may be able to run analysis on Linux by setting up a [manual build command][2].\n"
|
||||||
@@ -22,7 +22,8 @@ constexpr codeql::SwiftDiagnostic incompatibleOs{
|
|||||||
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
|
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
|
||||||
"automatically-scanning-your-code-for-vulnerabilities-and-errors/"
|
"automatically-scanning-your-code-for-vulnerabilities-and-errors/"
|
||||||
"configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-"
|
"configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-"
|
||||||
"language"};
|
"language",
|
||||||
|
};
|
||||||
|
|
||||||
static codeql::Logger& logger() {
|
static codeql::Logger& logger() {
|
||||||
static codeql::Logger ret{"main"};
|
static codeql::Logger ret{"main"};
|
||||||
|
|||||||
@@ -9,9 +9,8 @@
|
|||||||
#include "swift/xcode-autobuilder/CustomizingBuildDiagnostics.h"
|
#include "swift/xcode-autobuilder/CustomizingBuildDiagnostics.h"
|
||||||
|
|
||||||
constexpr codeql::SwiftDiagnostic buildCommandFailed{
|
constexpr codeql::SwiftDiagnostic buildCommandFailed{
|
||||||
"build-command-failed", "Detected build command failed",
|
"build-command-failed", "Detected build command failed", codeql::customizingBuildAction,
|
||||||
codeql::SwiftDiagnostic::Format::plaintext, codeql::customizingBuildAction,
|
codeql::SwiftDiagnostic::Format::plaintext, codeql::customizingBuildHelpLinks};
|
||||||
codeql::customizingBuildHelpLinks};
|
|
||||||
|
|
||||||
static codeql::Logger& logger() {
|
static codeql::Logger& logger() {
|
||||||
static codeql::Logger ret{"build"};
|
static codeql::Logger ret{"build"};
|
||||||
|
|||||||
@@ -13,18 +13,16 @@ static const char* unitTest = "com.apple.product-type.bundle.unit-test";
|
|||||||
const std::string_view codeql::programName = "autobuilder";
|
const std::string_view codeql::programName = "autobuilder";
|
||||||
|
|
||||||
constexpr codeql::SwiftDiagnostic noProjectFound{
|
constexpr codeql::SwiftDiagnostic noProjectFound{
|
||||||
"no-project-found", "No Xcode project or workspace detected",
|
"no-project-found", "No Xcode project or workspace detected", codeql::customizingBuildAction,
|
||||||
codeql::SwiftDiagnostic::Format::plaintext, codeql::customizingBuildAction,
|
codeql::SwiftDiagnostic::Format::plaintext, codeql::customizingBuildHelpLinks};
|
||||||
codeql::customizingBuildHelpLinks};
|
|
||||||
|
|
||||||
constexpr codeql::SwiftDiagnostic noSwiftTarget{
|
constexpr codeql::SwiftDiagnostic noSwiftTarget{
|
||||||
"no-swift-target", "No Swift compilation target found",
|
"no-swift-target", "No Swift compilation target found", codeql::customizingBuildAction,
|
||||||
codeql::SwiftDiagnostic::Format::plaintext, codeql::customizingBuildAction,
|
codeql::SwiftDiagnostic::Format::plaintext, codeql::customizingBuildHelpLinks};
|
||||||
codeql::customizingBuildHelpLinks};
|
|
||||||
|
|
||||||
constexpr codeql::SwiftDiagnostic spmNotSupported{
|
constexpr codeql::SwiftDiagnostic spmNotSupported{
|
||||||
"spm-not-supported", "Swift Package Manager build unsupported by autobuild",
|
"spm-not-supported", "Swift Package Manager build unsupported by autobuild",
|
||||||
codeql::SwiftDiagnostic::Format::plaintext, codeql::customizingBuildAction,
|
codeql::customizingBuildAction, codeql::SwiftDiagnostic::Format::plaintext,
|
||||||
codeql::customizingBuildHelpLinks};
|
codeql::customizingBuildHelpLinks};
|
||||||
|
|
||||||
static codeql::Logger& logger() {
|
static codeql::Logger& logger() {
|
||||||
|
|||||||
Reference in New Issue
Block a user