From a8c0099576720fcf3c17a56238d87b21fa0cf089 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Thu, 8 Jun 2023 05:37:19 -0700 Subject: [PATCH] separate generated env files between container and make uses --- Makefile | 29 ++++++++++++++++++++--------- scripts/environment | 9 ++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 5869bab..cc5e180 100644 --- a/Makefile +++ b/Makefile @@ -45,18 +45,28 @@ BIN_DIR := $(CACHE_DIR_ROOT)/bin SRC_DIR := src KEY_DIR := keys OUT_DIR := out - -export - docker = docker include $(CONFIG_DIR)/toolchain.env export $(shell sed 's/=.*//' $(CONFIG_DIR)/toolchain.env) +export + +AUTOBUILD_TOOLCHAIN := true +ifeq ($(AUTOBUILD_TOOLCHAIN),true) +ifeq ("$(wildcard $(CACHE_DIR_ROOT)/make.env)","") + echo := $(info $(shell echo "Initializing toolchain.")) + build_env := $(shell $(MAKE) AUTOBUILD_TOOLCHAIN=false toolchain ) +endif +endif +ifneq (,$(wildcard $(CACHE_DIR_ROOT)/make.env)) + include $(CACHE_DIR_ROOT)/make.env + export $(shell sed 's/=.*//' $(CACHE_DIR_ROOT)/make.env) +endif ## Use env vars from existing release if present ifneq (,$(wildcard $(DIST_DIR)/release.env)) - include $(DIST_DIR)/release.env - export + include $(DIST_DIR)/release.env + export endif executables = $(docker) git git-lfs patch @@ -68,7 +78,8 @@ toolchain: \ $(BIN_DIR) \ $(OUT_DIR) \ $(CACHE_DIR_ROOT)/toolchain.state \ - $(CACHE_DIR_ROOT)/toolchain.env + $(CACHE_DIR_ROOT)/container.env \ + $(CACHE_DIR_ROOT)/make.env # Launch a shell inside the toolchain container .PHONY: toolchain-shell @@ -129,7 +140,7 @@ $(FETCH_DIR): $(OUT_DIR): mkdir -p $@ -$(CACHE_DIR_ROOT)/toolchain.env: \ +$(CACHE_DIR_ROOT)/make.env $(CACHE_DIR_ROOT)/container.env: \ $(CACHE_DIR_ROOT)/toolchain.state env > $(CACHE_DIR)/bootstrap.env docker run \ @@ -141,7 +152,7 @@ $(CACHE_DIR_ROOT)/toolchain.env: \ --volume $(TOOLCHAIN_VOLUME) \ --workdir $(TOOLCHAIN_WORKDIR) \ $(shell cat cache/toolchain.state 2> /dev/null) \ - $(SRC_DIR)/toolchain/scripts/environment > $@ + $(SRC_DIR)/toolchain/scripts/environment $(CACHE_DIR_ROOT) rm $(CACHE_DIR)/bootstrap.env $(CACHE_DIR_ROOT)/toolchain.tar: \ @@ -234,7 +245,7 @@ define toolchain --cpus $(CPUS) \ --volume $(TOOLCHAIN_VOLUME) \ --workdir $(TOOLCHAIN_WORKDIR) \ - --env-file=$(CACHE_DIR_ROOT)/toolchain.env \ + --env-file=$(CACHE_DIR_ROOT)/container.env \ $(shell cat cache/toolchain.state 2> /dev/null) \ $(SRC_DIR)/toolchain/scripts/host-env bash -c $(1) endef diff --git a/scripts/environment b/scripts/environment index ed939ce..5f41ccc 100755 --- a/scripts/environment +++ b/scripts/environment @@ -1,11 +1,12 @@ #!/bin/sh +CACHE_DIR_ROOT=${1?} HOME=/home/build CONFIG_DIR=/home/build/config -cat ${CONFIG_DIR}/toolchain.env +cat ${CONFIG_DIR}/toolchain.env > ${CACHE_DIR_ROOT}/container.env -cat <<- EOF +cat <<- EOF >> ${CACHE_DIR_ROOT}/container.env HOME=${HOME} PATH=${HOME}/${BIN_DIR}:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin TZ=UTC @@ -38,4 +39,6 @@ cat <<- EOF FETCH_DIR=${HOME}/${FETCH_DIR} EOF -envsubst < ${CONFIG_DIR}/global.env +envsubst < ${CONFIG_DIR}/global.env > ${CACHE_DIR_ROOT}/make.env + +cat ${CACHE_DIR_ROOT}/make.env >> ${CACHE_DIR_ROOT}/container.env