File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
Tests/PackageLoadingTests Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -135,13 +135,27 @@ extension ManifestBuilder {
135
135
condition = try parseCondition ( conditionJSON)
136
136
}
137
137
138
+ let value = try json. get ( [ String ] . self, forKey: " value " )
139
+
140
+ // Diagnose invalid values.
141
+ for item in value {
142
+ let groups = Self . invalidValueRegex. matchGroups ( in: item) . flatMap { $0 }
143
+ if !groups. isEmpty {
144
+ let error = " the build setting ' \( name) ' contains invalid component(s): \( groups. joined ( separator: " " ) ) "
145
+ throw ManifestParseError . runtimeManifestErrors ( [ error] )
146
+ }
147
+ }
148
+
138
149
return . init(
139
150
tool: tool, name: name,
140
- value: try json . get ( " value " ) ,
151
+ value: value,
141
152
condition: condition
142
153
)
143
154
}
144
155
156
+ /// Looks for Xcode-style build setting macros "$()".
157
+ private static let invalidValueRegex = try ! RegEx ( pattern: #"(\$\(.*?\))"# )
158
+
145
159
func parseCondition( _ json: JSON ) throws -> TargetBuildSettingDescription . Condition {
146
160
let platformNames : [ String ] ? = try ? json. getArray ( " platforms " ) . map ( { try $0. get ( " name " ) } )
147
161
return . init(
Original file line number Diff line number Diff line change @@ -369,4 +369,29 @@ class PackageDescription5LoadingTests: XCTestCase {
369
369
XCTAssertNotNil ( contents)
370
370
}
371
371
}
372
+
373
+ func testInvalidBuildSettings( ) throws {
374
+ let stream = BufferedOutputByteStream ( )
375
+ stream <<< """
376
+ import PackageDescription
377
+ let package = Package(
378
+ name: " Foo " ,
379
+ targets: [
380
+ .target(
381
+ name: " Foo " ,
382
+ cSettings: [
383
+ .headerSearchPath( " $(BYE)/path/to/foo/$(SRCROOT)/$(HELLO) " ),
384
+ ]
385
+ ),
386
+ ]
387
+ )
388
+ """
389
+
390
+ do {
391
+ try loadManifestThrowing ( stream. bytes) { _ in }
392
+ XCTFail ( " Unexpected success " )
393
+ } catch ManifestParseError . runtimeManifestErrors( let errors) {
394
+ XCTAssertEqual ( errors, [ " the build setting 'headerSearchPath' contains invalid component(s): $(BYE) $(SRCROOT) $(HELLO) " ] )
395
+ }
396
+ }
372
397
}
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ extension PackageDescription5LoadingTests {
110
110
static let __allTests__PackageDescription5LoadingTests = [
111
111
( " testBasics " , testBasics) ,
112
112
( " testBuildSettings " , testBuildSettings) ,
113
+ ( " testInvalidBuildSettings " , testInvalidBuildSettings) ,
113
114
( " testPlatforms " , testPlatforms) ,
114
115
( " testSerializedDiagnostics " , testSerializedDiagnostics) ,
115
116
( " testSwiftLanguageVersion " , testSwiftLanguageVersion) ,
You can’t perform that action at this time.
0 commit comments