Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xcodebuild to actually work on Darwin even without ZAP installed. #24539

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ jobs:
if: github.actor != 'restyled-io[bot]'
runs-on: macos-latest

env:
# NOTE: Generally kept in sync within the repo using
# scripts/tools/zap/version_update.py
ZAP_VERSION: v2023.01.18-nightly
ZAP_INSTALL_PATH: /usr/local/zap/zap-v2023.01.18-nightly

steps:
- uses: Wandalen/[email protected]
name: Checkout
Expand Down Expand Up @@ -68,6 +62,12 @@ jobs:
unzip zap-mac.zip zap-cli
rm zap-mac.zip
./zap-cli --version
env:
# NOTE: Generally kept in sync within the repo using
# scripts/tools/zap/version_update.py
# This is scoped to only the steps that don't use xcodebuild.
ZAP_VERSION: v2023.01.18-nightly
ZAP_INSTALL_PATH: /usr/local/zap/zap-v2023.01.18-nightly
- name: Bootstrap
timeout-minutes: 25
run: scripts/build/gn_bootstrap.sh
Expand Down Expand Up @@ -122,14 +122,32 @@ jobs:
timeout-minutes: 15
run: |
scripts/examples/gn_build_example.sh examples/all-clusters-app/linux out/debug chip_config_network_layer_ble=false
env:
# NOTE: Generally kept in sync within the repo using
# scripts/tools/zap/version_update.py
# This is scoped to only the steps that don't use xcodebuild.
ZAP_VERSION: v2023.01.18-nightly
ZAP_INSTALL_PATH: /usr/local/zap/zap-v2023.01.18-nightly
- name: Build example OTA Provider
timeout-minutes: 10
run: |
scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/debug chip_config_network_layer_ble=false
env:
# NOTE: Generally kept in sync within the repo using
# scripts/tools/zap/version_update.py
# This is scoped to only the steps that don't use xcodebuild.
ZAP_VERSION: v2023.01.18-nightly
ZAP_INSTALL_PATH: /usr/local/zap/zap-v2023.01.18-nightly
- name: Build example OTA Requestor
timeout-minutes: 10
run: |
scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux out/debug chip_config_network_layer_ble=false
env:
# NOTE: Generally kept in sync within the repo using
# scripts/tools/zap/version_update.py
# This is scoped to only the steps that don't use xcodebuild.
ZAP_VERSION: v2023.01.18-nightly
ZAP_INSTALL_PATH: /usr/local/zap/zap-v2023.01.18-nightly
- name: Delete Defaults
run: defaults delete com.apple.dt.xctest.tool
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion scripts/codegen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
9 changes: 6 additions & 3 deletions scripts/codepregen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright (c) 2022 Project CHIP Authors
#
Expand Down Expand Up @@ -74,7 +74,7 @@ def _ParallelGenerateOne(arg):
@click.option(
'--generator',
default='all',
type=click.Choice(['all', 'zap', 'codegen']),
type=click.Choice(['all', 'zap', 'codegen', 'codegen-cpp-only']),
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
help='To what code generator to restrict the generation.')
@click.option(
'--input-glob',
Expand Down Expand Up @@ -119,9 +119,12 @@ def main(log_level, parallel, dry_run, generator, input_glob, sdk_root, output_d

if generator == 'zap':
filter.file_type = IdlFileType.ZAP
elif generator == 'codegen':
elif generator == 'codegen' or generator == 'codegen-cpp-only':
filter.file_type = IdlFileType.MATTER

if generator == 'codegen-cpp-only':
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
filter.cpp_only = True

targets = FindPregenerationTargets(sdk_root, filter, runner)

runner.ensure_directory_exists(output_dir)
Expand Down
4 changes: 3 additions & 1 deletion scripts/pregenerate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class TargetFilter:
# If non-empty only the given paths will be code-generated
path_glob: List[str] = field(default_factory=list)

cpp_only: bool = False
andy31415 marked this conversation as resolved.
Show resolved Hide resolved


# TODO: the build GlobMatcher is more complete by supporting `{}` grouping
# For now this limited glob seems sufficient.
Expand Down Expand Up @@ -98,5 +100,5 @@ def FindPregenerationTargets(sdk_root: str, filter: TargetFilter, runner):
continue

for generator in generators:
if generator.Accept(idl):
if generator.Accept(idl, filter.cpp_only):
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
yield generator.CreateTarget(idl, runner=runner)
13 changes: 8 additions & 5 deletions scripts/pregenerate/using_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CodegenBridgePregenerator:
def __init__(self, sdk_root):
self.sdk_root = sdk_root

def Accept(self, idl: InputIdlFile):
def Accept(self, idl: InputIdlFile, cpp_only: bool):
# Bridge is highly specific, a single path is acceptable for dynamic
# bridge codegen
return idl.relative_path == "examples/dynamic-bridge-app/bridge-common/bridge-app.matter"
Expand All @@ -79,9 +79,12 @@ class CodegenJavaPregenerator:
def __init__(self, sdk_root):
self.sdk_root = sdk_root

def Accept(self, idl: InputIdlFile):
# Java is highly specific, a single path is acceptable for dynamic
# bridge codegen
def Accept(self, idl: InputIdlFile, cpp_only: bool):
if cpp_only:
return False

# Java is highly specific, a single path is acceptable for java
# codegen
return idl.relative_path == "src/controller/data_model/controller-clusters.matter"

def CreateTarget(self, idl: InputIdlFile, runner):
Expand All @@ -94,7 +97,7 @@ class CodegenCppAppPregenerator:
def __init__(self, sdk_root):
self.sdk_root = sdk_root

def Accept(self, idl: InputIdlFile):
def Accept(self, idl: InputIdlFile, cpp_only: bool):
if idl.file_type != IdlFileType.MATTER:
return False

Expand Down
2 changes: 1 addition & 1 deletion scripts/pregenerate/using_zap.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ZapApplicationPregenerator:
def __init__(self, sdk_root):
self.sdk_root = sdk_root

def Accept(self, idl: InputIdlFile):
def Accept(self, idl: InputIdlFile, cpp_only: bool):
if idl.file_type != IdlFileType.ZAP:
return False

Expand Down
43 changes: 39 additions & 4 deletions scripts/tools/zap_regen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,41 @@ def generate(self) -> TargetRunStats:
)


class ZAPPregenerateTarget:
def __init__(self, input_glob, output_dir, generator=None):
self.input_glob = input_glob
self.output_dir = output_dir
self.script = "./scripts/codepregen.py"
self.command = [self.script, "--input-glob", input_glob]
self.generator = generator

if generator is not None:
self.command.extend(["--generator", generator])
self.command.append(output_dir)

def distinct_output(self):
input_template = self.input_glob
if self.generator is not None:
input_template += " " + self.generator
return ZapDistinctOutput(input_template=input_template, output_directory=self.output_dir)

def log_command(self):
logging.info(" %s" % " ".join(self.command))

def generate(self) -> TargetRunStats:
logging.info("Generating target: %s" % " ".join(self.command))

generate_start = time.time()
subprocess.check_call(self.command)
generate_end = time.time()

return TargetRunStats(
generate_time=generate_end - generate_start,
config=self.script,
template=self.script,
)


def checkPythonVersion():
if sys.version_info[0] < 3:
print('Must use Python 3. Current version is ' +
Expand Down Expand Up @@ -200,10 +235,10 @@ def getGlobalTemplatesTargets():
#
# TODO: These files can be code generated at compile time, we should figure
# out a path for this codegen to not be required.
targets.append(ZAPGenerateTarget(
'src/controller/data_model/controller-clusters.zap',
template="src/app/zap-templates/app-templates.json",
output_dir=os.path.join('zzz_generated/darwin/controller-clusters/zap-generated')))
targets.append(ZAPPregenerateTarget(
"*controller-clusters*", "zzz_generated/darwin", generator="zap"))
targets.append(ZAPPregenerateTarget(
"*controller-clusters*", "zzz_generated/darwin", generator="codegen-cpp-only"))

return targets

Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/Matter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@
"$(CHIP_ROOT)/zzz_generated/app-common",
"$(CHIP_ROOT)/zzz_generated/controller-clusters",
/* darwin-specific bypassing compile time codegen for header inclusion */
"$(CHIP_ROOT)/zzz_generated/darwin/controller-clusters",
"$(CHIP_ROOT)/zzz_generated/darwin/src/controller/data_model/controller-clusters/zap/app-templates",
);
INFOPLIST_FILE = CHIP/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand Down Expand Up @@ -1172,7 +1172,7 @@
"$(CHIP_ROOT)/zzz_generated/app-common",
"$(CHIP_ROOT)/zzz_generated/controller-clusters",
/* darwin-specific bypassing compile time codegen for header inclusion */
"$(CHIP_ROOT)/zzz_generated/darwin/controller-clusters",
"$(CHIP_ROOT)/zzz_generated/darwin/src/controller/data_model/controller-clusters/zap/app-templates",
);
INFOPLIST_FILE = CHIP/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/chip_xcode_build_connector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ declare -a args=(
"target_defines=$target_defines"
"target_cflags=[$target_cflags]"
"mac_target_arch=\"$target_arch\""
"chip_code_pre_generated_directory=\"$CHIP_ROOT/zzz_generated/darwin\""
"mac_deployment_target=\"$LLVM_TARGET_TRIPLE_OS_VERSION$LLVM_TARGET_TRIPLE_SUFFIX\""
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#define MATTER_PLUGINS_INIT \
(void)0; /* No server side clusters */

Loading