Skip to content

Commit 78c6a7e

Browse files
Avoid editable install of py_matter_idl in build env (#39826)
* Avoid editable install of py_matter_idl in build env The editable install creates a problem for the way the configure script creates the build env, because it assumes that it can create a self-contained, reusable build env that keeps working even if the original source directory is removed or moved to a different location. This is no longer true when the build env contains effectively a "symlink" into the source tree. This change instead modifies codegen.py and codegen_paths.py to directly find py_matter_idl relative to the script directory and import them from there, without relying on the editable install. The python-path pip package is used to do this (essentially it's just a small utility for resolving a path and prepending it to sys.path, allowing the code in the script itself to remain readable and straightforward.) * Avoid empty path in error message * Include py_matter_idl dependencies in requirements.build.txt * Ensure CDPATH doesn't affect configure script
1 parent 5b51867 commit 78c6a7e

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

scripts/codegen.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# py_matter_idl may not be installed in the pigweed venv.
17+
# Reference it directly from the source tree.
18+
from python_path import PythonPath
19+
20+
with PythonPath('py_matter_idl', relative_to=__file__):
21+
from matter.idl.generators.path_resolution import expand_path_for_idl
22+
from matter.idl.generators.registry import GENERATORS, CodeGenerator
23+
from matter.idl.generators.storage import FileSystemGeneratorStorage, GeneratorStorage
24+
from matter.idl.matter_idl_parser import CreateParser
25+
1626
import logging
1727
import sys
1828

@@ -24,11 +34,6 @@
2434
except ImportError:
2535
_has_coloredlogs = False
2636

27-
from matter.idl.generators.path_resolution import expand_path_for_idl
28-
from matter.idl.generators.registry import GENERATORS, CodeGenerator
29-
from matter.idl.generators.storage import FileSystemGeneratorStorage, GeneratorStorage
30-
from matter.idl.matter_idl_parser import CreateParser
31-
3237

3338
class ListGeneratedFilesStorage(GeneratorStorage):
3439
"""

scripts/codegen_paths.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# py_matter_idl may not be installed in the pigweed venv.
17+
# Reference it directly from the source tree.
18+
from python_path import PythonPath
19+
20+
with PythonPath('py_matter_idl', relative_to=__file__):
21+
from matter.idl.generators.path_resolution import expand_path_for_idl
22+
from matter.idl.matter_idl_parser import CreateParser
23+
1624
import logging
1725

1826
import click
@@ -23,9 +31,6 @@
2331
except ImportError:
2432
_has_coloredlogs = False
2533

26-
from matter.idl.generators.path_resolution import expand_path_for_idl
27-
from matter.idl.matter_idl_parser import CreateParser
28-
2934
# Supported log levels, mapping string values required for argument
3035
# parsing into logging constants
3136
__LOG_LEVELS__ = {

scripts/configure

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
set -o pipefail
3838
shopt -s extglob
39+
unset CDPATH
3940

4041
function usage() { # status
4142
info "Usage: $0 [OPTIONS] [--project=... [PROJECT OPTIONS]]"
@@ -67,7 +68,7 @@ function usage() { # status
6768
}
6869

6970
function main() { # ...
70-
CHIP_ROOT=$(cd "$(dirname "$0")/.." >/dev/null && pwd)
71+
CHIP_ROOT=$(cd "$(dirname "$0")/.." && pwd)
7172
BUILD_ENV_DEPS=(
7273
"${CHIP_ROOT}/scripts/setup/requirements.build.txt"
7374
"${CHIP_ROOT}/scripts/setup/constraints.txt"
@@ -99,8 +100,8 @@ function main() { # ...
99100
[[ -n "$PROJECT" || -n "$BUILD_ENV_DIR" ]] || usage 1
100101

101102
if [[ -n "$PROJECT" ]]; then
102-
PROJECT_PATH="$(cd "${CHIP_ROOT}" >/dev/null && cd "${PROJECT}" >/dev/null && pwd)"
103-
[[ -n "$PROJECT_PATH" && -r "${PROJECT_PATH}/.gn" ]] || fail "Invalid project '${PROJECT}' - missing .gn at '${PROJECT_PATH}'"
103+
PROJECT_PATH="$(cd "${CHIP_ROOT}" 2>/dev/null && cd "${PROJECT}" 2>/dev/null && pwd)"
104+
[[ -n "$PROJECT_PATH" && -r "${PROJECT_PATH}/.gn" ]] || fail "Invalid project '${PROJECT}' (no such directory or missing .gn file)"
104105
fi
105106

106107
if [[ -n "$PW_ROOT" ]]; then
@@ -131,7 +132,7 @@ function main() { # ...
131132

132133
if [[ -n "$BUILD_ENV_DIR" ]]; then
133134
mkdir -p "$BUILD_ENV_DIR"
134-
BUILD_ENV_PATH="$(cd "$BUILD_ENV_DIR" >/dev/null && pwd)"
135+
BUILD_ENV_PATH="$(cd "$BUILD_ENV_DIR" && pwd)"
135136
[[ -n "$BUILD_ENV_PATH" ]] || fail "Invalid build-env-dir '${BUILD_ENV_DIR}'"
136137
BUILD_ENV_DIR="$BUILD_ENV_PATH" # absolute
137138
else
@@ -281,7 +282,6 @@ function configure_python_env() {
281282
# Ensure pip and wheel are up to date first (using pip.pyz if necessary)
282283
"${BUILD_ENV_PATH}/bin/python3" "$pip" install --require-virtualenv --quiet --upgrade pip wheel
283284

284-
export PW_PROJECT_ROOT=$CHIP_ROOT
285285
"${BUILD_ENV_PATH}/bin/pip" install --require-virtualenv --quiet \
286286
-r "${CHIP_ROOT}/scripts/setup/requirements.build.txt" \
287287
-c "${CHIP_ROOT}/scripts/setup/constraints.txt"

scripts/setup/requirements.all.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pyobjc-core; sys_platform == 'darwin'
1919
pyobjc-framework-cocoa; sys_platform == 'darwin'
2020
pyobjc-framework-corebluetooth; sys_platform == 'darwin'
2121

22+
# other tools
23+
click-option-group
24+
2225
# python unit tests run directly without installing
2326
# built venv
2427
#

scripts/setup/requirements.build.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
# Ideally, core build scripts should depend only on the standard library.
77

8-
# scripts/build
8+
# scripts/build, scripts/codegen, py_matter_idl
99
click
10-
click-option-group
11-
12-
-e ${PW_PROJECT_ROOT}/scripts/py_matter_idl
10+
coloredlogs
11+
jinja2
12+
lark
13+
python-path

0 commit comments

Comments
 (0)