Skip to content

Commit b572273

Browse files
authored
Merge pull request #544 from swiftlang/automerge/merge-main-2025-06-02_09-02
Merge `release/6.2` into `main`
2 parents 475fde5 + b51f812 commit b572273

File tree

5 files changed

+99
-23
lines changed

5 files changed

+99
-23
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,7 @@ public final class BuiltinMacros {
10101010
public static let SWIFT_ENABLE_BARE_SLASH_REGEX = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_BARE_SLASH_REGEX")
10111011
public static let SWIFT_ENABLE_EMIT_CONST_VALUES = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_EMIT_CONST_VALUES")
10121012
public static let SWIFT_ENABLE_OPAQUE_TYPE_ERASURE = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_OPAQUE_TYPE_ERASURE")
1013+
public static let SWIFT_ENABLE_LANGUAGE_FEATURE_ENABLEMENT_DIAGNOSTICS = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_LANGUAGE_FEATURE_ENABLEMENT_DIAGNOSTICS")
10131014
public static let SWIFT_EMIT_CONST_VALUE_PROTOCOLS = BuiltinMacros.declareStringListMacro("SWIFT_EMIT_CONST_VALUE_PROTOCOLS")
10141015
public static let SWIFT_GENERATE_ADDITIONAL_LINKER_ARGS = BuiltinMacros.declareBooleanMacro("SWIFT_GENERATE_ADDITIONAL_LINKER_ARGS")
10151016
public static let SWIFT_USE_INTEGRATED_DRIVER = BuiltinMacros.declareBooleanMacro("SWIFT_USE_INTEGRATED_DRIVER")
@@ -2182,6 +2183,7 @@ public final class BuiltinMacros {
21822183
SWIFT_ENABLE_BARE_SLASH_REGEX,
21832184
SWIFT_ENABLE_EMIT_CONST_VALUES,
21842185
SWIFT_ENABLE_OPAQUE_TYPE_ERASURE,
2186+
SWIFT_ENABLE_LANGUAGE_FEATURE_ENABLEMENT_DIAGNOSTICS,
21852187
SWIFT_EMIT_CONST_VALUE_PROTOCOLS,
21862188
SWIFT_GENERATE_ADDITIONAL_LINKER_ARGS,
21872189
SWIFT_ENABLE_TESTABILITY,

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,9 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
14431443
}
14441444

14451445
private func diagnoseFeatureEnablement(_ cbc: CommandBuildContext, _ languageFeatureEnablementInfo: SwiftBlocklists.LanguageFeatureEnablementInfo, _ delegate: any TaskGenerationDelegate) {
1446+
guard cbc.scope.evaluate(BuiltinMacros.SWIFT_ENABLE_LANGUAGE_FEATURE_ENABLEMENT_DIAGNOSTICS) else {
1447+
return
1448+
}
14461449
let moduleName = cbc.scope.evaluate(BuiltinMacros.SWIFT_MODULE_NAME)
14471450
let otherFlags = cbc.scope.evaluate(BuiltinMacros.OTHER_SWIFT_FLAGS)
14481451
var otherFlagsFeatures: [String] = []

Sources/SWBTaskConstruction/TaskProducers/OtherTaskProducers/CustomTaskProducer.swift

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,43 @@ final class CustomTaskProducer: PhasedTaskProducer, TaskProducer {
3434
let workingDirectory = customTask.workingDirectory.map { Path(context.settings.globalScope.evaluate($0)).normalize() } ?? context.defaultWorkingDirectory
3535
let inputPaths = customTask.inputFilePaths.map { Path(context.settings.globalScope.evaluate($0)).normalize() }
3636
let inputs = inputPaths.map { delegate.createNode($0) }
37-
var outputs: [any PlannedNode] = customTask.outputFilePaths.map { Path(context.settings.globalScope.evaluate($0)).normalize() }.map { delegate.createNode($0) }
38-
37+
let outputPaths = customTask.outputFilePaths.map { Path(context.settings.globalScope.evaluate($0)).normalize() }
38+
var outputs: [any PlannedNode] = outputPaths.map { delegate.createNode($0) }
39+
40+
let md5Context = InsecureHashContext()
41+
for arg in commandLine {
42+
md5Context.add(string: arg)
43+
md5Context.add(number: 0)
44+
}
45+
md5Context.add(number: 1)
46+
for (key, value) in environment.bindingsDictionary {
47+
md5Context.add(string: key)
48+
md5Context.add(number: 0)
49+
md5Context.add(string: value)
50+
md5Context.add(number: 0)
51+
}
52+
md5Context.add(number: 1)
53+
md5Context.add(string: workingDirectory.str)
54+
md5Context.add(number: 1)
55+
for input in inputPaths {
56+
md5Context.add(string: input.str)
57+
md5Context.add(number: 0)
58+
}
59+
md5Context.add(number: 1)
60+
for output in outputPaths {
61+
md5Context.add(string: output.str)
62+
md5Context.add(number: 0)
63+
}
64+
let taskSignature = md5Context.signature.asString
65+
3966
if outputs.isEmpty {
4067
// If there are no outputs, create a virtual output that can be wired up to gates
41-
let md5Context = InsecureHashContext()
42-
for arg in commandLine {
43-
md5Context.add(string: arg)
44-
}
45-
for (key, value) in environment.bindingsDictionary {
46-
md5Context.add(string: key)
47-
md5Context.add(string: value)
48-
}
49-
md5Context.add(string: workingDirectory.str)
50-
for input in inputPaths {
51-
md5Context.add(string: input.str)
52-
}
53-
outputs.append(delegate.createVirtualNode("CustomTask-\(md5Context.signature.asString)"))
68+
outputs.append(delegate.createVirtualNode("CustomTask-\(taskSignature)"))
5469
}
5570

5671
delegate.createTask(
5772
type: CustomTaskTypeDescription.only,
58-
ruleInfo: ["CustomTask", context.settings.globalScope.evaluate(customTask.executionDescription)],
73+
ruleInfo: ["CustomTask", context.settings.globalScope.evaluate(customTask.executionDescription), taskSignature],
5974
commandLine: commandLine,
6075
environment: environment,
6176
workingDirectory: workingDirectory,

Tests/SWBBuildSystemTests/SwiftDriverTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,6 +4821,7 @@ fileprivate struct SwiftDriverTests: CoreBasedTests {
48214821
TestBuildConfiguration(
48224822
"Debug",
48234823
buildSettings: [
4824+
"SWIFT_ENABLE_LANGUAGE_FEATURE_ENABLEMENT_DIAGNOSTICS": "YES",
48244825
"PRODUCT_NAME": "$(TARGET_NAME)",
48254826
"SWIFT_VERSION": "5",
48264827
"BUILD_VARIANTS": "normal",

Tests/SWBTaskConstructionTests/CustomTaskConstructionTests.swift

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fileprivate struct CustomTaskConstructionTests: CoreBasedTests {
5959
await tester.checkBuild(runDestination: .host) { results in
6060
results.checkNoDiagnostics()
6161

62-
results.checkTask(.matchRule(["CustomTask", "My Custom Task"])) { task in
62+
results.checkTask(.matchRulePattern(["CustomTask", "My Custom Task", .any])) { task in
6363
task.checkCommandLine(["tool", "-foo", "-bar"])
6464
task.checkEnvironment(["ENVVAR": "VALUE"])
6565
#expect(task.workingDirectory == Path.root.join("working/directory"))
@@ -119,14 +119,14 @@ fileprivate struct CustomTaskConstructionTests: CoreBasedTests {
119119
await tester.checkBuild(runDestination: .host) { results in
120120
results.checkNoDiagnostics()
121121

122-
results.checkTask(.matchRule(["CustomTask", "My Custom Task"])) { task in
122+
results.checkTask(.matchRulePattern(["CustomTask", "My Custom Task", .any])) { task in
123123
task.checkCommandLine(["tool", "-foo", "-bar"])
124-
results.checkTaskDoesNotFollow(task, .matchRule(["CustomTask", "My Custom Task 2"]))
124+
results.checkTaskDoesNotFollow(task, .matchRulePattern(["CustomTask", "My Custom Task 2", .any]))
125125
}
126126

127-
results.checkTask(.matchRule(["CustomTask", "My Custom Task 2"])) { task in
127+
results.checkTask(.matchRulePattern(["CustomTask", "My Custom Task 2", .any])) { task in
128128
task.checkCommandLine(["tool2", "-bar", "-foo"])
129-
results.checkTaskDoesNotFollow(task, .matchRule(["CustomTask", "My Custom Task"]))
129+
results.checkTaskDoesNotFollow(task, .matchRulePattern(["CustomTask", "My Custom Task", .any]))
130130
}
131131
}
132132
}
@@ -170,7 +170,7 @@ fileprivate struct CustomTaskConstructionTests: CoreBasedTests {
170170
await tester.checkBuild(runDestination: .host) { results in
171171
results.checkNoDiagnostics()
172172

173-
results.checkTask(.matchRule(["CustomTask", "My Custom Task"])) { task in
173+
results.checkTask(.matchRulePattern(["CustomTask", "My Custom Task", .any])) { task in
174174
task.checkCommandLine(["tool", "-foo", "-bar"])
175175
task.checkOutputs([
176176
// Virtual output
@@ -223,9 +223,64 @@ fileprivate struct CustomTaskConstructionTests: CoreBasedTests {
223223
await tester.checkBuild(runDestination: .host) { results in
224224
results.checkNoDiagnostics()
225225

226-
results.checkTask(.matchRule(["CustomTask", "My Custom Task"])) { task in
226+
results.checkTask(.matchRulePattern(["CustomTask", "My Custom Task", .any])) { task in
227227
task.checkEnvironment(["ENVVAR": "VALUE", "MY_SETTING": "FOO"])
228228
}
229229
}
230230
}
231+
232+
@Test(.requireSDKs(.host))
233+
func customTasksWithDuplicateDescriptions() async throws {
234+
let testProject = TestProject(
235+
"aProject",
236+
groupTree: TestGroup(
237+
"SomeFiles", path: "Sources",
238+
children: [
239+
TestFile("input.txt"),
240+
TestFile("input2.txt"),
241+
TestFile("main.c"),
242+
]),
243+
buildConfigurations: [
244+
TestBuildConfiguration(
245+
"Debug",
246+
buildSettings: [
247+
"GENERATE_INFOPLIST_FILE": "YES",
248+
"PRODUCT_NAME": "$(TARGET_NAME)",
249+
"SDKROOT": "auto",
250+
]),
251+
],
252+
targets: [
253+
TestStandardTarget(
254+
"CoreFoo", type: .framework,
255+
buildPhases: [
256+
TestSourcesBuildPhase(["main.c"])
257+
],
258+
customTasks: [
259+
TestCustomTask(
260+
commandLine: ["tool", "-foo", "-bar"],
261+
environment: ["ENVVAR": "VALUE"],
262+
workingDirectory: Path.root.join("working/directory").str,
263+
executionDescription: "My Custom Task",
264+
inputs: ["$(SRCROOT)/Sources/input.txt"],
265+
outputs: [Path.root.join("output").str],
266+
enableSandboxing: false,
267+
preparesForIndexing: false),
268+
TestCustomTask(
269+
commandLine: ["tool", "-foo", "-bar"],
270+
environment: ["ENVVAR": "VALUE"],
271+
workingDirectory: Path.root.join("working/directory").str,
272+
executionDescription: "My Custom Task",
273+
inputs: ["$(SRCROOT)/Sources/input2.txt"],
274+
outputs: [Path.root.join("output2").str],
275+
enableSandboxing: false,
276+
preparesForIndexing: false)
277+
]
278+
),
279+
])
280+
let tester = try await TaskConstructionTester(getCore(), testProject)
281+
await tester.checkBuild(runDestination: .host) { results in
282+
// Ensure we don't incorrectly diagnose duplicate custom tasks
283+
results.checkNoDiagnostics()
284+
}
285+
}
231286
}

0 commit comments

Comments
 (0)