From 78563e210e7b75d1c6dc7931420a6297cb455a9a Mon Sep 17 00:00:00 2001 From: Goktug Gokdogan Date: Tue, 16 Apr 2024 19:33:37 -0700 Subject: [PATCH] Cleanup more unfurl usages (#609) --- closure/compiler/closure_js_library.bzl | 2 -- closure/private/defs.bzl | 12 +++++------- closure/stylesheets/closure_css_binary.bzl | 3 ++- closure/stylesheets/closure_css_library.bzl | 6 ++++-- closure/templates/closure_js_template_library.bzl | 6 +++--- closure/testing/phantomjs_test.bzl | 3 ++- java/io/bazel/rules/closure/testing/TestDriver.java | 7 ++----- 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/closure/compiler/closure_js_library.bzl b/closure/compiler/closure_js_library.bzl index be10a221a..3a0a8b18c 100644 --- a/closure/compiler/closure_js_library.bzl +++ b/closure/compiler/closure_js_library.bzl @@ -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, @@ -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, diff --git a/closure/private/defs.bzl b/closure/private/defs.bzl index fd6e4416d..f09807766 100644 --- a/closure/private/defs.bzl +++ b/closure/private/defs.bzl @@ -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: @@ -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), diff --git a/closure/stylesheets/closure_css_binary.bzl b/closure/stylesheets/closure_css_binary.bzl index a16004952..aaa9c9004 100644 --- a/closure/stylesheets/closure_css_binary.bzl +++ b/closure/stylesheets/closure_css_binary.bzl @@ -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") diff --git a/closure/stylesheets/closure_css_library.bzl b/closure/stylesheets/closure_css_library.bzl index c6b13db5b..ebf3b8766 100644 --- a/closure/stylesheets/closure_css_library.bzl +++ b/closure/stylesheets/closure_css_library.bzl @@ -21,11 +21,13 @@ 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( @@ -33,7 +35,7 @@ def _closure_css_library(ctx): 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( diff --git a/closure/templates/closure_js_template_library.bzl b/closure/templates/closure_js_template_library.bzl index 771f44f13..145adfc77 100644 --- a/closure/templates/closure_js_template_library.bzl +++ b/closure/templates/closure_js_template_library.bzl @@ -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" @@ -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) diff --git a/closure/testing/phantomjs_test.bzl b/closure/testing/phantomjs_test.bzl index 1bb071996..5152ecb6f 100644 --- a/closure/testing/phantomjs_test.bzl +++ b/closure/testing/phantomjs_test.bzl @@ -23,6 +23,7 @@ load( "ClosureJsLibraryInfo", "HTML_FILE_TYPE", "collect_runfiles", + "extract_providers", "long_path", "unfurl", ) @@ -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) diff --git a/java/io/bazel/rules/closure/testing/TestDriver.java b/java/io/bazel/rules/closure/testing/TestDriver.java index 776743021..8515c7891 100644 --- a/java/io/bazel/rules/closure/testing/TestDriver.java +++ b/java/io/bazel/rules/closure/testing/TestDriver.java @@ -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; @@ -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; @@ -77,4 +75,3 @@ public void quit() { driver.quit(); } } -