Skip to content

Commit 2cc574d

Browse files
committed
Swift extractor: Use a global variable for the extractor name
1 parent 39edfa3 commit 2cc574d

File tree

6 files changed

+26
-37
lines changed

6 files changed

+26
-37
lines changed

swift/extractor/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using namespace std::string_literals;
2525
using namespace codeql::main_logger;
2626

2727
const std::string_view codeql::programName = "extractor";
28+
const std::string_view codeql::extractorName = "swift";
2829

2930
// must be called before processFrontendOptions modifies output paths
3031
static void lockOutputSwiftModuleTraps(codeql::SwiftExtractorState& state,

swift/logging/SwiftDiagnostics.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace codeql {
2020

2121
extern const std::string_view programName;
22+
extern const std::string_view extractorName;
2223

2324
struct DiagnosticsLocation {
2425
std::string_view file;
@@ -52,15 +53,6 @@ class Diagnostic {
5253
error,
5354
};
5455

55-
constexpr Diagnostic(std::string_view extractorName,
56-
std::string_view id,
57-
std::string_view name,
58-
std::string_view action,
59-
Severity severity)
60-
: extractorName(extractorName), id(id), name(name), action(action), severity(severity) {}
61-
62-
std::string_view extractorName;
63-
6456
std::string_view id;
6557
std::string_view name;
6658
std::string_view action;
@@ -105,20 +97,13 @@ inline constexpr Diagnostic::Visibility operator&(Diagnostic::Visibility lhs,
10597
static_cast<unsigned char>(rhs));
10698
}
10799

108-
constexpr Diagnostic swiftDiagnostic(std::string_view id,
109-
std::string_view name,
110-
std::string_view action,
111-
Diagnostic::Severity severity = Diagnostic::Severity::error) {
112-
return Diagnostic("swift", id, name, action, severity);
113-
}
114-
115-
constexpr Diagnostic internalError = swiftDiagnostic(
116-
"internal-error", "Internal error",
117-
"Some or all of the Swift analysis may have failed.\n"
100+
constexpr Diagnostic internalError = Diagnostic{
101+
.id="internal-error", .name="Internal error",
102+
.action="Some or all of the Swift analysis may have failed.\n"
118103
"\n"
119104
"If the error persists, contact support, quoting the error message and describing what "
120105
"happened, or [open an issue in our open source repository][1].\n"
121106
"\n"
122107
"[1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md",
123-
Diagnostic::Severity::warning);
108+
.severity=Diagnostic::Severity::warning};
124109
} // namespace codeql

swift/logging/tests/assertion-diagnostics/AssertFalse.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "swift/logging/SwiftAssert.h"
22

33
const std::string_view codeql::programName = "test";
4+
const std::string_view codeql::extractorName = "swift";
45

56
static codeql::Logger& logger() {
67
static codeql::Logger ret{"main"};

swift/swift-autobuilder/BuildRunner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#include "swift/logging/SwiftLogging.h"
99
#include "swift/swift-autobuilder/CustomizingBuildLink.h"
1010

11-
constexpr codeql::Diagnostic buildCommandFailed = codeql::swiftDiagnostic(
12-
"build-command-failed", "Detected build command failed",
13-
"Set up a [manual build command][1] or [check the logs of the autobuild step][2].\n"
14-
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK "\n[2]: " CHECK_LOGS_HELP_LINK);
11+
constexpr codeql::Diagnostic buildCommandFailed = codeql::Diagnostic{
12+
.id="build-command-failed", .name="Detected build command failed",
13+
.action="Set up a [manual build command][1] or [check the logs of the autobuild step][2].\n"
14+
"\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK "\n[2]: " CHECK_LOGS_HELP_LINK};
1515

1616
static codeql::Logger& logger() {
1717
static codeql::Logger ret{"build"};

swift/swift-autobuilder/swift-autobuilder.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ static constexpr std::string_view unitTest = "com.apple.product-type.bundle.unit
1212
static constexpr std::string_view unknownType = "<unknown_target_type>";
1313

1414
const std::string_view codeql::programName = "autobuilder";
15+
const std::string_view codeql::extractorName = "swift";
1516

16-
constexpr codeql::Diagnostic noProjectFound = codeql::swiftDiagnostic(
17-
"no-project-found",
18-
"No Xcode project or workspace found",
19-
"Set up a [manual build command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK);
17+
constexpr codeql::Diagnostic noProjectFound = codeql::Diagnostic{
18+
.id="no-project-found",
19+
.name="No Xcode project or workspace found",
20+
.action="Set up a [manual build command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
2021

21-
constexpr codeql::Diagnostic noSwiftTarget = codeql::swiftDiagnostic(
22-
"no-swift-target",
23-
"No Swift compilation target found",
24-
"To analyze a custom set of source files, set up a [manual build "
25-
"command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK);
22+
constexpr codeql::Diagnostic noSwiftTarget = codeql::Diagnostic{
23+
.id="no-swift-target",
24+
.name="No Swift compilation target found",
25+
.action="To analyze a custom set of source files, set up a [manual build "
26+
"command][1].\n\n[1]: " MANUAL_BUILD_COMMAND_HELP_LINK};
2627

2728
static codeql::Logger& logger() {
2829
static codeql::Logger ret{"main"};

swift/tools/diagnostics/AutobuilderIncompatibleOs.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
#include "swift/logging/SwiftLogging.h"
88

99
const std::string_view codeql::programName = "autobuilder";
10+
const std::string_view codeql::extractorName = "swift";
1011

11-
constexpr codeql::Diagnostic incompatibleOs = codeql::swiftDiagnostic(
12-
"incompatible-os",
13-
"Incompatible operating system (expected macOS)",
14-
"[Change the Actions runner][1] to run on macOS.\n"
12+
constexpr codeql::Diagnostic incompatibleOs = codeql::Diagnostic(
13+
.id="incompatible-os",
14+
.name="Incompatible operating system (expected macOS)",
15+
.action="[Change the Actions runner][1] to run on macOS.\n"
1516
"\n"
1617
"You may be able to run analysis on Linux by setting up a [manual build command][2].\n"
1718
"\n"

0 commit comments

Comments
 (0)