Commit cb1b1db7 authored by Drew's avatar Drew

Copyright and documentation

parent 7375e641
//
// PlatformPaths.swift
// AnarchyToolsXcode
//
// Created by Drew Crawford on 1/13/16.
// Copyright © 2016 Drew Crawford. All rights reserved.
//
// © 2016 Anarchy Tools Contributors.
// This file is part of atbuild. It is subject to the license terms in the LICENSE
// file found in the top level of this distribution
// No part of atbuild, including this file, may be copied, modified,
// propagated, or distributed except according to the terms contained
// in the LICENSE file.
import Foundation
......
// main.swift
// © 2016 Anarchy Tools Contributors.
// This file is part of atbuild. It is subject to the license terms in the LICENSE
// file found in the top level of this distribution
// No part of atbuild, including this file, may be copied, modified,
// propagated, or distributed except according to the terms contained
// in the LICENSE file.
import Foundation
///The Shell tool runs a shell script. It expects a zero return code.
final class Shell : Tool {
func run(args: [Yaml: Yaml]) throws {
guard let script = args["script"]?.string else { throw AnarchyBuildError.CantParseYaml("Invalid 'script' argument to shell tool.") }
......
// Task.swift
// © 2016 Anarchy Tools Contributors.
// This file is part of atbuild. It is subject to the license terms in the LICENSE
// file found in the top level of this distribution
// No part of atbuild, including this file, may be copied, modified,
// propagated, or distributed except according to the terms contained
// in the LICENSE file.
///A Task is a CLI entry point to `atbuild`. If you call `atbuild` with no arguments, we run a task called "default".
final class Task {
let tool: String
let name: String
let yaml: [Yaml: Yaml]
let tool: String ///The tool that implements this task. See Tools.swift
let name: String ///The name of this task as it appears in the configuration file
let yaml: [Yaml: Yaml] ///The full YAML description of the task
init(yaml: [Yaml:Yaml], name: String) throws {
self.yaml = yaml
self.name = name
......
// Tools.swift
// © 2016 Anarchy Tools Contributors.
// This file is part of atbuild. It is subject to the license terms in the LICENSE
// file found in the top level of this distribution
// No part of atbuild, including this file, may be copied, modified,
// propagated, or distributed except according to the terms contained
// in the LICENSE file.
///A tool is a function that performs some operation, like building, or running a shell command.
///We provide several builtin tools, but users can build new ones out of the existing ones.
protocol Tool {
func run(args: [Yaml: Yaml]) throws
}
///The builtin tools.
let tools : [String: Tool] = ["shell":Shell(),"atllbuild":ATllbuild()]
///Look up a tool by name. Throws if there is no such tool.
func toolByName(name: String) throws -> Tool {
guard let tool = tools[name] else { throw AnarchyBuildError.CantParseYaml("Unknown build tool \(name)") }
return tool
......
// atllbuild.swift
// © 2016 Anarchy Tools Contributors.
// This file is part of atbuild. It is subject to the license terms in the LICENSE
// file found in the top level of this distribution
// No part of atbuild, including this file, may be copied, modified,
// propagated, or distributed except according to the terms contained
// in the LICENSE file.
import Foundation
/**The ATllbuild tool builds a swift module via llbuild.
For more information on this tool, see `docs/attllbuild.md` */
final class ATllbuild : Tool {
/**This function resolves wildcards in source descriptions to complete values
- parameter sourceDescriptions: a descriptions of sources such as ["src/**.swift"] */
- returns: A list of resolved sources such as ["src/a.swift", "src/b.swift"]
*/
func collectSources(sourceDescriptions: [String]) -> [String] {
var sources : [String] = []
for description in sourceDescriptions {
......@@ -22,6 +36,11 @@ final class ATllbuild : Tool {
return sources
}
/**Calculates the llbuild.yaml contents for the given configuration options
- parameter sources: A resolved list of swift sources
- parameter workdir: A temporary working directory for `atllbuild` to use
- parameter modulename: The name of the module to be built.
- returns: The string contents for llbuild.yaml suitable for processing by swift-build-tool */
func llbuildyaml(sources: [String], workdir: String, modulename: String) -> String {
//this format is largely undocumented, but I reverse-engineered it from SwiftPM.
var yaml = "client:\n name: swift-build\n\n"
......@@ -115,6 +134,7 @@ final class ATllbuild : Tool {
}
try llbuildyaml(sources, workdir: workDirectory, modulename: name).writeToFile(llbuildyamlpath, atomically: false, encoding: NSUTF8StringEncoding)
if bootstrapOnly { return }
//now we try running sbt
let args = ["-f",llbuildyamlpath]
let sbt = NSTask.launchedTaskWithLaunchPath(SwiftBuildToolpath, arguments: args)
......
// config.swift
// © 2016 Anarchy Tools Contributors.
// This file is part of atbuild. It is subject to the license terms in the LICENSE
// file found in the top level of this distribution
// No part of atbuild, including this file, may be copied, modified,
// propagated, or distributed except according to the terms contained
// in the LICENSE file.
///Load the contents of atbuild.yaml
func loadyaml() throws -> [Yaml:Yaml] {
guard let yamlContents = try? String(contentsOfFile: "atbuild.yaml") else { throw AnarchyBuildError.CantParseYaml("Can't load atbuild.yaml") }
let yaml = Yaml.load(yamlContents)
......
import Foundation
// errors
// © 2016 Anarchy Tools Contributors.
// This file is part of atbuild. It is subject to the license terms in the LICENSE
// file found in the top level of this distribution
// No part of atbuild, including this file, may be copied, modified,
// propagated, or distributed except according to the terms contained
// in the LICENSE file.
enum AnarchyBuildError : ErrorType {
case CantParseYaml(String)
case ExternalToolFailed(String)
case CantParseYaml(String) ///There is a problem with your yaml file.
case ExternalToolFailed(String) ///An external tool returned a non-zero status code. The string should contain the entire invocation of the tool, so the user can debug.
}
\ No newline at end of file
// main.swift
// © 2016 Anarchy Tools Contributors.
// This file is part of atbuild. It is subject to the license terms in the LICENSE
// file found in the top level of this distribution
// No part of atbuild, including this file, may be copied, modified,
// propagated, or distributed except according to the terms contained
// in the LICENSE file.
let version = "0.1.0-dev"
import Foundation
//usage message
if Process.arguments.count > 1 && Process.arguments[1] == "--help" {
print("atbuild - Anarchy Tools Build Tool \(version)")
print("https://github.com/AnarchyTools")
......@@ -19,6 +27,7 @@ if Process.arguments.count > 1 && Process.arguments[1] == "--help" {
exit(1)
}
//load configuration
let yaml = try! loadyaml()
guard let package = yaml["package"]?.dictionary else { fatalError("No package in YAML") }
guard let name = package["name"]?.string else { fatalError("No package name") }
......@@ -31,6 +40,7 @@ func runtask(taskName: String) {
try! t.run()
}
//choose which task to run
if Process.arguments.count > 1 {
runtask(Process.arguments[1])
}
......@@ -38,4 +48,5 @@ else {
runtask("default")
}
//success message
print("Built package \(name).")
\ No newline at end of file
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