diff options
-rw-r--r-- | .github/workflows/makefile-escaping.yml | 52 | ||||
-rw-r--r-- | makefile_escaping/escaping_env_vars.mk | 23 | ||||
-rw-r--r-- | makefile_escaping/escaping_quotes.mk | 2 | ||||
-rw-r--r-- | makefile_escaping/escaping_shell.mk | 18 | ||||
-rw-r--r-- | makefile_escaping/quoting_args.mk | 8 |
5 files changed, 36 insertions, 67 deletions
diff --git a/.github/workflows/makefile-escaping.yml b/.github/workflows/makefile-escaping.yml index d6cc01d..e2dbf6c 100644 --- a/.github/workflows/makefile-escaping.yml +++ b/.github/workflows/makefile-escaping.yml @@ -15,15 +15,11 @@ jobs: diff <( echo "$expected" ) <( make -f quoting_args.mk test ) env: expected: |- - printf '%s\n' Same line? Same line? - printf '%s\n' 'Same line?' Same line? - printf '%s\n' $test_var Same line? - printf '%s\n' "$test_var" Same line? escaping_quotes: name: Escaping quotes @@ -49,49 +45,53 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: make test + - name: "Includes ' quote" run: | cd makefile_escaping diff <( echo "$expected_includes_quote" ) <( mkdir -p -- "Includes ' quote" && cd -- "Includes ' quote" && make -f ../escaping_shell.mk test ) + - name: 'Maybe a comment #' + run: | + cd makefile_escaping diff <( echo "$expected_maybe_comment" ) <( mkdir -p -- 'Maybe a comment #' && cd -- 'Maybe a comment #' && make -f ../escaping_shell.mk test ) + - name: 'Variable ${reference}' + run: | + cd makefile_escaping diff <( echo "$expected_variable_reference" ) <( mkdir -p -- 'Variable ${reference}' && cd -- 'Variable ${reference}' && make -f ../escaping_shell.mk test ) env: expected_includes_quote: |- Includes ' quote - Includes ' quote - Includes ' quote - Includes ' quote - Outer variable - Inner variable - Includes ' quote - Outer variable - Inner variable - Includes ' quote + Composite value - Simple value - Includes ' quote expected_maybe_comment: |- Maybe a comment # - Maybe a comment # - Maybe a comment # - Maybe a comment # - Outer variable - Inner variable - Maybe a comment # - Outer variable - Inner variable - Maybe a comment # + Composite value - Simple value - Maybe a comment # expected_variable_reference: |- Variable ${reference} - Variable ${reference} - Variable ${reference} - Variable ${reference} - Outer variable - Inner variable - Variable ${reference} - Outer variable - Inner variable - Variable ${reference} + Composite value - Simple value - Variable ${reference} env_variables: name: Environment variables runs-on: ubuntu-18.04 steps: - name: Checkout uses: actions/checkout@v2 - - name: make test + - name: make test w/ default test_var + run: | + cd makefile_escaping + diff <( echo "$expected_default" ) <( make -f escaping_env_vars.mk test ) + - name: make test w/ tricky test_var + run: | + cd makefile_escaping + diff <( echo "$expected_tricky" ) <( test_var="Quote ' "'and variable ${reference}' make -f escaping_env_vars.mk test ) + - name: make test w/ overridden test_var run: | cd makefile_escaping - diff <( echo "$expected" ) <( test_var="Quote ' "'and variable ${reference}' make -f escaping_env_vars.mk test ) + diff <( echo "$expected_overridden" ) <( make -f escaping_env_vars.mk test test_var="Quote ' "'and variable ${reference}' ) env: - expected: |- - Quote ' and variable ${reference} - Quote ' and variable ${reference} - Quote ' and variable ${reference} + expected_default: |- + New simple value (in test_var) + Composite value - New simple value - New simple value (in test_var) + expected_tricky: |- Quote ' and variable ${reference} Composite value - New simple value - Quote ' and variable ${reference} + expected_overridden: |- + Quote ' and variable ${reference} Composite value - New simple value - Quote ' and variable ${reference} diff --git a/makefile_escaping/escaping_env_vars.mk b/makefile_escaping/escaping_env_vars.mk index 421c4b6..f2e7a2d 100644 --- a/makefile_escaping/escaping_env_vars.mk +++ b/makefile_escaping/escaping_env_vars.mk @@ -7,7 +7,7 @@ SHELL := bash escape = $(subst ','\'',$(1)) -define escape_arg +define escape_env ifeq ($$(origin $(1)),environment) $(1) := $$(value $(1)) endif @@ -19,32 +19,15 @@ override $(1) := $$(value $(1)) endif endef -# Simple variable. simple_var := Simple value -test_var ?= $(simple_var) -export test_var - -$(eval $(call escape_arg,test_var)) +test_var ?= $(simple_var) (in test_var) +$(eval $(call escape_env,test_var)) simple_var := New simple value - -# printf $test_var -echo_test_var := printf '%s\n' '$(call escape,$(test_var))' -# bash -c 'printf $test_var' -bash_test_var := bash -c '$(call escape,$(echo_test_var))' - -# Composite variable, includes both $simple_var and $test_var. composite_var := Composite value - $(simple_var) - $(test_var) -# printf $composite_var -echo_composite_var := printf '%s\n' '$(call escape,$(composite_var))' - .PHONY: test test: @printf '%s\n' '$(call escape,$(test_var))' - @printf '%s\n' "$$test_var" - @bash -c '$(call escape,$(echo_test_var))' - @bash -c '$(call escape,$(bash_test_var))' @printf '%s\n' '$(call escape,$(composite_var))' - @bash -c '$(call escape,$(echo_composite_var))' diff --git a/makefile_escaping/escaping_quotes.mk b/makefile_escaping/escaping_quotes.mk index 13835e7..2a43f69 100644 --- a/makefile_escaping/escaping_quotes.mk +++ b/makefile_escaping/escaping_quotes.mk @@ -9,9 +9,7 @@ escape = $(subst ','\'',$(1)) test_var := Includes ' quote -# printf $test_var echo_test_var := printf '%s\n' '$(call escape,$(test_var))' -# bash -c 'printf $test_var' bash_test_var := bash -c '$(call escape,$(echo_test_var))' test: diff --git a/makefile_escaping/escaping_shell.mk b/makefile_escaping/escaping_shell.mk index 39fabf2..1be9c02 100644 --- a/makefile_escaping/escaping_shell.mk +++ b/makefile_escaping/escaping_shell.mk @@ -8,26 +8,14 @@ SHELL := bash escape = $(subst ','\'',$(1)) cwd := $(shell basename -- "$$( pwd )") -export cwd -# printf $cwd echo_cwd := printf '%s\n' '$(call escape,$(cwd))' -# bash -c 'printf $cwd' bash_cwd := bash -c '$(call escape,$(echo_cwd))' -# Simple variable. -inner_var := Inner variable -# Composite variable, includes both $inner_var and $cwd. -outer_var := Outer variable - $(inner_var) - $(cwd) - -# printf $outer_var -echo_outer_var := printf '%s\n' '$(call escape,$(outer_var))' +simple_var := Simple value +compisite_var := Composite value - $(simple_var) - $(cwd) .PHONY: test test: @printf '%s\n' '$(call escape,$(cwd))' - @printf '%s\n' "$$cwd" - @bash -c '$(call escape,$(echo_cwd))' - @bash -c '$(call escape,$(bash_cwd))' - @printf '%s\n' '$(call escape,$(outer_var))' - @bash -c '$(call escape,$(echo_outer_var))' + @printf '%s\n' '$(call escape,$(compisite_var))' diff --git a/makefile_escaping/quoting_args.mk b/makefile_escaping/quoting_args.mk index ff55f51..db4f7cf 100644 --- a/makefile_escaping/quoting_args.mk +++ b/makefile_escaping/quoting_args.mk @@ -9,7 +9,7 @@ test_var := Same line? export test_var test: - printf '%s\n' $(test_var) - printf '%s\n' '$(test_var)' - printf '%s\n' $$test_var - printf '%s\n' "$$test_var" + @printf '%s\n' $(test_var) + @printf '%s\n' '$(test_var)' + @printf '%s\n' $$test_var + @printf '%s\n' "$$test_var" |