Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. PPC64LE := $(shell uname -m)
  79. include $(ROOT)/Makefile.vars.priv
  80. ###################################
  81. # Error checking
  82. ###################################
  83. .PHONY: default
  84. default:
  85. @echo 'The build targets for Hue $(DESKTOP_VERSION) are:'
  86. @echo ' install : Install at $$PREFIX ($(INSTALL_DIR)); need desktop'
  87. @echo ' apps : Build and register all desktop apps; need desktop'
  88. @echo ' desktop : Build desktop core only'
  89. @echo ' clean : Remove desktop build products'
  90. @echo ' distclean : Remove desktop and thirdparty build products'
  91. # <<<< DEV ONLY
  92. @echo ' doc : Build documentation'
  93. @echo ' prod : Generate a tar file for production distribution'
  94. @echo ' locales : Extract strings and update dictionary of each locale'
  95. @echo ' ace : Builds the Ace Editor tool'
  96. # END DEV ONLY >>>>
  97. .PHONY: all
  98. all: default
  99. # <<<< DEV ONLY
  100. include Makefile.tarball
  101. ###################################
  102. # Build docs (unused)
  103. ###################################
  104. test_prep:
  105. @$(ENV_PYTHON) -m pip install -r $(REQUIREMENT_TEST_FILE)
  106. ###################################
  107. # Build docs (unused)
  108. ###################################
  109. .PHONY: docs
  110. docs:
  111. @$(MAKE) -C docs
  112. # END DEV ONLY >>>>
  113. ###################################
  114. # Install parent POM
  115. ###################################
  116. .PHONY: parent-pom
  117. parent-pom:
  118. ifneq (,$(BUILD_DB_PROXY))
  119. cd $(ROOT)/maven && mvn install $(MAVEN_OPTIONS)
  120. endif
  121. $(info "PYTHON_VER is $(PYTHON_VER)")
  122. $(info "SYS_PYTHON is $(SYS_PYTHON)")
  123. $(info "ENV_PYTHON is $(ENV_PYTHON)")
  124. $(info "SYS_PIP is $(SYS_PIP)")
  125. $(info "ENV_PIP is $(ENV_PIP)")
  126. $(info "PYTHON_INCLUDE_DIR is $(PYTHON_INCLUDE_DIR)")
  127. $(info "PYTHON_H is $(PYTHON_H)")
  128. $(info "PIP_VERSION is $(PIP_VERSION)")
  129. $(info "VIRTUAL_ENV_VERSION is $(VIRTUAL_ENV_VERSION)")
  130. $(info "RELOCATABLE is $(RELOCATABLE)")
  131. $(info "LOCAL_PY_BIN is $(LOCAL_PY_BIN)")
  132. $(info "BLD_DIR_ENV is $(BLD_DIR_ENV)")
  133. $(info "REQUIREMENT_FILE is $(REQUIREMENT_FILE)")
  134. $(info "INSTALL_DIR is $(INSTALL_DIR)")
  135. $(info "INST_DIR_ENV is $(INST_DIR_ENV)")
  136. $(info "PPC64LE is $(PPC64LE)")
  137. ###################################
  138. # virtual-env
  139. # Enhanced to support building and packaging Hue for multiple Python versions.
  140. # Adds per-Python virtual environment creation, improved logging and diagnostics,
  141. # Test push
  142. ###################################
  143. virtual-env: $(BLD_DIR_ENV)/bin/python
  144. $(BLD_DIR_ENV)/bin/python:
  145. @echo "--- Creating virtual environment for $(PYTHON_VER) ---"
  146. @mkdir -p $(BLD_DIR_ENV)
  147. @$(SYS_PYTHON) -m pip install --upgrade pip==$(PIP_VERSION)
  148. @$(SYS_PYTHON) -m pip install virtualenv==$(VIRTUAL_ENV_VERSION) virtualenv-make-relocatable==$(VIRTUAL_ENV_RELOCATABLE_VERSION)
  149. @$(eval RELOCATABLE := $(shell which virtualenv-make-relocatable))
  150. @$(SYS_PYTHON) -m virtualenv -p $(PYTHON_VER) $(BLD_DIR_ENV) --copies
  151. @echo "REQUIREMENT_FILE is $(REQUIREMENT_FILE)"
  152. @$(ENV_PIP) install -r $(REQUIREMENT_FILE)
  153. @echo "--- Virtual environment setup complete for $(PYTHON_VER) ---"
  154. @$(ENV_PIP) install $(NAVOPTAPI_WHL)
  155. @echo "--- Finished installing $(NAVOPTAPI_WHL) into virtual-env ---"
  156. ###################################
  157. # Build desktop
  158. ###################################
  159. .PHONY: desktop
  160. # <<<< DEV ONLY
  161. desktop: parent-pom
  162. # END DEV ONLY >>>>
  163. desktop: virtual-env
  164. @$(MAKE) -C desktop
  165. ###################################
  166. # relocatable-env
  167. # Enhanced to support relocatable .pth files.
  168. ###################################
  169. relocatable-env:
  170. @$(MAKE) virtual-env
  171. @echo "--- Running $(SYS_PYTHON) $(RELOCATABLE) $(BLD_DIR_ENV)"
  172. @$(SYS_PYTHON) $(RELOCATABLE) $(BLD_DIR_ENV)
  173. @echo "--- Setting up pth files $(ENV_PYTHON) $(ROOT)/tools/relocatable.py"
  174. @$(ENV_PYTHON) $(ROOT)/tools/relocatable.py
  175. ###################################
  176. # Build apps
  177. ###################################
  178. .PHONY: apps
  179. apps: desktop
  180. @$(MAKE) npm-install
  181. @$(MAKE) -C $(APPS_DIR) env-install
  182. @$(MAKE) create-static
  183. ###################################
  184. # Install binary dist
  185. ###################################
  186. INSTALL_CORE_FILES = \
  187. Makefile* $(wildcard *.mk) \
  188. ext \
  189. tools/app_reg \
  190. $(INSTALL_DIR) \
  191. VERS* LICENSE* README*
  192. .PHONY: install
  193. install: virtual-env install-check install-core-structure install-desktop install-apps install-env
  194. .PHONY: install-check
  195. install-check:
  196. @if [ -n '$(wildcard $(INST_DIR_ENV)/*)' ] ; then \
  197. echo "ERROR: $(INST_DIR_ENV) is not empty. Contents:" ; \
  198. ls -la "$(INST_DIR_ENV)" ; \
  199. echo 'ERROR: $(INST_DIR_ENV) not empty. Cowardly refusing to continue.' ; \
  200. false ; \
  201. fi
  202. .PHONY: install-core-structure
  203. install-core-structure:
  204. @echo --- Installing core source structure in $(INSTALL_DIR)...
  205. @mkdir -p $(INSTALL_DIR)
  206. @tar cf - $(INSTALL_CORE_FILES) | tar -C $(INSTALL_DIR) -xf -
  207. @# Add some variables to Makefile to make sure that our virtualenv
  208. @# in the install root is the same one we built from - this also
  209. @# disables the check for python-devel packages which are no longer
  210. @# needed
  211. @echo "SYS_PYTHON=$(ENV_PYTHON_VERSION)" > $(INSTALL_DIR)/Makefile.buildvars
  212. @echo "SKIP_PYTHONDEV_CHECK=1" >> $(INSTALL_DIR)/Makefile.buildvars
  213. .PHONY: install-desktop
  214. install-desktop:
  215. @echo --- Installing Desktop core...
  216. INSTALL_DIR=$(realpath $(INSTALL_DIR)) $(MAKE) -C desktop install
  217. .PHONY: install-apps
  218. install-apps:
  219. @echo '--- Installing Applications...'
  220. INSTALL_DIR=$(realpath $(INSTALL_DIR)) $(MAKE) -C apps install
  221. .PHONY: install-env
  222. install-env:
  223. @echo --- Creating new virtual environment
  224. $(MAKE) -C $(INSTALL_DIR) virtual-env
  225. @echo --- Setting up Desktop core
  226. $(MAKE) -C $(INSTALL_DIR)/desktop env-install
  227. @echo --- Setting up Applications
  228. $(MAKE) -C $(INSTALL_DIR)/apps env-install
  229. @echo --- Setting up Frontend assets
  230. cp $(ROOT)/package.json $(INSTALL_DIR)
  231. cp $(ROOT)/package-lock.json $(INSTALL_DIR)
  232. cp $(ROOT)/webpack.config*.js $(INSTALL_DIR)
  233. cp $(ROOT)/babel.config.js $(INSTALL_DIR)
  234. cp $(ROOT)/tsconfig.json $(INSTALL_DIR)
  235. $(MAKE) -C $(INSTALL_DIR) npm-install
  236. $(MAKE) -C $(INSTALL_DIR) create-static
  237. ###################################
  238. # Frontend and static assets
  239. ###################################
  240. .PHONY: npm-install
  241. npm-install: .npm-install-lock
  242. .npm-install-lock:
  243. npm --version
  244. node --version
  245. npm install
  246. npm run webpack
  247. npm run webpack-login
  248. npm run webpack-workers
  249. node_modules/.bin/removeNPMAbsolutePaths .
  250. rm -rf node_modules
  251. touch .npm-install-lock
  252. .PHONY: create-static
  253. create-static:
  254. $(ENV_PYTHON) $(BLD_DIR_BIN)/hue collectstatic --noinput
  255. # <<<< DEV ONLY
  256. .PHONY: doc
  257. doc:
  258. hugo --source docs/docs-site
  259. # END DEV ONLY >>>>
  260. ###################################
  261. # Internationalization
  262. ###################################
  263. # <<<< DEV ONLY
  264. .PHONY: locales
  265. locales:
  266. @$(MAKE) -C desktop compile-locales
  267. @$(MAKE) -C apps compile-locales
  268. # END DEV ONLY >>>>
  269. ###################################
  270. # Ace Editor
  271. ###################################
  272. # <<<< DEV ONLY
  273. .PHONY: ace
  274. ace:
  275. @cd tools/ace-editor && ./hue-ace.sh
  276. # END DEV ONLY >>>>
  277. ###################################
  278. # JISON Parser Generators
  279. ###################################
  280. # <<<< DEV ONLY
  281. .PHONY: global-search-parser
  282. global-search-parser:
  283. @pushd tools/jison/ && npm install && node generateParsers.js globalSearchParser && popd
  284. .PHONY: solr-all-parsers
  285. solr-all-parsers:
  286. @pushd tools/jison/ && npm install && node generateParsers.js solrQueryParser solrFormulaParser && popd
  287. .PHONY: solr-query-parser
  288. solr-query-parser:
  289. @pushd tools/jison/ && npm install && node generateParsers.js solrQueryParser && popd
  290. .PHONY: solr-formula-parser
  291. solr-formula-parser:
  292. @pushd tools/jison/ && npm install && node generateParsers.js solrFormulaParser && popd
  293. .PHONY: sql-all-parsers
  294. sql-all-parsers:
  295. @pushd tools/jison/ && npm install && node generateParsers.js generic hive impala && popd
  296. .PHONY: sql-autocomplete-parser
  297. sql-autocomplete-parser:
  298. @pushd tools/jison/ && npm install && node generateParsers.js genericAutocomp hiveAutocomp impalaAutocomp && popd
  299. .PHONY: sql-statement-parser
  300. sql-statement-parser:
  301. @pushd tools/jison/ && npm install && node generateParsers.js sqlStatementsParser && popd
  302. .PHONY: sql-syntax-parser
  303. sql-syntax-parser:
  304. @pushd tools/jison/ && npm install && node generateParsers.js genericSyntax hiveSyntax impalaSyntax && popd
  305. # END DEV ONLY >>>>
  306. ###################################
  307. # Cleanup
  308. ###################################
  309. .PHONY: clean
  310. clean:
  311. @$(MAKE) -C desktop clean
  312. @$(MAKE) -C apps clean
  313. # <<<< DEV ONLY
  314. @$(MAKE) -C docs clean
  315. # END DEV ONLY >>>>
  316. @rm -rf $(BLD_DIR_ENV)
  317. @rm -rf $(STATIC_DIR)
  318. #
  319. # Note: It is important for clean targets to *ONLY* clean products of the
  320. # build, and not misc runtime generated files. Don't abuse Makefile.
  321. #
  322. .PHONY: distclean
  323. distclean: clean
  324. @# Remove the other directories in build/
  325. @$(MAKE) -C desktop distclean
  326. @$(MAKE) -C apps distclean
  327. @rm -rf $(BLD_DIR)
  328. .PHONY: ext-clean
  329. ext-clean:
  330. @$(MAKE) -C desktop ext-clean
  331. @$(MAKE) -C apps ext-clean
  332. # <<<< DEV ONLY
  333. ###############################################
  334. # Misc (some used by automated test scripts)
  335. ###############################################
  336. huecheck:
  337. @echo "Checking for release..."
  338. DESKTOP_DEBUG=1 $(ENV_PYTHON) $(BLD_DIR_BIN)/hue check
  339. test:
  340. DESKTOP_DEBUG=1 $(ENV_PYTHON) $(BLD_DIR_BIN)/hue test fast --with-xunit
  341. test-slow:
  342. DESKTOP_DEBUG=1 $(ENV_PYTHON) $(BLD_DIR_BIN)/hue test all --with-xunit --with-cover
  343. $(BLD_DIR_BIN)/coverage xml -i
  344. start-dev:
  345. DESKTOP_DEBUG=1 $(ENV_PYTHON) $(BLD_DIR_BIN)/hue runserver_plus
  346. devinstall:
  347. npm run devinstall
  348. css:
  349. npm run less
  350. # END DEV ONLY >>>>