Skip to content

NFC: Assert that we don't add llbuild commands with the same name twice #7698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions Sources/LLBuildManifest/LLBuildManifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,51 +226,52 @@ public struct LLBuildManifest {
targets[target, default: Target(name: target, nodes: [])].nodes.append(node)
}

private mutating func addCommand(name: String, tool: ToolProtocol) {
assert(commands[name] == nil, "already had a command named '\(name)'")
commands[name] = Command(name: name, tool: tool)
}

public mutating func addPhonyCmd(
name: String,
inputs: [Node],
outputs: [Node]
) {
assert(commands[name] == nil, "already had a command named '\(name)'")
let tool = PhonyTool(inputs: inputs, outputs: outputs)
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addTestDiscoveryCmd(
name: String,
inputs: [Node],
outputs: [Node]
) {
assert(commands[name] == nil, "already had a command named '\(name)'")
let tool = TestDiscoveryTool(inputs: inputs, outputs: outputs)
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addTestEntryPointCmd(
name: String,
inputs: [Node],
outputs: [Node]
) {
assert(commands[name] == nil, "already had a command named '\(name)'")
let tool = TestEntryPointTool(inputs: inputs, outputs: outputs)
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addCopyCmd(
name: String,
inputs: [Node],
outputs: [Node]
) {
assert(commands[name] == nil, "already had a command named '\(name)'")
let tool = CopyTool(inputs: inputs, outputs: outputs)
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addEntitlementPlistCommand(entitlement: String, outputPath: AbsolutePath) {
let inputs = WriteAuxiliary.EntitlementPlist.computeInputs(entitlement: entitlement)
let tool = WriteAuxiliaryFile(inputs: inputs, outputFilePath: outputPath)
let name = outputPath.pathString
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addWriteLinkFileListCommand(
Expand All @@ -280,7 +281,7 @@ public struct LLBuildManifest {
let inputs = WriteAuxiliary.LinkFileList.computeInputs(objects: objects)
let tool = WriteAuxiliaryFile(inputs: inputs, outputFilePath: linkFileListPath)
let name = linkFileListPath.pathString
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addWriteSourcesFileListCommand(
Expand All @@ -290,7 +291,7 @@ public struct LLBuildManifest {
let inputs = WriteAuxiliary.SourcesFileList.computeInputs(sources: sources)
let tool = WriteAuxiliaryFile(inputs: inputs, outputFilePath: sourcesFileListPath)
let name = sourcesFileListPath.pathString
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addSwiftGetVersionCommand(
Expand All @@ -300,14 +301,14 @@ public struct LLBuildManifest {
let inputs = WriteAuxiliary.SwiftGetVersion.computeInputs(swiftCompilerPath: swiftCompilerPath)
let tool = WriteAuxiliaryFile(inputs: inputs, outputFilePath: swiftVersionFilePath, alwaysOutOfDate: true)
let name = swiftVersionFilePath.pathString
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addWriteInfoPlistCommand(principalClass: String, outputPath: AbsolutePath) {
let inputs = WriteAuxiliary.XCTestInfoPlist.computeInputs(principalClass: principalClass)
let tool = WriteAuxiliaryFile(inputs: inputs, outputFilePath: outputPath)
let name = outputPath.pathString
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addWriteEmbeddedResourcesCommand(
Expand All @@ -317,17 +318,16 @@ public struct LLBuildManifest {
let inputs = WriteAuxiliary.EmbeddedResources.computeInputs(resources: resources)
let tool = WriteAuxiliaryFile(inputs: inputs, outputFilePath: outputPath)
let name = outputPath.pathString
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addPkgStructureCmd(
name: String,
inputs: [Node],
outputs: [Node]
) {
assert(commands[name] == nil, "already had a command named '\(name)'")
let tool = PackageStructureTool(inputs: inputs, outputs: outputs)
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addShellCmd(
Expand All @@ -340,7 +340,6 @@ public struct LLBuildManifest {
workingDirectory: String? = nil,
allowMissingInputs: Bool = false
) {
assert(commands[name] == nil, "already had a command named '\(name)'")
let tool = ShellTool(
description: description,
inputs: inputs,
Expand All @@ -350,7 +349,7 @@ public struct LLBuildManifest {
workingDirectory: workingDirectory,
allowMissingInputs: allowMissingInputs
)
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addSwiftFrontendCmd(
Expand All @@ -362,15 +361,14 @@ public struct LLBuildManifest {
outputs: [Node],
arguments: [String]
) {
assert(commands[name] == nil, "already had a command named '\(name)'")
let tool = SwiftFrontendTool(
moduleName: moduleName,
description: description,
inputs: inputs,
outputs: outputs,
arguments: arguments
)
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addClangCmd(
Expand All @@ -381,15 +379,14 @@ public struct LLBuildManifest {
arguments: [String],
dependencies: String? = nil
) {
assert(commands[name] == nil, "already had a command named '\(name)'")
let tool = ClangTool(
description: description,
inputs: inputs,
outputs: outputs,
arguments: arguments,
dependencies: dependencies
)
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}

public mutating func addSwiftCmd(
Expand All @@ -411,7 +408,6 @@ public struct LLBuildManifest {
outputFileMapPath: AbsolutePath,
prepareForIndexing: Bool
) {
assert(commands[name] == nil, "already had a command named '\(name)'")
let tool = SwiftCompilerTool(
inputs: inputs,
outputs: outputs,
Expand All @@ -430,6 +426,6 @@ public struct LLBuildManifest {
outputFileMapPath: outputFileMapPath,
prepareForIndexing: prepareForIndexing
)
commands[name] = Command(name: name, tool: tool)
addCommand(name: name, tool: tool)
}
}