diff mbox series

[2/3] utils/docker-run: also mount externals

Message ID 20240713144316.403640-2-arnout@mind.be
State New
Headers show
Series [1/3] utils/docker-run: allow to specify extra mount points to propagate | expand

Commit Message

Arnout Vandecappelle July 13, 2024, 2:43 p.m. UTC
When building in docker, we may want to include BR2_EXTERNALs that are
not in the current directory. These need to be mounted into the
container as well.

There is unfortunately no easy, generic way to find the list of
externals, except by running `make printvars`, but we'd need to run that
inside the container with all the command-line overrides set in order to
be fully correct. That is pretty hopeless, so as an approximation we
look for `.br2-external.mk` in the current directory.

Clearly this is quite limited because it doesn't support O= or
BR2_EXTERNAL= passed on the command line. This also means that the first
time, it doesn't work at all, because .br2-external.mk doesn't exist
yet. The EXTRA_MOUNTPOINTS feature can be used for that.

Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
---
Since this feature is not bulletproof, and EXTRA_MOUNTPOINTS already
covers the use case, it's perhaps not necessary to include this patch.
---
 utils/docker-run | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Brandon Maier July 13, 2024, 4:33 p.m. UTC | #1
Hi Arnout,

On Sat Jul 13, 2024 at 2:43 PM UTC, Arnout Vandecappelle via buildroot wrote:
> When building in docker, we may want to include BR2_EXTERNALs that are
> not in the current directory. These need to be mounted into the
> container as well.
>
> There is unfortunately no easy, generic way to find the list of
> externals, except by running `make printvars`, but we'd need to run that
> inside the container with all the command-line overrides set in order to
> be fully correct. That is pretty hopeless, so as an approximation we
> look for `.br2-external.mk` in the current directory.

I have a maybe bad idea. But Buildroot does have a feature where it will
call `make` inside of `make` to set umask and other args, the '_all'
target in '$(TOPDIR)/Makefile'. Could we support all of these features
like this?

    ifeq ($(BR2_ENABLE_DOCKER),y)
    ifeq ($(BR2_SOME_VARIABLE_SET_INSIDE_DOCKER),)
    _all:
        $(TOPDIR)/utils/docker-run umask $(REQ_UMASK) && $(MAKE) ...
    else
    _all:
        ...
    endif

Buildroot has access to the actual BR2_EXTERNAL, OUTPUT_DIR, etc. So it
would be able to call docker-run with the correct arguments. And then it
would work when calling make from $(TOPDIR), or from inside custom
scripts like `brmake`.

Thanks,
Brandon

>
> Clearly this is quite limited because it doesn't support O= or
> BR2_EXTERNAL= passed on the command line. This also means that the first
> time, it doesn't work at all, because .br2-external.mk doesn't exist
> yet. The EXTRA_MOUNTPOINTS feature can be used for that.
>
> Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
> ---
> Since this feature is not bulletproof, and EXTRA_MOUNTPOINTS already
> covers the use case, it's perhaps not necessary to include this patch.
> ---
>  utils/docker-run | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/utils/docker-run b/utils/docker-run
> index 3bb7b6a41b..76fb81b074 100755
> --- a/utils/docker-run
> +++ b/utils/docker-run
> @@ -29,6 +29,19 @@ declare -a mountpoints=(
>      "$(pwd)"
>  )
>
> +# If any externals are defined, mount them as well. We assume that the current
> +# directory is OUTPUT_DIR - ideally we'd parse O= and BR2_EXTERNAL= from the
> +# command line but that's not really feasible in practice.
> +if [ -e '.br2-external.mk' ]; then
> +    mapfile -t mountpoints_external < <(
> +        # We obviously want to quote the make syntax here
> +        # shellcheck disable=SC2016
> +        make -f .br2-external.mk -E \
> +            'default:; @:$(foreach external,$(BR2_EXTERNAL_DIRS),$(info $(external)))'
> +    )
> +    mountpoints+=("${mountpoints_external[@]}")
> +fi
> +
>  # We use the PODMAN_USERNS environment variable rather than using the
>  # --userns command line argument because Fedora system may have the
>  # podman-docker package installed, providing the "docker"
diff mbox series

Patch

diff --git a/utils/docker-run b/utils/docker-run
index 3bb7b6a41b..76fb81b074 100755
--- a/utils/docker-run
+++ b/utils/docker-run
@@ -29,6 +29,19 @@  declare -a mountpoints=(
     "$(pwd)"
 )
 
+# If any externals are defined, mount them as well. We assume that the current
+# directory is OUTPUT_DIR - ideally we'd parse O= and BR2_EXTERNAL= from the
+# command line but that's not really feasible in practice.
+if [ -e '.br2-external.mk' ]; then
+    mapfile -t mountpoints_external < <(
+        # We obviously want to quote the make syntax here
+        # shellcheck disable=SC2016
+        make -f .br2-external.mk -E \
+            'default:; @:$(foreach external,$(BR2_EXTERNAL_DIRS),$(info $(external)))'
+    )
+    mountpoints+=("${mountpoints_external[@]}")
+fi
+
 # We use the PODMAN_USERNS environment variable rather than using the
 # --userns command line argument because Fedora system may have the
 # podman-docker package installed, providing the "docker"