build: reduce build environment pollution

Instead of exporting various variables (unintendedly making them
available to the OpenWrt build, possibly bypassing .config), pass the
environment only to commands that need it.
This commit is contained in:
Matthias Schiffer 2020-03-07 13:47:59 +01:00 committed by Martin Weinelt
parent a180bb8689
commit 6155bf82c8

View File

@ -14,6 +14,8 @@ define mkabspath
override $(1) := $(abspath $($(1))) override $(1) := $(abspath $($(1)))
endef endef
escape = '$(subst ','\'',$(1))'
GLUON_SITEDIR ?= site GLUON_SITEDIR ?= site
$(eval $(call mkabspath,GLUON_SITEDIR)) $(eval $(call mkabspath,GLUON_SITEDIR))
@ -44,8 +46,13 @@ $(eval $(call mkabspath,GLUON_PATCHESDIR))
GLUON_MULTIDOMAIN ?= 0 GLUON_MULTIDOMAIN ?= 0
GLUON_DEBUG ?= 0 GLUON_DEBUG ?= 0
export GLUON_RELEASE GLUON_REGION GLUON_MULTIDOMAIN GLUON_DEBUG GLUON_DEPRECATED GLUON_DEVICES \ GLUON_VARS = \
GLUON_TARGETSDIR GLUON_PATCHESDIR GLUON_TMPDIR GLUON_IMAGEDIR GLUON_PACKAGEDIR GLUON_RELEASE GLUON_REGION GLUON_MULTIDOMAIN GLUON_DEBUG GLUON_DEPRECATED GLUON_DEVICES \
GLUON_TARGETSDIR GLUON_PATCHESDIR GLUON_TMPDIR GLUON_IMAGEDIR GLUON_PACKAGEDIR \
GLUON_SITEDIR GLUON_RELEASE GLUON_BRANCH GLUON_LANGS BOARD SUBTARGET
unexport $(GLUON_VARS)
GLUON_ENV = $(foreach var,$(GLUON_VARS),$(var)=$(call escape,$($(var))))
show-release: show-release:
@echo '$(GLUON_RELEASE)' @echo '$(GLUON_RELEASE)'
@ -53,18 +60,20 @@ show-release:
update: FORCE update: FORCE
@ @
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/update.sh export $(GLUON_ENV)
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/patch.sh scripts/update.sh
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/feeds.sh scripts/patch.sh
scripts/feeds.sh
update-patches: FORCE update-patches: FORCE
@ @
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/update.sh export $(GLUON_ENV)
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/update-patches.sh scripts/update.sh
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/patch.sh scripts/update-patches.sh
scripts/patch.sh
update-feeds: FORCE update-feeds: FORCE
@GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/feeds.sh @$(GLUON_ENV) scripts/feeds.sh
GLUON_TARGETS := GLUON_TARGETS :=
@ -84,14 +93,6 @@ OPENWRTMAKE = $(MAKE) -C openwrt
BOARD := $(GLUON_TARGET_$(GLUON_TARGET)_BOARD) BOARD := $(GLUON_TARGET_$(GLUON_TARGET)_BOARD)
SUBTARGET := $(GLUON_TARGET_$(GLUON_TARGET)_SUBTARGET) SUBTARGET := $(GLUON_TARGET_$(GLUON_TARGET)_SUBTARGET)
GLUON_CONFIG_VARS := \
GLUON_SITEDIR='$(GLUON_SITEDIR)' \
GLUON_RELEASE='$(GLUON_RELEASE)' \
GLUON_BRANCH='$(GLUON_BRANCH)' \
GLUON_LANGS='$(GLUON_LANGS)' \
BOARD='$(BOARD)' \
SUBTARGET='$(SUBTARGET)'
define CheckTarget define CheckTarget
if [ -z '$(BOARD)' ]; then if [ -z '$(BOARD)' ]; then
@ -177,21 +178,21 @@ config: $(LUA) FORCE
$(call CheckSite,$(conf)); \ $(call CheckSite,$(conf)); \
) )
$(GLUON_CONFIG_VARS) \ $(GLUON_ENV) \
$(LUA) scripts/target_config.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)' \ $(LUA) scripts/target_config.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)' \
> openwrt/.config > openwrt/.config
$(OPENWRTMAKE) defconfig $(OPENWRTMAKE) defconfig
$(GLUON_CONFIG_VARS) \ $(GLUON_ENV) \
$(LUA) scripts/target_config_check.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)' $(LUA) scripts/target_config_check.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)'
all: config all: config
+@ +@
$(GLUON_CONFIG_VARS) \ $(GLUON_ENV) \
$(LUA) scripts/clean_output.lua $(LUA) scripts/clean_output.lua
$(OPENWRTMAKE) $(OPENWRTMAKE)
$(GLUON_CONFIG_VARS) \ $(GLUON_ENV) \
$(LUA) scripts/copy_output.lua '$(GLUON_TARGET)' $(LUA) scripts/copy_output.lua '$(GLUON_TARGET)'
clean download: config clean download: config
@ -210,12 +211,13 @@ manifest: $(LUA) FORCE
$(CheckExternal) $(CheckExternal)
( (
export $(GLUON_ENV)
echo 'BRANCH=$(GLUON_BRANCH)' echo 'BRANCH=$(GLUON_BRANCH)'
echo "DATE=$$($(LUA) scripts/rfc3339date.lua)" echo "DATE=$$($(LUA) scripts/rfc3339date.lua)"
echo 'PRIORITY=$(GLUON_PRIORITY)' echo 'PRIORITY=$(GLUON_PRIORITY)'
echo echo
for target in $(GLUON_TARGETS); do for target in $(GLUON_TARGETS); do
GLUON_SITEDIR='$(GLUON_SITEDIR)' $(LUA) scripts/generate_manifest.lua "$$target" $(LUA) scripts/generate_manifest.lua "$$target"
done done
) > 'tmp/$(GLUON_BRANCH).manifest.tmp' ) > 'tmp/$(GLUON_BRANCH).manifest.tmp'