|
| 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