Chain build and upload

This commit is contained in:
Matthias Neeracher 2014-12-08 05:35:58 +01:00 committed by Matthias Neeracher
parent f8d5e6d9a4
commit 9ca39e0cb9
3 changed files with 32 additions and 22 deletions

View File

@ -11,6 +11,24 @@ import Foundation
class ASBuilder { class ASBuilder {
var dir = NSURL() var dir = NSURL()
var task : NSTask? var task : NSTask?
var continuation: (()->())?
var termination : AnyObject?
init() {
termination = NSNotificationCenter.defaultCenter().addObserverForName(NSTaskDidTerminateNotification,
object: nil, queue: nil, usingBlock:
{ (notification: NSNotification!) in
if notification.object as? NSTask == self.task && self.task!.terminationStatus == 0 {
if let cont = self.continuation {
self.continuation = nil
cont()
}
}
})
}
func finalize() {
NSNotificationCenter.defaultCenter().removeObserver(termination!)
}
func setProjectURL(url: NSURL) { func setProjectURL(url: NSURL) {
dir = url.URLByDeletingLastPathComponent!.standardizedURL! dir = url.URLByDeletingLastPathComponent!.standardizedURL!
@ -92,8 +110,12 @@ class ASBuilder {
let speed = boardProp["upload.speed"] ?? progProp?["speed"] let speed = boardProp["upload.speed"] ?? progProp?["speed"]
var args = ["-v", "-v", "-v", "-v", "-D", var args = ["-v", "-v", "-v", "-v", "-D",
"-C", "/usr/local/CrossPack-AVR/etc/avrdude.conf", "-C", "/usr/local/CrossPack-AVR/etc/avrdude.conf",
"-p", boardProp["build.mcu"], "-c", proto!, "-P", port, "-b", speed!, "-p", boardProp["build.mcu"]!, "-c", proto!, "-P", port,
"-U", "flash:w:build/"+board+"/"+dir.lastPathComponent+".hex:i"] "-U", "flash:w:build/"+board+"/"+dir.lastPathComponent+".hex:i"]
if speed != nil {
args.append("-b")
args.append(speed!)
}
task!.arguments = args; task!.arguments = args;
task!.launch() task!.launch()
} }

View File

@ -8,28 +8,13 @@
import Foundation import Foundation
class ASPropertyEntry { typealias ASPropertyEntry = [String: String]
private var storage = [String: String]()
subscript(key: String) -> String {
get {
if let value = storage[key] {
return value
} else {
return ""
}
}
set (newValue) {
storage[key] = newValue
}
}
}
typealias ASProperties = [String: ASPropertyEntry] typealias ASProperties = [String: ASPropertyEntry]
extension NSMenu { extension NSMenu {
func addSortedChoices(choices:[ASPropertyEntry], target: AnyObject, selector: Selector) { func addSortedChoices(choices:[ASPropertyEntry], target: AnyObject, selector: Selector) {
for choice in choices.sorted({ $0["name"] < $1["name"] }) { for choice in choices.sorted({ $0["name"] < $1["name"] }) {
let item = self.addItemWithTitle(choice["name"], action: selector, keyEquivalent: "") let item = self.addItemWithTitle(choice["name"]!, action: selector, keyEquivalent: "")
item?.target = target item?.target = target
} }
} }
@ -127,7 +112,7 @@ class ASHardware {
menu.addItem(NSMenuItem.separatorItem()) menu.addItem(NSMenuItem.separatorItem())
var seen = [String: Bool]() var seen = [String: Bool]()
for prop in choices.values { for prop in choices.values {
seen[prop["provenience"]] = true seen[prop["provenience"]!] = true
} }
var sortedKeys = [String](seen.keys) var sortedKeys = [String](seen.keys)
sortedKeys.sort { $0 < $1 } sortedKeys.sort { $0 < $1 }

View File

@ -447,9 +447,12 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate {
return NSSet(objects: "port", "board", "programmer") return NSSet(objects: "port", "board", "programmer")
} }
@IBAction func uploadProject(AnyObject) { @IBAction func uploadProject(sender: AnyObject) {
selectNode(files.uploadLog) builder.continuation = {
builder.uploadProject(board, programmer:programmer, port:port) self.selectNode(self.files.uploadLog)
self.builder.uploadProject(self.board, programmer:self.programmer, port:self.port)
}
buildProject(sender)
} }
} }