Skip to content

Commit 21c6684

Browse files
authored
llbuild: Support is-mutated/is-command-timestamp nodes (#7020)
Dependency of #7010. Added per the llbuild documentation at https://github.com/apple/swift-llbuild/blob/a3b8d34be319f1b3ba8de53c434386419dec1f4f/docs/buildsystem.rst#L387 and a corresponding test at https://github.com/apple/swift-llbuild/blob/a3b8d34be319f1b3ba8de53c434386419dec1f4f/tests/BuildSystem/Build/mutable-outputs.llbuild#L66. Newly introduced attributes are not used anywhere yet in this PR, so technically it is NFC. I also took the opportunity to get rid of deprecated TSC dependencies in `ManifestWriter.swift`, replacing it with string interpolation instead.
1 parent 5f0023c commit 21c6684

12 files changed

+431
-231
lines changed

Sources/Build/BuildManifest/LLBuildManifestBuilder+Swift.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import struct Basics.AbsolutePath
1717
import struct Basics.RelativePath
1818
import struct Basics.TSCAbsolutePath
1919
import struct LLBuildManifest.Node
20-
import struct LLBuildManifest.BuildManifest
20+
import struct LLBuildManifest.LLBuildManifest
2121
import struct SPMBuildCore.BuildParameters
2222
import class PackageGraph.ResolvedTarget
2323
import protocol TSCBasic.FileSystem

Sources/Build/BuildManifest/LLBuildManifestBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class LLBuildManifestBuilder {
4747
/// ObservabilityScope with which to emit diagnostics
4848
public let observabilityScope: ObservabilityScope
4949

50-
public internal(set) var manifest: BuildManifest = .init()
50+
public internal(set) var manifest: LLBuildManifest = .init()
5151

5252
var buildConfig: String { self.buildParameters.configuration.dirname }
5353
var buildParameters: BuildParameters { self.plan.buildParameters }
@@ -73,7 +73,7 @@ public class LLBuildManifestBuilder {
7373

7474
/// Generate manifest at the given path.
7575
@discardableResult
76-
public func generateManifest(at path: AbsolutePath) throws -> BuildManifest {
76+
public func generateManifest(at path: AbsolutePath) throws -> LLBuildManifest {
7777
self.swiftGetVersionFiles.removeAll()
7878

7979
self.manifest.createTarget(TargetKind.main.targetName)
@@ -109,7 +109,7 @@ public class LLBuildManifestBuilder {
109109
try self.createProductCommand(description)
110110
}
111111

112-
try ManifestWriter(fileSystem: self.fileSystem).write(self.manifest, at: path)
112+
try LLBuildManifestWriter.write(self.manifest, at: path, fileSystem: self.fileSystem)
113113
return self.manifest
114114
}
115115

Sources/Build/BuildOperation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
164164
}
165165
}
166166

167-
public func getBuildManifest() throws -> LLBuildManifest.BuildManifest {
167+
public func getBuildManifest() throws -> LLBuildManifest {
168168
return try self.plan().manifest
169169
}
170170

@@ -418,7 +418,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
418418
}
419419

420420
/// Create the build plan and return the build description.
421-
private func plan() throws -> (description: BuildDescription, manifest: LLBuildManifest.BuildManifest) {
421+
private func plan() throws -> (description: BuildDescription, manifest: LLBuildManifest) {
422422
// Load the package graph.
423423
let graph = try getPackageGraph()
424424

@@ -703,7 +703,7 @@ extension BuildOperation {
703703
}
704704

705705
extension BuildDescription {
706-
static func create(with plan: BuildPlan, disableSandboxForPluginCommands: Bool, fileSystem: Basics.FileSystem, observabilityScope: ObservabilityScope) throws -> (BuildDescription, LLBuildManifest.BuildManifest) {
706+
static func create(with plan: BuildPlan, disableSandboxForPluginCommands: Bool, fileSystem: Basics.FileSystem, observabilityScope: ObservabilityScope) throws -> (BuildDescription, LLBuildManifest) {
707707
// Generate the llbuild manifest.
708708
let llbuild = LLBuildManifestBuilder(plan, disableSandboxForPluginCommands: disableSandboxForPluginCommands, fileSystem: fileSystem, observabilityScope: observabilityScope)
709709
let buildManifest = try llbuild.generateManifest(at: plan.buildParameters.llbuildManifest)

Sources/Build/BuildOperationBuildSystemDelegateHandler.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ final class TestDiscoveryCommand: CustomLLBuildCommand, TestBuildCommand {
108108
try fileSystem.writeFileContents(path, string: content)
109109
}
110110

111-
private func execute(fileSystem: Basics.FileSystem, tool: LLBuildManifest.TestDiscoveryTool) throws {
111+
private func execute(fileSystem: Basics.FileSystem, tool: TestDiscoveryTool) throws {
112112
let index = self.context.buildParameters.indexStore
113113
let api = try self.context.indexStoreAPI.get()
114114
let store = try IndexStore.open(store: TSCAbsolutePath(index), api: api)
@@ -120,7 +120,7 @@ final class TestDiscoveryCommand: CustomLLBuildCommand, TestBuildCommand {
120120
let testsByModule = Dictionary(grouping: tests, by: { $0.module.spm_mangledToC99ExtendedIdentifier() })
121121

122122
func isMainFile(_ path: AbsolutePath) -> Bool {
123-
path.basename == LLBuildManifest.TestDiscoveryTool.mainFileName
123+
path.basename == TestDiscoveryTool.mainFileName
124124
}
125125

126126
var maybeMainFile: AbsolutePath?
@@ -152,7 +152,7 @@ final class TestDiscoveryCommand: CustomLLBuildCommand, TestBuildCommand {
152152
}
153153

154154
guard let mainFile = maybeMainFile else {
155-
throw InternalError("main output (\(LLBuildManifest.TestDiscoveryTool.mainFileName)) not found")
155+
throw InternalError("main output (\(TestDiscoveryTool.mainFileName)) not found")
156156
}
157157

158158
let testsKeyword = tests.isEmpty ? "let" : "var"
@@ -200,7 +200,7 @@ final class TestDiscoveryCommand: CustomLLBuildCommand, TestBuildCommand {
200200
}
201201

202202
final class TestEntryPointCommand: CustomLLBuildCommand, TestBuildCommand {
203-
private func execute(fileSystem: Basics.FileSystem, tool: LLBuildManifest.TestEntryPointTool) throws {
203+
private func execute(fileSystem: Basics.FileSystem, tool: TestEntryPointTool) throws {
204204
// Find the inputs, which are the names of the test discovery module(s)
205205
let inputs = tool.inputs.compactMap { try? AbsolutePath(validating: $0.name) }
206206
let discoveryModuleNames = inputs.map(\.basenameWithoutExt)
@@ -209,9 +209,9 @@ final class TestEntryPointCommand: CustomLLBuildCommand, TestBuildCommand {
209209

210210
// Find the main output file
211211
guard let mainFile = outputs.first(where: { path in
212-
path.basename == LLBuildManifest.TestEntryPointTool.mainFileName
212+
path.basename == TestEntryPointTool.mainFileName
213213
}) else {
214-
throw InternalError("main file output (\(LLBuildManifest.TestEntryPointTool.mainFileName)) not found")
214+
throw InternalError("main file output (\(TestEntryPointTool.mainFileName)) not found")
215215
}
216216

217217
let testObservabilitySetup: String
@@ -290,22 +290,22 @@ public struct BuildDescription: Codable {
290290
public typealias CommandLineFlag = String
291291

292292
/// The Swift compiler invocation targets.
293-
let swiftCommands: [BuildManifest.CmdName: SwiftCompilerTool]
293+
let swiftCommands: [LLBuildManifest.CmdName: SwiftCompilerTool]
294294

295295
/// The Swift compiler frontend invocation targets.
296-
let swiftFrontendCommands: [BuildManifest.CmdName: SwiftFrontendTool]
296+
let swiftFrontendCommands: [LLBuildManifest.CmdName: SwiftFrontendTool]
297297

298298
/// The map of test discovery commands.
299-
let testDiscoveryCommands: [BuildManifest.CmdName: LLBuildManifest.TestDiscoveryTool]
299+
let testDiscoveryCommands: [LLBuildManifest.CmdName: TestDiscoveryTool]
300300

301301
/// The map of test entry point commands.
302-
let testEntryPointCommands: [BuildManifest.CmdName: LLBuildManifest.TestEntryPointTool]
302+
let testEntryPointCommands: [LLBuildManifest.CmdName: TestEntryPointTool]
303303

304304
/// The map of copy commands.
305-
let copyCommands: [BuildManifest.CmdName: LLBuildManifest.CopyTool]
305+
let copyCommands: [LLBuildManifest.CmdName: CopyTool]
306306

307307
/// The map of write commands.
308-
let writeCommands: [BuildManifest.CmdName: LLBuildManifest.WriteAuxiliaryFile]
308+
let writeCommands: [LLBuildManifest.CmdName: WriteAuxiliaryFile]
309309

310310
/// A flag that indicates this build should perform a check for whether targets only import
311311
/// their explicitly-declared dependencies
@@ -328,12 +328,12 @@ public struct BuildDescription: Codable {
328328

329329
public init(
330330
plan: BuildPlan,
331-
swiftCommands: [BuildManifest.CmdName: SwiftCompilerTool],
332-
swiftFrontendCommands: [BuildManifest.CmdName: SwiftFrontendTool],
333-
testDiscoveryCommands: [BuildManifest.CmdName: LLBuildManifest.TestDiscoveryTool],
334-
testEntryPointCommands: [BuildManifest.CmdName: LLBuildManifest.TestEntryPointTool],
335-
copyCommands: [BuildManifest.CmdName: LLBuildManifest.CopyTool],
336-
writeCommands: [BuildManifest.CmdName: LLBuildManifest.WriteAuxiliaryFile],
331+
swiftCommands: [LLBuildManifest.CmdName: SwiftCompilerTool],
332+
swiftFrontendCommands: [LLBuildManifest.CmdName: SwiftFrontendTool],
333+
testDiscoveryCommands: [LLBuildManifest.CmdName: TestDiscoveryTool],
334+
testEntryPointCommands: [LLBuildManifest.CmdName: TestEntryPointTool],
335+
copyCommands: [LLBuildManifest.CmdName: CopyTool],
336+
writeCommands: [LLBuildManifest.CmdName: WriteAuxiliaryFile],
337337
pluginDescriptions: [PluginDescription]
338338
) throws {
339339
self.swiftCommands = swiftCommands

Sources/Commands/Utilities/DOTManifestSerializer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import protocol TSCBasic.OutputByteStream
1818
public struct DOTManifestSerializer {
1919
var kindCounter = [String: Int]()
2020
var hasEmittedStyling = Set<String>()
21-
let manifest: LLBuildManifest.BuildManifest
21+
let manifest: LLBuildManifest
2222

2323
/// Creates a serializer that will serialize the given manifest.
24-
public init(manifest: LLBuildManifest.BuildManifest) {
24+
public init(manifest: LLBuildManifest) {
2525
self.manifest = manifest
2626
}
2727

Sources/LLBuildManifest/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
add_library(LLBuildManifest STATIC
10-
BuildManifest.swift
1110
Command.swift
12-
ManifestWriter.swift
11+
LLBuildManifest.swift
12+
LLBuildManifestWriter.swift
1313
Node.swift
1414
Target.swift
1515
Tools.swift)

Sources/LLBuildManifest/BuildManifest.swift renamed to Sources/LLBuildManifest/LLBuildManifest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public enum WriteAuxiliary {
161161
}
162162
}
163163

164-
public struct BuildManifest {
164+
public struct LLBuildManifest {
165165
public typealias TargetName = String
166166
public typealias CmdName = String
167167

0 commit comments

Comments
 (0)