Skip to content

Commit 440803b

Browse files
committed
debug: build xcode by applescript
1 parent d90a1e7 commit 440803b

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

misc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
def bundle_path(path):
4+
return os.path.abspath(os.path.join(os.path.realpath(__file__), "..", path))
35

46
def get_mtime(path):
57
"""return mtime, or 0 when not exists"""

xcode-build-server

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import sys
6+
import misc
67

78
def show_help():
89
print(
@@ -94,6 +95,10 @@ def main():
9495
print(f"extract xcactivitylog at {path}")
9596
for l in xcactivitylog.extract_compile_log(path):
9697
print(l)
98+
if sys.argv[2] == "build":
99+
import subprocess
100+
code = subprocess.call(["osascript", "-l", "JavaScript", misc.bundle_path("xcode/build.js"), *sys.argv[3:]])
101+
exit(code)
97102
else:
98103
show_debug_help()
99104
else:

xcode/build.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env osascript -l JavaScript
2+
3+
// this need xcode call authorized
4+
function run(argv) {
5+
if (argv.length < 1 || argv[0] == "-h" || argv[0] == "--help") {
6+
console.log([
7+
`Usage: osascript -l JavaScript build.js <path_to_workspace> [scheme]`,
8+
"",
9+
"path_to_workspace, scheme can use . as current"
10+
].join("\n"))
11+
return;
12+
}
13+
var xcode = Application("Xcode");
14+
var path = argv[0];
15+
if (path == ".") {
16+
console.log("get active workspace")
17+
var workspace = xcode.activeWorkspaceDocument();
18+
if (!workspace) {
19+
console.log("no active workspace, choose one with path or in xcode")
20+
}
21+
} else {
22+
console.log(`open workspace ${path}`)
23+
var pathURL = $.NSURL.fileURLWithPath(path);
24+
var workspace = xcode.open(pathURL.path.UTF8String);
25+
26+
// ctrl-c can break
27+
for (var i = 0; i < 100; i++) {
28+
if (workspace.loaded()) {
29+
break
30+
}
31+
delay(1)
32+
}
33+
if (i == 3) {
34+
console.log(`workspace loaded timedout, try again later`)
35+
ObjC.import('stdlib') // for exit
36+
$.exit(16)
37+
}
38+
}
39+
var scheme = argv[1];
40+
if (scheme == "." || !scheme) {
41+
// seems no need to use scheme furthur
42+
// console.log("get active scheme")
43+
scheme = workspace.activeScheme()
44+
console.log(`active scheme is ${scheme.name()}`)
45+
} else {
46+
console.log(`get scheme by ${scheme}`)
47+
var scheme = workspace.schemes.byName(scheme)
48+
if (!scheme.exists()) {
49+
console.log("scheme not exist in workspace")
50+
//var schemes = workspace.schemes()
51+
//console.log(`available is ${Automation.getDisplayString(schemes)}`)
52+
return
53+
}
54+
console.log(`active scheme ${scheme.name()}`);
55+
workspace.activeScheme = scheme
56+
}
57+
58+
console.log("build");
59+
workspace.build();
60+
// TODO: query build status //
61+
}

0 commit comments

Comments
 (0)