lmi-commits
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]