Commit f8e53f6e authored by Drew's avatar Drew

Allow `-f [file]` to specify a build file

This allows the building of files other than build.atpkg
parent 889b61b0
Pipeline #964 passed with stage
......@@ -18,20 +18,33 @@ import Foundation
import atpkg
import attools
let defaultBuildFile = "build.atpkg"
enum Options: String {
case Overlay = "--overlay"
case CustomFile = "-f"
static var allOptions : [Options] { return [Overlay, CustomFile] }
}
let defaultPackageFile = "build.atpkg"
func loadPackageFile() -> Package {
//build overlays
var overlays : [String] = []
for (i, x) in Process.arguments.enumerate() {
if x == "--overlay" {
if x == Options.Overlay.rawValue {
let overlay = Process.arguments[i+1]
overlays.append(overlay)
}
}
guard let package = Package(filepath: defaultBuildFile, overlay: overlays) else {
print("Unable to load build file: \(defaultBuildFile)")
var packageFile = defaultPackageFile
for (i, x) in Process.arguments.enumerate() {
if x == Options.CustomFile.rawValue {
packageFile = Process.arguments[i+1]
}
}
guard let package = Package(filepath: packageFile, overlay: overlays) else {
print("Unable to load build file: \(packageFile)")
exit(1)
}
......@@ -45,7 +58,7 @@ if Process.arguments.contains("--help") {
print("© 2016 Anarchy Tools Contributors.")
print("")
print("Usage:")
print("atbuild [task]")
print("atbuild [-f packagefile] [task]")
let package = loadPackageFile()
print("tasks:")
......@@ -68,9 +81,18 @@ func runtask(taskName: String) {
//choose which task to run
var run = false
if Process.arguments.count > 1 {
if !Process.arguments[1].hasPrefix("--") {
run = true
runtask(Process.arguments[1])
var i = 1
while i < Process.arguments.count {
let arg = Process.arguments[i]
if Options.allOptions.map({$0.rawValue}).contains(arg) {
i += 1
}
else {
runtask(arg)
run = true
break
}
i += 1
}
}
if !run {
......
(package
:name "nonstandard"
:tasks {
:default {
:tool "shell"
:script "echo nonstandard"
}
}
)
\ No newline at end of file
......@@ -10,6 +10,10 @@ pwd
echo "****************SELF-HOSTING TEST**************"
$ATBUILD atbuild
echo "****************NONSTANDARD TEST**************"
cd $DIR/tests/fixtures/nonstandard_package_file
$ATBUILD -f nonstandard.atpkg
echo "****************AGRESSIVE TEST**************"
cd $DIR/tests/fixtures/agressive
if $ATBUILD 2&> /tmp/warnings.txt; then
......
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