diff mbox series

[v5,1/1] utils/docker-run: mount and pass BR2_EXTERNAL dirs

Message ID 20260405185608.1357633-1-fiona.klute@gmx.de
State Handled Elsewhere
Headers show
Series [v5,1/1] utils/docker-run: mount and pass BR2_EXTERNAL dirs | expand

Commit Message

Fiona Klute April 5, 2026, 6:56 p.m. UTC
The BR2_EXTERNAL environment variable is passed into the container,
and each path listed in it mounted. This allows using external trees
when running a build using utils/docker-run. Testing the existence of
the variable instead of a non-empty value allows passing an empty
BR2_EXTERNAL variable to disable currently set external trees.

Signed-off-by: Fiona Klute <fiona.klute@gmx.de>
---
Changes v4 -> v5:
* Avoid Bashism in "does BR2_EXTERNAL variable exist" check, suggested
  by Yann E. Morin.
* Make relative paths in BR2_EXTERNAL absolute for container bind
  mounts.

Changes v3 -> v4:
* Split BR2_EXTERNAL on spaces OR colons
* Revert changes to mountpoints processing loop

Changes v2 -> v3:
* Use read to make the loop that creates mount options more robust,
  removing pre-exisiting shellcheck override. Suggested by Brandon
  Maier.

Changes v1 -> v2:
* Correctly handle spaces in external tree paths

 utils/docker-run | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Fiona Klute April 24, 2026, 6:27 p.m. UTC | #1
Am 05.04.26 um 20:56 schrieb Fiona Klute:
> The BR2_EXTERNAL environment variable is passed into the container,
> and each path listed in it mounted. This allows using external trees
> when running a build using utils/docker-run. Testing the existence of
> the variable instead of a non-empty value allows passing an empty
> BR2_EXTERNAL variable to disable currently set external trees.
> 
> Signed-off-by: Fiona Klute <fiona.klute@gmx.de>

Gentle ping about this. Would be nice if it could be merged before 
reaching 2 years since v1. ;-)

Best regards,
Fiona

> ---
> Changes v4 -> v5:
> * Avoid Bashism in "does BR2_EXTERNAL variable exist" check, suggested
>    by Yann E. Morin.
> * Make relative paths in BR2_EXTERNAL absolute for container bind
>    mounts.
> 
> Changes v3 -> v4:
> * Split BR2_EXTERNAL on spaces OR colons
> * Revert changes to mountpoints processing loop
> 
> Changes v2 -> v3:
> * Use read to make the loop that creates mount options more robust,
>    removing pre-exisiting shellcheck override. Suggested by Brandon
>    Maier.
> 
> Changes v1 -> v2:
> * Correctly handle spaces in external tree paths
> 
>   utils/docker-run | 11 +++++++++++
>   1 file changed, 11 insertions(+)
> 
> diff --git a/utils/docker-run b/utils/docker-run
> index 27c169db72..37f6c12c0d 100755
> --- a/utils/docker-run
> +++ b/utils/docker-run
> @@ -97,6 +97,17 @@ if [ "${BR2_DL_DIR}" ]; then
>       docker_opts+=( --env BR2_DL_DIR )
>   fi
>   
> +# Testing the existence of the variable instead of a non-empty value
> +# allows passing an empty BR2_EXTERNAL variable to disable currently
> +# set external trees.
> +if [ "${BR2_EXTERNAL+set}" ]; then
> +    docker_opts+=( --env BR2_EXTERNAL )
> +    for br2_ext in ${BR2_EXTERNAL//:/ }; do
> +        # bind volume source paths must be absolute
> +        mountpoints+=( "$(realpath "$br2_ext")" )
> +    done
> +fi
> +
>   # shellcheck disable=SC2013 # can't use while-read because of the assignment
>   for dir in $(printf '%s\n' "${mountpoints[@]}" |LC_ALL=C sort -u); do
>       docker_opts+=( --mount "type=bind,src=${dir},dst=${dir}" )
diff mbox series

Patch

diff --git a/utils/docker-run b/utils/docker-run
index 27c169db72..37f6c12c0d 100755
--- a/utils/docker-run
+++ b/utils/docker-run
@@ -97,6 +97,17 @@  if [ "${BR2_DL_DIR}" ]; then
     docker_opts+=( --env BR2_DL_DIR )
 fi
 
+# Testing the existence of the variable instead of a non-empty value
+# allows passing an empty BR2_EXTERNAL variable to disable currently
+# set external trees.
+if [ "${BR2_EXTERNAL+set}" ]; then
+    docker_opts+=( --env BR2_EXTERNAL )
+    for br2_ext in ${BR2_EXTERNAL//:/ }; do
+        # bind volume source paths must be absolute
+        mountpoints+=( "$(realpath "$br2_ext")" )
+    done
+fi
+
 # shellcheck disable=SC2013 # can't use while-read because of the assignment
 for dir in $(printf '%s\n' "${mountpoints[@]}" |LC_ALL=C sort -u); do
     docker_opts+=( --mount "type=bind,src=${dir},dst=${dir}" )