Skip to content

Commit

Permalink
Fix error on build-test-windows workflow (open-telemetry#27250)
Browse files Browse the repository at this point in the history
Fix open-telemetry#25843

The issue is that the `go` tool generates directories as per its build
OS, so on Windows, `go list -f '{{ .Dir }}' ./...` outputs paths in
Windows format, e.g.: "c:\src\otel-col-contrib", however, the tools used
by the make expect paths to be in Unix format. This change adds a `sed`
expression to convert the Windows paths to Unix paths so they can be
passed to tools like `find`.
  • Loading branch information
pjanotti committed Sep 28, 2023
1 parent 281d1ad commit 189a64b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
# otherwise in the example command pipe, only the exit code of `tee` is recorded instead of `go test` which can cause
# test to pass in CI when they should not.
SHELL = /bin/bash
ifeq ($(shell uname -s),Windows)
.SHELLFLAGS = /o pipefile /c
.SHELLFLAGS = -o pipefail -c

SHELL_CASE_EXP = case "$$(uname -s)" in CYGWIN*|MINGW*|MSYS*) echo "true";; esac;
UNIX_SHELL_ON_WINDOWS := $(shell $(SHELL_CASE_EXP))

ifeq ($(UNIX_SHELL_ON_WINDOWS),true)
# The "sed" transformation below is needed on Windows, since commands like `go list -f '{{ .Dir }}'`
# return Windows paths and such paths are incompatible with other *nix tools, like `find`,
# used by the Makefile shell.
# The backslash needs to be doubled so its passed correctly to the shell.
NORMALIZE_DIRS = sed -e 's/^/\\//' -e 's/:https://' -e 's/\\\\/\\//g' | sort
else
.SHELLFLAGS = -o pipefail -c
NORMALIZE_DIRS = sort
endif

# SRC_ROOT is the top of the source tree.
Expand Down Expand Up @@ -63,7 +72,7 @@ GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck
# BUILD_TYPE should be one of (dev, release).
BUILD_TYPE?=release

ALL_PKG_DIRS := $(shell $(GOCMD) list -f '{{ .Dir }}' ./... | sort)
ALL_PKG_DIRS := $(shell $(GOCMD) list -f '{{ .Dir }}' ./... | $(NORMALIZE_DIRS))

ALL_SRC := $(shell find $(ALL_PKG_DIRS) -name '*.go' \
-not -path '*/third_party/*' \
Expand Down

0 comments on commit 189a64b

Please sign in to comment.