Add $(CURDIR) helper to expand the base path of the spec file

This commit is contained in:
Ell Neal
2019-01-10 11:43:04 +00:00
parent 43db3254d6
commit 05fa244a89
4 changed files with 58 additions and 0 deletions
+36
View File
@@ -43,6 +43,42 @@ extension Project {
}
json = merge(dictionary: json, onto: includeDictionary)
}
let basePath = path.parent()
json = expandPaths(in: json, basePath: basePath)
return json
}
private static func expandPaths(in source: Dictionary<String, Any>, basePath: Path) -> Dictionary<String, Any> {
var result = source
for (key, value) in source {
if let value = value as? String {
result[key] = value.replacingOccurrences(of: "$(CURDIR)", with: basePath.string)
} else if let value = value as? Array<Any> {
result[key] = expandPaths(in: value, basePath: basePath)
} else if let value = value as? Dictionary<String, Any> {
result[key] = expandPaths(in: value, basePath: basePath)
}
}
return result
}
private static func expandPaths(in source: Array<Any>, basePath: Path) -> Array<Any> {
var result = source
for (index, value) in source.enumerated() {
if let value = value as? String {
result[index] = value.replacingOccurrences(of: "$(CURDIR)", with: basePath.string)
} else if let value = value as? Array<Any> {
result[index] = expandPaths(in: value, basePath: basePath)
} else if let value = value as? Dictionary<String, Any> {
result[index] = expandPaths(in: value, basePath: basePath)
}
}
return result
}
}
+8
View File
@@ -0,0 +1,8 @@
include: paths_test/included_paths_test.yml
name: NewName
targets:
NewTarget:
type: application
platform: iOS
sources:
- $(CURDIR)/source
@@ -0,0 +1,6 @@
targets:
IncludedTarget:
type: application
platform: iOS
sources:
- $(CURDIR)/source
@@ -10,6 +10,14 @@ class SpecLoadingTests: XCTestCase {
func testSpecLoader() {
describe {
$0.it("expands directories") {
let path = fixturePath + "paths_test.yml"
let project = try Project(path: path)
try expect(project.targets.first!.sources.first!.path) == (fixturePath + "paths_test" + "source").string
try expect(project.targets.last!.sources.first!.path) == (fixturePath + "source").string
}
$0.it("merges includes") {
let path = fixturePath + "include_test.yml"
let project = try Project(path: path)