Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. # <<<< DEV ONLY
  19. #
  20. # Hue Build Process Overview
  21. # =======================================
  22. # This build process handles different types of builds:
  23. #
  24. # - The production release build, the main task of which is to install
  25. # Desktop in the local system. The main build products are:
  26. #
  27. # * build/env - The virtual environment, where Desktop core
  28. # and various apps install into.
  29. #
  30. # - The development build, which includes test and debugging tools. It
  31. # generates the production release, which boils down to a tarball that is
  32. # downloaded and installed. Additional build products include:
  33. #
  34. # * build/release/prod - The production tarball.
  35. # * build/docs - General Desktop and SDK docs.
  36. #
  37. # We achieve this by selecting the parts to be distributed, and by stripping
  38. # the Makefile's. Lines enclosed by the "DEV ONLY" marks are stripped for the
  39. # general release. Targets are split/expanded using multiple rules and
  40. # double-colon rules. The idea is to use almost identical build logic for the
  41. # different flavours.
  42. #
  43. # Logic Flow
  44. # ==========
  45. # Here we summarize the flow of the build logic. Lines represent dependency.
  46. #
  47. # virtual-bootstrap.py
  48. # |
  49. # virtual-env (./env)
  50. # |
  51. # +----------+
  52. # | |
  53. # | V
  54. # | desktop <--- recursive make in /desktop
  55. # | |
  56. # | V
  57. # | apps <--- recursive make in /apps
  58. # |
  59. # V
  60. # prod tarball <-- selective copying into /build/release/...
  61. #
  62. #
  63. # Application Build
  64. # =================
  65. # An app typically includes $(ROOT)/Makefile.sdk, which provides the standard
  66. # targets and facilities. ROOT, which points to the Hue installation root, is
  67. # always passed in.
  68. #
  69. # The application may also choose to not use the Hue build facilities. In that
  70. # case, its Makefile still receives $(ROOT), and needs to provide several
  71. # targets as specified in Makefile.sdk.
  72. #
  73. # END DEV ONLY >>>>
  74. ###################################
  75. # Global variables
  76. ###################################
  77. ROOT := $(realpath .)
  78. include $(ROOT)/Makefile.vars.priv
  79. ###################################
  80. # Error checking
  81. ###################################
  82. .PHONY: default
  83. default:
  84. @echo 'The build targets for Hue $(DESKTOP_VERSION) are:'
  85. @echo ' install : Install at $$PREFIX ($(INSTALL_DIR)); need desktop'
  86. @echo ' apps : Build and register all desktop apps; need desktop'
  87. @echo ' desktop : Build desktop core only'
  88. @echo ' clean : Remove desktop build products'
  89. @echo ' distclean : Remove desktop and thirdparty build products'
  90. # <<<< DEV ONLY
  91. @echo ' doc : Build documentation'
  92. @echo ' prod : Generate a tar file for production distribution'
  93. @echo ' locales : Extract strings and update dictionary of each locale'
  94. @echo ' ace : Builds the Ace Editor tool'
  95. # END DEV ONLY >>>>
  96. .PHONY: all
  97. all: default
  98. # <<<< DEV ONLY
  99. include Makefile.tarball
  100. ###################################
  101. # Build docs (unused)
  102. ###################################
  103. .PHONY: docs
  104. docs:
  105. @$(MAKE) -C docs
  106. # END DEV ONLY >>>>
  107. ###################################
  108. # Install parent POM
  109. ###################################
  110. parent-pom:
  111. ifneq (,$(BUILD_DB_PROXY))
  112. cd $(ROOT)/maven && mvn install $(MAVEN_OPTIONS)
  113. endif
  114. .PHONY: parent-pom
  115. ###################################
  116. # virtual-env
  117. ###################################
  118. virtual-env: $(BLD_DIR_ENV)/stamp
  119. $(BLD_DIR_ENV)/stamp:
  120. @echo "--- Creating virtual environment at $(BLD_DIR_ENV)"
  121. $(SYS_PYTHON) $(VIRTUAL_BOOTSTRAP) \
  122. $(VIRTUALENV_OPTS) --system-site-packages $(BLD_DIR_ENV)
  123. @touch $@
  124. @echo "--- $(BLD_DIR_ENV) ready"
  125. .PHONY: virtual-env
  126. ###################################
  127. # Build desktop
  128. ###################################
  129. .PHONY: desktop
  130. # <<<< DEV ONLY
  131. desktop: parent-pom
  132. # END DEV ONLY >>>>
  133. desktop: virtual-env
  134. @if [ "$(PYTHON_VER)" = "python2.7" ] && [ "$(MAKECMDGOALS)" = "apps" ]; then \
  135. $(ENV_PIP) install --upgrade pip; \
  136. $(ENV_PIP) install $(PIP_MODULES); \
  137. fi
  138. @$(MAKE) -C desktop
  139. ###################################
  140. # Build apps
  141. ###################################
  142. .PHONY: apps
  143. apps: desktop
  144. @$(MAKE) npm-install
  145. @$(MAKE) -C $(APPS_DIR) env-install
  146. @$(MAKE) create-static
  147. ###################################
  148. # Install binary dist
  149. ###################################
  150. INSTALL_CORE_FILES = \
  151. Makefile* $(wildcard *.mk) \
  152. ext \
  153. tools/app_reg \
  154. tools/virtual-bootstrap \
  155. tools/enable-python27.sh \
  156. tools/relocatable.sh \
  157. VERS* LICENSE* README* webpack-stats*.json
  158. .PHONY: install
  159. install: virtual-env install-check install-core-structure install-desktop install-apps install-env
  160. .PHONY: install-check
  161. install-check:
  162. @if [ -n '$(wildcard $(INSTALL_DIR)/*)' ] ; then \
  163. echo 'ERROR: $(INSTALL_DIR) not empty. Cowardly refusing to continue.' ; \
  164. false ; \
  165. fi
  166. .PHONY: install-core-structure
  167. install-core-structure:
  168. @echo --- Installing core source structure...
  169. @mkdir -p $(INSTALL_DIR)
  170. @tar cf - $(INSTALL_CORE_FILES) | tar -C $(INSTALL_DIR) -xf -
  171. @# Add some variables to Makefile to make sure that our virtualenv
  172. @# in the install root is the same one we built from - this also
  173. @# disables the check for python-devel packages which are no longer
  174. @# needed
  175. @echo "SYS_PYTHON=$(ENV_PYTHON_VERSION)" > $(INSTALL_DIR)/Makefile.buildvars
  176. @echo "SKIP_PYTHONDEV_CHECK=1" >> $(INSTALL_DIR)/Makefile.buildvars
  177. .PHONY: install-desktop
  178. install-desktop:
  179. @echo --- Installing Desktop core...
  180. INSTALL_DIR=$(realpath $(INSTALL_DIR)) $(MAKE) -C desktop install
  181. .PHONY: install-apps
  182. install-apps:
  183. @echo '--- Installing Applications...'
  184. INSTALL_DIR=$(realpath $(INSTALL_DIR)) $(MAKE) -C apps install
  185. .PHONY: install-env
  186. install-env:
  187. @echo --- Creating new virtual environment
  188. $(MAKE) -C $(INSTALL_DIR) virtual-env
  189. # This is needed as somehow Hue commands (app_reg, collectstatic..) import modules with hard uneeded dependencies on those.
  190. # We have two virt-env: $(ENV_PIP) aka /build/hue for build and $(PREFIX)/hue/build/env for destination.
  191. @if [ "$(PYTHON_VER)" = "python2.7" ] && [ "$(MAKECMDGOALS)" = "install" ]; then \
  192. $(PREFIX)/hue/build/env/bin/pip install $(PIP_MODULES); \
  193. fi
  194. # Alternative to ext-py directory but only due to the special case below.
  195. # Hackish way to get crypto to install with pre-compiled dependencies that now break as of today with Py2.
  196. @if [ "$(PYTHON_VER)" = "python2.7" ]; then \
  197. $(ENV_PIP) install --upgrade pip; \
  198. $(ENV_PIP) install $(PIP_MODULES); \
  199. fi
  200. @echo --- Setting up Desktop core
  201. $(MAKE) -C $(INSTALL_DIR)/desktop env-install
  202. @echo --- Setting up Applications
  203. $(MAKE) -C $(INSTALL_DIR)/apps env-install
  204. @echo --- Setting up Frontend assets
  205. cp $(ROOT)/package.json $(INSTALL_DIR)
  206. cp $(ROOT)/package-lock.json $(INSTALL_DIR)
  207. cp $(ROOT)/webpack.config*.js $(INSTALL_DIR)
  208. cp $(ROOT)/.babelrc $(INSTALL_DIR)
  209. cp $(ROOT)/tsconfig.json $(INSTALL_DIR)
  210. $(MAKE) -C $(INSTALL_DIR) npm-install
  211. @if [ "$(MAKECMDGOALS)" = "install" ]; then \
  212. $(MAKE) -C $(INSTALL_DIR) create-static; \
  213. fi
  214. ###################################
  215. # Frontend and static assets
  216. ###################################
  217. .PHONY: npm-install
  218. npm-install:
  219. npm --version
  220. node --version
  221. npm install
  222. npm run webpack
  223. npm run webpack-login
  224. npm run webpack-workers
  225. node_modules/.bin/removeNPMAbsolutePaths .
  226. @if [ "$(MAKECMDGOALS)" = "install" ]; then \
  227. rm -rf node_modules; \
  228. fi
  229. .PHONY: create-static
  230. create-static:
  231. ./build/env/bin/hue collectstatic --noinput
  232. # <<<< DEV ONLY
  233. .PHONY: doc
  234. doc:
  235. hugo --source docs/docs-site
  236. # END DEV ONLY >>>>
  237. ###################################
  238. # Internationalization
  239. ###################################
  240. # <<<< DEV ONLY
  241. .PHONY: locales
  242. locales:
  243. @$(MAKE) -C desktop compile-locales
  244. @$(MAKE) -C apps compile-locales
  245. # END DEV ONLY >>>>
  246. ###################################
  247. # Ace Editor
  248. ###################################
  249. # <<<< DEV ONLY
  250. .PHONY: ace
  251. ace:
  252. @cd tools/ace-editor && ./hue-ace.sh
  253. # END DEV ONLY >>>>
  254. ###################################
  255. # JISON Parser Generators
  256. ###################################
  257. # <<<< DEV ONLY
  258. .PHONY: global-search-parser
  259. global-search-parser:
  260. @pushd tools/jison/ && npm install && node generateParsers.js globalSearchParser && popd
  261. .PHONY: solr-all-parsers
  262. solr-all-parsers:
  263. @pushd tools/jison/ && npm install && node generateParsers.js solrQueryParser solrFormulaParser && popd
  264. .PHONY: solr-query-parser
  265. solr-query-parser:
  266. @pushd tools/jison/ && npm install && node generateParsers.js solrQueryParser && popd
  267. .PHONY: solr-formula-parser
  268. solr-formula-parser:
  269. @pushd tools/jison/ && npm install && node generateParsers.js solrFormulaParser && popd
  270. .PHONY: sql-all-parsers
  271. sql-all-parsers:
  272. @pushd tools/jison/ && npm install && node generateParsers.js generic hive impala && popd
  273. .PHONY: sql-autocomplete-parser
  274. sql-autocomplete-parser:
  275. @pushd tools/jison/ && npm install && node generateParsers.js genericAutocomp hiveAutocomp impalaAutocomp && popd
  276. .PHONY: sql-statement-parser
  277. sql-statement-parser:
  278. @pushd tools/jison/ && npm install && node generateParsers.js sqlStatementsParser && popd
  279. .PHONY: sql-syntax-parser
  280. sql-syntax-parser:
  281. @pushd tools/jison/ && npm install && node generateParsers.js genericSyntax hiveSyntax impalaSyntax && popd
  282. # END DEV ONLY >>>>
  283. ###################################
  284. # Cleanup
  285. ###################################
  286. .PHONY: clean
  287. clean:
  288. @$(MAKE) -C desktop clean
  289. @$(MAKE) -C apps clean
  290. # <<<< DEV ONLY
  291. @$(MAKE) -C docs clean
  292. # END DEV ONLY >>>>
  293. @rm -rf $(BLD_DIR_ENV)
  294. @rm -rf $(STATIC_DIR)
  295. #
  296. # Note: It is important for clean targets to *ONLY* clean products of the
  297. # build, and not misc runtime generated files. Don't abuse Makefile.
  298. #
  299. .PHONY: distclean
  300. distclean: clean
  301. @# Remove the other directories in build/
  302. @$(MAKE) -C desktop distclean
  303. @$(MAKE) -C apps distclean
  304. @rm -rf $(BLD_DIR)
  305. .PHONY: ext-clean
  306. ext-clean:
  307. @$(MAKE) -C desktop ext-clean
  308. @$(MAKE) -C apps ext-clean
  309. # <<<< DEV ONLY
  310. ###############################################
  311. # Misc (some used by automated test scripts)
  312. ###############################################
  313. test:
  314. DESKTOP_DEBUG=1 $(ENV_PYTHON) $(BLD_DIR_BIN)/hue test fast --with-xunit
  315. test-slow:
  316. DESKTOP_DEBUG=1 $(ENV_PYTHON) $(BLD_DIR_BIN)/hue test all --with-xunit --with-cover
  317. $(BLD_DIR_BIN)/coverage xml -i
  318. start-dev:
  319. DESKTOP_DEBUG=1 $(ENV_PYTHON) $(BLD_DIR_BIN)/hue runserver_plus
  320. devinstall:
  321. npm run devinstall
  322. css:
  323. npm run less
  324. # END DEV ONLY >>>>