From 3254ec74921577a83c9dc174860f0102f3780fc2 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Thu, 20 Oct 2016 14:26:11 +0200 Subject: [PATCH] bazel: generate polygerrit_ui.zip. Tested: verified that polygerrit-ui/app:polygerrit_ui zip contain same files for bazel and buck. Change-Id: I5fb1abbc6e68a593d6af0b7b1811608eb11f7e4c --- lib/fonts/BUILD | 7 ++-- lib/js/BUILD | 8 ++++- polygerrit-ui/BUILD | 15 +-------- polygerrit-ui/app/BUILD | 72 ++++++++++++++++++++++++++++++----------- tools/bzl/js.bzl | 18 ++++++----- 5 files changed, 74 insertions(+), 46 deletions(-) diff --git a/lib/fonts/BUILD b/lib/fonts/BUILD index 509ce3994a..92accea8bb 100644 --- a/lib/fonts/BUILD +++ b/lib/fonts/BUILD @@ -2,16 +2,13 @@ load('//tools/bzl:genrule2.bzl', 'genrule2') # Source Code Pro. Version 2.010 Roman / 1.030 Italics # https://github.com/adobe-fonts/source-code-pro/releases/tag/2.010R-ro%2F1.030R-it -genrule2( +filegroup( name = 'sourcecodepro', - cmd = 'zip -rq $@ $(SRCS)', srcs = [ 'SourceCodePro-Regular.woff', 'SourceCodePro-Regular.woff2' ], - out = 'sourcecodepro.zip', -# TODO(hanwen): fix this -# license = 'OFL1.1', + data = [ "//lib:LICENSE-OFL1.1" ], visibility = ['//visibility:public'], ) diff --git a/lib/js/BUILD b/lib/js/BUILD index 249f5d0d04..cc3d6e9f40 100644 --- a/lib/js/BUILD +++ b/lib/js/BUILD @@ -25,7 +25,13 @@ define_bower_components() js_component( name = 'highlightjs', srcs = [ "//lib/highlightjs:highlight.min.js" ], - license = '//lib:LICENSE-highlightjs', + license = '//lib:LICENSE-highlightjs', +) + +filegroup( + name = "highlightjs_files", + srcs = [ "//lib/highlightjs:highlight.min.js" ], + data = ['//lib:LICENSE-highlightjs',], ) bower_component( diff --git a/polygerrit-ui/BUILD b/polygerrit-ui/BUILD index 9191ab72fe..4cc68993e6 100644 --- a/polygerrit-ui/BUILD +++ b/polygerrit-ui/BUILD @@ -10,6 +10,7 @@ bower_component_bundle( deps = [ '//lib/js:es6-promise', '//lib/js:fetch', + # TODO(hanwen): this is inserted separately in the UI zip. Do we need this here? '//lib/js:highlightjs', '//lib/js:iron-autogrow-textarea', '//lib/js:iron-dropdown', @@ -21,17 +22,3 @@ bower_component_bundle( '//lib/js:polymer', '//lib/js:promise-polyfill', ]) - - -genrule2( - name = 'fonts', - cmd = ' && '.join([ - 'cd $$TMP; for file in $(SRCS); do unzip -q $$ROOT/$$file; done', - 'zip -q $$ROOT/$@ *', - ]), - srcs = [ - '//lib/fonts:sourcecodepro.zip', - ], - out = 'fonts.zip', - visibility = ['//visibility:public'], -) diff --git a/polygerrit-ui/app/BUILD b/polygerrit-ui/app/BUILD index 29bbfffe09..362a42b467 100644 --- a/polygerrit-ui/app/BUILD +++ b/polygerrit-ui/app/BUILD @@ -1,24 +1,8 @@ package( default_visibility = ["//visibility:public"]) + load("//tools/bzl:js.bzl", "bower_component_bundle", "vulcanize") -WCT_TEST_PATTERNS = [ - 'test/*.js', - 'test/*.html', - '**/*_test.html', -] -PY_TEST_PATTERNS = ['polygerrit_wct_tests.py'] -APP_SRCS = glob( - ['**'], - exclude = [ - 'BUCK', - '*~', - '**/BUILD', - 'index.html', - 'test/**', - ] + WCT_TEST_PATTERNS + PY_TEST_PATTERNS) - - bower_component_bundle( name = 'test_components', deps = [ @@ -32,6 +16,58 @@ bower_component_bundle( vulcanize( name = "gr-app", app = 'elements/gr-app.html', - srcs = APP_SRCS, + srcs = glob( + ['**'], + exclude = [ + '**/BUCK', + '**/BUILD', + '*~', + '#*', + 'index.html', + 'test/**', + '**/*_test.html', + "polygerrit_wct_tests.py"]), deps = [ "//polygerrit-ui:polygerrit_components"], ) + +filegroup( + name = "top_sources", + srcs = glob([ + 'favicon.ico', + 'index.html', + ]), +) + +filegroup( + name = "css_sources", + srcs = glob(['styles/**/*.css']) +) + +genrule( + name = "polygerrit_ui", + cmd = " && ".join([ + "t=$$(mktemp -d)", + "p=$$PWD", + "mkdir -p $$t/polygerrit_ui/{styles,fonts,bower_components/{highlightjs,webcomponentsjs},elements}", + "cp $(locations :gr-app) $$t/polygerrit_ui/elements/", + "cp $(locations //lib/fonts:sourcecodepro) $$t/polygerrit_ui/fonts/", + "for f in $(locations :top_sources); do cp $$f $$t/polygerrit_ui/; done", + "for f in $(locations :css_sources); do cp $$f $$t/polygerrit_ui/styles; done", + "for f in $(locations //lib/js:highlightjs_files); do cp $$f $$t/polygerrit_ui/bower_components/highlightjs/ ; done", + "unzip -qd $$t/polygerrit_ui/bower_components $(location @webcomponentsjs//:zipfile) webcomponentsjs/webcomponents-lite.js", + "cd $$t", + "find . -exec touch -t 198001010000 '{}' ';'", + "zip -qr $$p/$@ *", + ]), + srcs = [ + "//lib/fonts:sourcecodepro", + "//lib/js:highlightjs_files", + ":top_sources", + ":css_sources", + ":gr-app", + # we extract from the zip, but depend on the component for license checking. + "@webcomponentsjs//:zipfile", + "//lib/js:webcomponentsjs", + ], + outs = [ "polygerrit_ui.zip" ], +) diff --git a/tools/bzl/js.bzl b/tools/bzl/js.bzl index 38d6c9179f..d03faa530d 100644 --- a/tools/bzl/js.bzl +++ b/tools/bzl/js.bzl @@ -281,7 +281,10 @@ bower_component_bundle = rule( ) def _vulcanize_impl(ctx): - destdir = ctx.outputs.vulcanized.path + ".dir" + # intermediate artifact. + vulcanized = ctx.new_file( + ctx.configuration.genfiles_dir, ctx.outputs.html, ".vulcanized.html") + destdir = ctx.outputs.html.path + ".dir" zips = [z for d in ctx.attr.deps for z in d.transitive_zipfiles ] hermetic_npm_binary = " ".join([ @@ -291,7 +294,7 @@ def _vulcanize_impl(ctx): '--inline-scripts', '--inline-css', '--strip-comments', - '--out-html', "$p/" + ctx.outputs.vulcanized.path, + '--out-html', "$p/" + vulcanized.path, ctx.file.app.path ]) @@ -313,7 +316,7 @@ def _vulcanize_impl(ctx): inputs = [ctx.file._run_npm, ctx.file.app, ctx.file._vulcanize_archive ] + list(zips) + ctx.files.srcs, - outputs = [ctx.outputs.vulcanized], + outputs = [vulcanized], command = cmd) hermetic_npm_command = "export PATH && " + " ".join([ @@ -321,14 +324,14 @@ def _vulcanize_impl(ctx): ctx.file._run_npm.path, ctx.file._crisper_archive.path, "--always-write-script", - "--source", ctx.outputs.vulcanized.path, + "--source", vulcanized.path, "--html", ctx.outputs.html.path, "--js", ctx.outputs.js.path]) ctx.action( mnemonic = "Crisper", inputs = [ctx.file._run_npm, ctx.file.app, - ctx.file._crisper_archive, ctx.outputs.vulcanized], + ctx.file._crisper_archive, vulcanized], outputs = [ctx.outputs.js, ctx.outputs.html], command = hermetic_npm_command) @@ -355,9 +358,8 @@ _vulcanize_rule = rule( ), }, outputs = { - "vulcanized": "%{name}.vulcanized.html", - "html": "%{name}.crisped.html", - "js": "%{name}.crisped.js", + "html": "%{name}.html", + "js": "%{name}.js", } )