Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit d83ffd1

Browse files
committed
Fix windows shell makefile
Signed-off-by: Mathieu Champlon <mathieu.champlon@docker.com>
1 parent 1a3906a commit d83ffd1

2 files changed

Lines changed: 28 additions & 21 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ coverage: coverage-test-unit coverage-test-e2e ## run tests with coverage
6060
go tool cover -html _build/cov/all.out -o _build/cov/coverage.html
6161

6262
clean: ## clean build artifacts
63-
$(call rm,bin)
64-
$(call rm,_build)
63+
$(call rmdir,bin)
64+
$(call rmdir,_build)
6565
$(call rm,docker-app-*.tar.gz)
6666

6767
vendor: ## update vendoring
68-
$(call rm,vendor)
68+
$(call rmdir,vendor)
6969
dep ensure -v
7070

7171
help: ## this help

vars.mk

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,37 @@ EXPERIMENTAL := off
88
# Comma-separated list of renderers
99
RENDERERS := "none"
1010

11-
TAG ?= $(shell git describe --always --dirty 2>/dev/null)
12-
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null)
11+
# Failing to resolve sh.exe to a full path denotes a windows vanilla shell.
12+
# Although 'simple' commands are still exec'ed, 'complex' ones are batch'ed instead of sh'ed.
13+
ifeq ($(SHELL),sh.exe)
14+
mkdir = mkdir $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
15+
rm = del /F /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
16+
rmdir = rmdir /S /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
17+
chmod =
18+
BUILDTIME ?= unknown
19+
NULL := nul
20+
else
21+
# The no-op redirection forces make to shell out the commands instead of spawning a process as
22+
# the latter can fail on windows running cmd or powershell while having a unix style shell in the path.
23+
mkdir = mkdir -p $(1) 1>&1
24+
rm = rm -rf $(1) 1>&1
25+
rmdir = rm -rf $(1) 1>&1
26+
chmod = chmod $(1) $(2) 1>&1
27+
NULL := /dev/null
28+
endif
1329

14-
WINDOWS := no
15-
ifneq ($(filter cmd.exe powershell.exe,$(subst /, ,$(SHELL))),)
16-
WINDOWS := yes
17-
BUILDTIME := unknown
30+
ifeq ($(TAG),)
31+
TAG := $(shell git describe --always --dirty 2> $(NULL))
32+
endif
33+
ifeq ($(COMMIT),)
34+
COMMIT := $(shell git rev-parse --short HEAD 2> $(NULL))
1835
endif
1936

2037
ifeq ($(BUILDTIME),)
21-
BUILDTIME := ${shell date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/'}
38+
BUILDTIME := $(shell date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')
2239
endif
2340
ifeq ($(BUILDTIME),)
24-
BUILDTIME := ${shell gdate --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/'}
41+
BUILDTIME := $(shell gdate --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')
2542
endif
2643
ifeq ($(BUILDTIME),)
2744
$(error unable to set BUILDTIME, ensure that you have GNU date installed or set manually)
@@ -34,16 +51,6 @@ LDFLAGS := "-s -w \
3451
-X $(PKG_NAME)/internal.Renderers=$(RENDERERS) \
3552
-X $(PKG_NAME)/internal.BuildTime=$(BUILDTIME)"
3653

37-
ifeq ($(WINDOWS),yes)
38-
mkdir = mkdir $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
39-
rm = del /S /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
40-
chmod =
41-
else
42-
mkdir = mkdir -p $(1)
43-
rm = rm -rf $(1)
44-
chmod = chmod $(1) $(2)
45-
endif
46-
4754
EXEC_EXT :=
4855
ifeq ($(OS),Windows_NT)
4956
EXEC_EXT := .exe

0 commit comments

Comments
 (0)