Skip to content

Commit

Permalink
Allowing pregenerated files in python build (#24752)
Browse files Browse the repository at this point in the history
* checking that we can commit

* checking that we can commit by deleting file that was added

* modified build_python.sh to take argument to use pregenerated files as per issues - Build Python fails due to Zap Generation on Raspberry Pi (no ARM based version of zap-cli available) #24718

* Updated matter guide explaining how to use additional args for pregenerated code

* fixed misspelling of Raspberry as picked up by reviewdog in CI tests

* updated guide to state which things need to be pregenerated

* added more information to the matter-repl.md file on pregeneration

* fixed spelling mistakes such as pregeneration, pregenerated, pregen

* patched with what the restyler is suggesting

* Restyled by prettier-markdown

---------

Co-authored-by: oidebrett <[email protected]>
Co-authored-by: oidebrett <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
4 people authored Feb 2, 2023
1 parent 54b2461 commit 1ba581b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
29 changes: 29 additions & 0 deletions docs/guides/matter-repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ Please follow the instructions
[here](./python_chip_controller_building.md#building-and-installing) to build
the Python virtual environment.

### Building for `arm64` e.g. for Raspberry Pi

Matter code relies on code generation for cluster-specific data types and
callbacks. A subset of code generation is done at compile time by `zap-cli`. ZAP
is generally installed as a third-party tool via CIPD during the build
environment bootstrap. However, zap packages are currently NOT available for
`arm64` (like when compiling on Raspberry PI.). In this case, you have 2
choices.

1. You could check out zap from source as described in
[Code Generation - Installing zap and environment variables](https://github.com/project-chip/connectedhomeip/blob/master/docs/code_generation.md#Installing-zap-and-environment-variables)
and proceed with the
[instructions](./python_chip_controller_building.md#building-and-installing)
to build the Python virtual environment.

2. When compile-time code generation is not desirable, then pre-generated output
code can be used. To understand about code generation and pre-generating
matter code see.
[Code generation - Pre-generation](https://github.com/project-chip/connectedhomeip/blob/master/docs/code_generation.md#Pre-generation).
To build and install the Python CHIP controller with pre-generated files use
the -z argument that points to the directory of pre-generated code:

```
scripts/build_python.sh -m platform -i separate -z "/some/pregen/dir"
```
> Note: To get more details about available build configurations, run the
> following command: `scripts/build_python.sh --help`
## Launching the REPL
1. Activate the Python virtual environment:
Expand Down
10 changes: 8 additions & 2 deletions scripts/build_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Input Options:
no: Do not install
build-env: install to virtual env for build matter
separate: install to another virtual env (out/python_env)
-z --pregen_dir DIRECTORY Directory where generated zap files have been pre-generated.
"
}

Expand Down Expand Up @@ -94,6 +95,10 @@ while (($#)); do
install_wheel=$2
shift
;;
--pregen_dir | -z)
pregen_dir=$2
shift
;;
-*)
help
echo "Unknown Option \"$1\""
Expand All @@ -104,16 +109,17 @@ while (($#)); do
done

# Print input values
echo "Input values: chip_detail_logging = $chip_detail_logging , chip_mdns = \"$chip_mdns\", enable_pybindings = $enable_pybindings, chip_case_retry_delta=\"$chip_case_retry_delta\""
echo "Input values: chip_detail_logging = $chip_detail_logging , chip_mdns = \"$chip_mdns\", enable_pybindings = $enable_pybindings, chip_case_retry_delta=\"$chip_case_retry_delta\", pregen_dir=\"$pregen_dir\""

# Ensure we have a compilation environment
source "$CHIP_ROOT/scripts/activate.sh"

# Generates ninja files
[[ -n "$chip_mdns" ]] && chip_mdns_arg="chip_mdns=\"$chip_mdns\"" || chip_mdns_arg=""
[[ -n "$chip_case_retry_delta" ]] && chip_case_retry_arg="chip_case_retry_delta=$chip_case_retry_delta" || chip_case_retry_arg=""
[[ -n "$pregen_dir" ]] && pregen_dir_arg="chip_code_pre_generated_directory=\"$pregen_dir\"" || pregen_dir_arg=""

gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging enable_pylib=$enable_pybindings enable_rtti=$enable_pybindings chip_project_config_include_dirs=[\"//config/python\"] $chip_mdns_arg $chip_case_retry_arg"
gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging enable_pylib=$enable_pybindings enable_rtti=$enable_pybindings chip_project_config_include_dirs=[\"//config/python\"] $chip_mdns_arg $chip_case_retry_arg $pregen_dir_arg"

# Compiles python files
# Check pybindings was requested
Expand Down

0 comments on commit 1ba581b

Please sign in to comment.