Commit 2292f34f authored by Drew's avatar Drew

Preliminary configuration support

Close #2
parent 932df14e
Pipeline #684 passed with stage
......@@ -21,7 +21,18 @@ import attools
let defaultBuildFile = "build.atpkg"
func loadPackageFile() -> Package {
guard let package = Package(filepath: defaultBuildFile) else {
//build configurations
var configurations : [String:String] = [:]
for (i, x) in Process.arguments.enumerate() {
if x.hasPrefix("--") {
let configurationName = x.substringFromIndex(x.startIndex.advancedBy(2))
let configurationValue = Process.arguments[i+1]
configurations[configurationName] = configurationValue
}
}
print("configurations \(configurations)")
guard let package = Package(filepath: defaultBuildFile, configurations: configurations) else {
print("Unable to load build file: \(defaultBuildFile)")
exit(1)
}
......@@ -57,7 +68,9 @@ func runtask(taskName: String) {
//choose which task to run
if Process.arguments.count > 1 {
runtask(Process.arguments[1])
if !Process.arguments[1].hasPrefix("--") {
runtask(Process.arguments[1])
}
}
else {
runtask("default")
......
......@@ -50,12 +50,12 @@ final public class Package {
self.name = name
}
public convenience init?(filepath: String) {
public convenience init?(filepath: String, configurations: [String: String] = [:]) {
guard let parser = Parser(filepath: filepath) else { return nil }
do {
let result = try parser.parse()
self.init(type: result)
self.init(type: result, configurations: configurations)
}
catch {
print("error: \(error)")
......@@ -63,7 +63,7 @@ final public class Package {
}
}
public init?(type: ParseType) {
public init?(type: ParseType, configurations: [String: String]) {
if type.name != "package" { return nil }
if let value = type.properties["name"]?.string { self.name = value }
......@@ -80,5 +80,33 @@ final public class Package {
}
}
}
//swap in configurations
for requestedConfiguration in configurations.keys {
let requestedConfigurationValue = configurations[requestedConfiguration]!
//find the overrides specific to this configuration
guard let parsedConfigurations = type.properties["configurations"]?.map else {
fatalError("You requested configuration --\(requestedConfiguration) but no configurations were present in the package file.")
}
guard let parsedConfiguration = parsedConfigurations[requestedConfiguration]?.map else {
fatalError("You requested configuration --\(requestedConfiguration) but we only have \(Array(parsedConfigurations.keys))")
}
guard let overrideSpecifications = parsedConfiguration[requestedConfigurationValue]?.map else {
fatalError("You requested configuration --\(requestedConfiguration) \(requestedConfigurationValue) but we only have \(Array(parsedConfiguration.keys))")
}
for taskSpec in overrideSpecifications.keys {
guard let overrideSpecification = overrideSpecifications[taskSpec]?.map else {
fatalError("Cannot get override specification for --\(requestedConfiguration) \(requestedConfigurationValue)")
}
if let task = tasks[taskSpec] {
for(k,v) in overrideSpecification {
task.kvp[k] = v
}
}
else {
fatalError("Global configurations not implemented; can't configure option \(requestedConfigurationValue) for non-task spec \(taskSpec)")
}
}
}
}
}
\ No newline at end of file
......@@ -10,18 +10,17 @@ commands:
<atllbuild-swiftc>:
tool: swift-compiler
executable: "/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc"
inputs: ["attools/src/atllbuild.swift", "attools/src/Nop.swift", "attools/src/PlatformPaths.swift", "attools/src/Shell.swift", "attools/src/TaskRunner.swift", "attools/src/Tools.swift"]
sources: ["attools/src/atllbuild.swift", "attools/src/Nop.swift", "attools/src/PlatformPaths.swift", "attools/src/Shell.swift", "attools/src/TaskRunner.swift", "attools/src/Tools.swift"]
objects: [".atllbuild/objects/atllbuild.swift.o", ".atllbuild/objects/Nop.swift.o", ".atllbuild/objects/PlatformPaths.swift.o", ".atllbuild/objects/Shell.swift.o", ".atllbuild/objects/TaskRunner.swift.o", ".atllbuild/objects/Tools.swift.o"]
outputs: ["<atllbuild-swiftc>", ".atllbuild/objects/atllbuild.swift.o", ".atllbuild/objects/Nop.swift.o", ".atllbuild/objects/PlatformPaths.swift.o", ".atllbuild/objects/Shell.swift.o", ".atllbuild/objects/TaskRunner.swift.o", ".atllbuild/objects/Tools.swift.o"]
is-library: true
module-name: attools
module-output-path: .atllbuild/products/attools.swiftmodule
inputs: ["atbuild/src/main.swift"]
sources: ["atbuild/src/main.swift"]
objects: [".atllbuild/objects/main.swift.o"]
outputs: ["<atllbuild-swiftc>", ".atllbuild/objects/main.swift.o"]
module-name: atbuild
module-output-path: .atllbuild/products/atbuild.swiftmodule
temps-path: .atllbuild//llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/atllbuild.swift.o", ".atllbuild/objects/Nop.swift.o", ".atllbuild/objects/PlatformPaths.swift.o", ".atllbuild/objects/Shell.swift.o", ".atllbuild/objects/TaskRunner.swift.o", ".atllbuild/objects/Tools.swift.o"]
outputs: ["<atllbuild>", ".atllbuild/products/attools.a"]
args: ["/bin/sh","-c",rm -rf .atllbuild/products/attools.a; ar cr '.atllbuild/products/attools.a' '.atllbuild/objects/atllbuild.swift.o' '.atllbuild/objects/Nop.swift.o' '.atllbuild/objects/PlatformPaths.swift.o' '.atllbuild/objects/Shell.swift.o' '.atllbuild/objects/TaskRunner.swift.o' '.atllbuild/objects/Tools.swift.o']
description: "Linking Library: .atllbuild/products/attools.a"
\ No newline at end of file
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/main.swift.o", ".atllbuild/products/attools.a", ".atllbuild/products/atpkg.a"]
outputs: ["<atllbuild>", ".atllbuild/products/atbuild"]
args: ["/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc", "-o", ".atllbuild/products/atbuild", ".atllbuild/objects/main.swift.o", ".atllbuild/products/attools.a", ".atllbuild/products/atpkg.a"]
description: Linking executable .atllbuild/products/atbuild
......@@ -16,40 +16,37 @@
(package
:name "atbuild"
:tasks {:bootstrap {:tool "shell"
:script "./bootstrap/build.sh"}
:bootstrap-osx {:tool "atllbuild"
:source ["atbuild/src/**.swift"]
:name "atbuild"
:outputType "executable"
:bootstrapOnly true
:llbuildyaml "bootstrap/bootstrap-macosx.swift-build"
:linkWithProduct ["attools.a" "atpkg.a"]
:dependencies ["bootstrap-osx-attools" "bootstrap-osx-atpkg"]
}
:bootstrap-osx-attools {
:tool "atllbuild"
:source ["attools/src/**.swift"]
:name "attools"
:outputType "static-library"
:bootstrapOnly true
:llbuildyaml "bootstrap/bootstrap-macosx-attools.swift-build"
}
:configurations {
:bootstrap {
:yes {
:atpkg {
:bootstrapOnly true
:llbuildyaml "bootstrap/bootstrap-macosx-atpkg.swift-build"
}
:attools {
:bootstrapOnly true
:llbuildyaml "bootstrap/bootstrap-macosx-attools.swift-build"
}
:atbuild {
:bootstrapOnly true
:llbuildyaml "bootstrap/bootstrap-macosx-attools.swift-build"
}
}
}
}
:tasks {
:bootstrap-osx-atpkg {
:tool "atllbuild"
:source ["atpkg/src/**.swift"]
:name "atpkg"
:outputType "static-library"
:bootstrapOnly true
:llbuildyaml "bootstrap/bootstrap-macosx-atpkg.swift-build"
:atbuild {
:tool "atllbuild"
:source ["atbuild/src/**.swift"]
:name "atbuild"
:outputType "executable"
:linkWithProduct ["attools.a" "atpkg.a"]
:dependencies ["attools" "atpkg"]
}
:atpkg {:tool "atllbuild"
:source ["atpkg/src/**.swift"]
:name "atpkg"
......
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