From 4bf1cb0841d4f88a25ecd6ba66615e861c799aae Mon Sep 17 00:00:00 2001 From: goktug Date: Thu, 5 Dec 2024 14:06:26 -0800 Subject: [PATCH] Remove AutoValue and JSR 250 embedded into unshaded jar. This CL also adds a test that ensures we don't accidentally pull in non-compiler code into the maven artifact again. This should address the problem in https://github.com/google/closure-compiler/issues/4161 PiperOrigin-RevId: 703246074 --- .bazelrc | 2 ++ BUILD.bazel | 37 ++++++++++++++++++++++++++++++++++++- build_test.sh | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index 32928b0e989..b1e62afe7c8 100644 --- a/.bazelrc +++ b/.bazelrc @@ -13,3 +13,5 @@ build --define=COMPILER_VERSION=1.0-SNAPSHOT # Setting for running in remote CI build --color=yes + +test --test_output=errors \ No newline at end of file diff --git a/BUILD.bazel b/BUILD.bazel index ebc5ab5eee6..1c1fc0701f0 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -106,13 +106,48 @@ genrule( java_export( name = "compiler_unshaded", + # Compile time dependencies that are not added as @maven//: need to be excluded. + excluded_workspaces = { + "javax_annotation_jsr250_api": None, + "com_google_auto_value_auto_value_annotations": None, + }, maven_coordinates = "com.google.javascript:closure-compiler-unshaded:{0}".format(version), pom_template = "maven/closure-compiler-unshaded.pom.xml.tpl", + tags = [ + "no-javadocs", # Generated from the compiler_lib_no_runtime_libs.javadoc target. + ], runtime_deps = [ "//:compiler_unshaded_lib", ], ) +# Owned packages. Everything else should be a maven dependency. +ALLOWED_PACKAGES = [ + "com.google.javascript", # Compiler code + "com.google.debugging", # Compiler code + "com.google.protobuf.Descriptors", # Generated proto + "com.google.protobuf.MapField", # Generated proto +] + +sh_test( + name = "compiler_unshaded_content_test", + srcs = ["check_jar_content.sh"], + args = [ + "$(location compiler_unshaded)", + "\\\\|".join(ALLOWED_PACKAGES).replace(".", "/"), + ], + data = [":compiler_unshaded"], +) + +genrule( + name = "check_jar_content", + outs = ["check_jar_content.sh"], + cmd = """echo ' + OUT=$$(jar -tf $$1|grep \\.class|grep -v "$$2"); + if [[ -n $$OUT ]]; then echo Unexpected: $$OUT && exit 1; fi + ' > $@""", +) + java_library( name = "compiler_unshaded_lib", srcs = [ @@ -147,9 +182,9 @@ java_library( java_library( name = "compiler_lib", resources = [ - ":src/java/com/google/javascript/jscomp/js/polyfills.txt", ":runtime_libs_srcs", ":runtime_libs_typedast", + ":src/java/com/google/javascript/jscomp/js/polyfills.txt", ], exports = [":compiler_lib_no_runtime_libs"], ) diff --git a/build_test.sh b/build_test.sh index b6eba5b8baf..9c6bfa0a0fb 100755 --- a/build_test.sh +++ b/build_test.sh @@ -22,4 +22,5 @@ unset ANDROID_HOME bazel build :all +bazel test :compiler_unshaded_content_test --test_output=errors # TODO: Run other tests needed for open source verification