Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[storage] Makefile improvements #170

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Run tests
run: docker run -v $PWD:/workdir ghcr.io/igorshubovych/markdownlint-cli:latest --ignore ./storage/v1alpha1/autogen.md --ignore ./security/v1/autogen.md --ignore ./network/v1/autogen.md --ignore ./common/v1/autogen.md --disable=MD013 "**/*.md"
run: docker run -v $PWD:/workdir ghcr.io/igorshubovych/markdownlint-cli:latest --ignore ./storage/v1alpha1/gen/ --ignore ./security/v1/autogen.md --ignore ./network/v1/autogen.md --ignore ./common/v1/autogen.md --disable=MD013 "**/*.md"

api-lint:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions storage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
googleapis
96 changes: 83 additions & 13 deletions storage/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,89 @@
# Copyright (C) 2022 Intel Corporation
# Copyright (c) 2022 Dell Inc, or its subsidiaries.

all:
rm -rf ./v1alpha1/{autogen.md,gen,google}
mkdir -p ./v1alpha1/gen/{go,cpp,python,java}
CURRENT_VERSION := v1alpha1
COMMON_VERSION := v1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to call it v1 as yet?


docker run --user=$$(id -u):$$(id -g) --rm -v "${PWD}":/defs -v "${PWD}/../common/v1":/common namely/protoc-all:1.47_2 -i /common --lint -d v1alpha1 -l go -o ./v1alpha1/gen/go/ --go-source-relative
docker run --user=$$(id -u):$$(id -g) --rm -v "${PWD}":/defs -v "${PWD}/../common/v1":/common namely/protoc-all:1.47_2 -i /common --lint -d v1alpha1 -l cpp -o ./v1alpha1/gen/cpp/ --go-source-relative
docker run --user=$$(id -u):$$(id -g) --rm -v "${PWD}":/defs -v "${PWD}/../common/v1":/common namely/protoc-all:1.47_2 -i /common --lint -d v1alpha1 -l python -o ./v1alpha1/gen/python/ --go-source-relative
docker run --user=$$(id -u):$$(id -g) --rm -v "${PWD}":/defs -v "${PWD}/../common/v1":/common namely/protoc-all:1.47_2 -i /common --lint -d v1alpha1 -l java -o ./v1alpha1/gen/java/ --go-source-relative
# Make a variable named ','. Used to pass arguments to functions that contain a comma
, := ,

# protoc doesn't include annotation and http googleapis, so we have to get them here
define protoc_compile
mkdir -p $(CURRENT_VERSION)/gen/$(1)
protoc --proto_path=../common/$(COMMON_VERSION) --proto_path=$(CURRENT_VERSION) --proto_path=googleapis \
--$(1)_out=$(CURRENT_VERSION)/gen/$(1) \
$(2) \
$(CURRENT_VERSION)/*.proto
endef

define docker_compile
rm -rf ./$(CURRENT_VERSION)/gen/$(1)
mkdir -p ./$(CURRENT_VERSION)/gen/$(1)
docker run --user=$$(id -u):$$(id -g) --rm -v "${PWD}":/defs -v "${PWD}/../common/$(COMMON_VERSION)":/common namely/protoc-all:1.47_2 \
-i /common --lint -d "$(CURRENT_VERSION)" -l $(1) -o ./$(CURRENT_VERSION)/gen/$(1)/ --go-source-relative
endef

define docker_run
docker run --user=$$(id -u):$$(id -g) --rm --entrypoint=sh \
-v "${PWD}/../common/$(COMMON_VERSION)":/common \
-v "${PWD}/$(CURRENT_VERSION)/":/out \
-v "${PWD}/googleapis":/googleapis \
-w /out \
$(1) \
-c "$(2)"
endef

all: python cpp go java doc lint

.PHONY: python cpp go java lint doc

python:
$(call docker_compile,python)

cpp:
$(call docker_compile,cpp)

go:
$(call docker_compile,go)

java:
$(call docker_compile,java)

lint: googleapis/google
$(call docker_run,\
ghcr.io/docker-multiarch/google-api-linter:1.36.0,\
api-linter -I /common -I /googleapis /out/*.proto --output-format summary)

$(call docker_run,\
ghcr.io/docker-multiarch/google-api-linter:1.36.0,\
api-linter -I /common -I /googleapis /out/*.proto --output-format github --disable-rule=core::0192::has-comments --disable-rule=core::0136 --disable-rule=core::0127 --set-exit-status)

doc: googleapis/google
$(call docker_run,\
pseudomuto/protoc-gen-doc,\
protoc -I /common -I /googleapis -I /out --doc_out=/out/gen/doc --doc_opt=markdown$(,)autogen.md /out/*.proto /common/*.proto)

googleapis/google:
curl -kL https://github.com/googleapis/googleapis/archive/master.tar.gz | tar --strip=1 -zxvf - googleapis-master/google/api
mv google "${PWD}"/v1alpha1/
docker run --user=$$(id -u):$$(id -g) --rm --entrypoint=sh -v "${PWD}/../common/v1":/common -v "${PWD}"/v1alpha1/:/out -w /out ghcr.io/docker-multiarch/google-api-linter:1.36.0 -c "api-linter -I /common /out/*.proto --output-format summary"
docker run --user=$$(id -u):$$(id -g) --rm --entrypoint=sh -v "${PWD}/../common/v1":/common -v "${PWD}"/v1alpha1/:/out -w /out ghcr.io/docker-multiarch/google-api-linter:1.36.0 -c "api-linter -I /common /out/*.proto --output-format github --disable-rule=core::0192::has-comments --disable-rule=core::0136 --disable-rule=core::0127 --set-exit-status"
docker run --user=$$(id -u):$$(id -g) --rm --entrypoint=sh -v "${PWD}/../common/v1":/common -v "${PWD}"/v1alpha1/:/out -w /out -v "${PWD}"/v1alpha1:/protos pseudomuto/protoc-gen-doc -c "protoc -I /common -I /protos --doc_out=/out --doc_opt=markdown,autogen.md /protos/*.proto /common/*.proto"
rm -rf "${PWD}"/v1alpha1/google
mkdir -p googleapis
mv google googleapis/

clean:
rm -rf googleapis

local: python_local cpp_local go_local java_local doc_local

python_local: googleapis/google
$(call protoc_compile,python,)

cpp_local: googleapis/google
$(call protoc_compile,cpp,)

go_local: googleapis/google
$(call protoc_compile,go,)
mv $(CURRENT_VERSION)/gen/go/github.com/opiproject/opi-api/storage/$(CURRENT_VERSION)/gen/go/* $(CURRENT_VERSION)/gen/go/

java_local: googleapis/google
$(call protoc_compile,java,)

doc_local: googleapis/google
$(call protoc_compile,doc,--doc_opt=markdown$(,)autogen.md)
File renamed without changes.