Commit 9edddb6c authored by Drew's avatar Drew

Overlay strings

parent 6f68ec66
......@@ -77,29 +77,40 @@ final public class Task {
private func applyOverlay(name: String, overlay: [String: ParseValue]) -> Bool {
precondition(!appliedOverlays.contains(name), "Already applied overlay named \(name)")
for (optionName, optionValue) in overlay {
guard let vectorValue = optionValue.vector else {
fatalError("Unsupported non-vector type \(optionValue)")
}
guard let existingValue = self[optionName]?.vector else {
fatalError("Can't overlay on \(self.key)[\(optionName)]")
}
guard let optionValueVec = optionValue.vector else {
fatalError("Non-vector option value \(optionValue)")
}
var newValue = existingValue
newValue.appendContentsOf(optionValueVec)
self.kvp[optionName] = ParseValue.Vector(newValue)
switch(optionValue) {
case ParseValue.Vector(let vectorValue):
guard let existingValue = self[optionName]?.vector else {
fatalError("Can't overlay on \(self.key)[\(optionName)]")
}
//apply overlays to the model property
if optionName == "overlay" {
for overlayName in optionValueVec {
guard let overlayNameStr = overlayName.string else {
fatalError("Non-string overlayname \(overlayName)")
guard let optionValueVec = optionValue.vector else {
fatalError("Non-vector option value \(optionValue)")
}
var newValue = existingValue
newValue.appendContentsOf(optionValueVec)
self.kvp[optionName] = ParseValue.Vector(newValue)
//apply overlays to the model property
if optionName == "overlay" {
for overlayName in optionValueVec {
guard let overlayNameStr = overlayName.string else {
fatalError("Non-string overlayname \(overlayName)")
}
self.overlay.append(overlayNameStr)
}
self.overlay.append(overlayNameStr)
}
case ParseValue.StringLiteral(let str):
if let existingValue = self[optionName] {
fatalError("Can't overlay on \(self.key)[\(optionName)] which already has a value")
}
self.kvp[optionName] = ParseValue.StringLiteral(str)
default:
fatalError("Canot overlay value \(optionValue); please file a bug")
}
}
appliedOverlays.append(name)
return overlay.keys.contains("overlay")
......
......@@ -14,6 +14,12 @@
:most-awesome {
:compileOptions ["-D" "MOST_AWESOME"]
}
:stringOption {
:stringOption "stringOption"
}
:emptyVecOption {
:emptyVecOption ["OVERLAY"]
}
}
:tasks {
......
......@@ -100,6 +100,11 @@ class PackageTests: Test {
try test.assert(compileOptions4[2].string == "-D")
try test.assert(compileOptions4[3].string == "MOST_AWESOME")
guard let package5 = Package(filepath: filepath, overlay: ["stringOption"]) else { print("error"); try test.assert(false); return }
guard let stringOption = package5.tasks["build"]?["stringOption"]?.string else {
fatalError("no string option?")
}
}
static func testExportedOverlays() throws {
......
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