Skip to content

Commit d033418

Browse files
committed
Running buildifier on all bzl files
1 parent d1ab6e7 commit d033418

File tree

5 files changed

+1270
-1236
lines changed

5 files changed

+1270
-1236
lines changed

tensorboard/defs/defs.bzl

Lines changed: 24 additions & 23 deletions
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

@@ -256,7 +257,7 @@ def tf_sass_binary(deps = [], include_paths = [], strict_deps = True, **kwargs):
256257
internally.
257258
"""
258259
if (strict_deps):
259-
fail("all tf_sass_binary calls need to have the strict_deps = False override for internal calls");
260+
fail("all tf_sass_binary calls need to have the strict_deps = False override for internal calls")
260261
sass_binary(
261262
deps = deps,
262263
include_paths = include_paths + [

tensorboard/defs/hacks.bzl

Lines changed: 61 additions & 60 deletions
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+
)

0 commit comments

Comments
 (0)