Commit 875dd392 authored by David Owens II's avatar David Owens II

Significant refactoring to support the new atpkg format.

The bootstrap scripts were also updated to build the entire product properly into libs; no more compiler flags.
Project structure simplified to at* for each of our targets.
The YAML parser completely removed.
parent c30cb26a
......@@ -12,117 +12,33 @@
// See the License for the specific language governing permissions and
// limitations under the License.
public enum OutputType {
case Executable
case StaticLibrary
case DynamicLibrary
}
public class FilePath {
public var path: String
public init(path: String) {
self.path = path
}
init?(value: ParseValue) {
guard let str = value.stringLiteral else { return nil }
self.path = str
}
}
public class Dependency {
public var name: String
public init(name: String) {
self.name = name
}
init?(value: ParseValue) {
guard let str = value.stringLiteral else { return nil }
self.name = str
}
}
public class Task {
// The required properties.
public var name: String
// The optional properties. All optional properties must have a default value.
public var dependencies: [Dependency] = []
final public class Task {
public var key: String = ""
public var dependencies: [String] = []
public var tool: String = "atllbuild"
public var sources: [FilePath] = []
public var bootstrapOnly: Bool = false
public var llbuildyaml: String = ""
public var linkSDK: Bool = false
public var compilerOptions: [String] = []
public var outputType: OutputType = OutputType.StaticLibrary
public var linkWithProduct: [String] = []
public init(name: String) {
self.name = name
}
private var kvp: [String:ParseValue]
init?(value: ParseValue, name: String) {
guard let kvp = value.map else { return nil }
if let value = kvp["name"]?.stringLiteral { self.name = value }
else {
print("ERROR: Name is a required property on task.")
return nil
}
if let value = kvp["tool"]?.stringLiteral { self.tool = value }
if let value = kvp["bootstrapOnly"]?.boolLiteral { self.bootstrapOnly = value }
if let value = kvp["llbuildyaml"]?.stringLiteral { self.llbuildyaml = value }
if let value = kvp["linkSDK"]?.boolLiteral { self.linkSDK = value }
if let value = kvp["outputType"]?.stringLiteral {
switch value {
case "lib": self.outputType = .StaticLibrary
case "static-library": self.outputType = .StaticLibrary
case "dylib": self.outputType = .DynamicLibrary
case "dynamic-library": self.outputType = .DynamicLibrary
case "exe": self.outputType = .Executable
case "executable": self.outputType = .Executable
default: print("ERROR: unsupported outputType: \(value), defaulting to: \(self.outputType)")
}
}
self.kvp = kvp
self.key = name
self.tool = kvp["tool"]?.string ?? self.tool
if let values = kvp["dependencies"]?.vector {
for value in values {
if let dep = Dependency(value: value) { self.dependencies.append(dep) }
}
}
if let values = kvp["sources"]?.vector {
for value in values {
if let filepath = FilePath(value: value) { self.sources.append(filepath) }
}
}
if let values = kvp["source"]?.vector {
for value in values {
if let filepath = FilePath(value: value) { self.sources.append(filepath) }
}
}
if let values = kvp["compilerOptions"]?.vector {
for value in values {
if let value = value.stringLiteral { self.compilerOptions.append(value) }
}
}
if let values = kvp["linkWithProduct"]?.vector {
for value in values {
if let value = value.stringLiteral { self.linkWithProduct.append(value) }
if let dep = value.string { self.dependencies.append(dep) }
}
}
}
public subscript(key: String) -> ParseValue? {
return kvp[key]
}
}
public class Package {
final public class Package {
// The required properties.
public var name: String
......@@ -134,15 +50,28 @@ public class Package {
self.name = name
}
public convenience init?(filepath: String) {
guard let parser = Parser(filepath: filepath) else { return nil }
do {
let result = try parser.parse()
self.init(type: result)
}
catch {
print("error: \(error)")
return nil
}
}
public init?(type: ParseType) {
if type.name != "package" { return nil }
if let value = type.properties["name"]?.stringLiteral { self.name = value }
if let value = type.properties["name"]?.string { self.name = value }
else {
print("ERROR: No name specified for the package.")
return nil
}
if let value = type.properties["version"]?.stringLiteral { self.version = value }
if let value = type.properties["version"]?.string { self.version = value }
if let parsedTasks = type.properties["tasks"]?.map {
for (key, value) in parsedTasks {
......
......@@ -31,22 +31,22 @@ public enum ParseValue {
}
extension ParseValue {
public var stringLiteral: String? {
public var string: String? {
if case let .StringLiteral(value) = self { return value }
return nil
}
public var integerLiteral: Int? {
public var integer: Int? {
if case let .IntegerLiteral(value) = self { return value }
return nil
}
public var floatLiteral: Double? {
public var float: Double? {
if case let .FloatLiteral(value) = self { return value }
return nil
}
public var boolLiteral: Bool? {
public var bool: Bool? {
if case let .BoolLiteral(value) = self { return value }
return nil
}
......@@ -63,12 +63,12 @@ extension ParseValue {
}
public class ParseType {
final public class ParseType {
public var name: String = ""
public var properties: [String:ParseValue] = [:]
}
public class Parser {
final public class Parser {
let lexer: Lexer
private func next() -> Token? {
......
......@@ -18,7 +18,7 @@ public struct ScannerInfo {
public let column: Int
}
public class Scanner {
final public class Scanner {
var content: String
var index: String.Index
......
......@@ -75,8 +75,7 @@ func isWhitespace(c: Character?) -> Bool {
return isCharacterPartOfSet(c, set: NSCharacterSet.whitespaceCharacterSet())
}
public class Lexer {
final public class Lexer {
var scanner: Scanner
var current: Token? = nil
......
......@@ -7,7 +7,7 @@
:tasks {:build {:tool "lldb-build"
:name "json-swift"
:output-type "lib"
:source [ "src/**.swift" ]}}
:source [ "src/**.swift" "lib/**.swift" ]}}
)
; End of the sample.
\ No newline at end of file
......@@ -41,23 +41,11 @@ class PackageTests: Test {
for (key, task) in package.tasks {
try test.assert(key == "build")
try test.assert(task.tool == "lldb-build")
try test.assert(task.name == "json-swift")
try test.assert(task.outputType == .StaticLibrary)
try test.assert(task.sources.count == 1)
try test.assert(task.sources[0].path == "src/**.swift")
try test.assert(task["name"]?.string == "json-swift")
try test.assert(task["output-type"]?.string == "lib")
try test.assert(task["source"]?.vector?.count == 2)
try test.assert(task["source"]?.vector?[0].string == "src/**.swift")
try test.assert(task["source"]?.vector?[1].string == "lib/**.swift")
}
// (package
// :name "basic"
// :version "0.1.0-dev"
// :tasks {:build {:tool "lldb-build"
// :name "json-swift"
// :output-type "lib"
// :source [ "src/**.swift" ]}}
// )
// ; End of the sample.
}
}
This diff is collapsed.
......@@ -34,11 +34,11 @@ class ParserTests: Test {
let name = result.properties["name"]
try test.assert(name != nil)
try test.assert(name?.stringLiteral == "basic")
try test.assert(name?.string == "basic")
let version = result.properties["version"]
try test.assert(version != nil)
try test.assert(version?.stringLiteral == "0.1.0-dev")
try test.assert(version?.string == "0.1.0-dev")
let tasks = result.properties["tasks"]
try test.assert(tasks != nil)
......@@ -48,19 +48,20 @@ class ParserTests: Test {
let tool = build?.map?["tool"]
try test.assert(tool != nil)
try test.assert(tool?.stringLiteral == "lldb-build")
try test.assert(tool?.string == "lldb-build")
let buildName = build?.map?["name"]
try test.assert(buildName != nil)
try test.assert(buildName?.stringLiteral == "json-swift")
try test.assert(buildName?.string == "json-swift")
let outputType = build?.map?["output-type"]
try test.assert(outputType != nil)
try test.assert(outputType?.stringLiteral == "lib")
try test.assert(outputType?.string == "lib")
let source = build?.map?["source"]
try test.assert(source != nil)
try test.assert(source?.vector != nil)
try test.assert(source?.vector?[0].stringLiteral == "src/**.swift")
try test.assert(source?.vector?[0].string == "src/**.swift")
try test.assert(source?.vector?[1].string == "lib/**.swift")
}
}
\ No newline at end of file
......@@ -299,6 +299,21 @@ class ScannerTests: Test {
try test.assert(scanner.next()?.character == "t")
try test.assert(scanner.next()?.character == "\"")
try test.assert(scanner.next()?.character == " ")
try test.assert(scanner.next()?.character == "\"")
try test.assert(scanner.next()?.character == "l")
try test.assert(scanner.next()?.character == "i")
try test.assert(scanner.next()?.character == "b")
try test.assert(scanner.next()?.character == "/")
try test.assert(scanner.next()?.character == "*")
try test.assert(scanner.next()?.character == "*")
try test.assert(scanner.next()?.character == ".")
try test.assert(scanner.next()?.character == "s")
try test.assert(scanner.next()?.character == "w")
try test.assert(scanner.next()?.character == "i")
try test.assert(scanner.next()?.character == "f")
try test.assert(scanner.next()?.character == "t")
try test.assert(scanner.next()?.character == "\"")
try test.assert(scanner.next()?.character == " ")
try test.assert(scanner.next()?.character == "]")
try test.assert(scanner.next()?.character == "}")
try test.assert(scanner.next()?.character == "}")
......
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