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; using namespace codeql::main_logger;
const std::string_view codeql::programName = "extractor"; const std::string_view codeql::programName = "extractor";
const std::string_view codeql::extractorName = "swift";
// must be called before processFrontendOptions modifies output paths // must be called before processFrontendOptions modifies output paths
static void lockOutputSwiftModuleTraps(codeql::SwiftExtractorState& state, static void lockOutputSwiftModuleTraps(codeql::SwiftExtractorState& state,

View File

@@ -19,6 +19,7 @@
namespace codeql { namespace codeql {
extern const std::string_view programName; extern const std::string_view programName;
extern const std::string_view extractorName;
struct DiagnosticsLocation { struct DiagnosticsLocation {
std::string_view file; std::string_view file;
@@ -52,15 +53,6 @@ class Diagnostic {
error, 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 id;
std::string_view name; std::string_view name;
std::string_view action; std::string_view action;
@@ -105,20 +97,13 @@ inline constexpr Diagnostic::Visibility operator&(Diagnostic::Visibility lhs,
static_cast<unsigned char>(rhs)); static_cast<unsigned char>(rhs));
} }
constexpr Diagnostic swiftDiagnostic(std::string_view id, constexpr Diagnostic internalError = Diagnostic{
std::string_view name, .id="internal-error", .name="Internal error",
std::string_view action, .action="Some or all of the Swift analysis may have failed.\n"
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"
"\n" "\n"
"If the error persists, contact support, quoting the error message and describing what " "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" "happened, or [open an issue in our open source repository][1].\n"
"\n" "\n"
"[1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md", "[1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md",
Diagnostic::Severity::warning); .severity=Diagnostic::Severity::warning};
} // namespace codeql } // namespace codeql

View File

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

View File

@@ -8,10 +8,10 @@
#include "swift/logging/SwiftLogging.h" #include "swift/logging/SwiftLogging.h"
#include "swift/swift-autobuilder/CustomizingBuildLink.h" #include "swift/swift-autobuilder/CustomizingBuildLink.h"
constexpr codeql::Diagnostic buildCommandFailed = codeql::swiftDiagnostic( constexpr codeql::Diagnostic buildCommandFailed = codeql::Diagnostic{
"build-command-failed", "Detected build command failed", .id="build-command-failed", .name="Detected build command failed",
"Set up a [manual build command][1] or [check the logs of the autobuild step][2].\n" .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); "\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK "\n[2]: " CHECK_LOGS_HELP_LINK};
static codeql::Logger& logger() { static codeql::Logger& logger() {
static codeql::Logger ret{"build"}; 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>"; static constexpr std::string_view unknownType = "<unknown_target_type>";
const std::string_view codeql::programName = "autobuilder"; const std::string_view codeql::programName = "autobuilder";
const std::string_view codeql::extractorName = "swift";
constexpr codeql::Diagnostic noProjectFound = codeql::swiftDiagnostic( constexpr codeql::Diagnostic noProjectFound = codeql::Diagnostic{
"no-project-found", .id="no-project-found",
"No Xcode project or workspace found", .name="No Xcode project or workspace found",
"Set up a [manual build command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK); .action="Set up a [manual build command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
constexpr codeql::Diagnostic noSwiftTarget = codeql::swiftDiagnostic( constexpr codeql::Diagnostic noSwiftTarget = codeql::Diagnostic{
"no-swift-target", .id="no-swift-target",
"No Swift compilation target found", .name="No Swift compilation target found",
"To analyze a custom set of source files, set up a [manual build " .action="To analyze a custom set of source files, set up a [manual build "
"command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK); "command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
static codeql::Logger& logger() { static codeql::Logger& logger() {
static codeql::Logger ret{"main"}; static codeql::Logger ret{"main"};

View File

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