• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

gitリポジトリのurlを貼り付けるだけでアプリケーションのビルドを実行するアプリ。 macOS用


Commit MetaInfo

Revision401881ee109078d94650a8f7cbe5d53b66d8f1aa (tree)
Time2017-08-16 22:06:59
Authormasakih <masakih@user...>
Commitermasakih

Log Message

コマンドのログを残すようにした

Change Summary

Incremental Difference

--- a/AppBuilderWithGit.xcodeproj/project.pbxproj
+++ b/AppBuilderWithGit.xcodeproj/project.pbxproj
@@ -17,6 +17,7 @@
1717 F41A45081F3D98180066F83D /* ProjectBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45071F3D98180066F83D /* ProjectBuilder.swift */; };
1818 F41A45141F3E9DFA0066F83D /* BuildInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45131F3E9DFA0066F83D /* BuildInfo.swift */; };
1919 F41A45161F3EC0950066F83D /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45151F3EC0950066F83D /* WindowController.swift */; };
20+ F41A45181F401D4B0066F83D /* LogStocker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45171F401D4B0066F83D /* LogStocker.swift */; };
2021 /* End PBXBuildFile section */
2122
2223 /* Begin PBXFileReference section */
@@ -32,6 +33,7 @@
3233 F41A45071F3D98180066F83D /* ProjectBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProjectBuilder.swift; sourceTree = "<group>"; };
3334 F41A45131F3E9DFA0066F83D /* BuildInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BuildInfo.swift; sourceTree = "<group>"; };
3435 F41A45151F3EC0950066F83D /* WindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; };
36+ F41A45171F401D4B0066F83D /* LogStocker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogStocker.swift; sourceTree = "<group>"; };
3537 /* End PBXFileReference section */
3638
3739 /* Begin PBXFrameworksBuildPhase section */
@@ -71,6 +73,7 @@
7173 F41A45031F3D782A0066F83D /* Git.swift */,
7274 F41A45051F3D83AE0066F83D /* ProjectFinder.swift */,
7375 F41A45071F3D98180066F83D /* ProjectBuilder.swift */,
76+ F41A45171F401D4B0066F83D /* LogStocker.swift */,
7477 F41A45131F3E9DFA0066F83D /* BuildInfo.swift */,
7578 F41A44F21F3D6B1B0066F83D /* Assets.xcassets */,
7679 F41A44F41F3D6B1B0066F83D /* Main.storyboard */,
@@ -150,6 +153,7 @@
150153 isa = PBXSourcesBuildPhase;
151154 buildActionMask = 2147483647;
152155 files = (
156+ F41A45181F401D4B0066F83D /* LogStocker.swift in Sources */,
153157 F41A45021F3D77020066F83D /* ApplicationDirecrories.swift in Sources */,
154158 F41A45081F3D98180066F83D /* ProjectBuilder.swift in Sources */,
155159 F41A45041F3D782A0066F83D /* Git.swift in Sources */,
--- a/AppBuilderWithGit/Git.swift
+++ b/AppBuilderWithGit/Git.swift
@@ -70,6 +70,11 @@ final class Git {
7070
7171 private func excuteGit(workingURL: URL, args: [String]) throws {
7272
73+ guard !args.isEmpty else {
74+
75+ throw GitError.other("Iligal arguments")
76+ }
77+
7378 let xcodeURL = NSApplication.appDelegate.xcodeURL
7479 guard let gitURL = xcodeURL?.appendingPathComponent("/Contents/Developer/usr/bin/git") else {
7580
@@ -91,6 +96,12 @@ final class Git {
9196 let pipe = Pipe()
9297 git.standardError = pipe
9398
99+ let logPipe = Pipe()
100+ git.standardOutput = logPipe
101+ git.standardError = logPipe
102+ let log = LogStocker("git-" + args[0] + ".log")
103+ log?.read(logPipe.fileHandleForReading)
104+
94105 git.launch()
95106 git.waitUntilExit()
96107
--- /dev/null
+++ b/AppBuilderWithGit/LogStocker.swift
@@ -0,0 +1,66 @@
1+//
2+// LogStocker.swift
3+// AppBuilderWithGit
4+//
5+// Created by Hori,Masaki on 2017/08/13.
6+// Copyright © 2017年 Hori,Masaki. All rights reserved.
7+//
8+
9+import Foundation
10+
11+private func fileURL(for name: String) -> URL? {
12+
13+ let base = ApplicationDirecrories.support.appendingPathComponent("Logs")
14+ guard checkDirectory(base) else {
15+
16+ return base.appendingPathComponent(name)
17+ }
18+
19+ return base.appendingPathComponent(name)
20+}
21+
22+private func nameWithDate(_ name: String) -> String {
23+
24+ let formatter = DateFormatter()
25+ formatter.dateFormat = "yyyy-MM-dd-HH-mm-ss-A"
26+
27+ return formatter.string(from: Date()) + "-" + name
28+
29+}
30+
31+final class LogStocker {
32+
33+ private let output: FileHandle
34+
35+ init?(_ name: String) {
36+
37+ do {
38+
39+ let datename = nameWithDate(name)
40+ guard let url = fileURL(for: datename) else { return nil }
41+
42+ try Data().write(to: url)
43+
44+ output = try FileHandle(forWritingTo: url)
45+
46+ } catch {
47+
48+ print("can not open file for log writing.\n\(error)")
49+
50+ return nil
51+ }
52+
53+ }
54+
55+ deinit { output.closeFile() }
56+
57+ func read(_ fileHandle: FileHandle) {
58+
59+ DispatchQueue.global().async {
60+
61+ self.output.write(fileHandle.readDataToEndOfFile())
62+ }
63+
64+ }
65+
66+}
--- a/AppBuilderWithGit/ProjectBuilder.swift
+++ b/AppBuilderWithGit/ProjectBuilder.swift
@@ -56,34 +56,9 @@ final class ProjectBuilder {
5656
5757 let pipe = Pipe()
5858 xcodebuild.standardOutput = pipe
59-
60- weak var token: NSObjectProtocol?
61- token = NotificationCenter.default
62- .addObserver(forName: FileHandle.readCompletionNotification,
63- object: pipe.fileHandleForReading,
64- queue: nil) { [weak xcodebuild] notifiction in
65-
66- if let data = notifiction.userInfo?[NSFileHandleNotificationDataItem] as? Data,
67- let string = String(data: data, encoding: .utf8) {
68-
69- print(string)
70-
71- }
72-
73- if let task = xcodebuild,
74- task.isRunning,
75- let handle = notifiction.object as? FileHandle {
76-
77- handle.readInBackgroundAndNotify()
78-
79- } else {
80-
81- token.map(NotificationCenter.default.removeObserver)
82- }
83-
84- }
85-
86- pipe.fileHandleForReading.readInBackgroundAndNotify()
59+ xcodebuild.standardError = pipe
60+ let log = LogStocker("xcodebuild.log")
61+ log?.read(pipe.fileHandleForReading)
8762
8863 xcodebuild.launch()
8964 xcodebuild.waitUntilExit()