Skip to content

Commit

Permalink
fix: macos compatibility (#111)
Browse files Browse the repository at this point in the history
Signed-off-by: Tronje Krop <[email protected]>
  • Loading branch information
tkrop committed Oct 30, 2024
1 parent f0ac228 commit 8c1f321
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
37 changes: 32 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Go Build
on: [push]

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -17,13 +18,14 @@ jobs:
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
LANG: en_US.UTF-8
run: make --file=config/Makefile.base --trace all
run: make --file=config/Makefile.base --trace all;

- name: Send coverage report
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: ./build/test-all.cover


bash:
runs-on: ubuntu-latest
steps:
Expand All @@ -43,7 +45,8 @@ jobs:
- name: Run Bash compatibility tests
env:
BASH_COMPAT: 3.2
run: make --file=config/Makefile.base --trace test-self
run: make --file=config/Makefile.base --trace test-self;


linux:
runs-on: ubuntu-latest
Expand All @@ -63,15 +66,38 @@ jobs:

- name: Run Bash compatibility tests
run: |-
make --version
make --file=config/Makefile.base --trace test-self
make --version;
make --file=config/Makefile.base --trace test-self;
macos:
runs-on: macos-latest
steps:
# - name: Set up Docker
# uses: crazy-max/ghaction-setup-docker@v3

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.23.2

- name: Checkout code
uses: actions/checkout@v4

- name: Run MacOS compatibility tests
env:
BASH_COMPAT: 3.2
run: |-
make --version;
make --file=config/Makefile.base test-self;
macos-brewed:
runs-on: macos-latest
steps:
# - name: Set up Docker
# uses: crazy-max/ghaction-setup-docker@v3

- name: Set up Go
uses: actions/setup-go@v5
with:
Expand All @@ -87,7 +113,8 @@ jobs:
brew install make;
export PATH="/opt/homebrew/opt/make/libexec/gnubin:${PATH}";
make --version;
make --file=config/Makefile.base --trace test-self
make --file=config/Makefile.base --trace test-self;
release:
runs-on: ubuntu-latest
Expand Down
29 changes: 18 additions & 11 deletions config/Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
SHELL := /bin/bash

# Setup variables for special purposes.
NULL :=
COMMA := ,
SPACE := $(NULL) $(NULL)
TAB := $(NULL) $(NULL)
SPACE := $(SPACE) $(SPACE)
TAB := $(TAB) $(TAB)
define NEWLINE


Expand Down Expand Up @@ -46,14 +45,14 @@ endif

# System depdendent helper functions.
ifeq ("$(shell uname)","Linux")
MAKESHELL := PATH=$(PATH) /bin/bash
else ifeq ($(shell uname),Darwin)
path-setup = $(shell \
if [ "$(1)" == "opt" ]; then \
XPATH="$(shell brew --prefix)/$(1)/$(2)/libexec/gnubin"; \
else XPATH="$(shell brew --prefix)/$(1)"; fi; \
test ! -e "$${XPATH}/$(3)" && brew install $(2) >&2; \
echo -n "$${XPATH}:$(4)")
if [ -n "$(4)" ]; then echo -n "$${XPATH}:$(4)"; \
else echo -n "$${XPATH}"; fi)
export PATH := $(call path-setup,opt,coreutils,ls,$(PATH))
export PATH := $(call path-setup,opt,findutils,find,$(PATH))
export PATH := $(call path-setup,bin,bash,bash,$(PATH))
Expand All @@ -62,15 +61,21 @@ else ifeq ($(shell uname),Darwin)
export PATH := $(call path-setup,opt,gsed,sed,$(PATH))
export PATH := $(call path-setup,opt,make,make,$(PATH))
# Ensure export of path to $(shell ...) in gmake 3.81.
MAKESHELL := PATH=$(PATH) /bin/bash
ifeq (3.81,$(MAKE_VERSION))
export SHELL := PATH="$(PATH)" $(shell brew --prefix)/bin/bash
else
export SHELL := $(shell brew --prefix)/bin/bash
endif
else
$(call cerror,unsupported operating system [$(shell uname --all)])
endif

# Log execution environment for debugging.
$(call cdebug,$(shell uname --all))
$(call cdebug,using PATH [$${PATH}])
$(call cdebug,using SHELL [$${SHELL}])
$(call cdebug,using BASH [$${0} - $${BASH_VERSION}])
$(call cdebug,using PATH [$(shell echo -n "$${PATH}")])
$(call cdebug,using AWK [$(shell awk --version | head -n 1)])

# Helper function to find and remove source files.
find-all = find $(1) ! -path "./run/*" ! -path "./build/*" \( $(2) \) 2>/dev/null | \
Expand Down Expand Up @@ -130,9 +135,11 @@ INSTALL_FLAGS ?= $(strip $(mod-readonly) -buildvcs=auto $(INSTALLFLAGS))


# Function to ensure compatibility of gawk and mawk.
ifneq ($(shell echo "false" | \
awk '{ print gensub("false","true","g") }' 2>/dev/null),true)
awk-gensub := function gensub(r, s, h, t) { \
awk-gensub = $(shell echo "false" | \
awk '{ print gensub("false","true","g") }' 2>/dev/null)
$(call cdebug,using GENSUB [$(awk-gensub)])
ifneq ($(awk-gensub),true)
awk-gensub = function gensub(r, s, h, t) { \
if (t == 0) { t = $$0 } \
if (h ~ "^[gG]") { gsub(r, s, t) } \
else if (int(h) != 0) { \
Expand All @@ -145,7 +152,7 @@ ifneq ($(shell echo "false" | \
return t \
}
else
awk-gensub :=
awk-gensub =
endif


Expand Down

0 comments on commit 8c1f321

Please sign in to comment.