Skip to content

Commit 6f94303

Browse files
swiftlysinghowenv
authored andcommitted
Add dedicated settings flags for swift warnings
Seperate warning and errors Add tests Update test case, passing in argument Update the target swift version Update test case pattern
1 parent 7782771 commit 6f94303

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,8 @@ public final class BuiltinMacros {
10171017
public static let SWIFT_LTO = BuiltinMacros.declareEnumMacro("SWIFT_LTO") as EnumMacroDeclaration<LTOSetting>
10181018
public static let SWIFT_MODULE_NAME = BuiltinMacros.declareStringMacro("SWIFT_MODULE_NAME")
10191019
public static let SWIFT_MODULE_ALIASES = BuiltinMacros.declareStringListMacro("SWIFT_MODULE_ALIASES")
1020+
public static let SWIFT_WARNINGS_AS_WARNINGS_GROUPS = BuiltinMacros.declareStringListMacro("SWIFT_WARNINGS_AS_WARNINGS_GROUPS")
1021+
public static let SWIFT_WARNINGS_AS_ERRORS_GROUPS = BuiltinMacros.declareStringListMacro("SWIFT_WARNINGS_AS_ERRORS_GROUPS")
10201022
public static let SWIFT_OBJC_BRIDGING_HEADER = BuiltinMacros.declareStringMacro("SWIFT_OBJC_BRIDGING_HEADER")
10211023
public static let SWIFT_OBJC_INTERFACE_HEADER_NAME = BuiltinMacros.declareStringMacro("SWIFT_OBJC_INTERFACE_HEADER_NAME")
10221024
public static let SWIFT_OBJC_INTERFACE_HEADER_DIR = BuiltinMacros.declareStringMacro("SWIFT_OBJC_INTERFACE_HEADER_DIR")
@@ -2164,6 +2166,8 @@ public final class BuiltinMacros {
21642166
SWIFT_LIBRARY_PATH,
21652167
SWIFT_LTO,
21662168
SWIFT_MODULE_ALIASES,
2169+
SWIFT_WARNINGS_AS_WARNINGS_GROUPS,
2170+
SWIFT_WARNINGS_AS_ERRORS_GROUPS,
21672171
SWIFT_MODULE_NAME,
21682172
SWIFT_MODULE_ONLY_ARCHS,
21692173
SWIFT_MODULE_ONLY_MACOSX_DEPLOYMENT_TARGET,

Sources/SWBProjectModel/PIFGenerationModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,8 @@ public enum PIF {
10231023
public var SWIFT_INSTALL_OBJC_HEADER: String?
10241024
public var SWIFT_LOAD_BINARY_MACROS: [String]?
10251025
public var SWIFT_MODULE_ALIASES: [String]?
1026+
public var SWIFT_WARNINGS_AS_WARNINGS_GROUPS: [String]?
1027+
public var SWIFT_WARNINGS_AS_ERRORS_GROUPS: [String]?
10261028
public var SWIFT_OBJC_INTERFACE_HEADER_NAME: String?
10271029
public var SWIFT_OBJC_INTERFACE_HEADER_DIR: String?
10281030
public var SWIFT_OPTIMIZATION_LEVEL: String?

Sources/SWBUniversalPlatform/Specs/Swift.xcspec

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,24 @@
202202
DefaultValue = "";
203203
CommandLineFlag = "-module-alias";
204204
},
205+
{
206+
Name = "SWIFT_WARNINGS_AS_WARNINGS_GROUPS";
207+
Type = StringList;
208+
DefaultValue = "";
209+
Category = BuildOptions;
210+
DisplayName = "Diagnostic Groups Remain Warnings";
211+
Description = "Specify diagnostic groups that should remain warnings (format: '<group>')";
212+
CommandLineFlag = "-Wwarning";
213+
},
214+
{
215+
Name = "SWIFT_WARNINGS_AS_ERRORS_GROUPS";
216+
Type = StringList;
217+
DefaultValue = "";
218+
Category = BuildOptions;
219+
DisplayName = "Diagnostic Groups Treated as Errors";
220+
Description = "Specify diagnostic groups that should be treated as errors (format: '<group>')";
221+
CommandLineFlag = "-Werror";
222+
},
205223
{
206224
Name = "SWIFT_OBJC_BRIDGING_HEADER";
207225
Type = String;

Sources/SwiftBuild/ProjectModel/BuildSettings.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ extension ProjectModel {
124124
case SWIFT_ACTIVE_COMPILATION_CONDITIONS
125125
case SWIFT_IMPLEMENTS_MACROS_FOR_MODULE_NAMES
126126
case SWIFT_MODULE_ALIASES
127+
case SWIFT_WARNINGS_AS_WARNINGS_GROUPS
128+
case SWIFT_WARNINGS_AS_ERRORS_GROUPS
127129
}
128130

129131
public enum Declaration: String, Hashable, CaseIterable, Sendable {

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3917,6 +3917,94 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
39173917
results.checkNoDiagnostics()
39183918
}
39193919
}
3920+
3921+
@Test(.requireSDKs(.host))
3922+
func warningAsWarningsGroups() async throws {
3923+
try await withTemporaryDirectory { tmpDir in
3924+
let testProject = try await TestProject(
3925+
"ProjectName",
3926+
sourceRoot: tmpDir.join("srcroot"),
3927+
groupTree: TestGroup(
3928+
"SomeFiles",
3929+
children: [
3930+
TestFile("File1.swift"),
3931+
]),
3932+
targets: [
3933+
TestStandardTarget(
3934+
"TargetName",
3935+
type: .framework,
3936+
buildConfigurations: [
3937+
TestBuildConfiguration("Debug", buildSettings: [
3938+
"SWIFT_WARNINGS_AS_WARNINGS_GROUPS": "Unsafe DeprecatedDeclaration",
3939+
"SWIFT_EXEC": swiftCompilerPath.str,
3940+
"CODE_SIGN_IDENTITY": ""
3941+
]),
3942+
],
3943+
buildPhases: [
3944+
TestSourcesBuildPhase([
3945+
TestBuildFile("File1.swift"),
3946+
]),
3947+
])
3948+
])
3949+
3950+
let tester = try await TaskConstructionTester(getCore(), testProject)
3951+
3952+
try await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["SWIFT_VERSION": swiftVersion])) { results in
3953+
results.checkTarget("TargetName") { target in
3954+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
3955+
task.checkCommandLineContains([
3956+
"-Wwarning", "Unsafe",
3957+
"-Wwarning", "DeprecatedDeclaration"
3958+
])
3959+
}
3960+
}
3961+
}
3962+
}
3963+
}
3964+
3965+
@Test(.requireSDKs(.host))
3966+
func warningAsErrorsGroups() async throws {
3967+
try await withTemporaryDirectory { tmpDir in
3968+
let testProject = try await TestProject(
3969+
"ProjectName",
3970+
sourceRoot: tmpDir.join("srcroot"),
3971+
groupTree: TestGroup(
3972+
"SomeFiles",
3973+
children: [
3974+
TestFile("File1.swift"),
3975+
]),
3976+
targets: [
3977+
TestStandardTarget(
3978+
"TargetName",
3979+
type: .framework,
3980+
buildConfigurations: [
3981+
TestBuildConfiguration("Debug", buildSettings: [
3982+
"SWIFT_WARNINGS_AS_ERRORS_GROUPS": "UnknownWarningGroup PreconcurrencyImport",
3983+
"SWIFT_EXEC": swiftCompilerPath.str,
3984+
"CODE_SIGN_IDENTITY": ""
3985+
]),
3986+
],
3987+
buildPhases: [
3988+
TestSourcesBuildPhase([
3989+
TestBuildFile("File1.swift"),
3990+
]),
3991+
])
3992+
])
3993+
3994+
let tester = try await TaskConstructionTester(getCore(), testProject)
3995+
3996+
try await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["SWIFT_VERSION": swiftVersion])) { results in
3997+
results.checkTarget("TargetName") { target in
3998+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
3999+
task.checkCommandLineContains([
4000+
"-Werror", "UnknownWarningGroup",
4001+
"-Werror","PreconcurrencyImport"
4002+
])
4003+
}
4004+
}
4005+
}
4006+
}
4007+
}
39204008
}
39214009

39224010
private func XCTAssertEqual(_ lhs: EnvironmentBindings, _ rhs: [String: String], file: StaticString = #filePath, line: UInt = #line) {

0 commit comments

Comments
 (0)