David Ostrovsky | ae9c201 | 2019-01-09 22:34:36 +0100 | [diff] [blame] | 1 | load("//tools/bzl:genrule2.bzl", "genrule2") |
David Ostrovsky | 6b6dfcb | 2020-06-27 10:27:25 +0200 | [diff] [blame] | 2 | load("@npm//@bazel/rollup:index.bzl", "rollup_bundle") |
Viktar Donich | dbe8aa8 | 2017-06-23 16:04:04 -0700 | [diff] [blame] | 3 | |
Dmitrii Filippov | 9095f30 | 2021-07-05 16:42:51 +0200 | [diff] [blame] | 4 | def polygerrit_bundle(name, srcs, outs, entry_point, app_name): |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 5 | """Build .zip bundle from source code |
Viktar Donich | dbe8aa8 | 2017-06-23 16:04:04 -0700 | [diff] [blame] | 6 | |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 7 | Args: |
| 8 | name: rule name |
| 9 | srcs: source files |
| 10 | outs: array with a single item - the output file name |
Tao Zhou | 0de9ec5 | 2020-06-25 09:40:20 +0200 | [diff] [blame] | 11 | entry_point: application js entry-point |
Dmitrii Filippov | 9095f30 | 2021-07-05 16:42:51 +0200 | [diff] [blame] | 12 | app_name: defines the application name. Bundled js code is added to .zip |
| 13 | archive with this name. |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 14 | """ |
Viktar Donich | dbe8aa8 | 2017-06-23 16:04:04 -0700 | [diff] [blame] | 15 | |
Dmitrii Filippov | c2aac21 | 2020-03-11 13:33:06 +0100 | [diff] [blame] | 16 | native.filegroup( |
| 17 | name = app_name + "-full-src", |
| 18 | srcs = srcs + [ |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 19 | "@ui_npm//:node_modules", |
| 20 | ], |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | rollup_bundle( |
| 24 | name = app_name + "-bundle-js", |
Dmitrii Filippov | c2aac21 | 2020-03-11 13:33:06 +0100 | [diff] [blame] | 25 | srcs = [app_name + "-full-src"], |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 26 | config_file = ":rollup.config.js", |
Tao Zhou | 0de9ec5 | 2020-06-25 09:40:20 +0200 | [diff] [blame] | 27 | entry_point = entry_point, |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 28 | rollup_bin = "//tools/node_tools:rollup-bin", |
Martin Waitz | f047bbd | 2021-12-16 21:39:14 +0100 | [diff] [blame] | 29 | silent = True, |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 30 | sourcemap = "hidden", |
| 31 | deps = [ |
| 32 | "@tools_npm//rollup-plugin-node-resolve", |
| 33 | ], |
| 34 | ) |
| 35 | |
Ben Rohlfs | de5c02e | 2022-02-01 12:42:12 +0100 | [diff] [blame] | 36 | rollup_bundle( |
| 37 | name = "syntax-worker", |
| 38 | srcs = [app_name + "-full-src"], |
| 39 | config_file = ":rollup.config.js", |
| 40 | entry_point = "_pg_ts_out/workers/syntax-worker.js", |
| 41 | rollup_bin = "//tools/node_tools:rollup-bin", |
David Ostrovsky | 70ae8c2 | 2022-02-22 06:33:20 +0100 | [diff] [blame] | 42 | silent = True, |
Ben Rohlfs | de5c02e | 2022-02-01 12:42:12 +0100 | [diff] [blame] | 43 | sourcemap = "hidden", |
| 44 | deps = [ |
| 45 | "@tools_npm//rollup-plugin-node-resolve", |
| 46 | ], |
| 47 | ) |
| 48 | |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 49 | native.filegroup( |
| 50 | name = name + "_app_sources", |
| 51 | srcs = [ |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 52 | app_name + "-bundle-js.js", |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 53 | ], |
| 54 | ) |
Viktar Donich | dbe8aa8 | 2017-06-23 16:04:04 -0700 | [diff] [blame] | 55 | |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 56 | native.filegroup( |
| 57 | name = name + "_css_sources", |
| 58 | srcs = native.glob(["styles/**/*.css"]), |
| 59 | ) |
Viktar Donich | dbe8aa8 | 2017-06-23 16:04:04 -0700 | [diff] [blame] | 60 | |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 61 | native.filegroup( |
Ben Rohlfs | de5c02e | 2022-02-01 12:42:12 +0100 | [diff] [blame] | 62 | name = name + "_worker_sources", |
| 63 | srcs = [ |
| 64 | "syntax-worker.js", |
| 65 | ], |
| 66 | ) |
| 67 | |
| 68 | native.filegroup( |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 69 | name = name + "_top_sources", |
| 70 | srcs = [ |
| 71 | "favicon.ico", |
| 72 | ], |
| 73 | ) |
Viktar Donich | dbe8aa8 | 2017-06-23 16:04:04 -0700 | [diff] [blame] | 74 | |
Dmitrii Filippov | d97c843 | 2020-01-15 00:49:56 +0100 | [diff] [blame] | 75 | # Preserve bower_components directory in the final directory layout to |
| 76 | # avoid plugins break |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 77 | genrule2( |
| 78 | name = name, |
| 79 | srcs = [ |
| 80 | name + "_app_sources", |
| 81 | name + "_css_sources", |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 82 | name + "_top_sources", |
Ben Rohlfs | de5c02e | 2022-02-01 12:42:12 +0100 | [diff] [blame] | 83 | name + "_worker_sources", |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 84 | "//lib/fonts:robotofonts", |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 85 | "//lib/js:highlightjs__files", |
| 86 | "@ui_npm//:node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js", |
Paladox none | e3747cee | 2021-08-03 21:36:24 +0000 | [diff] [blame] | 87 | "@ui_npm//:node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js.map", |
Dmitrii Filippov | ba3dc7a | 2021-06-28 14:42:15 +0200 | [diff] [blame] | 88 | "@ui_npm//:node_modules/resemblejs/resemble.js", |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 89 | "@ui_npm//@polymer/font-roboto-local", |
| 90 | "@ui_npm//:node_modules/@polymer/font-roboto-local/package.json", |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 91 | ], |
| 92 | outs = outs, |
| 93 | cmd = " && ".join([ |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 94 | "FONT_DIR=$$(dirname $(location @ui_npm//:node_modules/@polymer/font-roboto-local/package.json))/fonts", |
Ben Rohlfs | de5c02e | 2022-02-01 12:42:12 +0100 | [diff] [blame] | 95 | "mkdir -p $$TMP/polygerrit_ui/{workers,styles/themes,fonts/{roboto,robotomono},bower_components/{highlightjs,webcomponentsjs,resemblejs},elements}", |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 96 | "for f in $(locations " + name + "_app_sources); do ext=$${f##*.}; cp -p $$f $$TMP/polygerrit_ui/elements/" + app_name + ".$$ext; done", |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 97 | "cp $(locations //lib/fonts:robotofonts) $$TMP/polygerrit_ui/fonts/", |
| 98 | "for f in $(locations " + name + "_top_sources); do cp $$f $$TMP/polygerrit_ui/; done", |
| 99 | "for f in $(locations " + name + "_css_sources); do cp $$f $$TMP/polygerrit_ui/styles; done", |
Ben Rohlfs | de5c02e | 2022-02-01 12:42:12 +0100 | [diff] [blame] | 100 | "for f in $(locations " + name + "_worker_sources); do cp $$f $$TMP/polygerrit_ui/workers; done", |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 101 | "for f in $(locations //lib/js:highlightjs__files); do cp $$f $$TMP/polygerrit_ui/bower_components/highlightjs/ ; done", |
| 102 | "cp $(location @ui_npm//:node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js) $$TMP/polygerrit_ui/bower_components/webcomponentsjs/webcomponents-lite.js", |
Paladox none | e3747cee | 2021-08-03 21:36:24 +0000 | [diff] [blame] | 103 | "cp $(location @ui_npm//:node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js.map) $$TMP/polygerrit_ui/bower_components/webcomponentsjs/webcomponents-lite.js.map", |
Dmitrii Filippov | ba3dc7a | 2021-06-28 14:42:15 +0200 | [diff] [blame] | 104 | "cp $(location @ui_npm//:node_modules/resemblejs/resemble.js) $$TMP/polygerrit_ui/bower_components/resemblejs/resemble.js", |
Dmitrii Filippov | fbdc89d | 2020-01-20 19:38:06 +0100 | [diff] [blame] | 105 | "cp $$FONT_DIR/roboto/*.ttf $$TMP/polygerrit_ui/fonts/roboto/", |
| 106 | "cp $$FONT_DIR/robotomono/*.ttf $$TMP/polygerrit_ui/fonts/robotomono/", |
Han-Wen Nienhuys | a667b4c | 2018-07-10 11:51:36 +0200 | [diff] [blame] | 107 | "cd $$TMP", |
| 108 | "find . -exec touch -t 198001010000 '{}' ';'", |
| 109 | "zip -qr $$ROOT/$@ *", |
| 110 | ]), |
| 111 | ) |