Makefile.sdk 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. #
  19. # A Makefile to be (optionally) included by any SDK applications.
  20. #
  21. # This Makefile assumes the following environment variables:
  22. # ROOT
  23. # Points to the root of the Hue installation. From here, we
  24. # can include $(ROOT)/Makefile.vars to access various variables.
  25. #
  26. # This Makefile (or any custom application Makefile) MUST provide the following
  27. # targets:
  28. # egg-info
  29. # Responsible for creating the egg-info directory for the application.
  30. #
  31. # ext-eggs
  32. # Responsible for creating a Python egg for each external Python
  33. # dependency. These eggs should be placed in the
  34. # $(APP_ROOT)/ext-py/<package>/dist directory.
  35. #
  36. # clean
  37. # Remove build products.
  38. #
  39. # sdist
  40. # Responsible for making a source distribution directory at
  41. # $(APP_ROOT)/build/sdist/$(APP_NAME).
  42. #
  43. # install-bdist
  44. # Responsible for installing a built distribution to a target directory,
  45. # as specified by $(INSTALL_DIR).
  46. #
  47. include $(ROOT)/Makefile.vars
  48. SETUPTOOLS_NAME = $(shell $(ENV_PYTHON) setup.py --name)
  49. APP_ROOT := $(realpath .)
  50. APP_NAME ?= $(SETUPTOOLS_NAME)
  51. APP_VERSION ?= $(shell $(ENV_PYTHON) setup.py --version)
  52. APP_FULL_NAME ?= $(APP_NAME)-$(APP_VERSION)
  53. RSYNC_OPT ?= --copy-unsafe-links -a
  54. PYBABEL := $(ROOT)/build/env/bin/pybabel
  55. LOCALE_ROOT := $(APP_ROOT)/src/$(APP_NAME)/locale
  56. BUILD_DIR := $(APP_ROOT)/build
  57. EGG_INFO_DIR := $(APP_ROOT)/src/$(SETUPTOOLS_NAME).egg-info
  58. .PHONY: default
  59. default::
  60. @echo 'The build targets for $(APP_NAME) are: (*) is required'
  61. @echo ' compile : Compile $(APP_NAME)'
  62. @echo ' egg-info * : Create a python egg for $(APP_NAME)'
  63. @echo ' ext-eggs * : Create python eggs for external dependencies'
  64. @echo ' sdist * : Create a source distribution tree and tarball'
  65. @echo ' bdist : Create a built distribution tree'
  66. @echo ' install-bdist *: Install a built distribution to a target location'
  67. @echo ' ext-env-install: Install external dependencies into virtual-env'
  68. @echo ' ext-clean : Clean external dependencies'
  69. @echo ' clean * : Clean $(APP_NAME). Requires ext-clean'
  70. @echo ' distclean : Dist clean $(APP_NAME). Requires clean'
  71. .PHONY: egg
  72. egg-info: compile $(EGG_INFO_DIR)
  73. $(EGG_INFO_DIR): $(APP_ROOT)/setup.py
  74. @echo '--- Making egg-info for $(APP_NAME)'
  75. @$(ENV_PYTHON) setup.py -q egg_info
  76. # Hook to allow extra build steps (eg java builds)
  77. .PHONY: compile
  78. compile:
  79. ##############################
  80. # The following installs the external Python dependencies under the ext-py/
  81. # directory.
  82. EXT_PY_DIRS := $(wildcard ext-py/*)
  83. EXT_PYS := $(notdir $(EXT_PY_DIRS))
  84. ext_py_stamp = $(BUILD_DIR)/$(1)/$(2).stamp
  85. ##############################
  86. # Macros
  87. ##############################
  88. EXT_PY_EGG_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,egg))
  89. EXT_PY_CLEAN_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,clean))
  90. EXT_PY_ENV_INSTALL_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,env-install))
  91. $(EXT_PY_EGG_TARGETS): CUR_EXT_PY=$(notdir $(@D))
  92. $(EXT_PY_CLEAN_TARGETS): CUR_EXT_PY=$(notdir $(@D))
  93. $(EXT_PY_ENV_INSTALL_TARGETS): CUR_EXT_PY=$(notdir $(@D))
  94. #
  95. # ext-env-pip-install
  96. # Pip install any 3rd party package that are based on requirements.txt
  97. #
  98. .PHONY: ext-env-pip-install
  99. ext-env-pip-install:
  100. @echo '--- Installing $(REQUIREMENT_FILE) into virtual-env via $(ENV_PIP)'
  101. @$(ENV_PIP) install -r $(REQUIREMENT_FILE)
  102. @echo '--- Finished $(REQUIREMENT_FILE) into virtual-env'
  103. @$(ENV_PIP) install $(NAVOPTAPI_WHL)
  104. @echo '--- Finished $(NAVOPTAPI_WHL) into virtual-env'
  105. @echo '--- Installing ext-py3 into virtual-env via $(ENV_PIP)'
  106. @$(ENV_PIP) install -e $(BOTO_PKG)
  107. @$(ENV_PIP) install -e $(REQUEST_PKG)
  108. @$(ENV_PIP) install -e $(PYSAML2_PKG)
  109. @echo '--- Finished installing ext-py3 into virtual-env via $(ENV_PIP)'
  110. @touch $@
  111. #
  112. # ext-eggs
  113. # Builds a binary egg for any 3rd party package that are based on the
  114. # earlier distutils (rather than setuptools).
  115. #
  116. .PHONY: ext-eggs
  117. ext-eggs: $(EXT_PY_EGG_TARGETS)
  118. $(EXT_PY_EGG_TARGETS):
  119. ifeq ($(PYTHON_VER),python2.7)
  120. @echo '--- Building egg for $(CUR_EXT_PY)'
  121. @cd ext-py/$(CUR_EXT_PY) && $(ENV_PYTHON) \
  122. -c '__import__("setuptools.sandbox").sandbox.run_setup("setup.py", __import__("sys").argv[1:])' \
  123. bdist_egg
  124. endif
  125. @mkdir -p $(@D) && touch $@
  126. #
  127. # ext-clean
  128. # Clean the 3rd party package. This will NOT uninstall it from Desktop.
  129. #
  130. .PHONY: ext-clean
  131. ext-clean: $(EXT_PY_CLEAN_TARGETS)
  132. $(EXT_PY_CLEAN_TARGETS):
  133. @echo '--- Cleaning $(CUR_EXT_PY)'
  134. @rm -Rf $(BUILD_DIR)/$(CUR_EXT_PY)
  135. @cd ext-py/$(CUR_EXT_PY) && rm -Rf dist build temp *.egg-info
  136. @find ext-py/$(CUR_EXT_PY) -name \*.egg-info -o -name \*.py[co] -prune -exec rm -Rf {} \;
  137. #
  138. # ext-env-install
  139. # Install all 3rd party packages into the Desktop environment. Used by
  140. # desktop core. We look for egg files in two locations:
  141. # (1) ext-py/<pkg>/dist/*.egg
  142. # (2) ext-eggs/*.egg
  143. #
  144. .PHONY: ext-env-install
  145. ext-env-install: ext-eggs $(EXT_PY_ENV_INSTALL_TARGETS)
  146. @for i in $(wildcard ext-eggs/*.egg) ; do \
  147. echo "--- Installing $$i into virtual environment" ; \
  148. $(ENV_EASY_INSTALL) -Z -N $$i 2> /dev/null ; \
  149. done
  150. $(EXT_PY_ENV_INSTALL_TARGETS):
  151. @echo '--- Installing $(CUR_EXT_PY) into virtual environment'
  152. @# If there are no binary eggs, maybe this package decided
  153. @# it wasn't necessary. If the build had failed, the command that produced
  154. @# the egg should have thrown an error.
  155. @cd ext-py/$(CUR_EXT_PY) && [ ! -e dist ] || $(ENV_EASY_INSTALL) -Z -N dist/*egg 2>/dev/null
  156. @mkdir -p $(@D) && touch $@
  157. .PHONY: clean
  158. clean:: ext-clean
  159. @echo --- Cleaning $(APP_NAME)
  160. @# Use SYS_PYTHON because ENV_PYTHON may not be available.
  161. @$(SYS_PYTHON) setup.py clean || :
  162. @rm -Rf $(BUILD_DIR) dist
  163. @find . -name \*.egg-info -prune -exec rm -Rf {} \;
  164. @find . -name \*.py[co] -exec rm -f {} \;
  165. .PHONY: distclean
  166. distclean:: clean
  167. .PHONY: compile-locale
  168. compile-locale:
  169. $(PYBABEL) extract . -F babel.cfg -k _ -k _t -o $(LOCALE_ROOT)/en_US.pot --copyright-holder="Cloudera, Inc" --project="Hue" --version=""
  170. $(PYBABEL) update -D django -i $(LOCALE_ROOT)/en_US.pot -d $(LOCALE_ROOT)
  171. $(PYBABEL) compile -D django -d $(LOCALE_ROOT)
  172. #####################################
  173. # Distribution builds
  174. #####################################
  175. # Items that should not be included in the source/built distribution.
  176. # Apps can list this in their own Makefile before including this file
  177. # in order to exclude their own sources, non-distributables, etc.
  178. # This list is rsync friendly.
  179. COMMON_EXCLUDES := \
  180. --exclude=build \
  181. --exclude=\*.py[co] \
  182. --exclude=.\*.sw[op] \
  183. --exclude=~\* \
  184. --exclude=.gitignore \
  185. --exclude=tag \
  186. --exclude=target
  187. SDIST_EXCLUDES += $(COMMON_EXCLUDES) --exclude=java-lib
  188. BDIST_EXCLUDES += $(COMMON_EXCLUDES) --exclude=ext-py
  189. SDIST_DIR := $(BUILD_DIR)/sdist/$(APP_FULL_NAME)
  190. BDIST_DIR := $(BUILD_DIR)/bdist/$(APP_FULL_NAME)
  191. SDIST_TGZ := $(BUILD_DIR)/sdist/$(APP_FULL_NAME).tgz
  192. #
  193. # sdist
  194. # Simply copy the essential sources to the target directory.
  195. #
  196. .PHONY: sdist
  197. sdist:
  198. @echo '--- Making source distribution at $(SDIST_DIR)'
  199. @rm -rf $(SDIST_DIR)
  200. @mkdir -p $(SDIST_DIR)
  201. @# Copy sources of our app
  202. @rsync $(RSYNC_OPT) ./ $(SDIST_DIR)/ $(SDIST_EXCLUDES)
  203. @$(MAKE) -C $(SDIST_DIR) clean
  204. @# Also make a tarball
  205. @tar -C $(SDIST_DIR)/.. -czf $(SDIST_TGZ) $(APP_FULL_NAME)
  206. @echo "--- Created $(SDIST_TGZ)"
  207. #
  208. # bdist
  209. # Like sdist. For ext-py, we copy the eggs only (into a separate ext-eggs
  210. # directory). Apps with non-python source (e.g. Java, C) should also
  211. # exclude the source files.
  212. #
  213. .PHONY: bdist
  214. bdist: ext-eggs compile
  215. @echo '--- Making built distribution at $(BDIST_DIR)'
  216. @rm -rf $(BDIST_DIR)
  217. @mkdir -p $(BDIST_DIR)
  218. @# Copy built sources of our app
  219. @rsync $(RSYNC_OPT) ./ $(BDIST_DIR)/ $(BDIST_EXCLUDES)
  220. @# Copy thirdparty eggs into the ext-eggs dir
  221. @mkdir -p $(BDIST_DIR)/ext-eggs
  222. @if test -n '$(wildcard ext-py/*/dist)' ; then \
  223. find ext-py/*/dist -type f -name '*.egg' -exec cp {} $(BDIST_DIR)/ext-eggs \; ; \
  224. fi
  225. #
  226. # install-bdist
  227. # Install the built distribution in $(INSTALL_DIR).
  228. # NOTE that this does NOT install the app into the virtual environment.
  229. #
  230. .PHONY: install-bdist
  231. install-bdist: bdist
  232. @echo "--- Install built distribution for $(APP_NAME) at $(INSTALL_DIR)"
  233. @# Check that INSTALL_DIR is empty
  234. @if [ -n '$(wildcard $(INSTALL_DIR)/*)' ] ; then \
  235. echo 'ERROR: $(INSTALL_DIR) not empty. Cowardly refusing to continue.' ; \
  236. false ; \
  237. fi
  238. @mkdir -p $(INSTALL_DIR)
  239. @rsync -a $(BDIST_DIR)/ $(INSTALL_DIR)