Skip to content

Commit

Permalink
makefile: utilities and review layout
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Mar 30, 2022
1 parent 1b9bd75 commit 7b13168
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ help: ## show make targets

.PHONY: clean-src
clean-src:
[ ! -d src ] || $(CHOWN) -R $(shell id -u):$(shell id -g) src
$(RM) -r src
@[ ! -d src ] || $(CHOWN) -R $(shell id -u):$(shell id -g) src
@$(RM) -r src

.PHONY: src
src: src/github.com/docker/cli src/github.com/docker/docker src/github.com/docker/buildx src/github.com/docker/compose src/github.com/docker/scan-cli-plugin ## clone source
Expand Down Expand Up @@ -50,22 +50,27 @@ src/github.com/docker/scan-cli-plugin:

.PHONY: checkout-cli
checkout-cli: src/github.com/docker/cli
$(call title,Checkout $(DOCKER_CLI_REPO)#$(DOCKER_CLI_REF))
./scripts/checkout.sh src/github.com/docker/cli "$(DOCKER_CLI_REF)"

.PHONY: checkout-docker
checkout-docker: src/github.com/docker/docker
$(call title,Checkout $(DOCKER_ENGINE_REPO)#$(DOCKER_ENGINE_REF))
./scripts/checkout.sh src/github.com/docker/docker "$(DOCKER_ENGINE_REF)"

.PHONY: checkout-buildx
checkout-buildx: src/github.com/docker/buildx
$(call title,Checkout $(DOCKER_BUILDX_REPO)#$(DOCKER_BUILDX_REF))
./scripts/checkout.sh src/github.com/docker/buildx "$(DOCKER_BUILDX_REF)"

.PHONY: checkout-compose
checkout-compose: src/github.com/docker/compose
$(call title,Checkout $(DOCKER_COMPOSE_REPO)#$(DOCKER_COMPOSE_REF))
./scripts/checkout.sh src/github.com/docker/compose "$(DOCKER_COMPOSE_REF)"

.PHONY: checkout-scan-cli-plugin
checkout-scan-cli-plugin: src/github.com/docker/scan-cli-plugin
$(call title,Checkout $(DOCKER_SCAN_REPO)#$(DOCKER_SCAN_REF))
./scripts/checkout.sh src/github.com/docker/scan-cli-plugin "$(DOCKER_SCAN_REF)"

.PHONY: checkout
Expand Down
14 changes: 14 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,17 @@ export DOCKER_ENGINE_REF
export DOCKER_SCAN_REF
export DOCKER_COMPOSE_REF
export DOCKER_BUILDX_REF

# utilities
BOLD := $(shell tput -T linux bold)
PURPLE := $(shell tput -T linux setaf 5)
GREEN := $(shell tput -T linux setaf 2)
CYAN := $(shell tput -T linux setaf 6)
RED := $(shell tput -T linux setaf 1)
RESET := $(shell tput -T linux sgr0)
TITLE := $(BOLD)$(PURPLE)
SUCCESS := $(BOLD)$(GREEN)

define title
@printf '$(TITLE)$(1)$(RESET)\n'
endef
10 changes: 6 additions & 4 deletions scripts/checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

checkout() (
set -ex
set -e
SRC="$1"
REF="$2"
REF_FETCH="$REF"
Expand All @@ -27,11 +27,13 @@ checkout() (
else
REF="FETCH_HEAD"
fi
git -C "$SRC" fetch --update-head-ok --depth 1 origin "$REF_FETCH"
git -C "$SRC" checkout -q "$REF"
(
set -x
git -C "$SRC" fetch --update-head-ok --depth 1 origin "$REF_FETCH"
git -C "$SRC" checkout -q "$REF"
)
)


# Only execute checkout function above if this file is executed, not sourced from another script
prog=checkout.sh # needs to be in sync with this file's name
if [ "$(basename -- $0)" = "$prog" ]; then
Expand Down
8 changes: 5 additions & 3 deletions static/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ export CONTAINERD_VERSION
export RUNC_VERSION

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(BOLD)$(CYAN)%-25s$(RESET)%s\n", $$1, $$2}'
help: ## show make targets
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

.PHONY: clean
clean: ## remove build artifacts
$(call title,Removing build artifacts)
@[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build
@$(RM) -r build

.PHONY: build
build: ## build static package
$(call title,Building static package for $(TARGETPLATFORM))
./build-static "$(CURDIR)" "$(TARGETPLATFORM)"

.PHONY: hash_files
hash_files: ## hash files
@echo "Hashing directory $(DIR_TO_HASH)"
$(call title,Hashing directory $(DIR_TO_HASH))
$(HASH_CMD) "$(DIR_TO_HASH)"

0 comments on commit 7b13168

Please sign in to comment.