-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
178 lines (149 loc) · 5.61 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Copyright 2023 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0
###############
## Builder Images.
FLATC_BUILDER_IMAGE ?= ghcr.io/boschglobal/dse-flatc-builder:main
PYTHON_BUILDER_IMAGE ?= ghcr.io/boschglobal/dse-python-builder:main
###############
## Packaging.
PACKAGE_NAME = dse-schemas
PACKAGE_FILENAME = $(PACKAGE_NAME).tar.gz
PACKAGE_VERSION ?= 0.0.2
PYPI_NAMESPACE_NAME = dse
PYPI_PACKAGE_NAME = $(PYPI_NAMESPACE_NAME).schemas
###############
## Build parameters.
SCHEMA_LIB = dse_schemas
PLATFORM = linux64
DIST_DIR = $(shell pwd -P)/dist
OUT_DIR = $(shell pwd -P)/dist/$(PACKAGE_NAME)
# Flatbuffers
FBS_OUT_DIR = $(OUT_DIR)/flatbuffers
FBS_SCHEMA_DIR = $(shell pwd -P)/schemas
FBS_SCHEMA_SOURCES = $(shell ls $(FBS_SCHEMA_DIR)/**/*.fbs)
# FlatC
FLATC = flatc
FLATC_OPTIONS =
FLATCC = flatcc
# FlatCC
FLATCC_SRC_RUNTIME_DIR = /usr/local/src/flatcc/src/runtime
FLATCC_SRC_INCLUDE_DIR = /usr/local/include/flatcc
FLATCC_SRC_LICENSE_DIR = /usr/local/src/flatcc
FLATCC_DIST_RUNTIME_DIR = $(FBS_OUT_DIR)/c/$(SCHEMA_LIB)/flatcc/src
FLATCC_DIST_INCLUDE_DIR = $(FBS_OUT_DIR)/c/$(SCHEMA_LIB)/flatcc/include/flatcc
# MsgPack
MPK_OUT_DIR = $(OUT_DIR)/msgpack
MPK_SCHEMA_DIR = $(shell pwd -P)/schemas/msgpack
MPK_SCHEMA_SOURCES = $(shell ls $(MPK_SCHEMA_DIR)/*.yaml)
# Python (for creating a Python Package)
PYTHON_SRC_DIR = $(FBS_OUT_DIR)/python
PYTHON_DIST_DIR = $(DIST_DIR)/python
# YAML
YAML_SCHEMA_DIR = $(shell pwd -P)/schemas/yaml
###############
## Generate options
DOC_SCHEMA_DIR = $(shell pwd -P)/doc/content/schemas
DOC_SCHEMA_YAML_DIR = $(DOC_SCHEMA_DIR)/yaml
DOC_YAML_SCHEMAS = $(shell ls $(YAML_SCHEMA_DIR)/[A-Z]*.yaml) $(shell ls $(MPK_SCHEMA_DIR)/[A-Z]*.yaml)
default: build
build:
@docker run -it --rm \
--volume $$(pwd):/tmp/repo \
--env PACKAGE_VERSION=$(PACKAGE_VERSION) \
--workdir /tmp/repo \
$(FLATC_BUILDER_IMAGE) \
/bin/bash -c "make fbs"
@docker run -it --rm \
--volume $$(pwd):/tmp/repo \
--env PIP_EXTRA_INDEX_URL=$(PIP_EXTRA_INDEX_URL) \
--env PACKAGE_VERSION=$(PACKAGE_VERSION) \
--workdir /tmp/repo \
$(PYTHON_BUILDER_IMAGE) \
/bin/bash -c "make python; make msgpack"
@echo ""
@echo "Generated files:"
@echo "---------------"
@ls -R $(FBS_OUT_DIR)
@ls -R $(MPK_OUT_DIR)
$(FBS_SCHEMA_SOURCES):
@echo $@
# Setup the directory structure.
mkdir -p $(FBS_OUT_DIR)/c/$(SCHEMA_LIB)/$$(basename $$(dirname $@))
mkdir -p $(FBS_OUT_DIR)/cpp/$(SCHEMA_LIB)/$$(basename $$(dirname $@))
mkdir -p $(FBS_OUT_DIR)/fbs/$$(basename $$(dirname $@))
mkdir -p $(FBS_OUT_DIR)/fbs/$$(basename $$(dirname $@))
mkdir -p $(FBS_OUT_DIR)/fbs/$$(basename $$(dirname $@))
mkdir -p $(FBS_OUT_DIR)/go
mkdir -p $(FBS_OUT_DIR)/lua
# Generate Flatbuffers code.
$(FLATCC) -a $(FLATC_OPTIONS) -o $(FBS_OUT_DIR)/c/$(SCHEMA_LIB)/$$(basename $$(dirname $@)) $@
$(FLATC) --cpp $(FLATC_OPTIONS) --filename-suffix '' -o $(FBS_OUT_DIR)/cpp/$(SCHEMA_LIB)/$$(basename $$(dirname $@)) $@
cd $(FBS_OUT_DIR)/go; $(FLATC) --go $(FLATC_OPTIONS) $@
$(FLATC) --python $(FLATC_OPTIONS) -o $(FBS_OUT_DIR)/python $@
cd $(FBS_OUT_DIR)/lua; $(FLATC) --lua $(FLATC_OPTIONS) $@
# Copy over the original Flatbuffer schemas.
cp $@ $(FBS_OUT_DIR)/fbs/$$(basename $$(dirname $@))
fbs: $(FBS_SCHEMA_SOURCES)
mkdir -p $(FLATCC_DIST_RUNTIME_DIR)
cp $(FLATCC_SRC_RUNTIME_DIR)/builder.c $(FLATCC_DIST_RUNTIME_DIR)
cp $(FLATCC_SRC_RUNTIME_DIR)/emitter.c $(FLATCC_DIST_RUNTIME_DIR)
cp $(FLATCC_SRC_RUNTIME_DIR)/refmap.c $(FLATCC_DIST_RUNTIME_DIR)
cp $(FLATCC_SRC_LICENSE_DIR)/LICENSE $(FLATCC_DIST_RUNTIME_DIR)
mkdir -p $(FLATCC_DIST_INCLUDE_DIR)
cp -r $(FLATCC_SRC_INCLUDE_DIR)/* $(FLATCC_DIST_INCLUDE_DIR)
$(MPK_SCHEMA_SOURCES):
@echo $@
mkdir -p $(MPK_OUT_DIR)/$$(basename $$(dirname $@))
cp $@ $(MPK_OUT_DIR)/$$(basename $$(dirname $@))
msgpack: $(MPK_SCHEMA_SOURCES)
python:
mkdir -p $(PYTHON_DIST_DIR)
cp -r $(PYTHON_SRC_DIR)/* $(PYTHON_DIST_DIR)
rm $(PYTHON_DIST_DIR)/dse/__init__.py
cp -r templates/python/* $(PYTHON_DIST_DIR)
cd $(PYTHON_DIST_DIR) && python3 setup.py sdist bdist_wheel
dist_package:
@mkdir -p $(DIST_DIR)
@mkdir -p $(OUT_DIR)
@echo $(PACKAGE_VERSION) > $(OUT_DIR)/VERSION
@tar -czf $(DIST_DIR)/$(PACKAGE_FILENAME) -C $(DIST_DIR) $(PACKAGE_NAME)
dist:
@docker run -it --rm \
--volume $$(pwd):/tmp/repo \
--env PIP_EXTRA_INDEX_URL=$(PIP_EXTRA_INDEX_URL) \
--env PACKAGE_VERSION=$(PACKAGE_VERSION) \
--workdir /tmp/repo \
$(PYTHON_BUILDER_IMAGE) \
/bin/bash -c "make dist_package"
@echo ""
@echo "Distribution package files:"
@echo "--------------------------"
@ls -1sh $(DIST_DIR)/*.*
@ls -1sh $(PYTHON_DIST_DIR)/dist/*.*
generate_clean:
-@rm -rf $(DOC_SCHEMA_YAML_DIR)
$(MAKE) -C code/go/dse clean
generate_doc:
for d in $(DOC_YAML_SCHEMAS) ;\
do \
swagger-cli validate $$d ;\
mkdir -p $(DOC_SCHEMA_YAML_DIR) ;\
widdershins --environment doc/templates/__doc_opts__.json $$d -o $(DOC_SCHEMA_YAML_DIR)/$$(basename $$d .yaml).md ;\
sed -i "1s;^;---\n;" $(DOC_SCHEMA_YAML_DIR)/$$(basename $$d .yaml).md ;\
sed -i "1s;^;linkTitle: \"$$(basename $$d .yaml)\"\n;" $(DOC_SCHEMA_YAML_DIR)/$$(basename $$d .yaml).md ;\
sed -i "1s;^;title: \"Schema: $$(basename $$d .yaml)\"\n;" $(DOC_SCHEMA_YAML_DIR)/$$(basename $$d .yaml).md ;\
sed -i '1s;^;---\n;' $(DOC_SCHEMA_YAML_DIR)/$$(basename S$$d .yaml).md ;\
done;
cp doc/templates/yaml/_index.md $(DOC_SCHEMA_YAML_DIR)/_index.md
generate_code:
$(MAKE) -C code/go/dse generate
generate: generate_clean generate_code $(DOC_YAML_SCHEMAS) generate_doc
test:
install:
pip install -e $(PYTHON_DIST_DIR)/.
remove:
-pip uninstall -y $(PYPI_PACKAGE_NAME)
clean:
-@rm -rf $(DIST_DIR)
.PHONY: default build fbs msgpack python dist dist_package clean $(FBS_SCHEMA_SOURCES) $(MPK_SCHEMA_SOURCES)