Skip to content

Commit 852af8d

Browse files
authored
Remove legacy providers (#6721)
## Motivation for features / changes Legacy struct providers have been deprecated by Bazel. Replacing them with modern providers, will make it possible to simplify and remove legacy handling from Bazel. Prerequiste: bazelbuild/rules_closure#599 is merged and released. Googlers, see cl/597800285.
1 parent 4d55fda commit 852af8d

File tree

8 files changed

+1286
-1280
lines changed

8 files changed

+1286
-1280
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ permissions:
2525
env:
2626
# Keep this Bazel version in sync with the `versions.check` directive
2727
# in our WORKSPACE file.
28-
BAZEL_VERSION: '4.2.2'
29-
BAZEL_SHA256SUM: '11dea6c7cfd866ed520af19a6bb1d952f3e9f4ee60ffe84e63c0825d95cb5859'
28+
BAZEL_VERSION: '6.5.0'
29+
BAZEL_SHA256SUM: 'a40ac69263440761199fcb8da47ad4e3f328cbe79ffbf4ecc14e5ba252857307'
3030
BUILDTOOLS_VERSION: '3.0.0'
3131
BUILDIFIER_SHA256SUM: 'e92a6793c7134c5431c58fbc34700664f101e5c9b1c1fcd93b97978e8b7f88db'
3232
BUILDOZER_SHA256SUM: '3d58a0b6972e4535718cdd6c12778170ea7382de7c75bc3728f5719437ffb84d'

WORKSPACE

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ versions.check(
2121
maximum_bazel_version = "6.999.0",
2222
# Keep this version in sync with:
2323
# * The BAZEL environment variable defined in .github/workflows/ci.yml, which is used for CI and nightly builds.
24-
minimum_bazel_version = "4.2.2",
24+
minimum_bazel_version = "6.5.0",
2525
)
2626

2727
http_archive(
2828
name = "io_bazel_rules_webtesting",
29-
sha256 = "e9abb7658b6a129740c0b3ef6f5a2370864e102a5ba5ffca2cea565829ed825a",
30-
urls = [
31-
"http://mirror.tensorflow.org/github.com/bazelbuild/rules_webtesting/releases/download/0.3.5/rules_webtesting.tar.gz",
32-
"https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.5/rules_webtesting.tar.gz",
33-
],
29+
sha256 = "6e104e54c283c94ae3d5c6573cf3233ce478e89e0f541a869057521966a35b8f",
30+
strip_prefix = "rules_webtesting-b6fc79c5a37cd18a5433fd080c9d2cc59548222c",
31+
urls = ["https://github.com/bazelbuild/rules_webtesting/archive/b6fc79c5a37cd18a5433fd080c9d2cc59548222c.tar.gz"],
3432
)
3533

3634
load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")
@@ -55,11 +53,10 @@ py_repositories()
5553

5654
http_archive(
5755
name = "io_bazel_rules_closure",
58-
sha256 = "6a900831c1eb8dbfc9d6879b5820fd614d4ea1db180eb5ff8aedcb75ee747c1f",
59-
strip_prefix = "rules_closure-db4683a2a1836ac8e265804ca5fa31852395185b",
56+
sha256 = "ae060075a7c468eee42e6a08ddbb83f5a6663bdfdbd461261a465f4a3ae8598c",
57+
strip_prefix = "rules_closure-7f3d3351a8cc31fbaa403de7d35578683c17b447",
6058
urls = [
61-
"http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/db4683a2a1836ac8e265804ca5fa31852395185b.tar.gz",
62-
"https://github.com/bazelbuild/rules_closure/archive/db4683a2a1836ac8e265804ca5fa31852395185b.tar.gz", # 2020-01-15
59+
"https://github.com/bazelbuild/rules_closure/archive/7f3d3351a8cc31fbaa403de7d35578683c17b447.tar.gz", # 2024-03-11
6360
],
6461
)
6562

@@ -191,6 +188,11 @@ http_archive(
191188
],
192189
)
193190

191+
# WORKAROUND for rules_webtesting not declaring used com_github_gorilla_mux repo:
192+
load("@io_bazel_rules_webtesting//web:go_repositories.bzl", "com_github_gorilla_mux")
193+
194+
com_github_gorilla_mux()
195+
194196
# Please add all new dependencies in workspace.bzl.
195197
load("//third_party:workspace.bzl", "tensorboard_workspace")
196198

tensorboard/defs/defs.bzl

+23-22
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite", "ts_library")
2222
load("@npm//@bazel/esbuild:index.bzl", "esbuild")
2323
load("@npm//@bazel/typescript:index.bzl", "ts_config")
2424

25-
2625
def tensorboard_webcomponent_library(**kwargs):
2726
"""Rules referencing this will be deleted from the codebase soon."""
2827
pass
@@ -72,8 +71,8 @@ def tf_js_binary(
7271
# the global level and tends to overwrite `window` functions. "iife" is
7372
# just a thin wrapper around "esm" (it adds 11 bytes) and doesn't
7473
# suffer from the same overwriting problem.
75-
format="iife",
76-
minify= False if dev_mode_only else True,
74+
format = "iife",
75+
minify = False if dev_mode_only else True,
7776
args = {
7877
# Must specify that 'mjs' extensions are preferred, since that is
7978
# the extension that is used for es2015/esm code generated by
@@ -91,7 +90,6 @@ def tf_js_binary(
9190
**kwargs
9291
)
9392

94-
9593
def tf_ng_prod_js_binary(
9694
name,
9795
compile,
@@ -114,7 +112,7 @@ def tf_ng_prod_js_binary(
114112
https://esbuild.github.io/api/ for more details.
115113
"""
116114

117-
app_bundle_name = '%s_app_bundle' % name
115+
app_bundle_name = "%s_app_bundle" % name
118116
app_bundle(
119117
name = app_bundle_name,
120118
**kwargs
@@ -124,8 +122,8 @@ def tf_ng_prod_js_binary(
124122
# through a terser pass to be the output of this rule.
125123
copy_file(
126124
name = name,
127-
src = '%s.min.js' % app_bundle_name,
128-
out = '%s.js' % name,
125+
src = "%s.min.js" % app_bundle_name,
126+
out = "%s.js" % name,
129127
)
130128

131129
def tf_ts_config(**kwargs):
@@ -148,22 +146,24 @@ def tf_ts_library(srcs = [], strict_checks = True, **kwargs):
148146
kwargs.setdefault("deps", []).extend(["@npm//tslib", "//tensorboard/defs:strict_types"])
149147

150148
new_srcs = []
149+
151150
# Find test.ts and testbed.ts files and rename to test.spec.ts to be
152151
# compatible with spec_bundle() tooling.
153152
for s in srcs:
154-
if s.endswith("_test.ts") or s.endswith("-test.ts") or s.endswith("_testbed.ts"):
155-
# Make a copy of the file with name .spec.ts and switch to that as
156-
# the src file.
157-
new_src = s[0:s.rindex('.ts')] + ".spec.ts"
158-
copy_file(
159-
name = new_src + '_spec_copy',
160-
src = s,
161-
out = new_src,
162-
allow_symlink = True)
163-
new_srcs.append(new_src)
164-
else:
165-
# Not a test file. Nothing to do here.
166-
new_srcs.append(s)
153+
if s.endswith("_test.ts") or s.endswith("-test.ts") or s.endswith("_testbed.ts"):
154+
# Make a copy of the file with name .spec.ts and switch to that as
155+
# the src file.
156+
new_src = s[0:s.rindex(".ts")] + ".spec.ts"
157+
copy_file(
158+
name = new_src + "_spec_copy",
159+
src = s,
160+
out = new_src,
161+
allow_symlink = True,
162+
)
163+
new_srcs.append(new_src)
164+
else:
165+
# Not a test file. Nothing to do here.
166+
new_srcs.append(s)
167167

168168
ts_library(
169169
srcs = new_srcs,
@@ -176,7 +176,8 @@ def tf_ts_library(srcs = [], strict_checks = True, **kwargs):
176176
prodmode_target = "es2020",
177177
devmode_target = "es2020",
178178
devmode_module = "esnext",
179-
**kwargs)
179+
**kwargs
180+
)
180181

181182
def tf_ng_web_test_suite(name, deps = [], **kwargs):
182183
"""TensorBoard wrapper for the rule for a Karma web test suite.
@@ -231,7 +232,7 @@ def tf_ng_web_test_suite(name, deps = [], **kwargs):
231232
# karma_web_test_suite() will rebundle it along with the test framework
232233
# in a CommonJS bundle.
233234
deps = [
234-
"%s_bundle" % name,
235+
"%s_bundle" % name,
235236
],
236237
)
237238

tensorboard/defs/hacks.bzl

+61-60
Original file line numberDiff line numberDiff line change
@@ -16,65 +16,66 @@
1616
# TODO(@jart): Merge this file into defs.bzl once that file is sync unified.
1717

1818
def tensorboard_typescript_bundle(
19-
name,
20-
out,
21-
namespace_srcs,
22-
namespace_symbol_aliases={},
23-
namespace_symbol_aliases_public={},
24-
):
25-
"""Rolls TypeScript ES6 modules into one vanilla source file without imports.
19+
name,
20+
out,
21+
namespace_srcs,
22+
namespace_symbol_aliases = {},
23+
namespace_symbol_aliases_public = {}):
24+
"""Rolls TypeScript ES6 modules into one vanilla source file without imports.
2625
27-
This is a genrule wrapper that concatenates TypeScripts sources inside
28-
namespace blocks while removing ^import lines. Because the sources themselves
29-
are not parsed, the structure of the modules must be passed to this macro as
30-
a Skylark data structure.
26+
This is a genrule wrapper that concatenates TypeScripts sources inside
27+
namespace blocks while removing ^import lines. Because the sources themselves
28+
are not parsed, the structure of the modules must be passed to this macro as
29+
a Skylark data structure.
3130
32-
Args:
33-
name: Name of this build rule target.
34-
out: Path of outputted TypeScript source file.
35-
namespace_srcs: Multimap of namespace strings to build file targets. The
36-
ordering of the dictionary and nested lists does not matter when
37-
generating a typings file, but *does* matter when generating a source
38-
file.
39-
namespace_symbol_aliases: Map of namespace strings where each value is a
40-
map of symbol names to fully qualified symbol names.
41-
namespace_symbol_aliases_public: Same as namespace_symbol_aliases but the
42-
symbol will be visible to other namespaces.
43-
"""
44-
cmd = ["(", "echo // GENERATED BY TENSORBOARD_TYPESCRIPT_BUNDLE"]
45-
inputs_depsets = []
46-
for namespace, srcs in namespace_srcs.items():
47-
cmd.append("echo")
48-
if out[-5:] == ".d.ts":
49-
cmd.append("echo 'declare namespace %s {'" % namespace)
50-
elif out[-3:] == ".ts":
51-
cmd.append("echo 'module %s {'" % namespace)
52-
else:
53-
fail("'out' must end with .ts or .d.ts: " + out)
54-
for symbol, canon in namespace_symbol_aliases.get(namespace, {}).items():
55-
cmd.append("echo 'import %s = %s;'" % (symbol, canon))
56-
for symbol, canon in namespace_symbol_aliases_public.get(namespace,
57-
{}).items():
58-
cmd.append("echo 'export import %s = %s;'" % (symbol, canon))
59-
inputs_depsets.append(depset(srcs))
60-
for src in srcs:
61-
cmd.append("for f in $(locations %s); do" % src)
62-
cmd.append(" echo")
63-
cmd.append(" echo /////////////////////////////////////////////////////")
64-
cmd.append(" echo // " + namespace)
65-
cmd.append(" echo // $$f")
66-
cmd.append(" echo /////////////////////////////////////////////////////")
67-
cmd.append(" echo")
68-
cmd.append(" sed 's!^import !// import !' $$f \\")
69-
cmd.append(" | sed 's!^export declare !export !' \\")
70-
cmd.append(" | sed '/^export .* from /d' \\")
71-
cmd.append(" | sed '/^export {.*};$$/d'")
72-
cmd.append("done")
73-
cmd.append("echo '}'")
74-
cmd.append(") >$@")
75-
native.genrule(
76-
name = name,
77-
srcs = depset(transitive=inputs_depsets).to_list(),
78-
outs = [out],
79-
cmd = "\n".join(cmd),
80-
)
31+
Args:
32+
name: Name of this build rule target.
33+
out: Path of outputted TypeScript source file.
34+
namespace_srcs: Multimap of namespace strings to build file targets. The
35+
ordering of the dictionary and nested lists does not matter when
36+
generating a typings file, but *does* matter when generating a source
37+
file.
38+
namespace_symbol_aliases: Map of namespace strings where each value is a
39+
map of symbol names to fully qualified symbol names.
40+
namespace_symbol_aliases_public: Same as namespace_symbol_aliases but the
41+
symbol will be visible to other namespaces.
42+
"""
43+
cmd = ["(", "echo // GENERATED BY TENSORBOARD_TYPESCRIPT_BUNDLE"]
44+
inputs_depsets = []
45+
for namespace, srcs in namespace_srcs.items():
46+
cmd.append("echo")
47+
if out[-5:] == ".d.ts":
48+
cmd.append("echo 'declare namespace %s {'" % namespace)
49+
elif out[-3:] == ".ts":
50+
cmd.append("echo 'module %s {'" % namespace)
51+
else:
52+
fail("'out' must end with .ts or .d.ts: " + out)
53+
for symbol, canon in namespace_symbol_aliases.get(namespace, {}).items():
54+
cmd.append("echo 'import %s = %s;'" % (symbol, canon))
55+
for symbol, canon in namespace_symbol_aliases_public.get(
56+
namespace,
57+
{},
58+
).items():
59+
cmd.append("echo 'export import %s = %s;'" % (symbol, canon))
60+
inputs_depsets.append(depset(srcs))
61+
for src in srcs:
62+
cmd.append("for f in $(locations %s); do" % src)
63+
cmd.append(" echo")
64+
cmd.append(" echo /////////////////////////////////////////////////////")
65+
cmd.append(" echo // " + namespace)
66+
cmd.append(" echo // $$f")
67+
cmd.append(" echo /////////////////////////////////////////////////////")
68+
cmd.append(" echo")
69+
cmd.append(" sed 's!^import !// import !' $$f \\")
70+
cmd.append(" | sed 's!^export declare !export !' \\")
71+
cmd.append(" | sed '/^export .* from /d' \\")
72+
cmd.append(" | sed '/^export {.*};$$/d'")
73+
cmd.append("done")
74+
cmd.append("echo '}'")
75+
cmd.append(") >$@")
76+
native.genrule(
77+
name = name,
78+
srcs = depset(transitive = inputs_depsets).to_list(),
79+
outs = [out],
80+
cmd = "\n".join(cmd),
81+
)

tensorboard/defs/internal/html.bzl

+20-31
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Rule for building the HTML binary."""
1616

1717
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_aspect")
18-
load("@io_bazel_rules_closure//closure/private:defs.bzl", "collect_js", "long_path", "unfurl") # buildifier: disable=bzl-visibility
18+
load("@io_bazel_rules_closure//closure/private:defs.bzl", "WebFilesInfo", "collect_runfiles", "extract_providers", "long_path", "unfurl") # buildifier: disable=bzl-visibility
1919

2020
def _tb_combine_html_impl(ctx):
2121
"""Compiles HTMLs into one HTML.
@@ -25,18 +25,12 @@ def _tb_combine_html_impl(ctx):
2525
JavaScript file when `js_path` is specified.
2626
"""
2727

28-
deps = unfurl(ctx.attr.deps, provider = "webfiles")
29-
manifests = depset(order = "postorder")
30-
files = depset()
31-
webpaths = depset()
32-
for dep in deps:
33-
manifests = depset(transitive = [manifests, dep.webfiles.manifests])
34-
webpaths = depset(transitive = [webpaths, dep.webfiles.webpaths])
35-
files = depset(transitive = [files, dep.data_runfiles.files])
28+
deps = extract_providers(ctx.attr.deps, provider = WebFilesInfo)
29+
deps = unfurl(deps)
30+
manifests = depset(order = "postorder", transitive = [dep.manifests for dep in deps])
31+
webpaths = depset(transitive = [dep.webpaths for dep in deps])
32+
files = depset(transitive = [dep[DefaultInfo].data_runfiles.files for dep in ctx.attr.deps])
3633
webpaths = depset([ctx.attr.output_path], transitive = [webpaths])
37-
closure_js_library = collect_js(
38-
unfurl(ctx.attr.deps, provider = "closure_js_library"),
39-
)
4034

4135
# vulcanize
4236
ctx.actions.run(
@@ -84,30 +78,25 @@ def _tb_combine_html_impl(ctx):
8478
)
8579
manifests = depset([manifest], transitive = [manifests])
8680

87-
transitive_runfiles = depset()
88-
for dep in deps:
89-
transitive_runfiles = depset(transitive = [
90-
transitive_runfiles,
91-
dep.data_runfiles.files,
92-
])
93-
94-
return struct(
95-
files = depset([ctx.outputs.html, ctx.outputs.js]),
96-
webfiles = struct(
81+
return [
82+
DefaultInfo(
83+
files = depset([ctx.outputs.html, ctx.outputs.js]),
84+
runfiles = collect_runfiles(
85+
ctx,
86+
files = ctx.files.data + [
87+
manifest,
88+
ctx.outputs.html,
89+
ctx.outputs.js,
90+
],
91+
),
92+
),
93+
WebFilesInfo(
9794
manifest = manifest,
9895
manifests = manifests,
9996
webpaths = webpaths,
10097
dummy = ctx.outputs.html,
10198
),
102-
runfiles = ctx.runfiles(
103-
files = ctx.files.data + [
104-
manifest,
105-
ctx.outputs.html,
106-
ctx.outputs.js,
107-
],
108-
transitive_files = transitive_runfiles,
109-
),
110-
)
99+
]
111100

112101
tb_combine_html = rule(
113102
implementation = _tb_combine_html_impl,

0 commit comments

Comments
 (0)