mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
Add $(CURDIR) helper to expand the base path of the spec file
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user