Commit 35359b51 authored by Drew's avatar Drew

Support for importing tasks from remote files

parent fecd5219
Pipeline #702 failed with stage
......@@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import Foundation
final public class Task {
public var key: String = ""
......@@ -75,7 +76,8 @@ final public class Package {
do {
let result = try parser.parse()
self.init(type: result, configurations: configurations)
let basepath = (filepath as NSString).stringByDeletingLastPathComponent
self.init(type: result, configurations: configurations, pathOnDisk:basepath)
}
catch {
print("error: \(error)")
......@@ -83,7 +85,7 @@ final public class Package {
}
}
public init?(type: ParseType, configurations: [String: String]) {
public init?(type: ParseType, configurations: [String: String], pathOnDisk: String) {
if type.name != "package" { return nil }
if let value = type.properties["name"]?.string { self.name = value }
......@@ -128,5 +130,19 @@ final public class Package {
}
}
}
//load imported tasks
if let imports = type.properties["import"]?.vector {
for importFile in imports {
guard let importFileString = importFile.string else { fatalError("Non-string import \(importFile)")}
guard let remotePackage = Package(filepath: pathOnDisk + "/" + importFileString, configurations: configurations) else {
fatalError("Can't load remote package \(pathOnDisk + "/" + importFileString)")
}
for task in remotePackage.tasks.keys {
self.tasks["\(remotePackage.name).\(task)"] = remotePackage.tasks[task]
}
}
}
}
}
\ No newline at end of file
......@@ -19,7 +19,8 @@ import atpkg
class PackageTests: Test {
required init() {}
let tests = [
PackageTests.testBasic
PackageTests.testBasic,
PackageTests.testImport
]
let filename = __FILE__
......@@ -32,7 +33,7 @@ class PackageTests: Test {
}
let result = try parser.parse()
guard let package = Package(type: result, configurations: [:]) else { try test.assert(false); return }
guard let package = Package(type: result, configurations: [:], pathOnDisk: "./tests/collateral") else { try test.assert(false); return }
try test.assert(package.name == "basic")
try test.assert(package.version == "0.1.0-dev")
......@@ -48,4 +49,18 @@ class PackageTests: Test {
try test.assert(task["source"]?.vector?[1].string == "lib/**.swift")
}
}
static func testImport() throws {
let filepath = "./tests/collateral/import_src.atpkg"
guard let parser = Parser(filepath: filepath) else {
print("error")
try test.assert(false); return
}
let result = try parser.parse()
guard let package = Package(type: result, configurations: [:], pathOnDisk: "./tests/collateral") else { print("error"); try test.assert(false); return }
try test.assert(package.tasks["import_dst.build"] != nil)
}
}
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