Skip to content

Commit

Permalink
Cleanup more unfurl usages (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkdn authored Apr 17, 2024
1 parent 6c55ab8 commit 78563e2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
2 changes: 0 additions & 2 deletions closure/compiler/closure_js_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def _closure_js_library_impl(
includes = (),
exports = depset(),
deps_stylesheets = [],
exports_stylesheets = [],
internal_descriptors = depset(),
no_closure_library = False,
internal_expect_failure = False,
Expand Down Expand Up @@ -396,7 +395,6 @@ def _closure_js_library(ctx):
getattr(ctx.attr, "includes", []),
extract_providers(ctx.attr.exports, ClosureJsLibraryInfo),
extract_providers(ctx.attr.deps, ClosureCssLibraryInfo),
extract_providers(ctx.attr.exports, ClosureCssLibraryInfo),
ctx.files.internal_descriptors,
ctx.attr.no_closure_library,
ctx.attr.internal_expect_failure,
Expand Down
12 changes: 5 additions & 7 deletions closure/private/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_jsfile_path(f):
def extract_providers(deps, provider):
return [dep[provider] for dep in deps if provider in dep]

def unfurl(deps, provider = ""):
def unfurl(deps):
"""Returns deps as well as deps exported by parent rules."""
res = []
for dep in deps:
Expand Down Expand Up @@ -198,14 +198,12 @@ def collect_css(deps, orientation = None):
srcs = []
labels = []
for dep in deps:
if hasattr(dep[ClosureCssLibraryInfo], "srcs"):
srcs.append(getattr(dep[ClosureCssLibraryInfo], "srcs"))
if hasattr(dep[ClosureCssLibraryInfo], "labels"):
labels.append(getattr(dep[ClosureCssLibraryInfo], "labels"))
srcs.append(getattr(dep, "srcs", []))
labels.append(getattr(dep, "labels", []))
if orientation:
if dep[ClosureCssLibraryInfo].orientation != orientation:
if dep.orientation != orientation:
fail("%s does not have the same orientation" % dep.label)
orientation = dep[ClosureCssLibraryInfo].orientation
orientation = dep.orientation
return struct(
srcs = depset(transitive = srcs),
labels = depset(transitive = labels),
Expand Down
3 changes: 2 additions & 1 deletion closure/stylesheets/closure_css_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ load(
"ClosureCssLibraryInfo",
"collect_css",
"collect_runfiles",
"extract_providers",
"unfurl",
)

def _closure_css_binary(ctx):
if not ctx.attr.deps:
fail("closure_css_binary rules can not have an empty 'deps' list")
deps = unfurl(ctx.attr.deps, provider = ClosureCssLibraryInfo)
deps = unfurl(extract_providers(ctx.attr.deps, provider = ClosureCssLibraryInfo))
css = collect_css(deps)
if not css.srcs:
fail("There are no CSS source files in the transitive closure")
Expand Down
6 changes: 4 additions & 2 deletions closure/stylesheets/closure_css_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ load(
"ClosureJsLibraryInfo",
"collect_css",
"collect_runfiles",
"extract_providers",
"unfurl",
)

def _closure_css_library(ctx):
deps = unfurl(ctx.attr.deps, provider = ClosureCssLibraryInfo)
deps = unfurl(extract_providers(ctx.attr.deps, provider = ClosureCssLibraryInfo))
exports = unfurl(extract_providers(ctx.attr.exports, provider = ClosureCssLibraryInfo))
css = collect_css(deps, ctx.attr.orientation)
return [
ClosureCssLibraryInfo(
label = ctx.label,
srcs = depset(ctx.files.srcs, transitive = [css.srcs]),
labels = depset([ctx.label], transitive = [css.labels]),
orientation = ctx.attr.orientation,
exports = unfurl(ctx.attr.exports),
exports = exports,
),
ClosureJsLibraryInfo(),
DefaultInfo(
Expand Down
6 changes: 3 additions & 3 deletions closure/templates/closure_js_template_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

load("//closure/compiler:closure_js_aspect.bzl", "closure_js_aspect")
load("//closure/compiler:closure_js_library.bzl", "closure_js_library")
load("//closure/private:defs.bzl", "ClosureJsLibraryInfo", "SOY_FILE_TYPE", "unfurl")
load("//closure/private:defs.bzl", "ClosureJsLibraryInfo", "SOY_FILE_TYPE", "extract_providers", "unfurl")
load("//closure/templates:closure_templates_plugin.bzl", "SoyPluginInfo")

_SOYTOJSSRCCOMPILER = "@com_google_template_soy//:SoyToJsSrcCompiler"
Expand Down Expand Up @@ -47,8 +47,8 @@ def _impl(ctx):
if ctx.file.globals:
args += ["--compileTimeGlobalsFile", ctx.file.globals.path]
inputs.append(ctx.file.globals)
for dep in unfurl(ctx.attr.deps, provider = ClosureJsLibraryInfo):
for f in dep[ClosureJsLibraryInfo].descriptors.to_list():
for dep in unfurl(extract_providers(ctx.attr.deps, provider = ClosureJsLibraryInfo)):
for f in dep.descriptors.to_list():
args.append("--protoFileDescriptors=%s" % f.path)
inputs.append(f)

Expand Down
3 changes: 2 additions & 1 deletion closure/testing/phantomjs_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ load(
"ClosureJsLibraryInfo",
"HTML_FILE_TYPE",
"collect_runfiles",
"extract_providers",
"long_path",
"unfurl",
)
Expand All @@ -33,7 +34,7 @@ def _impl(ctx):
files = [ctx.outputs.executable]
srcs = []
direct_srcs = []
deps = unfurl(ctx.attr.deps, provider = ClosureJsLibraryInfo)
deps = list(ctx.attr.deps)
for dep in deps:
if ClosureJsBinaryInfo in dep:
direct_srcs.append(dep[ClosureJsBinaryInfo].bin)
Expand Down
7 changes: 2 additions & 5 deletions java/io/bazel/rules/closure/testing/TestDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

/** The test driver that triggers test running on the browser and collects test results. */
public class TestDriver {

private static final Logger logger = Logger.getLogger(TestDriver.class.getName());
private static final long POLL_INTERVAL = 100;
private static final long TEST_TIMEOUT = 300;
Expand All @@ -51,9 +50,8 @@ public boolean run() {
new FluentWait<>((JavascriptExecutor) driver)
.pollingEvery(Duration.ofMillis(POLL_INTERVAL))
.withTimeout(Duration.ofSeconds(TEST_TIMEOUT))
.until(
executor -> (boolean) executor.executeScript("return window.top.G_testRunner.isFinished()")
);
.until(executor
-> (boolean) executor.executeScript("return window.top.G_testRunner.isFinished()"));
} catch (TimeoutException e) {
logger.log(Level.SEVERE, String.format("Test timeout after %s seconds", TEST_TIMEOUT));
return false;
Expand All @@ -77,4 +75,3 @@ public void quit() {
driver.quit();
}
}

0 comments on commit 78563e2

Please sign in to comment.