Skip to content

Commit 5734fea

Browse files
committed
feat: support latest scheme
1 parent 440803b commit 5734fea

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Go to your workspace directory and execute one of the following commands:
3535

3636
```bash
3737
# *.xcworkspace or *.xcodeproj should be unique. can be omit and will auto choose the unique workspace or project.
38+
# -scheme can also be omit to auto bind the latest scheme build result. even change it in xcode after the buildServer.json generated
3839
xcode-build-server config -workspace *.xcworkspace -scheme <XXX>
3940
xcode-build-server config -project *.xcodeproj -scheme <XXX>
4041
```

config/cmd.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import subprocess
66
import sys
7+
import json
78

89
from .config import ServerConfig
910

@@ -19,7 +20,8 @@ def usage(name, msg=None):
1920
{name} -workspace *.xcworkspace -scheme <schemename>
2021
{name} -project *.xcodeproj -scheme <schemename>
2122
22-
workspace and project and be infered if only one in pwd. scheme must be specified.
23+
workspace and project and be infered if only one in pwd.
24+
scheme can be omit to bind the lastest build scheme.
2325
see also `man xcodebuild` and xcodebuild -showBuildSettings
2426
2527
Other Options:
@@ -57,9 +59,6 @@ def main(argv=sys.argv):
5759
else:
5860
_usage(f"unknown arg {arg}")
5961

60-
if scheme is None:
61-
_usage("you need to specify scheme!")
62-
6362
if workspace is None:
6463

6564
def get_workspace():
@@ -82,17 +81,26 @@ def get_workspace():
8281

8382
workspace = get_workspace()
8483

84+
lastest_scheme = False
85+
if scheme is None:
86+
output = subprocess.check_output(f"xcodebuild -list -json -workspace '{workspace}'", shell=True, universal_newlines=True)
87+
output = json.loads(output)
88+
scheme = output["workspace"]["schemes"][0]
89+
lastest_scheme = True
90+
# _usage("you need to specify scheme!")
91+
8592
# find and record build_root for workspace and scheme
86-
cmd = f"""xcodebuild -showBuildSettings -workspace '{workspace}' -scheme '{scheme}' 2>/dev/null | grep "\\bSYMROOT =" | head -1 | awk -F" = " '{{print $2}}' | tr -d '"' """
87-
build_dir = subprocess.check_output(cmd, shell=True, universal_newlines=True)
88-
build_root = os.path.join(build_dir, "../..")
89-
build_root = os.path.abspath(build_root)
93+
output = subprocess.check_output(f"xcodebuild -showBuildSettings -json -workspace '{workspace}' -scheme '{scheme}' 2>/dev/null", shell=True, universal_newlines=True)
94+
output = json.loads(output)
95+
build_dir = output[0]["buildSettings"]["SYMROOT"]
96+
build_root = os.path.abspath(os.path.join(build_dir, "../.."))
97+
9098
print("find root:", build_root)
9199

92100
config = ServerConfig.shared()
93101
config.workspace = os.path.abspath(os.path.expanduser(workspace))
94102
config.build_root = build_root
95-
config.scheme = scheme
103+
config.scheme = None if lastest_scheme else scheme
96104
config.kind = "xcode"
97105
config.skip_validate_bin = skip_validate_bin
98106
config.save()

server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ def __init__(self, root_path: str, cache_path):
7373
# can only changed in sync_compile_file, which block all thread and no one access it.
7474
# other time, the shared state is readonly and safe..
7575

76-
def get_compile_file(self, config):
76+
def get_compile_file(self, config: ServerConfig):
7777
# isolate xcode generate compile file and manual compile_file
7878
if config.kind == "xcode":
7979
hash = hashlib.md5(config.build_root.encode("utf-8")).hexdigest()
80-
name = ["compile_file", config.scheme, hash]
80+
name = ["compile_file", config.scheme or "_last", hash]
8181
if config.skip_validate_bin:
8282
name[0] = "compile_file1"
8383
return os.path.join(self.cache_path, "-".join(name))

0 commit comments

Comments
 (0)