Display and update build logs
This commit is contained in:
parent
2835a477fc
commit
ef13cd0c83
|
@ -9,19 +9,24 @@
|
|||
import Foundation
|
||||
|
||||
class ASBuilder {
|
||||
var dir = NSURL()
|
||||
var task : NSTask?
|
||||
var dir = NSURL()
|
||||
var task : NSTask?
|
||||
|
||||
func setProjectURL(url: NSURL) {
|
||||
dir = url.URLByDeletingLastPathComponent!.standardizedURL!
|
||||
}
|
||||
|
||||
func stop() {
|
||||
task?.terminate()
|
||||
task?.waitUntilExit()
|
||||
}
|
||||
|
||||
func buildProject(board: String, files: ASFileTree) {
|
||||
task = NSTask()
|
||||
task!.currentDirectoryPath = dir.path!
|
||||
task!.launchPath = NSBundle.mainBundle().pathForResource("BuildProject", ofType: "")!
|
||||
|
||||
let fileManager = NSFileManager.defaultManager()
|
||||
let fileManager = NSFileManager.defaultManager()
|
||||
let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":")
|
||||
var args = [NSString]()
|
||||
let boardProp = ASHardware.instance().boards[board]!
|
||||
|
@ -57,10 +62,8 @@ class ASBuilder {
|
|||
args.append("variant_path="+variantPath!)
|
||||
}
|
||||
args.append("--")
|
||||
args += files.paths
|
||||
task!.arguments = args;
|
||||
args += files.paths
|
||||
task!.arguments = args;
|
||||
task!.launch()
|
||||
|
||||
files.paths
|
||||
}
|
||||
}
|
|
@ -81,6 +81,19 @@ class ASFileNode {
|
|||
}
|
||||
}
|
||||
|
||||
class ASLogNode : ASFileNode {
|
||||
var name : String
|
||||
var path : String
|
||||
|
||||
init(name: String, path: String) {
|
||||
self.name = name
|
||||
self.path = path
|
||||
}
|
||||
override func nodeName() -> String {
|
||||
return "📜 "+name
|
||||
}
|
||||
}
|
||||
|
||||
class ASFileGroup : ASFileNode {
|
||||
var name : String
|
||||
var children : [ASFileNode]
|
||||
|
@ -186,8 +199,10 @@ class ASFileItem : ASFileNode {
|
|||
}
|
||||
|
||||
class ASFileTree : NSObject, NSOutlineViewDataSource {
|
||||
var root = ASProject()
|
||||
var dir = NSURL()
|
||||
var root = ASProject()
|
||||
var dir = NSURL()
|
||||
var buildLog = ASLogNode(name: "Build Log", path: "build/build.log")
|
||||
var uploadLog = ASLogNode(name: "Upload Log", path: "build/upload.log")
|
||||
|
||||
func addFileURL(url: NSURL, omitUnknown: Bool = true) {
|
||||
let type = ASFileType.guessForURL(url)
|
||||
|
@ -215,14 +230,21 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
|
|||
// MARK: Outline Data Source
|
||||
func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
|
||||
if item == nil {
|
||||
return 1
|
||||
return 3
|
||||
} else {
|
||||
return (item as ASFileGroup).children.count
|
||||
}
|
||||
}
|
||||
func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
|
||||
if item == nil {
|
||||
return root
|
||||
switch index {
|
||||
case 1:
|
||||
return buildLog
|
||||
case 2:
|
||||
return uploadLog
|
||||
default:
|
||||
return root
|
||||
}
|
||||
} else {
|
||||
let group = item as ASFileGroup
|
||||
return group.children[index]
|
||||
|
|
|
@ -22,6 +22,8 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
|||
var board : String = "uno"
|
||||
var programmer : String = ""
|
||||
var port : String = ""
|
||||
var logModified = NSDate.distantPast() as NSDate
|
||||
var updateLogTimer : NSTimer?
|
||||
|
||||
let kVersionKey = "Version"
|
||||
let kCurVersion = 1.0
|
||||
|
@ -61,6 +63,9 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
|||
board = userDefaults.stringForKey(kBoardKey)!
|
||||
programmer = userDefaults.stringForKey(kProgrammerKey)!
|
||||
port = userDefaults.stringForKey(kPortKey)!
|
||||
|
||||
updateLogTimer =
|
||||
NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "updateLog:", userInfo: nil, repeats: true)
|
||||
}
|
||||
override func finalize() {
|
||||
saveCurEditor()
|
||||
|
@ -168,10 +173,23 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
|||
return true
|
||||
}
|
||||
|
||||
// MARK: Outline View Delegate
|
||||
|
||||
func outlineViewSelectionDidChange(notification: NSNotification) {
|
||||
let selection = outline.itemAtRow(outline.selectedRow) as ASFileNode?
|
||||
func updateLog(AnyObject?) {
|
||||
if let logNode = mainEditor as? ASLogNode {
|
||||
let url = fileURL!.URLByDeletingLastPathComponent?.URLByAppendingPathComponent(logNode.path)
|
||||
if url == nil {
|
||||
return
|
||||
}
|
||||
var modified : AnyObject?
|
||||
if (url!.getResourceValue(&modified, forKey:NSURLAttributeModificationDateKey, error:nil)) {
|
||||
if (modified as NSDate).compare(logModified) == .OrderedDescending {
|
||||
var enc : UInt = 0
|
||||
editor.setString(NSString(contentsOfURL:url!, usedEncoding:&enc, error:nil))
|
||||
logModified = modified as NSDate
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func selectNode(selection: ASFileNode?) {
|
||||
if selection !== mainEditor {
|
||||
saveCurEditor()
|
||||
}
|
||||
|
@ -180,10 +198,24 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
|||
editor.setString(NSString(contentsOfURL:file.url, usedEncoding:&enc, error:nil))
|
||||
editor.setMode(UInt(file.type.aceMode))
|
||||
editor.alphaValue = 1.0
|
||||
mainEditor = selection
|
||||
} else if let log = (selection as? ASLogNode) {
|
||||
editor.setString("")
|
||||
editor.setMode(UInt(ACEModeASCIIDoc))
|
||||
editor.alphaValue = 0.8
|
||||
logModified = NSDate.distantPast() as NSDate
|
||||
mainEditor = selection
|
||||
updateLog(nil)
|
||||
} else {
|
||||
editor.alphaValue = 0.0
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Outline View Delegate
|
||||
|
||||
func outlineViewSelectionDidChange(notification: NSNotification) {
|
||||
selectNode(outline.itemAtRow(outline.selectedRow) as ASFileNode?)
|
||||
}
|
||||
func outlineViewItemDidExpand(notification: NSNotification) {
|
||||
let group = notification.userInfo!["NSObject"] as ASFileGroup
|
||||
group.expanded = true
|
||||
|
@ -194,6 +226,13 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
|||
group.expanded = false
|
||||
updateChangeCount(.ChangeDone)
|
||||
}
|
||||
func outlineView(outlineView: NSOutlineView, willDisplayCell cell: AnyObject, forTableColumn tableColumn: NSTableColumn?, item: AnyObject) {
|
||||
if item === files.root || item === files.buildLog || item === files.uploadLog {
|
||||
(cell as NSCell).font = NSFont.boldSystemFontOfSize(13.0)
|
||||
} else {
|
||||
(cell as NSCell).font = NSFont.systemFontOfSize(13.0)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Editor configuration
|
||||
|
||||
|
@ -240,6 +279,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
|||
// MARK: Build / Upload
|
||||
|
||||
@IBAction func buildProject(AnyObject) {
|
||||
selectNode(files.buildLog)
|
||||
builder.buildProject(board, files: files)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,6 +179,5 @@ task :default => ['#{BUILD['project']}.eep', '#{BUILD['project']}.hex']
|
|||
END_RAKE
|
||||
end
|
||||
|
||||
sh 'rake'
|
||||
|
||||
sh 'rake >& ../build.log'
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user