Skip to content

Commit

Permalink
feat: support latest scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
SolaWing committed Jan 1, 2025
1 parent 440803b commit 5734fea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Go to your workspace directory and execute one of the following commands:

```bash
# *.xcworkspace or *.xcodeproj should be unique. can be omit and will auto choose the unique workspace or project.
# -scheme can also be omit to auto bind the latest scheme build result. even change it in xcode after the buildServer.json generated
xcode-build-server config -workspace *.xcworkspace -scheme <XXX>
xcode-build-server config -project *.xcodeproj -scheme <XXX>
```
Expand Down
26 changes: 17 additions & 9 deletions config/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import subprocess
import sys
import json

from .config import ServerConfig

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

if scheme is None:
_usage("you need to specify scheme!")

if workspace is None:

def get_workspace():
Expand All @@ -82,17 +81,26 @@ def get_workspace():

workspace = get_workspace()

lastest_scheme = False
if scheme is None:
output = subprocess.check_output(f"xcodebuild -list -json -workspace '{workspace}'", shell=True, universal_newlines=True)
output = json.loads(output)
scheme = output["workspace"]["schemes"][0]
lastest_scheme = True
# _usage("you need to specify scheme!")

# find and record build_root for workspace and scheme
cmd = f"""xcodebuild -showBuildSettings -workspace '{workspace}' -scheme '{scheme}' 2>/dev/null | grep "\\bSYMROOT =" | head -1 | awk -F" = " '{{print $2}}' | tr -d '"' """
build_dir = subprocess.check_output(cmd, shell=True, universal_newlines=True)
build_root = os.path.join(build_dir, "../..")
build_root = os.path.abspath(build_root)
output = subprocess.check_output(f"xcodebuild -showBuildSettings -json -workspace '{workspace}' -scheme '{scheme}' 2>/dev/null", shell=True, universal_newlines=True)
output = json.loads(output)
build_dir = output[0]["buildSettings"]["SYMROOT"]
build_root = os.path.abspath(os.path.join(build_dir, "../.."))

print("find root:", build_root)

config = ServerConfig.shared()
config.workspace = os.path.abspath(os.path.expanduser(workspace))
config.build_root = build_root
config.scheme = scheme
config.scheme = None if lastest_scheme else scheme
config.kind = "xcode"
config.skip_validate_bin = skip_validate_bin
config.save()
Expand Down
4 changes: 2 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def __init__(self, root_path: str, cache_path):
# can only changed in sync_compile_file, which block all thread and no one access it.
# other time, the shared state is readonly and safe..

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

0 comments on commit 5734fea

Please sign in to comment.