[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 01aee1e 04/16: Construct a unique temporary f
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 01aee1e 04/16: Construct a unique temporary filename to avoid collisions |
Date: |
Sat, 18 May 2019 20:53:35 -0400 (EDT) |
branch: master
commit 01aee1e6e270f49536caa1ecbffd1f181405c557
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Construct a unique temporary filename to avoid collisions
Replaced a static filename with a uniquified one. Added a recipe line
to remove that file after use. Noted an open question: is the former
static filename, now still used as a target name, utterly arbitrary?
---
gwc/parent.make | 16 +++++++++++++---
gwc/set.sh | 5 ++++-
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/gwc/parent.make b/gwc/parent.make
index 09eefce..6808af1 100644
--- a/gwc/parent.make
+++ b/gwc/parent.make
@@ -1,3 +1,9 @@
+# IMPORTANT: the former 'env.make' has been replaced by
+# env.$(LMI_TIMESTAMP).eraseme
+# in the non-commented-out code, but not in any comments.
+# Yet 'env.make' remains as a target; is that target's name
+# actually arbitrary?
+
# This demonstration shows a way to source a script in a makefile,
# and export environment variables set by that script to make's
# environment, thus:
@@ -7,8 +13,8 @@
# then writes 'make' assignments like "export foo := bar"
# for each desired environment variable
# To test:
-# $export LMI_IN=X; make -f parent.make all
-# $export LMI_IN=Q; make -f parent.make all
+# $export LMI_IN=Russia; LANG=ru_RU make -f parent.make all
+# $export LMI_IN=Mongolia; LANG=mn_MN make -f parent.make all
# and check what appears on stdout.
# A file named 'env.make' is created in the source directory.
@@ -21,6 +27,8 @@
# prerequisite may impair the efficiency that was gained by
# writing the double-colon rule.
+export LMI_TIMESTAMP := $(shell date -u +'%s.%N')
+
# No good: syntax error.
#include set.sh
@@ -31,10 +39,12 @@
#parent.make: env.make
parent.make parent.make:: env.make ;
# $(eval include) here is necessary and sufficient.
- $(eval include env.make)
+ $(eval include env.$(LMI_TIMESTAMP).eraseme)
@echo "eval: LMI_IN in 'parent.make': $$LMI_IN"
@echo "eval: LMI_OUT1 in 'parent.make': $$LMI_OUT1"
@echo "eval: LMI_OUT2 in 'parent.make': $$LMI_OUT2"
+# '--force': the file won't be there when this makefile is remade
+ rm --force env.$(LMI_TIMESTAMP).eraseme
# Doesn't execute recipe without ".PHONY":
.PHONY: env.make
diff --git a/gwc/set.sh b/gwc/set.sh
index 8ae899a..07483b6 100755
--- a/gwc/set.sh
+++ b/gwc/set.sh
@@ -2,6 +2,9 @@
foo()
{
+# $LMI_TIMESTAMP is defined by the makefile that sources this script.
+# shellcheck disable=SC2154
+echo "LMI_TIMESTAMP in 'set.sh': $LMI_TIMESTAMP"
echo "LMI_IN in 'set.sh': $LMI_IN"
echo "LMI_OUT1 entering 'set.sh': $LMI_OUT1"
echo "LMI_OUT2 entering 'set.sh': $LMI_OUT2"
@@ -12,7 +15,7 @@ echo "LMI_OUT2 leaving 'set.sh': $LMI_OUT2"
{
echo "export LMI_OUT1 := $LMI_OUT1"
echo "export LMI_OUT2 := $LMI_OUT2"
-} > env.make
+} > env."$LMI_TIMESTAMP".eraseme
}
foo
- [lmi-commits] [lmi] master 20f6dd2 15/16: Add git instructions to copy a branch into a master subdirectory, (continued)
- [lmi-commits] [lmi] master 20f6dd2 15/16: Add git instructions to copy a branch into a master subdirectory, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master 8b0a768 14/16: Invoke 'rm' without '--force', Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master 3ff6c00 16/16: Rewrite for clarity, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master fa96c05 13/16: Make tracing information easier to follow, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master f8d4676 11/16: Improve and compress output trace, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master b00ad83 10/16: Remove duplicated target name; improve documentation, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master 0ca7d61 09/16: Don't write env file if its name is empty or unset, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master 294f232 12/16: Improve documentation, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master c10b229 08/16: Actually perform some work in the script, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master a87426e 07/16: Name temporary environment-variables file OAOO, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master 01aee1e 04/16: Construct a unique temporary filename to avoid collisions,
Greg Chicares <=
- [lmi-commits] [lmi] master 315d415 03/16: Improve encapsulation, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master b4dd6ce 06/16: Resolve an open issue, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master 65cbb2f 05/16: Remove obsolete commentary, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master 6eace72 01/16: Source a shell script in a makefile, Greg Chicares, 2019/05/18
- [lmi-commits] [lmi] master 0401064 02/16: Set multiple variables, Greg Chicares, 2019/05/18