Swift extractor: Use a global variable for the extractor name

This commit is contained in:
Calum Grant
2024-01-16 10:56:18 +00:00
parent 39edfa3c14
commit 2cc574dc70
6 changed files with 26 additions and 37 deletions

View File

@@ -25,6 +25,7 @@ using namespace std::string_literals;
using namespace codeql::main_logger;
const std::string_view codeql::programName = "extractor";
const std::string_view codeql::extractorName = "swift";
// must be called before processFrontendOptions modifies output paths
static void lockOutputSwiftModuleTraps(codeql::SwiftExtractorState& state,

View File

@@ -19,6 +19,7 @@
namespace codeql {
extern const std::string_view programName;
extern const std::string_view extractorName;
struct DiagnosticsLocation {
std::string_view file;
@@ -52,15 +53,6 @@ class Diagnostic {
error,
};
constexpr Diagnostic(std::string_view extractorName,
std::string_view id,
std::string_view name,
std::string_view action,
Severity severity)
: extractorName(extractorName), id(id), name(name), action(action), severity(severity) {}
std::string_view extractorName;
std::string_view id;
std::string_view name;
std::string_view action;
@@ -105,20 +97,13 @@ inline constexpr Diagnostic::Visibility operator&(Diagnostic::Visibility lhs,
static_cast<unsigned char>(rhs));
}
constexpr Diagnostic swiftDiagnostic(std::string_view id,
std::string_view name,
std::string_view action,
Diagnostic::Severity severity = Diagnostic::Severity::error) {
return Diagnostic("swift", id, name, action, severity);
}
constexpr Diagnostic internalError = swiftDiagnostic(
"internal-error", "Internal error",
"Some or all of the Swift analysis may have failed.\n"
constexpr Diagnostic internalError = Diagnostic{
.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",
Diagnostic::Severity::warning);
.severity=Diagnostic::Severity::warning};
} // namespace codeql

View File

@@ -1,6 +1,7 @@
#include "swift/logging/SwiftAssert.h"
const std::string_view codeql::programName = "test";
const std::string_view codeql::extractorName = "swift";
static codeql::Logger& logger() {
static codeql::Logger ret{"main"};

View File

@@ -8,10 +8,10 @@
#include "swift/logging/SwiftLogging.h"
#include "swift/swift-autobuilder/CustomizingBuildLink.h"
constexpr codeql::Diagnostic buildCommandFailed = codeql::swiftDiagnostic(
"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);
constexpr codeql::Diagnostic buildCommandFailed = codeql::Diagnostic{
.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"};

View File

@@ -12,17 +12,18 @@ static constexpr std::string_view unitTest = "com.apple.product-type.bundle.unit
static constexpr std::string_view unknownType = "<unknown_target_type>";
const std::string_view codeql::programName = "autobuilder";
const std::string_view codeql::extractorName = "swift";
constexpr codeql::Diagnostic noProjectFound = codeql::swiftDiagnostic(
"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::Diagnostic noProjectFound = codeql::Diagnostic{
.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::Diagnostic noSwiftTarget = codeql::swiftDiagnostic(
"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);
constexpr codeql::Diagnostic noSwiftTarget = codeql::Diagnostic{
.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};
static codeql::Logger& logger() {
static codeql::Logger ret{"main"};

View File

@@ -7,11 +7,12 @@
#include "swift/logging/SwiftLogging.h"
const std::string_view codeql::programName = "autobuilder";
const std::string_view codeql::extractorName = "swift";
constexpr codeql::Diagnostic incompatibleOs = codeql::swiftDiagnostic(
"incompatible-os",
"Incompatible operating system (expected macOS)",
"[Change the Actions runner][1] to run on macOS.\n"
constexpr codeql::Diagnostic incompatibleOs = codeql::Diagnostic(
.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"