forked from ni/nimi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.mak
More file actions
157 lines (119 loc) · 7.56 KB
/
rules.mak
File metadata and controls
157 lines (119 loc) · 7.56 KB
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
include $(BUILD_HELPER_DIR)/tools.mak
README := $(OUTPUT_DIR)/README.rst
SETUP := $(OUTPUT_DIR)/setup.py
TOX_INI := $(OUTPUT_DIR)/tox-system_tests.ini
MODULE_FILES := \
$(addprefix $(MODULE_DIR)/,$(MODULE_FILES_TO_GENERATE)) \
$(addprefix $(MODULE_DIR)/,$(MODULE_FILES_TO_COPY)) \
$(addprefix $(MODULE_DIR)/,$(CUSTOM_TYPES_TO_COPY)) \
$(README) \
$(SETUP) \
$(TOX_INI) \
RST_FILES := \
$(addprefix $(DRIVER_DOCS_DIR)/,$(RST_FILES_TO_GENERATE)) \
EXAMPLE_FILES := $(if $(wildcard src/$(DRIVER)/examples/*),$(shell find src/$(DRIVER)/examples/* -type f -print),)
# If there are any examples, we will need to build the examples zip file for this driver
ifneq (,$(EXAMPLE_FILES))
EXAMPLES_DIR := $(GENERATED_DIR)/examples
MKDIRECTORIES += $(EXAMPLES_DIR)
DRIVER_EXAMPLES_ZIP_FILE := $(EXAMPLES_DIR)/$(DRIVER)_examples.zip
MODULE_FILES += $(DRIVER_EXAMPLES_ZIP_FILE)
endif # ifneq (,$(EXAMPLE_FILES))
MKDIR: $(MKDIRECTORIES)
define mkdir_rule
$1:
$(call trace_to_console, "Making dir",$1)
$(_hide_cmds)$(call log_command,mkdir -p $1)
endef
$(foreach d,$(MKDIRECTORIES),$(eval $(call mkdir_rule,$(d))))
# We set up some additional dependencies for specific files
# examples.rst needs to use find since there may be folders of files and it needs to be recursive. wildcard is not recursive
$(MODULE_DIR)/session.py: $(wildcard $(TEMPLATE_DIR)/session.py/*.mako) $(wildcard $(DRIVER_DIR)/templates/session.py/*.mako)
$(MODULE_DIR)/_grpc_stub_interpreter.py: $(wildcard $(TEMPLATE_DIR)/_grpc_stub_interpreter.py/*.mako) $(wildcard $(DRIVER_DIR)/templates/_grpc_stub_interpreter.py/*.mako)
$(MODULE_DIR)/_library_interpreter.py: $(wildcard $(TEMPLATE_DIR)/_library_interpreter.py/*.mako) $(wildcard $(DRIVER_DIR)/templates/_library_interpreter.py/*.mako)
$(DRIVER_DOCS_DIR)/class.rst: $(wildcard $(TEMPLATE_DIR)/functions.rst/*.mako) $(wildcard $(DRIVER_DIR)/templates/functions.rst/*.mako)
$(DRIVER_DOCS_DIR)/examples.rst: $(EXAMPLE_FILES) $(MODULE_DIR)/VERSION
$(MODULE_DIR)/%.py: %.py.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR)))
$(MODULE_DIR)/unit_tests/%.py: %.py.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR)))
$(MODULE_DIR)/%: %.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR)))
$(MODULE_DIR)/%_pb2.py: %.proto
$(call trace_to_console, "Generating",$@ and $(notdir $*)_pb2_grpc.py)
$(_hide_cmds)$(call log_command,python -m grpc_tools.protoc $(addprefix -I=,$(PROTO_DIRS)) --python_out=$(MODULE_DIR) --grpc_python_out=$(MODULE_DIR) $*.proto)
$(_hide_cmds)$(call log_command,sed -i 's/^import session_pb2/from . import session_pb2/' $(MODULE_DIR)/$*_pb2*.py)
$(_hide_cmds)$(call log_command,sed -i 's/^import nidevice_pb2/from . import nidevice_pb2/' $(MODULE_DIR)/$*_pb2*.py)
$(_hide_cmds)$(call log_command,sed -i 's/^import $(notdir $*)_pb2/from . import $(notdir $*)_pb2/' $(MODULE_DIR)/$*_pb2*.py)
vpath %.proto $(PROTO_DIRS)
$(MODULE_DIR)/%_pb2_grpc.py: $(MODULE_DIR)/%_pb2.py
$(MODULE_DIR)/%.py: %.py
$(call trace_to_console, "Copying",$@)
$(_hide_cmds)cp $< $@
$(MODULE_DIR)/%.py: $(DRIVER_DIR)/custom_types/%.py
$(call trace_to_console, "Copying",$@)
$(_hide_cmds)cp $< $@
$(DRIVER_DOCS_DIR)/%.rst: %.rst.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR)))
$(DRIVER_DOCS_DIR)/$(DRIVER).rst: driver.rst.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR), $(notdir $@)))
$(DRIVER_DOCS_DIR)/%.inc: %.inc.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR)))
$(SPHINX_CONF_PY): $(TEMPLATE_DIR)/conf.py.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR)))
$(READTHEDOCS_CONFIG): $(TEMPLATE_DIR)/.readthedocs.yaml.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR)))
$(DRIVER_EXAMPLES_ZIP_FILE): $(EXAMPLE_FILES)
$(call trace_to_console, "Zipping",$@)
$(_hide_cmds)$(call log_command,cd src/$(DRIVER)/examples && zip -u -r -9 $@ * || ([ $$? -eq 12 ] && exit 0) || exit)
UNIT_TEST_FILES_TO_COPY := $(wildcard $(DRIVER_DIR)/unit_tests/*.py)
UNIT_TEST_FILES := $(addprefix $(UNIT_TEST_DIR)/,$(notdir $(UNIT_TEST_FILES_TO_COPY)))
$(UNIT_TEST_DIR)/%.py: $(DRIVER_DIR)/unit_tests/%.py
$(call trace_to_console, "Copying",$@)
$(_hide_cmds)$(call log_command,cp $< $@)
clean:
.PHONY: module doc_files sdist wheel installers
module: $(MODULE_FILES) $(UNIT_TEST_FILES)
doc_files: $(RST_FILES) $(SPHINX_CONF_PY) $(READTHEDOCS_CONFIG)
installers: sdist wheel
$(UNIT_TEST_FILES): $(MODULE_FILES)
$(SETUP): $(TEMPLATE_DIR)/setup.py.mako $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR)))
$(TOX_INI): $(TEMPLATE_DIR)/tox-system_tests.ini.mako $(METADATA_FILES)
$(call trace_to_console, "Generating",$@)
$(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR)))
sdist wheel: $(SDIST_WHEEL_BUILD_DONE)
$(SDIST_WHEEL_BUILD_DONE): # codegen should have already run or just use what is in git
$(call trace_to_console, "Creating sdist and wheel",$(OUTPUT_DIR)/dist)
$(_hide_cmds)$(call log_command_no_tracking,cd $(OUTPUT_DIR) && $(PYTHON_CMD) -m build $(LOG_OUTPUT) $(LOG_DIR)/sdist_wheel.log)
$(_hide_cmds)$(call log_command_no_tracking,touch $@)
# If we are building nifake, we just need a placeholder file for inclusion into the wheel that will never be used. We can't build the actual readme since not all the files are created
ifeq (nifake,$(DRIVER))
$(README):
$(call trace_to_console, "Copying",$@)
$(_hide_cmds)$(call log_command,cp $(ROOT_DIR)/LICENSE $@)
else
# We piece together the readme files instead of relying on the rst include directive because we need these files to be standalone and not require any additional files that are in specific locations.
$(README): $(RST_FILES) $(wildcard $(STATIC_DOCS_DIR)/*)
$(call trace_to_console, "Creating",$@)
$(_hide_cmds)$(call log_command,cat $(STATIC_DOCS_DIR)/status_project.inc \
$(STATIC_DOCS_DIR)/about.inc \
$(DRIVER_DOCS_DIR)/status.inc \
$(DRIVER_DOCS_DIR)/installation.inc \
$(STATIC_DOCS_DIR)/contributing.inc \
$(STATIC_DOCS_DIR)/$(DRIVER)_usage.inc \
$(STATIC_DOCS_DIR)/support.inc \
$(STATIC_DOCS_DIR)/documentation.inc \
$(STATIC_DOCS_DIR)/license.inc > $@)
endif
# From https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
print-%: ; $(info $(DRIVER): $* is $(flavor $*) variable set to [$($*)]) @true