diff --git a/Makefile b/Makefile index 66cbd1e4e..50ac87297 100644 --- a/Makefile +++ b/Makefile @@ -35,8 +35,13 @@ GO_LD_FLAGS+=' SOCI_SNAPSHOTTER_PROJECT_ROOT ?= $(shell pwd) LTAG_TEMPLATE_FLAG=-t ./.headers -FBS_FILE_PATH=$(CURDIR)/ztoc/fbs/ztoc.fbs -FBS_FILE_PATH_COMPRESSION=$(CURDIR)/ztoc/compression/fbs/zinfo.fbs +ZTOC_FBS_DIR=$(CURDIR)/ztoc/fbs +ZTOC_FBS_FILE=$(ZTOC_FBS_DIR)/ztoc.fbs +ZTOC_FBS_GO_FILES=$(wildcard $(ZTOC_FBS_DIR)/ztoc/*.go) +COMPRESSION_FBS_DIR=$(CURDIR)/ztoc/compression/fbs +COMPRESSION_FBS_FILE=$(COMPRESSION_FBS_DIR)/zinfo.fbs +COMPRESSION_FBS_GO_FILES=$(wildcard $(COMPRESSION_FBS_DIR)/zinfo/*.go) + COMMIT=$(shell git rev-parse HEAD) STARGZ_BINARY?=/usr/local/bin/containerd-stargz-grpc @@ -46,7 +51,7 @@ CMD_BINARIES=$(addprefix $(OUTDIR)/,$(CMD)) GO_BENCHMARK_TESTS?=. -.PHONY: all build check add-ltag install uninstall tidy vendor clean \ +.PHONY: all build check flatc add-ltag install uninstall tidy vendor clean \ test integration release benchmarks build-benchmarks \ benchmarks-perf-test benchmarks-comparison-test @@ -56,7 +61,7 @@ build: $(CMD) FORCE: -soci-snapshotter-grpc: FORCE +soci-snapshotter-grpc: flatc FORCE cd cmd/ ; GO111MODULE=$(GO111MODULE_VALUE) go build -o $(OUTDIR)/$@ $(GO_BUILD_FLAGS) $(GO_LD_FLAGS) $(GO_TAGS) ./soci-snapshotter-grpc soci: FORCE @@ -65,11 +70,15 @@ soci: FORCE check: cd scripts/ ; ./check-all.sh -flatc: - rm -rf $(CURDIR)/ztoc/fbs/ztoc - flatc -o $(CURDIR)/ztoc/fbs -g $(FBS_FILE_PATH) - rm -rf $(CURDIR)/ztoc/compression/fbs/zinfo - flatc -o $(CURDIR)/ztoc/compression/fbs -g $(FBS_FILE_PATH_COMPRESSION) +flatc: $(ZTOC_FBS_GO_FILES) $(COMPRESSION_FBS_GO_FILES) + +$(ZTOC_FBS_GO_FILES): $(ZTOC_FBS_FILE) + rm -rf $(ZTOC_FBS_DIR)/ztoc + flatc -o $(ZTOC_FBS_DIR) -g $(ZTOC_FBS_FILE) + +$(COMPRESSION_FBS_GO_FILES): $(COMPRESSION_FBS_FILE) + rm -rf $(COMPRESSION_FBS_DIR)/zinfo + flatc -o $(COMPRESSION_FBS_DIR) -g $(COMPRESSION_FBS_FILE) install: @echo "$@" @@ -98,7 +107,6 @@ test: @echo "$@" @GO111MODULE=$(GO111MODULE_VALUE) go test $(GO_TEST_FLAGS) $(GO_LD_FLAGS) -race ./... - integration: build @echo "$@" @echo "SOCI_SNAPSHOTTER_PROJECT_ROOT=$(SOCI_SNAPSHOTTER_PROJECT_ROOT)" diff --git a/scripts/check-flatc.sh b/scripts/check-flatc.sh index 2beaefd01..95b343078 100755 --- a/scripts/check-flatc.sh +++ b/scripts/check-flatc.sh @@ -16,12 +16,21 @@ set -eux -o pipefail -CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -SOCI_SNAPSHOTTER_PROJECT_ROOT="${CUR_DIR}/.." -FBS_FILE_PATH=${SOCI_SNAPSHOTTER_PROJECT_ROOT}/ztoc/fbs/ztoc.fbs - -# check if flatbuffers needs to be generated again -TMPDIR=$(mktemp -d) -flatc -o "${TMPDIR}" -g "${FBS_FILE_PATH}" -diff -qr "${TMPDIR}/ztoc" "${SOCI_SNAPSHOTTER_PROJECT_ROOT}/ztoc/fbs/ztoc" || (printf "\n\nThe Ztoc schema seems to be modified. Please run 'make flatc' to re-generate Go files\n\n"; rm -rf "${TMPDIR}"; exit 1) -rm -rf "${TMPDIR}" +cur_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +soci_snapshotter_project_root="${cur_dir}/.." +ztoc_fbs_dir="${soci_snapshotter_project_root}"/ztoc/fbs +ztoc_fbs_file="${ztoc_fbs_dir}"/ztoc.fbs +compression_fbs_dir="${soci_snapshotter_project_root}"/ztoc/compression/fbs +compression_fbs_file="${compression_fbs_dir}"/zinfo.fbs + +# check if ztoc flatbuffers needs to be generated again +tmpdir=$(mktemp -d) +flatc -o "${tmpdir}" -g "${ztoc_fbs_file}" +diff -qr "${tmpdir}/ztoc" "${ztoc_fbs_dir}/ztoc" || (printf "\n\nThe Ztoc schema seems to be modified. Please run 'make flatc' to re-generate Go files\n\n"; rm -rf "${tmpdir}"; exit 1) +rm -rf "${tmpdir}" + +# check if zinfo flatbuffers needs to be generated again +tmpdir=$(mktemp -d) +flatc -o "${tmpdir}" -g "${compression_fbs_file}" +diff -qr "${tmpdir}/zinfo" "${compression_fbs_dir}/zinfo" || (printf "\n\nThe Zinfo schema seems to be modified. Please run 'make flatc' to re-generate Go files\n\n"; rm -rf "${tmpdir}"; exit 1) +rm -rf "${tmpdir}"