Skip to content

Commit 46a0b7d

Browse files
authored
Fix ES6 module resolution and polish build tooling (#1123)
This change fixes a regression that might have been introduced by a TypeScript upgrade a few months ago, where Facets wasn't able to compile, possibly due to tsc.js no longer adding .js to ES6 imports. The solution was to set module resolution to NODE in the Closure Compiler. The Polymer dep was upstreamed for more completeness for Facets. This change also ensures that the development web server, when we `bazel run` a `tf_web_library` or `tensorboard_html_binary` rule, will display sources in the correct order we had originally, before Bazel changed from set() to depset().
1 parent 16029cb commit 46a0b7d

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed

WORKSPACE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ workspace(name = "org_tensorflow_tensorboard")
22

33
http_archive(
44
name = "io_bazel_rules_closure",
5-
sha256 = "6691c58a2cd30a86776dd9bb34898b041e37136f2dc7e24cadaeaf599c95c657",
6-
strip_prefix = "rules_closure-08039ba8ca59f64248bb3b6ae016460fe9c9914f",
5+
sha256 = "7fb23196455e26d83559cf8a2afa13f720d512f10215228186badfe6d6ad1b18",
6+
strip_prefix = "rules_closure-0.6.0",
77
urls = [
8-
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/08039ba8ca59f64248bb3b6ae016460fe9c9914f.tar.gz",
9-
"https://github.com/bazelbuild/rules_closure/archive/08039ba8ca59f64248bb3b6ae016460fe9c9914f.tar.gz", # 2018-01-16
8+
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/0.6.0.tar.gz",
9+
"https://github.com/bazelbuild/rules_closure/archive/0.6.0.tar.gz",
1010
],
1111
)
1212

tensorboard/defs/vulcanize.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ load("//tensorboard/defs:web.bzl", "web_aspect")
1818

1919
def _tensorboard_html_binary(ctx):
2020
deps = unfurl(ctx.attr.deps, provider="webfiles")
21-
manifests = depset(order="topological")
21+
manifests = depset(order="postorder")
2222
files = depset()
2323
webpaths = depset()
2424
for dep in deps:

tensorboard/defs/web.bzl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,22 @@ def _tf_web_library(ctx):
187187
web_srcs.append(dummy)
188188

189189
# define development web server that only applies to this transitive closure
190+
if ctx.attr.srcs:
191+
devserver_manifests = manifests
192+
export_deps = []
193+
else:
194+
# If a rule exists purely to export other build rules, then it's
195+
# appropriate for the exported sources to be included in the
196+
# development web server.
197+
devserver_manifests = depset(order="postorder")
198+
export_deps = unfurl(ctx.attr.exports, provider="webfiles")
199+
for dep in export_deps:
200+
devserver_manifests += dep.webfiles.manifests
201+
devserver_manifests = manifests + devserver_manifests
190202
params = struct(
191203
label=str(ctx.label),
192204
bind="[::]:6006",
193-
manifest=[long_path(ctx, man) for man in manifests],
205+
manifest=[long_path(ctx, man) for man in devserver_manifests],
194206
external_asset=[struct(webpath=k, path=v)
195207
for k, v in ctx.attr.external_assets.items()])
196208
params_file = _new_file(ctx, "-params.pbtxt")
@@ -235,6 +247,7 @@ def _tf_web_library(ctx):
235247
dummy],
236248
transitive_files=(collect_runfiles([ctx.attr._WebfilesServer]) |
237249
collect_runfiles(deps) |
250+
collect_runfiles(export_deps) |
238251
collect_runfiles(ctx.attr.data) |
239252
aspect_runfiles)))
240253

@@ -284,7 +297,7 @@ def _make_manifest(ctx, src_list):
284297

285298
def _run_webfiles_validator(ctx, srcs, deps, manifest):
286299
dummy = _new_file(ctx, "-webfiles.ignoreme")
287-
manifests = depset(order="topological")
300+
manifests = depset(order="postorder")
288301
for dep in deps:
289302
manifests += dep.webfiles.manifests
290303
if srcs:
@@ -376,7 +389,7 @@ def _get_strip(ctx):
376389

377390
web_aspect = aspect(
378391
implementation=_web_aspect_impl,
379-
attr_aspects=["deps", "sticky_deps", "module_deps"],
392+
attr_aspects=["deps", "sticky_deps", "module_deps", "exports"],
380393
attrs={"_ClosureWorkerAspect": _CLOSURE_WORKER})
381394

382395
tf_web_library = rule(
@@ -418,4 +431,3 @@ tf_web_library = rule(
418431
"_closure_library_deps": CLOSURE_LIBRARY_DEPS_ATTR,
419432
}.items()),
420433
outputs=CLUTZ_OUTPUTS)
421-

tensorboard/defs/zipper.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ load("@io_bazel_rules_closure//closure/private:defs.bzl", "unfurl", "long_path")
1616

1717
def _tensorboard_zip_file(ctx):
1818
deps = unfurl(ctx.attr.deps, provider="webfiles")
19-
manifests = depset(order="topological")
19+
manifests = depset(order="postorder")
2020
files = depset()
2121
webpaths = depset()
2222
for dep in deps:

tensorboard/java/org/tensorflow/tensorboard/vulcanize/Vulcanize.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.google.javascript.jscomp.Result;
4545
import com.google.javascript.jscomp.SourceFile;
4646
import com.google.javascript.jscomp.WarningsGuard;
47+
import com.google.javascript.jscomp.deps.ModuleLoader;
4748
import com.google.protobuf.TextFormat;
4849
import io.bazel.rules.closure.Webpath;
4950
import io.bazel.rules.closure.webfiles.BuildInfo.Webfiles;
@@ -414,6 +415,7 @@ private static void compile() {
414415

415416
CompilerOptions options = new CompilerOptions();
416417
compilationLevel.setOptionsForCompilationLevel(options);
418+
options.setModuleResolutionMode(ModuleLoader.ResolutionMode.NODE);
417419

418420
// Nice options.
419421
options.setColorizeErrorOutput(true);

third_party/polymer.bzl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,23 @@ def tensorboard_polymer_workspace():
578578
],
579579
)
580580

581+
web_library_external(
582+
name = "org_polymer_iron_validator_behavior",
583+
srcs = ["iron-validator-behavior.html"],
584+
licenses = ["notice"], # BSD-3-Clause
585+
path = "/iron-validator-behavior",
586+
sha256 = "0956488f849c0528d66d5ce28bbfb66e163a7990df2cc5f157a5bf34dcb7dfd2",
587+
strip_prefix = "iron-validator-behavior-1.0.2",
588+
urls = [
589+
"http://mirror.bazel.build/github.com/PolymerElements/iron-validator-behavior/archive/v1.0.2.tar.gz",
590+
"https://github.com/PolymerElements/iron-validator-behavior/archive/v1.0.2.tar.gz",
591+
],
592+
deps = [
593+
"@org_polymer",
594+
"@org_polymer_iron_meta",
595+
],
596+
)
597+
581598
web_library_external(
582599
name = "org_polymer_marked",
583600
licenses = ["notice"], # MIT

0 commit comments

Comments
 (0)