From 4312181d322bc9dd7668dedf4f8b7966a4ddc9c5 Mon Sep 17 00:00:00 2001 From: Stephan Lee Date: Wed, 21 Apr 2021 14:34:12 -0700 Subject: [PATCH 1/5] infra: remove JSCompiler from Vulcanize TensorBoard no longer uses JSCompiler in a meaningful way. For the most TypeScript/JavaScript source, we use rollup via rules_nodejs. Hence, we now remove the JSCompiler portion from the Vulcanization. Soon after, vulcanize.bzl will be completely removed accordingly. --- tensorboard/defs/internal/html.bzl | 133 +++++++ .../tensorflow/tensorboard/vulcanize/BUILD | 2 - .../tensorboard/vulcanize/Vulcanize.java | 337 +----------------- tensorboard/plugins/graph/tf_graph_app/BUILD | 5 +- .../projector/tf_projector_plugin/BUILD | 5 +- .../plugins/projector/vz_projector/BUILD | 5 +- tensorboard/webapp/BUILD | 4 +- 7 files changed, 155 insertions(+), 336 deletions(-) create mode 100644 tensorboard/defs/internal/html.bzl diff --git a/tensorboard/defs/internal/html.bzl b/tensorboard/defs/internal/html.bzl new file mode 100644 index 0000000000..a1d27bad16 --- /dev/null +++ b/tensorboard/defs/internal/html.bzl @@ -0,0 +1,133 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Rule for building the HTML binary.""" + +load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_aspect") +load("@io_bazel_rules_closure//closure/private:defs.bzl", "collect_js", "long_path", "unfurl") + +def _tb_combine_html_impl(ctx): + """Compiles HTMLs into one HTML. + + The rule outputs a HTML that resolves all HTML `rel=import` statements into + one document. The rule also combines content of all script elements to a + JavaScript file when `js_path` is specified. + """ + + deps = unfurl(ctx.attr.deps, provider = "webfiles") + manifests = depset(order = "postorder") + files = depset() + webpaths = depset() + for dep in deps: + manifests = depset(transitive = [manifests, dep.webfiles.manifests]) + webpaths = depset(transitive = [webpaths, dep.webfiles.webpaths]) + files = depset(transitive = [files, dep.data_runfiles.files]) + webpaths = depset([ctx.attr.output_path], transitive = [webpaths]) + closure_js_library = collect_js( + unfurl(ctx.attr.deps, provider = "closure_js_library"), + ) + + # vulcanize + ignore_regexs_file_set = depset() + ignore_regexs_file_path = "NO_REGEXS" + ctx.actions.run( + inputs = depset(transitive = [ + manifests, + files, + ]).to_list(), + outputs = [ctx.outputs.html, ctx.outputs.js], + executable = ctx.executable._Vulcanize, + arguments = ([ + ctx.attr.input_path, + ctx.attr.output_path, + ctx.attr.js_path, + ctx.outputs.html.path, + ctx.outputs.js.path, + ] + + [f.path for f in manifests.to_list()]), + mnemonic = "Vulcanize", + progress_message = "Vulcanizing %s" % ctx.attr.input_path, + ) + + # webfiles manifest + manifest_srcs = [struct( + path = ctx.outputs.html.path, + longpath = long_path(ctx, ctx.outputs.html), + webpath = ctx.attr.output_path, + )] + + if ctx.attr.js_path: + manifest_srcs.append( + struct( + path = ctx.outputs.js.path, + longpath = long_path(ctx, ctx.outputs.js), + webpath = ctx.attr.js_path, + ), + ) + + manifest = ctx.actions.declare_file("%s.pbtxt" % ctx.label.name) + ctx.actions.write( + output = manifest, + content = struct( + label = str(ctx.label), + src = manifest_srcs, + ).to_proto(), + ) + manifests = depset([manifest], transitive = [manifests]) + + transitive_runfiles = depset() + for dep in deps: + transitive_runfiles = depset(transitive = [ + transitive_runfiles, + dep.data_runfiles.files, + ]) + + return struct( + files = depset([ctx.outputs.html, ctx.outputs.js]), + webfiles = struct( + manifest = manifest, + manifests = manifests, + webpaths = webpaths, + dummy = ctx.outputs.html, + ), + runfiles = ctx.runfiles( + files = ctx.files.data + [ + manifest, + ctx.outputs.html, + ctx.outputs.js, + ], + transitive_files = transitive_runfiles, + ), + ) + +tb_combine_html = rule( + implementation = _tb_combine_html_impl, + attrs = { + "input_path": attr.string(mandatory = True), + "output_path": attr.string(mandatory = True), + # If specified, it extracts scripts into {name}.js and inserts