From 1ba581b6ba02c29589052a3b1a267a03e369cc95 Mon Sep 17 00:00:00 2001 From: Oide Brett <32061073+oidebrett@users.noreply.github.com> Date: Thu, 2 Feb 2023 00:22:49 +0000 Subject: [PATCH] Allowing pregenerated files in python build (#24752) * 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 Co-authored-by: oidebrett Co-authored-by: Restyled.io --- docs/guides/matter-repl.md | 29 +++++++++++++++++++++++++++++ scripts/build_python.sh | 10 ++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/guides/matter-repl.md b/docs/guides/matter-repl.md index bf05be63ddb9a5..5b15ef583299c8 100644 --- a/docs/guides/matter-repl.md +++ b/docs/guides/matter-repl.md @@ -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: diff --git a/scripts/build_python.sh b/scripts/build_python.sh index 9247b873d568ee..866244c7e5379b 100755 --- a/scripts/build_python.sh +++ b/scripts/build_python.sh @@ -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. " } @@ -94,6 +95,10 @@ while (($#)); do install_wheel=$2 shift ;; + --pregen_dir | -z) + pregen_dir=$2 + shift + ;; -*) help echo "Unknown Option \"$1\"" @@ -104,7 +109,7 @@ 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" @@ -112,8 +117,9 @@ 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