Display and update build logs
This commit is contained in:
parent
2835a477fc
commit
ef13cd0c83
|
@ -16,6 +16,11 @@ class ASBuilder {
|
||||||
dir = url.URLByDeletingLastPathComponent!.standardizedURL!
|
dir = url.URLByDeletingLastPathComponent!.standardizedURL!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stop() {
|
||||||
|
task?.terminate()
|
||||||
|
task?.waitUntilExit()
|
||||||
|
}
|
||||||
|
|
||||||
func buildProject(board: String, files: ASFileTree) {
|
func buildProject(board: String, files: ASFileTree) {
|
||||||
task = NSTask()
|
task = NSTask()
|
||||||
task!.currentDirectoryPath = dir.path!
|
task!.currentDirectoryPath = dir.path!
|
||||||
|
@ -60,7 +65,5 @@ class ASBuilder {
|
||||||
args += files.paths
|
args += files.paths
|
||||||
task!.arguments = args;
|
task!.arguments = args;
|
||||||
task!.launch()
|
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 {
|
class ASFileGroup : ASFileNode {
|
||||||
var name : String
|
var name : String
|
||||||
var children : [ASFileNode]
|
var children : [ASFileNode]
|
||||||
|
@ -188,6 +201,8 @@ class ASFileItem : ASFileNode {
|
||||||
class ASFileTree : NSObject, NSOutlineViewDataSource {
|
class ASFileTree : NSObject, NSOutlineViewDataSource {
|
||||||
var root = ASProject()
|
var root = ASProject()
|
||||||
var dir = NSURL()
|
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) {
|
func addFileURL(url: NSURL, omitUnknown: Bool = true) {
|
||||||
let type = ASFileType.guessForURL(url)
|
let type = ASFileType.guessForURL(url)
|
||||||
|
@ -215,14 +230,21 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
|
||||||
// MARK: Outline Data Source
|
// MARK: Outline Data Source
|
||||||
func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
|
func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
|
||||||
if item == nil {
|
if item == nil {
|
||||||
return 1
|
return 3
|
||||||
} else {
|
} else {
|
||||||
return (item as ASFileGroup).children.count
|
return (item as ASFileGroup).children.count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
|
func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
|
||||||
if item == nil {
|
if item == nil {
|
||||||
|
switch index {
|
||||||
|
case 1:
|
||||||
|
return buildLog
|
||||||
|
case 2:
|
||||||
|
return uploadLog
|
||||||
|
default:
|
||||||
return root
|
return root
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let group = item as ASFileGroup
|
let group = item as ASFileGroup
|
||||||
return group.children[index]
|
return group.children[index]
|
||||||
|
|
|
@ -22,6 +22,8 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
||||||
var board : String = "uno"
|
var board : String = "uno"
|
||||||
var programmer : String = ""
|
var programmer : String = ""
|
||||||
var port : String = ""
|
var port : String = ""
|
||||||
|
var logModified = NSDate.distantPast() as NSDate
|
||||||
|
var updateLogTimer : NSTimer?
|
||||||
|
|
||||||
let kVersionKey = "Version"
|
let kVersionKey = "Version"
|
||||||
let kCurVersion = 1.0
|
let kCurVersion = 1.0
|
||||||
|
@ -61,6 +63,9 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
||||||
board = userDefaults.stringForKey(kBoardKey)!
|
board = userDefaults.stringForKey(kBoardKey)!
|
||||||
programmer = userDefaults.stringForKey(kProgrammerKey)!
|
programmer = userDefaults.stringForKey(kProgrammerKey)!
|
||||||
port = userDefaults.stringForKey(kPortKey)!
|
port = userDefaults.stringForKey(kPortKey)!
|
||||||
|
|
||||||
|
updateLogTimer =
|
||||||
|
NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "updateLog:", userInfo: nil, repeats: true)
|
||||||
}
|
}
|
||||||
override func finalize() {
|
override func finalize() {
|
||||||
saveCurEditor()
|
saveCurEditor()
|
||||||
|
@ -168,10 +173,23 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Outline View Delegate
|
func updateLog(AnyObject?) {
|
||||||
|
if let logNode = mainEditor as? ASLogNode {
|
||||||
func outlineViewSelectionDidChange(notification: NSNotification) {
|
let url = fileURL!.URLByDeletingLastPathComponent?.URLByAppendingPathComponent(logNode.path)
|
||||||
let selection = outline.itemAtRow(outline.selectedRow) as ASFileNode?
|
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 {
|
if selection !== mainEditor {
|
||||||
saveCurEditor()
|
saveCurEditor()
|
||||||
}
|
}
|
||||||
|
@ -180,10 +198,24 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
||||||
editor.setString(NSString(contentsOfURL:file.url, usedEncoding:&enc, error:nil))
|
editor.setString(NSString(contentsOfURL:file.url, usedEncoding:&enc, error:nil))
|
||||||
editor.setMode(UInt(file.type.aceMode))
|
editor.setMode(UInt(file.type.aceMode))
|
||||||
editor.alphaValue = 1.0
|
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 {
|
} else {
|
||||||
editor.alphaValue = 0.0
|
editor.alphaValue = 0.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Outline View Delegate
|
||||||
|
|
||||||
|
func outlineViewSelectionDidChange(notification: NSNotification) {
|
||||||
|
selectNode(outline.itemAtRow(outline.selectedRow) as ASFileNode?)
|
||||||
|
}
|
||||||
func outlineViewItemDidExpand(notification: NSNotification) {
|
func outlineViewItemDidExpand(notification: NSNotification) {
|
||||||
let group = notification.userInfo!["NSObject"] as ASFileGroup
|
let group = notification.userInfo!["NSObject"] as ASFileGroup
|
||||||
group.expanded = true
|
group.expanded = true
|
||||||
|
@ -194,6 +226,13 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
||||||
group.expanded = false
|
group.expanded = false
|
||||||
updateChangeCount(.ChangeDone)
|
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
|
// MARK: Editor configuration
|
||||||
|
|
||||||
|
@ -240,6 +279,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
|
||||||
// MARK: Build / Upload
|
// MARK: Build / Upload
|
||||||
|
|
||||||
@IBAction func buildProject(AnyObject) {
|
@IBAction func buildProject(AnyObject) {
|
||||||
|
selectNode(files.buildLog)
|
||||||
builder.buildProject(board, files: files)
|
builder.buildProject(board, files: files)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,6 +179,5 @@ task :default => ['#{BUILD['project']}.eep', '#{BUILD['project']}.hex']
|
||||||
END_RAKE
|
END_RAKE
|
||||||
end
|
end
|
||||||
|
|
||||||
sh 'rake'
|
sh 'rake >& ../build.log'
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user