Skip to content

Commit c534070

Browse files
authored
[external build systems] scripts/configure: allow out-of-tree project root (project-chip#29627)
The configure script, intended for external build systems such as openwrt, so far only allowed projects contained within the connectedhomeip source tree. This is the case for CHIP examples, but is NOT viable for actual applications, where connectedhomeip is usually a submodule of the main project. This PR changes `scripts/configure` in a backwards compatible way as follows: - absolute paths specified with `--project` are now supported - relative paths specified with `--project` are still relative to CHIP_ROOT, but are also allowed to point outside (using ../../... type path). Tested with actual build of p44mbrd (https://github.com/plan44/p44mbrd) as openwrt package (https://github.com/plan44/plan44-feed/tree/main/p44mbrd)
1 parent 43159a8 commit c534070

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

scripts/configure

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function usage() { # status
4141
info "Usage: $0 [OPTIONS] [--project=... [PROJECT OPTIONS]]"
4242
info "Options:"
4343
info " --build-env-dir=DIR Directory to create (host) build environment in"
44-
info " --project=DIR Sub-directory to build, eg examples/lighting-app/linux"
44+
info " --project=DIR directory to build, absolute or relative to chip root,"
45+
info " eg examples/lighting-app/linux or /my/dir/my/app"
4546
info ""
4647
info "Project options (mapped to GN build args):"
4748
info " --enable-<ARG>[=no] Enables (or disables with '=no') a bool build arg"
@@ -68,6 +69,7 @@ function main() { # ...
6869
# Parse global options, process VAR=VALUE style arguments, and collect project options
6970
BUILD_ENV_DIR=
7071
PROJECT=
72+
PROJECT_PATH=
7173
PROJECT_ARGS=()
7274
while [[ $# -gt 0 ]]; do
7375
case "$1" in
@@ -87,10 +89,8 @@ function main() { # ...
8789
[[ -n "$PROJECT" || -n "$BUILD_ENV_DIR" ]] || usage 1
8890

8991
if [[ -n "$PROJECT" ]]; then
90-
local subdir="$(cd "${CHIP_ROOT}/${PROJECT}" 2>/dev/null && pwd)"
91-
[[ -n "$subdir" && -r "${subdir}/.gn" ]] || fail "Invalid project '${PROJECT}'"
92-
PROJECT="${subdir#${CHIP_ROOT}/}"
93-
[[ "$subdir" == "${CHIP_ROOT}/${PROJECT}" ]] || fail "Unable to determine project path"
92+
PROJECT_PATH="$(cd "${CHIP_ROOT}" 2>/dev/null && cd "${PROJECT}" 2>/dev/null && pwd)"
93+
[[ -n "$PROJECT_PATH" && -r "${PROJECT_PATH}/.gn" ]] || fail "Invalid project '${PROJECT}' - missing .gn at '${PROJECT_PATH}'"
9494
fi
9595

9696
check_binary gn GN
@@ -177,13 +177,13 @@ function gn_generate() { # [project options]
177177
ensure_no_clobber "${BUILD_DIR}/args.gn"
178178

179179
# Pass --script-executable to all `gn` calls so scripts run in our venv
180-
local gn=(gn --script-executable="${BUILD_ENV_DIR}/bin/python" --root="${CHIP_ROOT}/${PROJECT}")
180+
local gn=(gn --script-executable="${BUILD_ENV_DIR}/bin/python" --root="${PROJECT_PATH}")
181181

182182
# Run gn gen with an empty args.gn first so we can list all arguments
183183
info "Configuring gn build arguments (see $BUILD_DIR/args.configured for full list)"
184184
{
185185
echo "# ${CONFIGURE_MARKER}"
186-
echo "# project root: ${PROJECT}"
186+
echo "# project root: ${PROJECT_PATH}"
187187
} >"${BUILD_DIR}/args.gn"
188188
"${gn[@]}" -q gen "$BUILD_DIR"
189189

0 commit comments

Comments
 (0)