Skip to content

Commit 14d2e0f

Browse files
committed
adjust
1 parent 21fe519 commit 14d2e0f

File tree

5 files changed

+22
-145
lines changed

5 files changed

+22
-145
lines changed

utils/swift-xcodegen/Sources/SwiftXcodeGen/BuildArgs/SwiftDriverUtils.swift

Lines changed: 0 additions & 126 deletions
This file was deleted.

utils/swift-xcodegen/Sources/SwiftXcodeGen/BuildArgs/SwiftTargets.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ struct SwiftTargets {
111111
func getSources(
112112
from edge: NinjaBuildFile.BuildEdge, buildDir: RepoBuildDir
113113
) throws -> SwiftTarget.Sources {
114-
// If we have SWIFT_SOURCES defined, use it, otherwise check the rule
115-
// inputs.
116114
let files: [AnyPath] = edge.inputs.map(AnyPath.init)
117115

118116
// Split the files into repo sources and external sources. Repo sources

utils/swift-xcodegen/Sources/SwiftXcodeGen/Ninja/NinjaBuildFile.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ fileprivate enum NinjaCommandLineError: Error {
9797
extension NinjaBuildFile {
9898

9999
func commandLine(for edge: BuildEdge) throws -> String {
100-
guard let rule = self.rules[edge.ruleName] else {
100+
guard let rule = self.rules[edge.ruleName] else {
101101
throw NinjaCommandLineError.unknownRule(edge.ruleName)
102102
}
103103

104104
// Helper to get a substitution value for ${key}.
105-
// Note that we don't declare built-in substitions (e.g. $in, $out) for now.
105+
// Note that we don't do built-in substitutions (e.g. $in, $out) for now.
106106
func value(for key: String) -> String? {
107107
edge.bindings[key] ?? rule.bindings[key] ?? self.bindings[key]
108108
}
@@ -125,17 +125,20 @@ extension NinjaBuildFile {
125125
key = String(rest[rest.index(after: rest.startIndex)..<rightBraceIdx])
126126
rest = rest[rest.index(after: rightBraceIdx)...]
127127
} else {
128-
let keyEnd = rest.firstIndex(where: { !$0.isLetter && $0 != "_" }) ?? rest.endIndex
128+
func isBindingChar(_ c: Character) -> Bool {
129+
c.isASCII && (c.isLetter || c.isNumber || c == "_" || c == "-")
130+
}
131+
let keyEnd = rest.firstIndex(where: { !isBindingChar($0) }) ?? rest.endIndex
129132
key = String(rest[rest.startIndex..<keyEnd])
130133
rest = rest[keyEnd...]
131134
}
132135

133-
// Peform substition.
136+
// Perform substitution.
134137
if let substituted = value(for: key) {
135138
// Recursive substitutions.
136139
result += eval(string: substituted)
137140
} else {
138-
// If the value is not found, keep the variable interporation.
141+
// If the value is not found, keep the interpolation.
139142
result += string[dollarIdx..<rest.startIndex]
140143
}
141144
}

utils/swift-xcodegen/Sources/SwiftXcodeGen/Ninja/NinjaParser.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ fileprivate extension NinjaParser {
7171
typealias Rule = NinjaBuildFile.Rule
7272
typealias BuildEdge = NinjaBuildFile.BuildEdge
7373

74-
struct ParsedAttribute: Hashable {
74+
struct ParsedBinding: Hashable {
7575
var key: String
7676
var value: String
7777
}
7878

7979
enum Lexeme: Hashable {
80-
case attribute(ParsedAttribute)
80+
case binding(ParsedBinding)
8181
case element(String)
8282
case rule
8383
case build
@@ -166,15 +166,15 @@ extension NinjaParser.Lexer {
166166
})
167167
}
168168

169-
private mutating func tryConsumeAttribute(key: String) -> Lexeme? {
169+
private mutating func tryConsumeBinding(key: String) -> Lexeme? {
170170
input.tryEating { input in
171171
input.skip(while: \.isSpaceOrTab)
172172
guard input.tryEat("=") else { return nil }
173173
input.skip(while: \.isSpaceOrTab)
174174
guard let value = input.consumeUnescaped(while: { !$0.isNewline }) else {
175175
return nil
176176
}
177-
return .attribute(.init(key: key, value: value))
177+
return .binding(.init(key: key, value: value))
178178
}
179179
}
180180

@@ -216,7 +216,7 @@ extension NinjaParser.Lexer {
216216

217217
// If we're on a newline, check to see if we can lex an attribute.
218218
if isAtStartOfLine {
219-
if let attr = tryConsumeAttribute(key: element) {
219+
if let attr = tryConsumeBinding(key: element) {
220220
return attr
221221
}
222222
}
@@ -238,8 +238,8 @@ fileprivate extension NinjaParser {
238238
while let lexeme = eat(), lexeme != .newline {}
239239
}
240240

241-
mutating func parseAttribute() throws -> ParsedAttribute? {
242-
guard case let .attribute(attr) = peek else { return nil }
241+
mutating func parseBinding() throws -> ParsedBinding? {
242+
guard case let .binding(attr) = peek else { return nil }
243243
eat()
244244
tryEat(.newline)
245245
return attr
@@ -262,7 +262,7 @@ fileprivate extension NinjaParser {
262262
}
263263

264264
var bindings: [String: String] = [:]
265-
while indent < lexer.leadingTriviaCount, let binding = try parseAttribute() {
265+
while indent < lexer.leadingTriviaCount, let binding = try parseBinding() {
266266
bindings[binding.key] = binding.value
267267
}
268268

@@ -322,7 +322,7 @@ fileprivate extension NinjaParser {
322322
skipLine()
323323

324324
var bindings: [String: String] = [:]
325-
while indent < lexer.leadingTriviaCount, let binding = try parseAttribute() {
325+
while indent < lexer.leadingTriviaCount, let binding = try parseBinding() {
326326
bindings[binding.key] = binding.value
327327
}
328328

@@ -345,7 +345,7 @@ fileprivate extension NinjaParser {
345345
throw NinjaParseError.expected(.element("<path>"))
346346
}
347347

348-
let baseDirectory = self.filePath.removingLastComponent()
348+
let baseDirectory = self.filePath.parentDir!
349349
let path = AnyPath(fileName).absolute(in: baseDirectory)
350350
return try NinjaParser.parse(filePath: path, input: path.read())
351351
}
@@ -363,14 +363,15 @@ fileprivate extension NinjaParser {
363363
buildEdges.append(edge)
364364
continue
365365
}
366-
if let binding = try parseAttribute() {
366+
if let binding = try parseBinding() {
367367
bindings[binding.key] = binding.value
368368
continue
369369
}
370370
if let included = try parseInclude() {
371371
bindings.merge(included.bindings.values, uniquingKeysWith: { _, other in other })
372372
rules.merge(included.rules, uniquingKeysWith: { _, other in other })
373373
buildEdges.append(contentsOf: included.buildEdges)
374+
continue
374375
}
375376
// Ignore unknown bits of syntax like 'subninja' for now.
376377
eat()

utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/RelativePath.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public extension RelativePath {
3838
}
3939

4040
func absolute(in base: AbsolutePath) -> AbsolutePath {
41-
base.appending(self)
41+
precondition(base.isDirectory, "Expected '\(base)' to be a directory")
42+
return base.appending(self)
4243
}
4344

4445
init(_ component: Component) {

0 commit comments

Comments
 (0)