Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 3 | # Copyright 2019-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
| 17 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 18 | .PHONY: test |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 19 | .DEFAULT_GOAL := test |
| 20 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 21 | ##-------------------## |
| 22 | ##---] GLOBALS [---## |
| 23 | ##-------------------## |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 24 | TOP ?= . |
| 25 | MAKEDIR ?= $(TOP)/makefiles |
| 26 | |
| 27 | $(if $(VERBOSE),$(eval export VERBOSE=$(VERBOSE))) # visible to include(s) |
| 28 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 29 | ##-------------------------- |
| 30 | ## Enable setup.py debugging |
| 31 | ##-------------------------- |
| 32 | # https://docs.python.org/3/distutils/setupscript.html#debugging-the-setup-script |
| 33 | export DISTUTILS_DEBUG := 1 |
| 34 | |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 35 | # Makefile for voltha-protos |
| 36 | default: test |
| 37 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 38 | ## Library linting |
| 39 | # NO-LINT-MAKEFILE := true # cleanup needed |
| 40 | NO-LINT-SHELL := true # cleanup needed |
| 41 | |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 42 | ##--------------------## |
| 43 | ##---] INCLUDES [---## |
| 44 | ##--------------------## |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 45 | include $(MAKEDIR)/include.mk |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 46 | |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 47 | # Function to extract the last path component from go_package line in .proto files |
| 48 | define go_package_path |
| 49 | $(shell grep go_package $(1) | sed -n 's/.*\/\(.*\)";/\1/p') |
| 50 | endef |
| 51 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 52 | # Function to extract the last path component from package line in .proto files |
| 53 | define java_package_path |
| 54 | $(shell grep package $(1) | sed -n 's/.*\/\(.*\)";/\1/p') |
| 55 | endef |
| 56 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 57 | # Variables |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 58 | PROTO_FILES := $(sort $(wildcard protos/voltha_protos/*.proto)) |
| 59 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 60 | PROTO_PYTHON_DEST_DIR := python/voltha_protos |
| 61 | PROTO_PYTHON_PB2 := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2.py,$(f))) |
Matt Jeanneret | 37e0fc6 | 2019-03-07 12:33:21 -0500 | [diff] [blame] | 62 | PROTO_PYTHON_PB2_GRPC := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2_grpc.py,$(f))) |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 63 | PROTO_GO_DEST_DIR := go |
| 64 | PROTO_GO_PB:= $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_GO_DEST_DIR)/$(call go_package_path,$(f))/%.pb.go,$(f))) |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 65 | PROTO_JAVA_DEST_DIR := java |
| 66 | PROTO_JAVA_PB := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_JAVA_DEST_DIR)/$(call java_package_path,$(f))/%.pb.java,$(f))) |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 67 | |
Zack Williams | 25e0a32 | 2019-06-07 14:07:21 -0700 | [diff] [blame] | 68 | # Force pb file to be regenrated every time. Otherwise the make process assumes generated version is still valid |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 69 | .PHONY: voltha.pb |
Matt Jeanneret | 15249fa | 2019-04-12 20:25:31 -0400 | [diff] [blame] | 70 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 71 | print: |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 72 | @echo "Proto files: $(PROTO_FILES)" |
| 73 | @echo "Python PB2 files: $(PROTO_PYTHON_PB2)" |
| 74 | @echo "Go PB files: $(PROTO_GO_PB)" |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 75 | @echo "JAVA PB files: $(PROTO_JAVA_PB)" |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 76 | |
| 77 | # Generic targets |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 78 | protos: python-protos go-protos java-protos |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 79 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 80 | build: protos python-build go-protos java-protos |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 81 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 82 | test: python-test go-test java-test |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 83 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 84 | clean :: python-clean java-clean go-clean |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 85 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 86 | sterile :: clean |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 87 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 88 | # Python targets |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 89 | python-protos: $(PROTO_PYTHON_PB2) |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 90 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 91 | ## ----------------------------------------------------------------------- |
| 92 | ## ----------------------------------------------------------------------- |
| 93 | $(PROTO_PYTHON_DEST_DIR)/%_pb2.py: \ |
| 94 | protos/voltha_protos/%.proto \ |
| 95 | Makefile \ |
| 96 | $(venv-activate-script) |
| 97 | $(activate) \ |
| 98 | && python -m grpc_tools.protoc \ |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 99 | -I protos \ |
| 100 | --python_out=python \ |
| 101 | --grpc_python_out=python \ |
| 102 | --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \ |
| 103 | --include_imports \ |
| 104 | --include_source_info \ |
| 105 | $< |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 106 | |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 107 | python-build: setup.py python-protos |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 108 | $(RM) -r dist/ |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 109 | python ./setup.py sdist |
| 110 | |
| 111 | python-test: tox.ini setup.py python-protos |
| 112 | tox |
| 113 | |
| 114 | python-clean: |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 115 | find python -name '__pycache__' -type d -print0 \ |
| 116 | | xargs -0 --no-run-if-empty $(RM) -r |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 117 | find python -name '*.pyc' -type f -print0 \ |
| 118 | | xargs -0 --no-run-if-empty $(RM) |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 119 | $(RM) -r \ |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 120 | .coverage \ |
| 121 | .tox \ |
| 122 | coverage.xml \ |
| 123 | dist \ |
| 124 | nose2-results.xml \ |
| 125 | python/__pycache__ \ |
| 126 | python/test/__pycache__ \ |
| 127 | python/voltha_protos.egg-info \ |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 128 | "$(venv-abs-path)" \ |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 129 | $(PROTO_PYTHON_DEST_DIR)/*.desc \ |
| 130 | $(PROTO_PYTHON_PB2) \ |
| 131 | $(PROTO_PYTHON_PB2_GRPC) |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 132 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 133 | ## ----------------------------------------------------------------------- |
| 134 | ## Intent: Revert go to a clean state. |
| 135 | ## o TODO - go/ directory should not be placed under revision control. |
| 136 | ## o Build should retrieve versioned sources from a central repo. |
| 137 | ## ----------------------------------------------------------------------- |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 138 | go-clean: |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 139 | $(RM) -r go/* |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 140 | $(HIDE)$(MAKE) repair |
| 141 | |
| 142 | ## ----------------------------------------------------------------------- |
| 143 | ## Intent: Recover from a fatal failed build state: |
| 144 | ## o build removes go/ while regenerating prototypes. |
| 145 | ## o chicken-n-egg: make becomes fatal when go/ is removed and proten fails. |
| 146 | ## ----------------------------------------------------------------------- |
| 147 | repair: |
| 148 | /usr/bin/env git checkout go |
| 149 | |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 150 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 151 | # Go targets |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 152 | go-protos: voltha.pb |
| 153 | @echo "Creating *.go.pb files" |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 154 | @echo "PROTO_FILES=$(PROTO_FILES)" | tr ' ' '\n' |
| 155 | ${PROTOC_SH} $(quote-double)\ |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 156 | set -e -o pipefail; \ |
| 157 | for x in ${PROTO_FILES}; do \ |
| 158 | echo \$$x; \ |
| 159 | protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \ |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 160 | done$(quote-double) |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 161 | |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 162 | voltha.pb: |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 163 | @echo "Creating $@" |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 164 | $(HIDE)${PROTOC} -I protos -I protos/google/api \ |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 165 | --include_imports --include_source_info \ |
| 166 | --descriptor_set_out=$@ \ |
| 167 | ${PROTO_FILES} |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 168 | |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 169 | go-test: |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 170 | test/test-go-proto-consistency.sh |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 171 | ${GO} mod verify |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 172 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 173 | # Java targets |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 174 | java-protos: voltha.pb |
| 175 | @echo "Creating java files" |
| 176 | @mkdir -p java_temp/src/main/java |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 177 | @${PROTOC_SH} $(quote-double) \ |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 178 | set -e -o pipefail; \ |
| 179 | for x in ${PROTO_FILES}; do \ |
| 180 | echo \$$x; \ |
| 181 | protoc --java_out=java_temp/src/main/java -I protos \$$x; \ |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame^] | 182 | done$(quote-double) |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 183 | #TODO: generate directly to the final location |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 184 | @mkdir -p java |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 185 | cp -r java_temp/src/main/java/* java/ |
| 186 | |
| 187 | # Tests if the generated java classes are compilable |
| 188 | java-test: java-protos |
| 189 | cp test/pom.xml java_temp |
| 190 | cd java_temp && mvn compile |
| 191 | |
| 192 | java-clean: |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 193 | $(RM) -r java |
| 194 | $(RM) -r java_temp |
| 195 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 196 | # placeholder for library targets |
| 197 | lint : |
| 198 | |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 199 | # [EOF] |