Skip to content

Commit a0f8e9c

Browse files
committed
Add ci
1 parent 6685d71 commit a0f8e9c

19 files changed

+376
-0
lines changed

ci/Makefile

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
PROJECT := coinutils
2+
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
3+
SHA1 := $(shell git rev-parse --verify HEAD)
4+
5+
# General commands
6+
.PHONY: help
7+
BOLD=\e[1m
8+
RESET=\e[0m
9+
10+
help:
11+
@echo -e "${BOLD}SYNOPSIS${RESET}"
12+
@echo -e "\tmake <target> [NOCACHE=1]"
13+
@echo
14+
@echo -e "${BOLD}DESCRIPTION${RESET}"
15+
@echo -e "\ttest build inside docker containers so we can test against various major distro setup."
16+
@echo
17+
@echo -e "${BOLD}MAKE TARGETS${RESET}"
18+
@echo -e "\t${BOLD}help${RESET}: display this help and exit."
19+
@echo
20+
@echo -e "\t${BOLD}docker${RESET}: generate all docker devel images."
21+
@echo -e "\t${BOLD}docker_<distro>${RESET}: generate docker devel image for the specified distro."
22+
@echo
23+
@echo -e "\t${BOLD}configure${RESET}: cmake 'configure' using all devel image containers."
24+
@echo -e "\t${BOLD}configure_<distro>${RESET}: cmake 'configure' using the devel image container specified."
25+
@echo
26+
@echo -e "\t${BOLD}build${RESET}: cmake 'build' target ${BOLD}all${RESET} using all the devel image containers."
27+
@echo -e "\t${BOLD}build_<distro>${RESET}: cmake 'build' target ${BOLD}all${RESET} using the devel image container specified."
28+
@echo
29+
@echo -e "\t${BOLD}test${RESET}: cmake 'build' target ${BOLD}test${RESET} using all devel image containers."
30+
@echo -e "\t${BOLD}test_<distro>${RESET}: cmake 'build' target ${BOLD}test${RESET} using the devel image container specified."
31+
@echo
32+
@echo -e "\t${BOLD}install${RESET}: execute the cmake target ${BOLD}install${RESET} using all devel image container, then create an install image with it."
33+
@echo -e "\t${BOLD}install_<distro>${RESET}: execute the cmake target ${BOLD}install${RESET} using the devel image container specified, then create an install image with it."
34+
@echo
35+
@echo -e "\t${BOLD}test_install${RESET}: configure, build, install then test a sample project against it using all ${BOLD}install${RESET} image containers."
36+
@echo -e "\t${BOLD}test_install_<distro>${RESET}: configure, build, install then test a sample project against it using the ${BOLD}install${RESET} image container specified."
37+
@echo
38+
@echo -e "\t${BOLD}clean${RESET}: Remove build directories and log files for all distros."
39+
@echo -e "\t${BOLD}clean_<distro>${RESET}: Remove build directories and log files for the distro specified."
40+
@echo
41+
@echo -e "\t${BOLD}distclean${RESET}: execute ${BOLD}clean${RESET} and also remove all docker images."
42+
@echo -e "\t${BOLD}distclean_<distro>${RESET}: execute ${BOLD}clean_<distro>${RESET} and also remove the docker images."
43+
@echo
44+
@echo -e "\t${BOLD}<distro>${RESET}:"
45+
@echo -e "\t\t${BOLD}alpine${RESET} (latest)"
46+
@echo -e "\t\t${BOLD}archlinux${RESET} (latest)"
47+
@echo -e "\t\t${BOLD}centos${RESET} (latest)"
48+
@echo -e "\t\t${BOLD}fedora${RESET} (latest)"
49+
@echo -e "\t\t${BOLD}opensuse${RESET} (latest)"
50+
@echo -e "\t\t${BOLD}debian${RESET} (latest)"
51+
@echo -e "\t\t${BOLD}ubuntu${RESET} (latest)"
52+
@echo -e "\t\t${BOLD}xenial${RESET} (Ubuntu 16.04 LTS)"
53+
@echo -e "\te.g. 'make test_ubuntu'"
54+
@echo
55+
@echo -e "\t${BOLD}NOCACHE=1${RESET}: use 'docker build --no-cache' when building container (default use cache)."
56+
@echo
57+
@echo -e "${BOLD}NOTES${RESET}"
58+
@echo -e "\tAll generated code will be located in the cache/ folder, use distclean to remove it."
59+
@echo
60+
@echo -e "branch: $(BRANCH)"
61+
@echo -e "sha1: $(SHA1)"
62+
63+
# Need to add cmd_distro to PHONY otherwise target are ignored since they do not
64+
# contain recipe (using FORCE do not work here)
65+
.PHONY: all
66+
all: build
67+
68+
# Delete all implicit rules to speed up makefile
69+
.SUFFIXES:
70+
# Remove some rules from gmake that .SUFFIXES does not remove.
71+
SUFFIXES =
72+
# Keep all intermediate files
73+
# ToDo: try to remove it later
74+
.SECONDARY:
75+
76+
# Docker image name prefix.
77+
IMAGE := ${PROJECT}
78+
79+
ifdef NOCACHE
80+
DOCKER_BUILD_CMD := docker build --no-cache
81+
else
82+
DOCKER_BUILD_CMD := docker build
83+
endif
84+
85+
# Use host user id instead of default root:root
86+
UID := $(shell id -u)
87+
GID := $(shell id -g)
88+
DOCKER_DEVEL_CMD := docker run --rm -it -v ${PWD}/..:/project -w /project --user ${UID}:${GID}
89+
#DOCKER_DEVEL_CMD := docker run --rm -it -v ${PWD}:/project -w /project
90+
91+
DOCKER_INSTALL_CMD := docker run --rm -it -v ${PWD}/sample:/project -w /project
92+
93+
# Currently supported distro
94+
DISTROS = alpine archlinux centos fedora opensuse debian ubuntu xenial
95+
96+
# $* stem
97+
# $< first prerequist
98+
# $@ target name
99+
100+
# DOCKER
101+
targets = $(addprefix docker_, $(DISTROS))
102+
.PHONY: docker $(targets)
103+
docker: $(targets)
104+
$(targets): docker_%: cache/%/docker_devel.tar
105+
cache/%/docker_devel.tar: docker/%/Dockerfile
106+
mkdir -p cache/$*
107+
@docker image rm -f ${IMAGE}_$*:devel 2>/dev/null
108+
@rm -f $@
109+
${DOCKER_BUILD_CMD} -t ${IMAGE}_$*:devel -f $< docker/$*
110+
docker save ${IMAGE}_$*:devel -o $@
111+
112+
# DOCKER BASH (debug)
113+
targets = $(addprefix bash_, $(DISTROS))
114+
.PHONY: $(targets)
115+
$(targets): bash_%: cache/%/docker_devel.tar
116+
${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh
117+
118+
# CONFIGURE
119+
targets = $(addprefix configure_, $(DISTROS))
120+
.PHONY: configure $(targets)
121+
configure: $(targets)
122+
$(targets): configure_%: cache/%/configure.log
123+
cache/%/configure.log: cache/%/docker_devel.tar \
124+
../CMakeLists.txt ../*/CMakeLists.txt ../cmake/*Config.cmake.in
125+
@rm -rf cache/$*/build
126+
@docker load -i $<
127+
${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh -c \
128+
"cmake -version && cmake -H. -Bci/cache/$*/build"
129+
@date > $@
130+
131+
# BUILD
132+
targets = $(addprefix build_, $(DISTROS))
133+
.PHONY: build $(targets)
134+
build: $(targets)
135+
$(targets): build_%: cache/%/build.log
136+
cache/%/build.log: cache/%/configure.log ../CoinUtils
137+
${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh -c \
138+
"cmake --build ci/cache/$*/build --target all"
139+
@date > $@
140+
141+
# TEST
142+
targets = $(addprefix test_, $(DISTROS))
143+
.PHONY: test $(targets)
144+
test: $(targets)
145+
$(targets): test_%: cache/%/test.log
146+
cache/%/test.log: cache/%/build.log
147+
${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh -c \
148+
"cmake --build ci/cache/$*/build --target test -- CTEST_OUTPUT_ON_FAILURE=1"
149+
@date > $@
150+
151+
# INSTALL
152+
targets = $(addprefix install_, $(DISTROS))
153+
.PHONY: install $(targets)
154+
install: $(targets)
155+
$(targets): install_%: cache/%/install.log
156+
cache/%/install.log: docker/%/InstallDockerfile cache/%/build.log
157+
${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh -c \
158+
"cmake --build ci/cache/$*/build --target install -- DESTDIR=../install"
159+
@docker image rm -f ${IMAGE}_$*:install 2>/dev/null
160+
@rm -f cache/$*/docker_install.tar
161+
${DOCKER_BUILD_CMD} -t ${IMAGE}_$*:install -f $< cache/$*
162+
docker save ${IMAGE}_$*:install -o cache/$*/docker_install.tar
163+
@date > $@
164+
165+
# DOCKER BASH INSTALL (debug)
166+
targets = $(addprefix bash_install_, $(DISTROS))
167+
.PHONY: $(targets)
168+
$(targets): bash_install_%: cache/%/install.log
169+
@docker load -i cache/$*/docker_install.tar
170+
${DOCKER_INSTALL_CMD} ${IMAGE}_$*:install /bin/sh
171+
172+
# TEST INSTALL of ProjectConfigs.cmake
173+
targets = $(addprefix test_install_, $(DISTROS))
174+
.PHONY: test_install $(targets)
175+
test_install: $(targets)
176+
$(targets): test_install_%: cache/%/test_install.log
177+
cache/%/test_install.log: cache/%/install.log sample
178+
@docker load -i cache/$*/docker_install.tar
179+
${DOCKER_INSTALL_CMD} ${IMAGE}_$*:install /bin/sh -c \
180+
"cmake -H. -B/cache; \
181+
cmake --build /cache; \
182+
cmake --build /cache --target test; \
183+
cmake --build /cache --target install"
184+
@date > $@
185+
186+
# CLEAN
187+
targets = $(addprefix clean_, $(DISTROS))
188+
.PHONY: clean $(targets)
189+
clean: $(targets)
190+
$(targets): clean_%:
191+
-rm -f cache/$*/test_install.log
192+
-rm -f cache/$*/install.log
193+
-rm -rf cache/$*/install
194+
-rm -f cache/$*/test.log
195+
-rm -f cache/$*/build.log
196+
-rm -f cache/$*/configure.log
197+
-rm -rf cache/$*/build
198+
199+
# DISTCLEAN
200+
targets = $(addprefix distclean_, $(DISTROS))
201+
.PHONY: distclean $(targets)
202+
distclean: $(targets)
203+
docker image prune -f
204+
rmdir cache
205+
$(targets): distclean_%: clean_%
206+
-docker image rm -f ${IMAGE}_$*:install 2>/dev/null
207+
-rm -f cache/$*/docker_install.tar
208+
-docker image rm -f ${IMAGE}_$*:devel 2>/dev/null
209+
-rm -f cache/$*/docker_devel.tar
210+
-rmdir cache/$*

ci/docker/alpine/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM alpine:latest
2+
LABEL maintainer="[email protected]"
3+
4+
RUN apk add --no-cache git build-base linux-headers cmake

ci/docker/alpine/InstallDockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine:latest
2+
LABEL maintainer="[email protected]"
3+
4+
RUN apk add --no-cache git build-base cmake
5+
6+
COPY install /

ci/docker/archlinux/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM archlinux/base
2+
LABEL maintainer="[email protected]"
3+
4+
RUN pacman -Syu --noconfirm base-devel git cmake

ci/docker/archlinux/InstallDockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM archlinux/base
2+
LABEL maintainer="[email protected]"
3+
4+
RUN pacman -Syu --noconfirm base-devel git cmake
5+
6+
COPY install /

ci/docker/centos/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM centos:latest
2+
LABEL maintainer="[email protected]"
3+
4+
RUN yum -y update \
5+
&& yum -y groupinstall "Development Tools" \
6+
&& yum -y install epel-release \
7+
&& yum -y install cmake3 \
8+
&& ln -s /usr/bin/cmake3 /usr/local/bin/cmake \
9+
&& yum clean all \
10+
&& rm -rf /var/cache/yum
11+
12+
# need recent git to avoid 'user not in passwd' issue
13+
# see: https://stackoverflow.com/questions/20271926/git-error-unable-to-look-up-current-user-in-the-passwd-file-no-such-user-wh
14+
RUN yum -y install \
15+
http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-1.noarch.rpm \
16+
&& yum -y install git \
17+
&& yum clean all \
18+
&& rm -rf /var/cache/yum

ci/docker/centos/InstallDockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM centos:latest
2+
LABEL maintainer="[email protected]"
3+
4+
RUN yum -y update \
5+
&& yum -y groupinstall "Development Tools" \
6+
&& yum -y install epel-release \
7+
&& yum -y install cmake3 \
8+
&& ln -s /usr/bin/cmake3 /usr/local/bin/cmake \
9+
&& yum clean all \
10+
&& rm -rf /var/cache/yum
11+
12+
# need recent git to avoid 'user not in passwd' issue
13+
# see: https://stackoverflow.com/questions/20271926/git-error-unable-to-look-up-current-user-in-the-passwd-file-no-such-user-wh
14+
RUN yum -y install \
15+
http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-1.noarch.rpm \
16+
&& yum -y install git \
17+
&& yum clean all \
18+
&& rm -rf /var/cache/yum
19+
20+
COPY install /

ci/docker/debian/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM debian:latest
2+
LABEL maintainer="[email protected]"
3+
4+
RUN apt-get update -q && \
5+
apt-get install -yq git build-essential cmake && \
6+
apt-get clean && \
7+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ci/docker/debian/InstallDockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM debian:latest
2+
LABEL maintainer="[email protected]"
3+
4+
RUN apt-get update -q && \
5+
apt-get install -yq git build-essential cmake && \
6+
apt-get clean && \
7+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
8+
9+
COPY install /

ci/docker/fedora/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM fedora:latest
2+
3+
RUN dnf -y update \
4+
&& dnf -y groupinstall "Development Tools" \
5+
&& dnf -y install cmake gcc-c++ \
6+
&& dnf clean all

ci/docker/fedora/InstallDockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM fedora:latest
2+
3+
RUN dnf -y update \
4+
&& dnf -y groupinstall "Development Tools" \
5+
&& dnf -y install cmake gcc-c++ \
6+
&& dnf clean all
7+
8+
COPY install /

ci/docker/opensuse/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM opensuse:latest
2+
3+
RUN zypper up -y \
4+
&& zypper install -y gcc8-c++ cmake git \
5+
&& zypper clean -a
6+
7+
ENV CC=gcc-8 CXX=g++-8

ci/docker/opensuse/InstallDockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM opensuse:latest
2+
3+
RUN zypper up -y \
4+
&& zypper install -y gcc8-c++ cmake git \
5+
&& zypper clean -a
6+
7+
ENV CC=gcc-8 CXX=g++-8
8+
9+
COPY install /

ci/docker/ubuntu/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM ubuntu:latest
2+
LABEL maintainer="[email protected]"
3+
4+
RUN apt-get update -q && \
5+
apt-get install -yq git build-essential cmake && \
6+
apt-get clean && \
7+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ci/docker/ubuntu/InstallDockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM ubuntu:latest
2+
LABEL maintainer="[email protected]"
3+
4+
RUN apt-get update -q && \
5+
apt-get install -yq git build-essential cmake && \
6+
apt-get clean && \
7+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
8+
9+
COPY install /

ci/docker/xenial/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM ubuntu:xenial
2+
LABEL maintainer="[email protected]"
3+
4+
RUN apt-get update -q && \
5+
apt-get install -yq git build-essential cmake && \
6+
apt-get clean && \
7+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ci/docker/xenial/InstallDockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM ubuntu:xenial
2+
LABEL maintainer="[email protected]"
3+
4+
RUN apt-get update -q && \
5+
apt-get install -yq git build-essential cmake && \
6+
apt-get clean && \
7+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
8+
9+
COPY install /

ci/sample/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(Sample VERSION 1.0.0 LANGUAGES CXX)
3+
4+
include(CTest)
5+
find_package(CoinUtils REQUIRED)
6+
7+
add_executable(sample main.cpp)
8+
#target_compile_features(sample PUBLIC cxx_std_11)
9+
set_target_properties(sample PROPERTIES
10+
CXX_STANDARD 11
11+
CXX_STANDARD_REQUIRED ON
12+
VERSION ${PROJECT_VERSION})
13+
target_link_libraries(sample PRIVATE Coin::CoinUtils)
14+
15+
if(BUILD_TESTING)
16+
add_test(NAME sample_UT COMMAND sample)
17+
endif()
18+
19+
include(GNUInstallDirs)
20+
install(TARGETS sample
21+
EXPORT SampleTargets
22+
DESTINATION ${CMAKE_INSTALL_BINDIR})

ci/sample/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <iostream>
2+
#include <coin/CoinUtilsConfig.h>
3+
4+
int main(int argc, char** argv) {
5+
std::cout << "version: " << COINUTILS_VERSION << std::endl;
6+
return 0;
7+
}
8+

0 commit comments

Comments
 (0)