Skip to content

Commit dea93c4

Browse files
authored
Add fine-grained Closure Library build rules (#269)
This change introduced a fine-grained build graph for the Closure Library. This is most useful when the Closure Compiler isn't being used. For example, it's now possible to depend on `@io_bazel_rules_closure//closure/library/object` which is 11mB smaller (in terms of naïvely concatenated JavaScript sources) than getting the same API from `@io_bazel_rules_closure//closure/library`. The latency of tools like Clutz should also be improved. The following additional changes needed to be made: - `deps.js` no longer needs to be an implicit dependency thanks to `transitionalforwarddeclarations.js`. - A `lenient` attribute is now available for `closure_js_library` which makes the compiler more easy-going. - `goog.labs`, `goog.ui`, and third party APIs may no longer be exported from `//closure/library` and `//closure/library:testing` by default.
1 parent 6403db4 commit dea93c4

131 files changed

Lines changed: 13768 additions & 1232 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

closure/compiler/closure_js_binary.bzl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
load("//closure/private:defs.bzl",
1818
"CLOSURE_WORKER_ATTR",
1919
"CLOSURE_LIBRARY_BASE_ATTR",
20-
"CLOSURE_LIBRARY_DEPS_ATTR",
2120
"JS_LANGUAGES",
2221
"JS_LANGUAGE_IN",
2322
"JS_LANGUAGE_OUT_DEFAULT",
@@ -43,8 +42,7 @@ def _impl(ctx):
4342
ctx.attr.language, ", ".join(JS_LANGUAGES)))
4443

4544
deps = unfurl(ctx.attr.deps, provider="closure_js_library")
46-
js = collect_js(deps, ctx.file._closure_library_base,
47-
ctx.file._closure_library_deps, css=ctx.attr.css)
45+
js = collect_js(deps, ctx.files._closure_library_base, css=ctx.attr.css)
4846
if not js.srcs:
4947
fail("There are no JS source files in the transitive closure")
5048

@@ -272,7 +270,6 @@ closure_js_binary = rule(
272270
"internal_expect_warnings": attr.bool(default=False),
273271
"_ClosureWorker": CLOSURE_WORKER_ATTR,
274272
"_closure_library_base": CLOSURE_LIBRARY_BASE_ATTR,
275-
"_closure_library_deps": CLOSURE_LIBRARY_DEPS_ATTR,
276273
},
277274
outputs={
278275
"bin": "%{name}.js",

closure/compiler/closure_js_deps.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ load("//closure/private:defs.bzl",
2424
def _impl(ctx):
2525
deps = unfurl(ctx.attr.deps, provider="closure_js_library")
2626
js = collect_js(deps)
27-
closure_root = _dirname(long_path(ctx, ctx.file._closure_library_base))
27+
closure_root = _dirname(long_path(ctx, ctx.files._closure_library_base[0]))
2828
closure_rel = '/'.join(['..' for _ in range(len(closure_root.split('/')))])
2929
outputs = [ctx.outputs.out]
3030
# XXX: Other files in same directory will get schlepped in w/o sandboxing.
@@ -44,7 +44,7 @@ def _impl(ctx):
4444
files=depset(outputs),
4545
runfiles=ctx.runfiles(
4646
files=outputs + ctx.files.data,
47-
transitive_files=(depset([ctx.file._closure_library_base]) |
47+
transitive_files=(depset(ctx.files._closure_library_base) |
4848
collect_runfiles(deps) |
4949
collect_runfiles(ctx.attr.data))))
5050

closure/compiler/closure_js_library.bzl

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
load("//closure/private:defs.bzl",
1818
"CLOSURE_WORKER_ATTR",
1919
"CLOSURE_LIBRARY_BASE_ATTR",
20-
"CLOSURE_LIBRARY_DEPS_ATTR",
2120
"JS_FILE_TYPE",
2221
"JS_LANGUAGE_IN",
2322
"library_level_checks",
@@ -41,8 +40,8 @@ def _maybe_declare_file(actions, file, name):
4140
def closure_js_library_impl(
4241
actions, label, workspace_name,
4342

44-
srcs, deps, testonly, suppress,
45-
closure_library_base, closure_library_deps, _ClosureWorker,
43+
srcs, deps, testonly, suppress, lenient,
44+
closure_library_base, _ClosureWorker,
4645

4746
includes=(),
4847
exports=depset(),
@@ -60,6 +59,20 @@ def closure_js_library_impl(
6059
# TODO(yannic): Figure out how to modify |find_js_module_roots|
6160
# so that we won't need |workspace_name| anymore.
6261

62+
if lenient:
63+
suppress = suppress + [
64+
"analyzerChecks",
65+
"analyzerChecksInternal",
66+
"deprecated",
67+
"legacyGoogScopeRequire",
68+
"lintChecks",
69+
"missingOverride",
70+
"reportUnknownTypes",
71+
"strictCheckTypes",
72+
"superfluousSuppress",
73+
"unnecessaryEscape",
74+
]
75+
6376
# TODO(yannic): Always use |actions.declare_file()|.
6477
info_file = _maybe_declare_file(
6578
actions, deprecated_info_file, '%s.pbtxt' % label.name)
@@ -74,8 +87,7 @@ def closure_js_library_impl(
7487

7588
# Collect all the transitive stuff the child rules have propagated. Bazel has
7689
# a special nested set data structure that makes this efficient.
77-
js = collect_js(deps, closure_library_base, closure_library_deps,
78-
bool(srcs), no_closure_library)
90+
js = collect_js(deps, closure_library_base, bool(srcs), no_closure_library)
7991

8092
# If closure_js_library depends on closure_css_library, that means
8193
# goog.getCssName() is being used in srcs to reference CSS names in the
@@ -176,7 +188,7 @@ def closure_js_library_impl(
176188
# The list of flags could potentially be very long. So we're going to write
177189
# them all to a file which gets loaded automatically by our BazelWorker
178190
# middleware.
179-
argfile = create_argfile(actions, label.name, args)
191+
argfile = create_argfile(actions, label.name, args)
180192
inputs.append(argfile)
181193

182194
# Add a JsChecker edge to the build graph. The command itself will only be
@@ -199,6 +211,7 @@ def closure_js_library_impl(
199211
output=_maybe_declare_file(
200212
actions, deprecated_typecheck_file, '%s_typecheck' % label.name),
201213
suppress=suppress,
214+
lenient=lenient,
202215
)
203216

204217
# We now export providers to any parent Target. This is considered a public
@@ -274,6 +287,8 @@ def _closure_js_library(ctx):
274287
fail("Either 'srcs' or 'exports' must be specified")
275288
if not ctx.files.srcs and ctx.attr.deps:
276289
fail("'srcs' must be set when using 'deps', otherwise consider 'exports'")
290+
if not ctx.files.srcs and (ctx.attr.suppress or ctx.attr.lenient):
291+
fail("'srcs' must be set when using 'suppress' or 'lenient'")
277292
if ctx.attr.language:
278293
print("The closure_js_library 'language' attribute is now removed and " +
279294
"is always set to " + JS_LANGUAGE_IN)
@@ -287,9 +302,9 @@ def _closure_js_library(ctx):
287302
library = closure_js_library_impl(
288303
ctx.actions, ctx.label, ctx.workspace_name,
289304
srcs, ctx.attr.deps, ctx.attr.testonly, ctx.attr.suppress,
305+
ctx.attr.lenient,
290306

291-
ctx.file._closure_library_base,
292-
ctx.file._closure_library_deps,
307+
ctx.files._closure_library_base,
293308
ctx.executable._ClosureWorker,
294309

295310
getattr(ctx.attr, "includes", []),
@@ -311,8 +326,7 @@ def _closure_js_library(ctx):
311326
runfiles=ctx.runfiles(
312327
files=srcs + ctx.files.data,
313328
transitive_files=(depset([] if ctx.attr.no_closure_library
314-
else [ctx.file._closure_library_base,
315-
ctx.file._closure_library_deps]) |
329+
else ctx.files._closure_library_base) |
316330
collect_runfiles(
317331
unfurl(ctx.attr.deps,
318332
provider="closure_js_library")) |
@@ -337,6 +351,7 @@ closure_js_library = rule(
337351
"no_closure_library": attr.bool(),
338352
"srcs": attr.label_list(allow_files=JS_FILE_TYPE),
339353
"suppress": attr.string_list(),
354+
"lenient": attr.bool(),
340355

341356
# deprecated
342357
"externs": attr.label_list(allow_files=JS_FILE_TYPE),
@@ -347,7 +362,6 @@ closure_js_library = rule(
347362
"internal_expect_failure": attr.bool(default=False),
348363
"_ClosureWorker": CLOSURE_WORKER_ATTR,
349364
"_closure_library_base": CLOSURE_LIBRARY_BASE_ATTR,
350-
"_closure_library_deps": CLOSURE_LIBRARY_DEPS_ATTR,
351365
},
352366
# TODO(yannic): Deprecate.
353367
# https://docs.bazel.build/versions/master/skylark/lib/globals.html#rule.outputs

closure/compiler/test/closure_js_deps/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ file_test(
6262
closure_js_library(
6363
name = "goblin",
6464
srcs = ["goblin.js"],
65-
deps = ["//closure/library"],
65+
deps = ["//closure/library/dom"],
6666
)
6767

6868
closure_js_deps(

0 commit comments

Comments
 (0)