Commit be41dddb authored by Drew's avatar Drew

Flatten overlay hierarchy

This flattens the namespace of overlays to match the flattened hierarchy of tasks
parent 7fb111c4
Pipeline #912 passed with stage
......@@ -151,7 +151,21 @@ final public class Package {
public var importedPath: String
var overlays: [String: [String: ParseValue]] = [:]
///Overlays that are a (direct) child of the receiver. These are indexed by unqualified name.
private var childOverlays: [String: [String: ParseValue]] = [:]
///Overlays that are an (indirect) child of the receiver. these are indexed by qualified name.
private var importedOverlays: [String: [String: ParseValue]] = [:]
///The union of childOverlays and importedOverlays
var overlays : [String: [String: ParseValue]] {
var arr = childOverlays
for (k,v) in importedOverlays {
arr[k] = v
}
return arr
}
var adjustedImportPath: String = ""
/**Calculate the pruned dependency graph for the given task
......@@ -229,9 +243,13 @@ final public class Package {
//load remote overlays
for remotePackage in remotePackages {
for (overlayName, value) in remotePackage.overlays {
self.overlays["\(remotePackage.name).\(overlayName)"] = value
for (overlayName, value) in remotePackage.childOverlays {
self.importedOverlays["\(remotePackage.name).\(overlayName)"] = value
}
for (overlayName, value) in remotePackage.importedOverlays {
self.importedOverlays[overlayName] = value
}
}
if let ol = type.properties["overlays"] {
guard let overlays = ol.map else {
......@@ -241,7 +259,7 @@ final public class Package {
guard let innerOverlay = overlay.map else {
fatalError("Non-map overlay \(overlay)")
}
self.overlays[name] = innerOverlay
self.childOverlays[name] = innerOverlay
}
}
......
(package
:name "a"
:import ["b.atpkg"]
:tasks {
:default {
:dependencies ["b.default"]
:name "a_default"
:overlay ["c.foo"]
}
}
)
\ No newline at end of file
(package
:name "b"
:import ["c.atpkg"]
:tasks {
:default {
:dependencies ["c.default" "foo"]
:name "b_default"
}
}
)
\ No newline at end of file
(package
:name "c"
:overlays {
:foo {
:compileOptions ["foo"]
}
}
:tasks {
:default {
:name "c_default"
}
}
)
\ No newline at end of file
......@@ -24,7 +24,8 @@ class PackageTests: Test {
PackageTests.testOverlays,
PackageTests.testExportedOverlays,
PackageTests.testChainedImports,
PackageTests.testImportPaths
PackageTests.testImportPaths,
PackageTests.testChainedImportOverlays
]
let filename = __FILE__
......@@ -41,7 +42,6 @@ class PackageTests: Test {
try test.assert(package.name == "basic")
try test.assert(package.version == "0.1.0-dev")
try test.assert(package.tasks.count == 2) //indexed twice, by qualified and unqualified name
for (key, task) in package.tasks {
try test.assert(key == "build" || key == "basic.build")
......@@ -199,7 +199,19 @@ class PackageTests: Test {
try test.assert(a_default_qualified.importedPath == "./tests/collateral/import_paths/")
try test.assert(b_default_qualified.importedPath == "./tests/collateral/import_paths/b/")
try test.assert(c_default_qualified.importedPath == "./tests/collateral/import_paths/b/c/")
}
static func testChainedImportOverlays() throws {
let filepath = "./tests/collateral/chained_import_overlays/a.atpkg"
guard let package = Package(filepath: filepath, overlay: ["b.foo"]) else { print("error"); try test.assert(false); return }
guard let a_qualified = package.tasks["a.default"] else { print("error"); try test.assert(false); return }
guard let options = a_qualified["compileOptions"]?.vector else {
fatalError("Invalid options vector")
}
try test.assert(options.count == 1)
for opt in options {
guard let str = opt.string else { fatalError("Non-string opt \(opt)")}
try test.assert(str == "foo")
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment