Commit 0c43ea3d authored by Drew's avatar Drew

Export mixins across files

See https://github.com/AnarchyTools/atbuild/issues/24
parent 43221b9c
Pipeline #743 passed with stage
......@@ -58,6 +58,9 @@ final public class Package {
public var version: String = ""
public var tasks: [String:Task] = [:]
var mixins: [String: ParseValue] = [:]
var adjustedImportPath: String = ""
/**Calculate the pruned dependency graph for the given task
- returns: A list of tasks in a reasonable order to be processed. */
public func prunedDependencyGraph(task: Task) -> [Task] {
......@@ -137,33 +140,10 @@ final public class Package {
print("Warning: configuration \(requestedConfiguration) had no effect.")
}
}
//swap in mixins
if let mixins = type.properties["mixins"]?.map {
for (name, task) in self.tasks {
for mixinName in task.mixins {
guard let mixin = mixins[mixinName]?.map else {
fatalError("Can't find mixin named \(mixinName) in \(mixins)")
}
for (optionName, optionValue) in mixin {
guard let vectorValue = optionValue.vector else {
fatalError("Unsupported non-vector type \(optionValue)")
}
guard let existingValue = task[optionName]?.vector else {
fatalError("Can't mixin to \(task.key)[\(optionName)]")
}
guard let optionValueVec = optionValue.vector else {
fatalError("Non-vector option value \(optionValue)")
}
var newValue = existingValue
newValue.appendContentsOf(optionValueVec)
task.kvp[optionName] = ParseValue.Vector(newValue)
}
}
}
}
var remotePackages: [Package] = []
//load imported tasks
//load remote packages
if let imports = type.properties["import"]?.vector {
for importFile in imports {
guard let importFileString = importFile.string else { fatalError("Non-string import \(importFile)")}
......@@ -172,11 +152,56 @@ final public class Package {
guard let remotePackage = Package(filepath: adjustedImportPath + adjustedFileName, configurations: configurations) else {
fatalError("Can't load remote package \(adjustedImportPath + adjustedFileName)")
}
for task in remotePackage.tasks.keys {
remotePackage.tasks[task]!.importedPath = adjustedImportPath
self.tasks["\(remotePackage.name).\(task)"] = remotePackage.tasks[task]
remotePackage.adjustedImportPath = adjustedImportPath
remotePackages.append(remotePackage)
}
}
//load remote mixins
for remotePackage in remotePackages {
for (mixinName, value) in remotePackage.mixins {
self.mixins["\(remotePackage.name).\(mixinName)"] = value
}
}
if let mixins = type.properties["mixins"]?.map {
for (name, mixin) in mixins {
self.mixins[name] = mixin
}
}
//swap in mixins
for (name, task) in self.tasks {
for mixinName in task.mixins {
guard let mixin = mixins[mixinName]?.map else {
fatalError("Can't find mixin named \(mixinName) in \(mixins)")
}
for (optionName, optionValue) in mixin {
guard let vectorValue = optionValue.vector else {
fatalError("Unsupported non-vector type \(optionValue)")
}
guard let existingValue = task[optionName]?.vector else {
fatalError("Can't mixin to \(task.key)[\(optionName)]")
}
guard let optionValueVec = optionValue.vector else {
fatalError("Non-vector option value \(optionValue)")
}
var newValue = existingValue
newValue.appendContentsOf(optionValueVec)
task.kvp[optionName] = ParseValue.Vector(newValue)
}
}
}
//load remote tasks
for remotePackage in remotePackages {
for task in remotePackage.tasks.keys {
remotePackage.tasks[task]!.importedPath = remotePackage.adjustedImportPath
self.tasks["\(remotePackage.name).\(task)"] = remotePackage.tasks[task]
}
}
}
}
\ No newline at end of file
(package
:name "mixins_dst"
:version "0.1.0-dev"
:mixins {
:exported-mixin {
:compileOptions ["-D" "MOST_AWESOME"]
}
}
)
\ No newline at end of file
;; A mixin sample file
(package
:name "mixins_src"
:version "0.1.0-dev"
:import ["mixins_dst.atpkg"]
:mixins {
:sample-mixin {
:compileOptions ["-D" "MORE_AWESOME"]
}
}
:tasks {
:build {
:tool "lldb-build"
:name "json-swift"
:output-type "lib"
:source [ "src/**.swift" "lib/**.swift" ]
:compileOptions ["-D" "AWESOME"]
:mixins ["sample-mixin" "mixins_dst.exported-mixin"]
}
}
)
; End of the sample.
\ No newline at end of file
......@@ -21,7 +21,8 @@ class PackageTests: Test {
let tests = [
PackageTests.testBasic,
PackageTests.testImport,
PackageTests.testMixins
PackageTests.testMixins,
PackageTests.testExportedMixins
]
let filename = __FILE__
......@@ -84,4 +85,21 @@ class PackageTests: Test {
try test.assert(compileOptions2[5].string == "MOST_AWESOME")
}
static func testExportedMixins() throws {
let filepath = "./tests/collateral/mixins_src.atpkg"
guard let package2 = Package(filepath: filepath, configurations: [:]) else { print("error"); try test.assert(false); return }
guard let compileOptions2 = package2.tasks["build"]?["compileOptions"]?.vector else {
fatalError("no compile options?")
}
try test.assert(compileOptions2.count == 6)
try test.assert(compileOptions2[0].string == "-D")
try test.assert(compileOptions2[1].string == "AWESOME")
try test.assert(compileOptions2[2].string == "-D")
try test.assert(compileOptions2[3].string == "MORE_AWESOME")
try test.assert(compileOptions2[4].string == "-D")
try test.assert(compileOptions2[5].string == "MOST_AWESOME")
}
}
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