From d4e6947d2bf56078ed5dd1b62ea94ce3b9a4aeb6 Mon Sep 17 00:00:00 2001 From: Goktug Gokdogan Date: Sat, 16 Mar 2024 01:13:45 -0700 Subject: [PATCH 1/2] Cleanup more unfurl usages --- 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 ++++-- .../templates/closure_js_template_library.bzl | 6 +++--- closure/testing/phantomjs_test.bzl | 3 ++- closure/webfiles/web_library.bzl | 20 +++++++++---------- .../rules/closure/testing/TestDriver.java | 7 ++----- 8 files changed, 27 insertions(+), 32 deletions(-) diff --git a/closure/compiler/closure_js_library.bzl b/closure/compiler/closure_js_library.bzl index 3431108ee..7b3067035 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 488f3215d..0e9613cf2 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 4caddd534..ae7e7c7d6 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 22ef6b50c..2574389a9 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 += ["--protoFileDescriptors=%s" % f.path] inputs.append(f) diff --git a/closure/testing/phantomjs_test.bzl b/closure/testing/phantomjs_test.bzl index 80b284bb8..0f5f9a225 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 += [dep[ClosureJsBinaryInfo].bin] diff --git a/closure/webfiles/web_library.bzl b/closure/webfiles/web_library.bzl index 43350e614..268e19601 100644 --- a/closure/webfiles/web_library.bzl +++ b/closure/webfiles/web_library.bzl @@ -19,6 +19,7 @@ load( "WebFilesInfo", "create_argfile", "difference", + "extract_providers", "long_path", "unfurl", ) @@ -40,12 +41,12 @@ def _web_library(ctx): fail("when \"*\" is suppressed no other items should be present") # process what came before - deps = unfurl(ctx.attr.deps, provider = WebFilesInfo) + deps = unfurl(extract_providers(ctx.attr.deps, provider = WebFilesInfo)) webpaths = [] manifests = [] for dep in deps: - webpaths.append(dep[WebFilesInfo].webpaths) - manifests += [dep[WebFilesInfo].manifests] + webpaths.append(dep.webpaths) + manifests += [dep.manifests] # process what comes now new_webpaths = [] @@ -103,13 +104,11 @@ def _web_library(ctx): args.append(category) inputs.extend(ctx.files.srcs) for dep in deps: - inputs.append(dep[WebFilesInfo].dummy) - for f in dep.files.to_list(): - inputs.append(f) - direct_manifests += [dep[WebFilesInfo].manifest] - inputs.append(dep[WebFilesInfo].manifest) + inputs.append(dep.dummy) + direct_manifests += [dep.manifest] + inputs.append(dep.manifest) args.append("--direct_dep") - args.append(dep[WebFilesInfo].manifest.path) + args.append(dep.manifest.path) for man in difference(manifests, depset(direct_manifests)): inputs.append(man) args.append("--transitive_dep") @@ -148,8 +147,7 @@ def _web_library(ctx): ) transitive_runfiles = depset( - transitive = [ctx.attr.server.data_runfiles.files] + - [dep.data_runfiles.files for dep in deps], + transitive = [ctx.attr.server.data_runfiles.files], ) return [ 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(); } } - From f31494e0ba1a133ab7159921591c0d6f00db630d Mon Sep 17 00:00:00 2001 From: Goktug Gokdogan Date: Tue, 16 Apr 2024 15:40:25 -0700 Subject: [PATCH 2/2] Update rules_java to a more recent version --- closure/repositories.bzl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/closure/repositories.bzl b/closure/repositories.bzl index f2c4f7b47..0577c87ab 100644 --- a/closure/repositories.bzl +++ b/closure/repositories.bzl @@ -1038,11 +1038,10 @@ def rules_cc(): def rules_java(): http_archive( name = "rules_java", - sha256 = "f5a3e477e579231fca27bf202bb0e8fbe4fc6339d63b38ccb87c2760b533d1c3", - strip_prefix = "rules_java-981f06c3d2bd10225e85209904090eb7b5fb26bd", + sha256 = "29ba147c583aaf5d211686029842c5278e12aaea86f66bd4a9eb5e525b7f2701", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_java/archive/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz", - "https://github.com/bazelbuild/rules_java/archive/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_java/releases/download/6.3.0/rules_java-6.3.0.tar.gz", + "https://github.com/bazelbuild/rules_java/releases/download/6.3.0/rules_java-6.3.0.tar.gz", ], )