Commit 80d55a94 authored by Drew's avatar Drew

Merge pull request #24 from AnarchyTools/required-overlays-bug

Revise required-overlays check
parents 1e79aacd 3bf876c1
Pipeline #1542 passed with stage
......@@ -331,28 +331,6 @@ final public class Package {
}
}
//error on required overlays
for (_, task) in self.tasks {
if let requiredOverlays_v = task["required-overlays"] {
guard let requiredOverlays = requiredOverlays_v.vector else {
fatalError("Non-vector \(requiredOverlays_v)")
}
nextSet: for overlaySet_v in requiredOverlays {
guard let overlaySet = overlaySet_v.vector else {
fatalError("Non-vector \(overlaySet_v)")
}
for overlay_s in overlaySet {
guard let overlay = overlay_s.string else {
fatalError("Non-string \(overlay_s)")
}
if task.appliedOverlays.contains(overlay) { continue nextSet }
}
print("Task \(task.qualifiedName) requires at least one of \(overlaySet.map() {$0.string}) but it was not applied. Applied overlays: \(task.appliedOverlays)")
throw PackageError.RequiredOverlayNotPresent(overlaySet.map() {$0.string!})
}
}
}
//load remote tasks
for remotePackage in remotePackages {
for (_, task) in remotePackage.tasks {
......
......@@ -107,4 +107,28 @@ final public class Task {
kvp[key] = newValue
}
}
///Checks that the required overlays in the task are present. We
///allow the parsing of a file that is missing some overlays since
///those overlays may not be required for the present task.
public func checkRequiredOverlays() throws {
if let requiredOverlays_v = self["required-overlays"] {
guard let requiredOverlays = requiredOverlays_v.vector else {
fatalError("Non-vector \(requiredOverlays_v)")
}
nextSet: for overlaySet_v in requiredOverlays {
guard let overlaySet = overlaySet_v.vector else {
fatalError("Non-vector \(overlaySet_v)")
}
for overlay_s in overlaySet {
guard let overlay = overlay_s.string else {
fatalError("Non-string \(overlay_s)")
}
if self.appliedOverlays.contains(overlay) { continue nextSet }
}
print("Task \(self.qualifiedName) requires at least one of \(overlaySet.map() {$0.string}) but it was not applied. Applied overlays: \(self.appliedOverlays)")
throw PackageError.RequiredOverlayNotPresent(overlaySet.map() {$0.string!})
}
}
}
}
\ No newline at end of file
......@@ -221,7 +221,8 @@ class PackageTests: Test {
static func testRequireOverlays() throws {
let filepath = "./tests/collateral/require_overlays.atpkg"
do {
let _ = try Package(filepath: filepath, overlay: [], focusOnTask: nil)
let p = try Package(filepath: filepath, overlay: [], focusOnTask: nil)
try p.tasks["build"]?.checkRequiredOverlays()
print("Overlays were not required")
try test.assert(false)
}
......
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