forked from kryton/hue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.sdk
253 lines (220 loc) · 8.31 KB
/
Makefile.sdk
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#
# Licensed to Cloudera, Inc. under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. Cloudera, Inc. licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# A Makefile to be (optionally) included by any SDK applications.
#
# This Makefile assumes the following environment variables:
# ROOT
# Points to the root of the Hue installation. From here, we
# can include $(ROOT)/Makefile.vars to access various variables.
#
# This Makefile (or any custom application Makefile) MUST provide the following
# targets:
# egg-info
# Responsible for creating the egg-info directory for the application.
#
# ext-eggs
# Responsible for creating a Python egg for each external Python
# dependency. These eggs should be placed in the
# $(APP_ROOT)/ext-py/<package>/dist directory.
#
# clean
# Remove build products.
#
# sdist
# Responsible for making a source distribution directory at
# $(APP_ROOT)/build/sdist/$(APP_NAME).
#
# install-bdist
# Responsible for installing a built distribution to a target directory,
# as specified by $(INSTALL_DIR).
#
include $(ROOT)/Makefile.vars
SETUPTOOLS_NAME = $(shell $(ENV_PYTHON) setup.py --name)
APP_ROOT := $(realpath .)
APP_NAME ?= $(SETUPTOOLS_NAME)
APP_VERSION ?= $(shell $(ENV_PYTHON) setup.py --version)
APP_FULL_NAME ?= $(APP_NAME)-$(APP_VERSION)
RSYNC_OPT ?= --copy-unsafe-links -a
PYBABEL := $(ROOT)/build/env/bin/pybabel
LOCALE_ROOT := $(APP_ROOT)/src/$(APP_NAME)/locale
BUILD_DIR := $(APP_ROOT)/build
EGG_INFO_DIR := $(APP_ROOT)/src/$(SETUPTOOLS_NAME).egg-info
.PHONY: default
default::
@echo 'The build targets for $(APP_NAME) are: (*) is required'
@echo ' compile : Compile $(APP_NAME)'
@echo ' egg-info * : Create a python egg for $(APP_NAME)'
@echo ' ext-eggs * : Create python eggs for external dependencies'
@echo ' sdist * : Create a source distribution tree and tarball'
@echo ' bdist : Create a built distribution tree'
@echo ' install-bdist *: Install a built distribution to a target location'
@echo ' ext-env-install: Install external dependencies into virtual-env'
@echo ' ext-clean : Clean external dependencies'
@echo ' clean * : Clean $(APP_NAME). Requires ext-clean'
@echo ' distclean : Dist clean $(APP_NAME). Requires clean'
.PHONY: egg
egg-info: compile $(EGG_INFO_DIR)
$(EGG_INFO_DIR): $(APP_ROOT)/setup.py
@echo '--- Making egg-info for $(APP_NAME)'
@$(ENV_PYTHON) setup.py -q egg_info
# Hook to allow extra build steps (eg java builds)
.PHONY: compile
compile:
##############################
# The following installs the external Python dependencies under the ext-py/
# directory.
EXT_PY_DIRS := $(wildcard ext-py/*)
EXT_PYS := $(notdir $(EXT_PY_DIRS))
ext_py_stamp = $(BUILD_DIR)/$(1)/$(2).stamp
##############################
# Macros
##############################
EXT_PY_EGG_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,egg))
EXT_PY_CLEAN_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,clean))
EXT_PY_ENV_INSTALL_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,env-install))
$(EXT_PY_EGG_TARGETS): CUR_EXT_PY=$(notdir $(@D))
$(EXT_PY_CLEAN_TARGETS): CUR_EXT_PY=$(notdir $(@D))
$(EXT_PY_ENV_INSTALL_TARGETS): CUR_EXT_PY=$(notdir $(@D))
#
# ext-eggs
# Builds a binary egg for any 3rd party package that are based on the
# earlier distutils (rather than setuptools).
#
.PHONY: ext-eggs
ext-eggs: $(EXT_PY_EGG_TARGETS)
$(EXT_PY_EGG_TARGETS):
@echo '--- Building egg for $(CUR_EXT_PY)'
@cd ext-py/$(CUR_EXT_PY) && $(ENV_PYTHON) \
-c '__import__("setuptools.sandbox").sandbox.run_setup("setup.py", __import__("sys").argv[1:])' \
bdist_egg
@mkdir -p $(@D) && touch $@
#
# ext-clean
# Clean the 3rd party package. This will NOT uninstall it from Desktop.
#
.PHONY: ext-clean
ext-clean: $(EXT_PY_CLEAN_TARGETS)
$(EXT_PY_CLEAN_TARGETS):
@echo '--- Cleaning $(CUR_EXT_PY)'
@rm -Rf $(BUILD_DIR)/$(CUR_EXT_PY)
@cd ext-py/$(CUR_EXT_PY) && rm -Rf dist build temp *.egg-info
@find ext-py/$(CUR_EXT_PY) -name \*.egg-info -o -name \*.py[co] -prune -exec rm -Rf {} \;
#
# ext-env-install
# Install all 3rd party packages into the Desktop environment. Used by
# desktop core. We look for egg files in two locations:
# (1) ext-py/<pkg>/dist/*.egg
# (2) ext-eggs/*.egg
#
.PHONY: ext-env-install
ext-env-install: ext-eggs $(EXT_PY_ENV_INSTALL_TARGETS)
@for i in $(wildcard ext-eggs/*.egg) ; do \
echo "--- Installing $$i into virtual environment" ; \
$(ENV_EASY_INSTALL) -Z -N $$i 2> /dev/null ; \
done
$(EXT_PY_ENV_INSTALL_TARGETS):
@echo '--- Installing $(CUR_EXT_PY) into virtual environment'
@# If there are no binary eggs, maybe this package decided
@# it wasn't necessary. If the build had failed, the command that produced
@# the egg should have thrown an error.
@cd ext-py/$(CUR_EXT_PY) && [ ! -e dist ] || $(ENV_EASY_INSTALL) -Z -N dist/*egg 2>/dev/null
@mkdir -p $(@D) && touch $@
.PHONY: clean
clean:: ext-clean
@echo --- Cleaning $(APP_NAME)
@# Use SYS_PYTHON because ENV_PYTHON may not be available.
@$(SYS_PYTHON) setup.py clean || :
@rm -Rf $(BUILD_DIR) dist
@find . -name \*.egg-info -prune -exec rm -Rf {} \;
@find . -name \*.py[co] -exec rm -f {} \;
.PHONY: distclean
distclean:: clean
.PHONY: compile-locale
compile-locale:
$(PYBABEL) extract . -F babel.cfg -k _ -k _t -o $(LOCALE_ROOT)/en_US.pot --copyright-holder="Cloudera, Inc" --project="Hue" --version=""
$(PYBABEL) update -D django -i $(LOCALE_ROOT)/en_US.pot -d $(LOCALE_ROOT)
$(PYBABEL) compile -D django -d $(LOCALE_ROOT)
#####################################
# Distribution builds
#####################################
# Items that should not be included in the source/built distribution.
# Apps can list this in their own Makefile before including this file
# in order to exclude their own sources, non-distributables, etc.
# This list is rsync friendly.
COMMON_EXCLUDES := \
--exclude=build \
--exclude=\*.py[co] \
--exclude=.\*.sw[op] \
--exclude=~\* \
--exclude=.gitignore \
--exclude=tag \
--exclude=target
SDIST_EXCLUDES += $(COMMON_EXCLUDES) --exclude=java-lib
BDIST_EXCLUDES += $(COMMON_EXCLUDES) --exclude=ext-py
SDIST_DIR := $(BUILD_DIR)/sdist/$(APP_FULL_NAME)
BDIST_DIR := $(BUILD_DIR)/bdist/$(APP_FULL_NAME)
SDIST_TGZ := $(BUILD_DIR)/sdist/$(APP_FULL_NAME).tgz
#
# sdist
# Simply copy the essential sources to the target directory.
#
.PHONY: sdist
sdist:
@echo '--- Making source distribution at $(SDIST_DIR)'
@rm -rf $(SDIST_DIR)
@mkdir -p $(SDIST_DIR)
@# Copy sources of our app
@rsync $(RSYNC_OPT) ./ $(SDIST_DIR)/ $(SDIST_EXCLUDES)
@$(MAKE) -C $(SDIST_DIR) clean
@# Also make a tarball
@tar -C $(SDIST_DIR)/.. -czf $(SDIST_TGZ) $(APP_FULL_NAME)
@echo "--- Created $(SDIST_TGZ)"
#
# bdist
# Like sdist. For ext-py, we copy the eggs only (into a separate ext-eggs
# directory). Apps with non-python source (e.g. Java, C) should also
# exclude the source files.
#
.PHONY: bdist
bdist: ext-eggs compile
@echo '--- Making built distribution at $(BDIST_DIR)'
@rm -rf $(BDIST_DIR)
@mkdir -p $(BDIST_DIR)
@# Copy built sources of our app
@rsync $(RSYNC_OPT) ./ $(BDIST_DIR)/ $(BDIST_EXCLUDES)
@# Copy thirdparty eggs into the ext-eggs dir
@mkdir -p $(BDIST_DIR)/ext-eggs
@if test -n '$(wildcard ext-py/*/dist)' ; then \
find ext-py/*/dist -type f -name '*.egg' -exec cp {} $(BDIST_DIR)/ext-eggs \; ; \
fi
#
# install-bdist
# Install the built distribution in $(INSTALL_DIR).
# NOTE that this does NOT install the app into the virtual environment.
#
.PHONY: install-bdist
install-bdist: bdist
@echo "--- Install built distribution for $(APP_NAME) at $(INSTALL_DIR)"
@# Check that INSTALL_DIR is empty
@if [ -n '$(wildcard $(INSTALL_DIR)/*)' ] ; then \
echo 'ERROR: $(INSTALL_DIR) not empty. Cowardly refusing to continue.' ; \
false ; \
fi
@mkdir -p $(INSTALL_DIR)
@rsync -a $(BDIST_DIR)/ $(INSTALL_DIR)