From 1d413456a291c595dab311893fe103ec8ec1fd79 Mon Sep 17 00:00:00 2001 From: nosamad <48175289+nosamad@users.noreply.github.com> Date: Fri, 29 Mar 2019 13:23:17 +0100 Subject: [PATCH] fix(webfuse): fix macros (#18) * fixes return code on error * fixes macro usage * adds clean target * fixes file mode * fixes image name * adds registry prefix to allow usage of custom registry (on-premise) * changes syntax in travis file for package installation * fixes duplicate settings discovery --- .cproject | 14 +++++---- .travis.yml | 10 ++++--- Makefile | 63 ++++++++++++++++++++------------------- build/get_container_id.sh | 2 +- 4 files changed, 48 insertions(+), 41 deletions(-) diff --git a/.cproject b/.cproject index ca3f25c..ba4e9d6 100644 --- a/.cproject +++ b/.cproject @@ -66,7 +66,6 @@ make - check true true @@ -74,7 +73,6 @@ make - memcheck true true @@ -82,7 +80,6 @@ make - distclean true true @@ -90,7 +87,6 @@ make - discover-cc true true @@ -98,7 +94,6 @@ make - all true true @@ -106,12 +101,19 @@ make - lint true true true + + make + + clean + true + true + true + diff --git a/.travis.yml b/.travis.yml index d0cb055..1ddfa3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,12 @@ services: addons: apt: update: true -before_install: -- sudo apt-get install -y curl openssl ca-certificates -- sudo apt-get install -y make -- sudo apt-get install -y qemu-user-static + packages: + - curl + - openssl + - ca-certificates + - make + - qemu-user-static env: global: - PARALLELMFLAGS="-j2" diff --git a/Makefile b/Makefile index 235d7f9..49a896e 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ UID ?= $(shell id -u) CONTAINER_USER ?= $(UID) CONTAINER_GROUP ?= $(shell id -g) +CONTAINER_CGROUP_PARENT ?= HOST_CONTAINER ?= $(shell $(PROJECT_ROOT)/build/get_container_id.sh) HOST_CONTAINER := $(HOST_CONTAINER) @@ -96,15 +97,17 @@ CMAKEFLAGS += '-GNinja' BUILDSILENT := $(if $(BUILDVERBOSE),,1) $(BUILDSILENT)NINJAFLAGS += -v +DOCKER_RUNFLAGS += --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined + DOCKER_RUNFLAGS += --interactive DOCKER_RUNFLAGS += --rm DOCKER_RUNFLAGS += --init DOCKER_RUNFLAGS += --user $(CONTAINER_USER):$(CONTAINER_GROUP) -DOCKER_RUNFLAGS += --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined DOCKER_RUNFLAGS += --env SOURCE_DATE_EPOCH DOCKER_RUNFLAGS += --env BUILDTIME DOCKER_RUNFLAGS += --env NINJA_STATUS DOCKER_RUNFLAGS += $(addprefix --volumes-from ,$(HOST_CONTAINER)) +DOCKER_RUNFLAGS += $(addprefix --cgroup-parent ,$(CONTAINER_CGROUP_PARENT)) DOCKER_BUILDARGS += CODENAME=$(CODENAME) DOCKER_BUILDARGS += PARALLELMFLAGS=$(PARALLELMFLAGS) @@ -139,60 +142,60 @@ $(VERBOSE)SILENT := @ $(HOST_CONTAINER)container_run_volumes += '$(realpath $(PROJECT_ROOT)):$(CONTAINER_PROJECT_ROOT):cached' $(HOST_CONTAINER)container_run_volumes += '$(realpath $(OUT)/$1):$(CONTAINER_OUT)/$1:delegated' +container_name = $(REGISTRY_PREFIX)$(subst -,/,$1)/$(PROJECT_NAME):$(VERSION) container_run = $(DOCKER) run $(DOCKER_RUNFLAGS) $3 \ $(addprefix --volume ,$(call container_run_volumes,$1)) \ --workdir '$(CONTAINER_OUT)/$1' \ - $(PROJECT_NAME)-$1:$(VERSION) \ + $(call container_name,$1) \ $2 image_rule = \ $$(OUT)/docker/$1: $$(OUT)/docker/$1.dockerfile $$(EXTRACT_TARGETS) $$(PROJECT_ROOT)/Makefile; \ - $$(call image,$1) -image = $(SILENT) \ - $(call echo_if_silent,docker build $(PROJECT_NAME)-$1:$(VERSION) $(OUT)) \ - && $(DOCKER) build $(DOCKER_BUILDFLAGS) --iidfile $@ --file $< --tag $(PROJECT_NAME)-$1:$(VERSION) $(OUT) - -run_rule = \ - run-$1: $$(OUT)/docker/$1; \ - $$(call run_recipe,$1,/bin/bash,--tty) -run = $(call echo_if_silent,TARGET=$1 $2) && $(call container_run,$1,$2,$3) -run_recipe = $(SILENT)-$(call run,$1,$2,$3) + $(SILENT)$$(call image,$1) +image = \ + $(call echo_if_silent,docker build $(call container_name,$1) $(OUT)) \ + && $(DOCKER) build $(DOCKER_BUILDFLAGS) --iidfile $@ --file $< --tag $(call container_name,$1) $(OUT) configure_rule = \ $$(OUT)/$1/CMakeCache.txt: $$(PROJECT_ROOT)/CMakeLists.txt $$(OUT)/docker/$1; \ - $$(call configure,$1) -configure = $(SILENT) \ + $(SILENT)$$(call configure,$1) +configure = \ $(call run,$1,sh -c 'cmake $(CMAKEFLAGS) $(CONTAINER_PROJECT_ROOT) && $(CONTAINER_PROJECT_ROOT)/build/discover_cc_settings.sh $(notdir $@) $(realpath $(dir $@))') \ - && touch $@ + && touch $(addprefix $(dir $@)/,include_dirs.txt) $@ build_rule = \ build-$1: $$(OUT)/$1/CMakeCache.txt; \ - $$(call build,$1) -build = $(SILENT)$(call run,$1,ninja $(PARALLELMFLAGS) $(NINJAFLAGS) $(GOALS)) + $(SILENT)$$(call build,$1) +build = $(call run,$1,ninja $(PARALLELMFLAGS) $(NINJAFLAGS) $(GOALS)) check_rule = \ check-$1: build-$1; memcheck_rule = \ memcheck-$1: build-$1; \ - $$(call memcheck,$1) -memcheck = $(SILENT)$(call run,$1,ctest -T memcheck $(CTESTFLAGS)) + $(SILENT)$$(call memcheck,$1) +memcheck = $(call run,$1,ctest -T memcheck $(CTESTFLAGS)) + +run_rule = \ + run-$1: $$(OUT)/docker/$1; \ + $(SILENT)$$(call run,$1,/bin/bash,--tty) || true +run = $(call echo_if_silent,TARGET=$1 $2) && $(call container_run,$1,$2,$3) + +clean_rule = \ + clean-$1: ; \ + $(SILENT)-$$(call clean,$1) +clean = rm -rf $(OUT)/$1 discover_cc_settings_rule = \ $$(OUT)/$1/include_dirs.txt: $$(OUT)/$1/CMakeCache.txt; \ - $$(call discover_cc_settings,$1) -discover_cc_settings = $(SILENT) \ + $(SILENT)$$(call discover_cc_settings,$1) +discover_cc_settings = \ $(call run,$1,$(CONTAINER_PROJECT_ROOT)/build/discover_cc_settings.sh $(notdir $<) $(realpath $(dir $<))) discover_cc_rule = \ discover-cc-$1: $$(OUT)/$1/include_dirs.txt; \ - $$(call discover_cc,$1) -discover_cc = $(SILENT)cat $< - -clean_rule = \ - clean-$1: ; \ - $$(call clean,$1) -clean = $(SILENT)-rm -rf $(OUT)/$1 + $(SILENT)$$(call discover_cc,$1) +discover_cc = cat $< # Rules @@ -216,11 +219,11 @@ $(RULE_TARGETS): $(PROJECT_ROOT)/Makefile | $(OUT_DIRS) echo; \ echo '$(call run_rule,$(TARGET))'; \ echo; \ + echo '$(call clean_rule,$(TARGET))'; \ + echo; \ echo '$(call discover_cc_settings_rule,$(TARGET))'; \ echo; \ echo '$(call discover_cc_rule,$(TARGET))'; \ - echo; \ - echo '$(call clean_rule,$(TARGET))'; \ } > $@ .PHONY: all build-% diff --git a/build/get_container_id.sh b/build/get_container_id.sh index d262287..59d134b 100755 --- a/build/get_container_id.sh +++ b/build/get_container_id.sh @@ -33,7 +33,7 @@ impl_container_id_by_cgroup() { DOCKER="${DOCKER:-docker}" if [ -z "${CONTAINER+x}" ] && [ -n "$DOCKER" ]; then - CONTAINER="$(container_id "$@")" || true + CONTAINER="$(container_id "$@")" fi echo "$CONTAINER"