From 02d4ee3f9aea7e296ac3f3afb39d4428c38c6251 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 15 Mar 2024 17:42:58 +0100 Subject: [PATCH] Makefile: generate-files: fix check for empty TMP_OUT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit c655b7dc78b3a0773f33f92e9c923a2e48e9c62b added a check to make sure the TMP_OUT variable was not set to an empty value, as such a situation would perform an `rm -rf /**` during cleanup. However, it was a bit too eager, because Makefile conditionals (`ifeq`) are evaluated when parsing the Makefile, which happens _before_ the make target is executed. As a result `$@_TMP_OUT` was always empty when the `ifeq` was evaluated, making it not possible to execute the `generate-files` target. This patch changes the check to use a shell command to evaluate if the var is set to an empty value. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 25c9e6e8df956fe342e6f1969c96921c4f15b4e4) Signed-off-by: Paweł Gronowski --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 99c8edbd57..b379d8cf7b 100644 --- a/Makefile +++ b/Makefile @@ -250,9 +250,10 @@ swagger-docs: ## preview the API documentation .PHONY: generate-files generate-files: $(eval $@_TMP_OUT := $(shell mktemp -d -t moby-output.XXXXXXXXXX)) - ifeq ($($@_TMP_OUT),) - $(error Could not create temp directory.) - endif + @if [ -z "$($@_TMP_OUT)" ]; then \ + echo "Temp dir is not set"; \ + exit 1; \ + fi $(BUILD_CMD) --target "update" \ --output "type=local,dest=$($@_TMP_OUT)" \ --file "./hack/dockerfiles/generate-files.Dockerfile" .