-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathMakefile
More file actions
161 lines (130 loc) · 4.39 KB
/
Makefile
File metadata and controls
161 lines (130 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
SHELL := bash
# Make sure we have git:
ifeq ($(shell which git),)
$(error 'git' is not installed on this system)
endif
# Set variables:
NAME := git-subrepo
LIB := lib/$(NAME)
DOC := doc/$(NAME).swim
MAN1 := man/man1
EXT := $(LIB).d
EXTS := $(shell find $(EXT) -type f) \
$(shell find $(EXT) -type l)
SHARE = share
# Install variables:
PREFIX ?= /usr/local
INSTALL_LIB ?= $(DESTDIR)$(shell git --exec-path)
INSTALL_EXT ?= $(INSTALL_LIB)/$(NAME).d
INSTALL_MAN1 ?= $(DESTDIR)$(PREFIX)/share/man/man1
# Docker variables:
DOCKER_TAG ?= admorgan/git-subrepo-testing:1.0
DOCKER_IMAGE := $(DOCKER_TAG)
BASH_VERSIONS ?= 5.3 5.2 5.1 5.0 4.4 4.3 4.2 4.1 4.0
GIT_VERSIONS := 2.51 2.48 2.40 2.30 2.29 2.25 2.23
# Create matrix of all bash/git combinations for comprehensive testing
BASH_GIT_COMBINATIONS := $(foreach bash,$(BASH_VERSIONS),$(foreach git,$(GIT_VERSIONS),$(bash)-$(git)))
DOCKER_TESTS := $(BASH_GIT_COMBINATIONS:%=docker-test-%)
DOCKER_BASH_TESTS := $(BASH_VERSIONS:%=docker-bash-test-%)
prove ?=
test ?= test/
bash ?= 5.3
git ?= 2.51
# Basic targets:
default: help
help:
@echo 'Makefile rules:'
@echo ''
@echo 'test Run all tests'
@echo 'install Install $(NAME)'
@echo 'uninstall Uninstall $(NAME)'
@echo 'env Show environment variables to set'
@echo ''
@echo 'Docker testing:'
@echo 'docker-build Build Docker image with multiple bash/git versions'
@echo 'docker-tests Test ALL bash/git combinations (comprehensive)'
@echo 'docker-bash-tests Test all bash versions with default git (faster)'
@echo 'docker-test Test specific bash/git: make docker-test bash=5.1 git=2.25'
@echo 'CI_TEST Test oldest and newest bash/git combinations for CI'
@echo ''
@echo 'Available bash versions: $(BASH_VERSIONS)'
@echo 'Available git versions: $(GIT_VERSIONS)'
@echo ''
.PHONY: test
test:
prove $(prove) $(test)
test-all: test docker-tests
CI_TEST:
@echo "Running CI tests with oldest and newest bash/git combinations"
$(call docker-make-test,$(lastword $(BASH_VERSIONS)),$(lastword $(GIT_VERSIONS)))
$(call docker-make-test,$(firstword $(BASH_VERSIONS)),$(firstword $(GIT_VERSIONS)))
docker-test:
$(call docker-make-test,$(bash),$(git))
docker-build:
docker build -t $(DOCKER_TAG) test/
# Test all bash/git combinations (comprehensive but slow)
docker-tests: $(DOCKER_TESTS)
# Test all bash versions with default git (faster option)
docker-bash-tests: $(DOCKER_BASH_TESTS)
# Parse bash-git combination from target name
$(DOCKER_TESTS):
$(eval BASH_VER := $(shell echo "$(@:docker-test-%=%)" | cut -d'-' -f1))
$(eval GIT_VER := $(shell echo "$(@:docker-test-%=%)" | cut -d'-' -f2))
$(call docker-make-test,$(BASH_VER),$(GIT_VER))
# Test specific bash version with default git
$(DOCKER_BASH_TESTS):
$(call docker-make-test,$(@:docker-bash-test-%=%),$(git))
# Install support:
install:
install -d -m 0755 $(INSTALL_LIB)/
install -C -m 0755 $(LIB) $(INSTALL_LIB)/
install -d -m 0755 $(INSTALL_EXT)/
install -C -m 0644 $(EXTS) $(INSTALL_EXT)/
install -d -m 0755 $(INSTALL_MAN1)/
install -C -m 0644 $(MAN1)/$(NAME).1 $(INSTALL_MAN1)/
# Uninstall support:
uninstall:
rm -f $(INSTALL_LIB)/$(NAME)
rm -fr $(INSTALL_EXT)
rm -f $(INSTALL_MAN1)/$(NAME).1
env:
@echo "export PATH=\"$$PWD/lib:\$$PATH\""
@echo "export MANPATH=\"$$PWD/man:\$$MANPATH\""
# Doc rules:
.PHONY: doc
update: doc compgen
force:
doc: ReadMe.pod Intro.pod $(MAN1)/$(NAME).1
perl pkg/bin/generate-help-functions.pl $(DOC) > \
$(EXT)/help-functions.bash
ReadMe.pod: $(DOC) force
swim --to=pod --wrap --complete $< > $@
Intro.pod: doc/intro-to-subrepo.swim force
swim --to=pod --wrap --complete $< > $@
$(MAN1)/%.1: doc/%.swim Makefile force
swim --to=man --wrap $< > $@
compgen: force
perl pkg/bin/generate-completion.pl bash $(DOC) $(LIB) > \
$(SHARE)/completion.bash
perl pkg/bin/generate-completion.pl zsh $(DOC) $(LIB) > \
$(SHARE)/zsh-completion/_git-subrepo
perl pkg/bin/generate-completion.pl fish $(DOC) $(LIB) > \
$(SHARE)/git-subrepo.fish
clean:
rm -fr tmp test/tmp
define docker-make-test
docker run --rm \
--user $(shell id -u):$(shell id -g) \
-v $(PWD):/git-subrepo \
-w /git-subrepo \
$(DOCKER_IMAGE) \
/bin/bash -c ' \
set -x && \
[[ -d /bash-$(1) ]] && \
[[ -d /git-$(2) ]] && \
export PATH=/bash-$(1)/bin:/git-$(2)/bin:$$PATH && \
bash --version && \
git --version && \
make test prove=$(prove) test=$(test) \
'
endef