Skip to content

Commit

Permalink
Following rules_closure changes to providers
Browse files Browse the repository at this point in the history
  • Loading branch information
comius committed Mar 13, 2024
1 parent 6b3d9e8 commit a08add7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 45 deletions.
22 changes: 8 additions & 14 deletions tensorboard/defs/internal/html.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""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", "WebFilesInfo", "long_path", "unfurl") # buildifier: disable=bzl-visibility
load("@io_bazel_rules_closure//closure/private:defs.bzl", "WebFilesInfo", "collect_runfiles", "extract_providers", "long_path", "unfurl") # buildifier: disable=bzl-visibility

def _tb_combine_html_impl(ctx):
"""Compiles HTMLs into one HTML.
Expand All @@ -25,10 +25,11 @@ def _tb_combine_html_impl(ctx):
JavaScript file when `js_path` is specified.
"""

deps = unfurl(ctx.attr.deps, provider = WebFilesInfo).exports
manifests = depset(order = "postorder", transitive = [dep[WebFilesInfo].manifests for dep in deps])
webpaths = depset(transitive = [dep[WebFilesInfo].webpaths for dep in deps])
files = depset(transitive = [dep.data_runfiles.files for dep in deps])
deps = extract_providers(ctx.attr.deps, provider = WebFilesInfo)
deps = unfurl(deps)
manifests = depset(order = "postorder", transitive = [dep.manifests for dep in deps])
webpaths = depset(transitive = [dep.webpaths for dep in deps])
files = depset(transitive = [dep[DefaultInfo].data_runfiles.files for dep in ctx.attr.deps])
webpaths = depset([ctx.attr.output_path], transitive = [webpaths])

# vulcanize
Expand Down Expand Up @@ -77,23 +78,16 @@ def _tb_combine_html_impl(ctx):
)
manifests = depset([manifest], transitive = [manifests])

transitive_runfiles = depset()
for dep in deps:
transitive_runfiles = depset(transitive = [
transitive_runfiles,
dep.data_runfiles.files,
])

return [
DefaultInfo(
files = depset([ctx.outputs.html, ctx.outputs.js]),
runfiles = ctx.runfiles(
runfiles = collect_runfiles(
ctx,
files = ctx.files.data + [
manifest,
ctx.outputs.html,
ctx.outputs.js,
],
transitive_files = transitive_runfiles,
),
),
WebFilesInfo(
Expand Down
32 changes: 14 additions & 18 deletions tensorboard/defs/web.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ load(
"collect_js",
"collect_runfiles",
"difference",
"extract_providers",
"long_path",
"unfurl",
)
Expand All @@ -51,8 +52,8 @@ def _tf_web_library(ctx):
fail("when \"*\" is suppressed no other items should be present")

# process what came before
deps = unfurl(ctx.attr.deps, provider = WebFilesInfo).exports
webpaths = depset(transitive = [dep[WebFilesInfo].webpaths for dep in deps])
deps = extract_providers(ctx.attr.deps, provider = WebFilesInfo)
webpaths = depset(transitive = [dep.webpaths for dep in deps])

# process what comes now
manifest_srcs = []
Expand Down Expand Up @@ -93,7 +94,7 @@ def _tf_web_library(ctx):
# If a rule exists purely to export other build rules, then it's
# appropriate for the exported sources to be included in the
# development web server.
export_deps = unfurl(ctx.attr.exports).exports
export_deps = unfurl(extract_providers(ctx.attr.exports))
devserver_manifests = depset(
order = "postorder",
transitive = (
Expand Down Expand Up @@ -150,15 +151,16 @@ def _tf_web_library(ctx):
manifests = manifests,
webpaths = webpaths,
dummy = dummy,
exports = export_deps,
),
unfurl(ctx.attr.exports),
collect_js(
unfurl(ctx.attr.deps, provider = ClosureJsLibraryInfo).exports,
unfurl(deps),
ctx.files._closure_library_base,
),
DefaultInfo(
files = depset(web_srcs + [dummy]),
runfiles = ctx.runfiles(
runfiles = collect_runfiles(
ctx,
files = (ctx.files.srcs +
ctx.files.data +
ctx.files._closure_library_base + [
Expand All @@ -167,12 +169,7 @@ def _tf_web_library(ctx):
ctx.outputs.executable,
dummy,
]),
transitive_files = depset(transitive = [
collect_runfiles([ctx.attr._WebfilesServer]),
collect_runfiles(deps),
collect_runfiles(export_deps),
collect_runfiles(ctx.attr.data),
]),
extra_runfiles_attrs = ["export_deps", "_WebfilesServer"],
),
),
]
Expand All @@ -190,7 +187,7 @@ def _make_manifest(ctx, src_list):

def _run_webfiles_validator(ctx, srcs, deps, manifest):
dummy = _new_file(ctx, "-webfiles.ignoreme")
manifests = depset(order = "postorder", transitive = [dep[WebFilesInfo].manifests for dep in deps])
manifests = depset(order = "postorder", transitive = [dep.manifests for dep in deps])
if srcs:
args = [
"WebfilesValidator",
Expand All @@ -205,13 +202,12 @@ def _run_webfiles_validator(ctx, srcs, deps, manifest):
args.append(category)
inputs = [] # list of depsets
inputs.append(depset([manifest] + srcs))
direct_manifests = depset([dep[WebFilesInfo].manifest for dep in deps])
direct_manifests = depset([dep.manifest for dep in deps])
for dep in deps:
inputs.append(depset([dep[WebFilesInfo].dummy]))
inputs.append(dep.files)
inputs.append(depset([dep[WebFilesInfo].manifest]))
inputs.append(depset([dep.dummy]))
inputs.append(depset([dep.manifest]))
args.append("--direct_dep")
args.append(dep[WebFilesInfo].manifest.path)
args.append(dep.manifest.path)
for man in difference(manifests, direct_manifests):
inputs.append(depset([man]))
args.append("--transitive_dep")
Expand Down
21 changes: 8 additions & 13 deletions tensorboard/defs/zipper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

"""Rule for zipping Webfiles."""

load("@io_bazel_rules_closure//closure/private:defs.bzl", "unfurl")
load("@io_bazel_rules_closure//closure/private:defs.bzl", "WebFilesInfo", "collect_runfiles", "extract_providers", "unfurl")

def _tensorboard_zip_file(ctx):
deps = unfurl(ctx.attr.deps, provider = WebFilesInfo).exports
manifests = depset(order = "postorder", transitive = [dep[WebFilesInfo].manifests for dep in deps])
webpaths = depset(transitive = [dep[WebFilesInfo].webpaths for dep in deps])
files = depset(transitive = [dep.data_runfiles.files for dep in deps])
deps = extract_providers(ctx.attr.deps, provider = WebFilesInfo)
deps = unfurl(deps)
manifests = depset(order = "postorder", transitive = [dep.manifests for dep in deps])
webpaths = depset(transitive = [dep.webpaths for dep in deps])
files = depset(transitive = [dep[DefaultInfo].data_runfiles.files for dep in ctx.attr.deps])
ctx.actions.run(
mnemonic = "Zipper",
inputs = depset(transitive = [manifests, files]).to_list(),
Expand All @@ -30,17 +31,11 @@ def _tensorboard_zip_file(ctx):
[m.path for m in manifests.to_list()]),
progress_message = "Zipping %d files" % len(webpaths.to_list()),
)
transitive_runfiles = depset()
for dep in deps:
transitive_runfiles = depset(transitive = [
transitive_runfiles,
dep.data_runfiles.files,
])
return DefaultInfo(
files = depset([ctx.outputs.zip]),
runfiles = ctx.runfiles(
runfiles = collect_runfiles(
ctx,
files = ctx.files.data + [ctx.outputs.zip],
transitive_files = transitive_runfiles,
),
)

Expand Down

0 comments on commit a08add7

Please sign in to comment.