From 3ea8c52db28d6a060c2a546e64cfcb08683f8af4 Mon Sep 17 00:00:00 2001 From: Evgenii Kliuchnikov Date: Sun, 31 Dec 2023 09:15:51 +0100 Subject: [PATCH] Update CI workflow / Bazel build files --- .gitattributes | 1 - .github/workflows/build_test.yml | 14 +++---- BUILD.bazel | 34 ++++------------ compiler_config_setting.bzl | 40 ------------------- go/WORKSPACE.bazel | 14 +++---- java/BUILD.bazel | 40 ++++++++++++++++--- java/org/brotli/integration/BUILD.bazel | 21 +++++----- .../brotli/integration/BrotliJniTestBase.java | 9 +++++ .../org/brotli/integration/BundleChecker.java | 4 +- java/org/brotli/wrapper/common/BUILD.bazel | 2 +- java/org/brotli/wrapper/dec/BUILD.bazel | 2 +- java/org/brotli/wrapper/enc/BUILD.bazel | 2 +- java/org/brotli/wrapper/enc/EncoderTest.java | 4 +- 13 files changed, 86 insertions(+), 101 deletions(-) delete mode 100644 compiler_config_setting.bzl diff --git a/.gitattributes b/.gitattributes index a0853c247..21e67b085 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,7 +7,6 @@ tests/testdata/* binary BUILD.bazel !export-ignore CHANGELOG.md !export-ignore CMakeLists.txt !export-ignore -compiler_config_setting.bzl !export-ignore CONTRIBUTING.md !export-ignore LICENSE !export-ignore MANIFEST.in !export-ignore diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 44f4116d4..408de2b37 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -86,17 +86,17 @@ jobs: cxx_compiler: g++ os: macos-latest - - name: cmake-win64:msvc2019-rel + - name: cmake-win64:msvc-rel build_system: cmake - cmake_generator: Visual Studio 16 2019 + cmake_generator: Visual Studio 17 2022 cmake_config: Release - os: windows-2019 + os: windows-latest - - name: cmake-win64:msvc2019-dbg + - name: cmake-win64:msvc-dbg build_system: cmake - cmake_generator: Visual Studio 16 2019 + cmake_generator: Visual Studio 17 2022 cmake_config: Debug - os: windows-2019 + os: windows-latest - name: fuzz:clang15 build_system: fuzz @@ -326,7 +326,7 @@ jobs: run: | cd ${GITHUB_WORKSPACE}/${{ matrix.bazel_project }} bazelisk query "tests(...)" --output=label > ${RUNNER_TEMP}/tests.lst - [ -s ${RUNNER_TEMP}/tests.lst ] && bazelisk test -c opt ...:all + [ -s ${RUNNER_TEMP}/tests.lst ] && bazelisk test -c opt ...:all --test_output=errors bazelisk clean - name: Build / Test with Maven diff --git a/BUILD.bazel b/BUILD.bazel index 34e4a5421..003c1b941 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,8 +1,6 @@ # Description: # Brotli is a generic-purpose lossless compression algorithm. -load(":compiler_config_setting.bzl", "create_msvc_config") - package( default_visibility = ["//visibility:public"], ) @@ -12,37 +10,21 @@ licenses(["notice"]) # MIT exports_files(["LICENSE"]) config_setting( - name = "darwin", - values = {"cpu": "darwin"}, - visibility = ["//visibility:public"], -) - -config_setting( - name = "darwin_x86_64", - values = {"cpu": "darwin_x86_64"}, - visibility = ["//visibility:public"], -) - -config_setting( - name = "windows", - values = {"cpu": "x64_windows"}, + name = "clang-cl", + flag_values = { + "@bazel_tools//tools/cpp:compiler": "clang-cl", + }, visibility = ["//visibility:public"], ) config_setting( - name = "windows_msvc", - values = {"cpu": "x64_windows_msvc"}, + name = "msvc", + flag_values = { + "@bazel_tools//tools/cpp:compiler": "msvc-cl", + }, visibility = ["//visibility:public"], ) -config_setting( - name = "windows_msys", - values = {"cpu": "x64_windows_msys"}, - visibility = ["//visibility:public"], -) - -create_msvc_config() - STRICT_C_OPTIONS = select({ ":msvc": [], ":clang-cl": [ diff --git a/compiler_config_setting.bzl b/compiler_config_setting.bzl deleted file mode 100644 index b7bb7b9d1..000000000 --- a/compiler_config_setting.bzl +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2018 Google Inc. All Rights Reserved. -# -# Distributed under MIT license. -# See file LICENSE for detail or copy at https://opensource.org/licenses/MIT - -"""Creates config_setting that allows selecting based on 'compiler' value.""" - -def create_msvc_config(): - # The "do_not_use_tools_cpp_compiler_present" attribute exists to - # distinguish between older versions of Bazel that do not support - # "@bazel_tools//tools/cpp:compiler" flag_value, and newer ones that do. - # In the future, the only way to select on the compiler will be through - # flag_values{"@bazel_tools//tools/cpp:compiler"} and the else branch can - # be removed. - if hasattr(cc_common, "do_not_use_tools_cpp_compiler_present"): - native.config_setting( - name = "clang-cl", - flag_values = { - "@bazel_tools//tools/cpp:compiler": "clang-cl", - }, - visibility = ["//visibility:public"], - ) - native.config_setting( - name = "msvc", - flag_values = { - "@bazel_tools//tools/cpp:compiler": "msvc-cl", - }, - visibility = ["//visibility:public"], - ) - else: - native.config_setting( - name = "clang-cl", - values = {"compiler": "clang-cl"}, - visibility = ["//visibility:public"], - ) - native.config_setting( - name = "msvc", - values = {"compiler": "msvc-cl"}, - visibility = ["//visibility:public"], - ) diff --git a/go/WORKSPACE.bazel b/go/WORKSPACE.bazel index 570e250a3..a633dbb49 100644 --- a/go/WORKSPACE.bazel +++ b/go/WORKSPACE.bazel @@ -9,10 +9,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "io_bazel_rules_go", - sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f", + sha256 = "c8035e8ae248b56040a65ad3f0b7434712e2037e5dfdcebfe97576e620422709", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.44.0/rules_go-v0.44.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.44.0/rules_go-v0.44.0.zip", ], ) @@ -20,14 +20,14 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe go_rules_dependencies() -go_register_toolchains(version = "1.17.1") +go_register_toolchains(version = "1.21.5") http_archive( name = "bazel_gazelle", - sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", + sha256 = "b7387f72efb59f876e4daae42f1d3912d0d45563eac7cb23d1de0b094ab588cf", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz", ], ) diff --git a/java/BUILD.bazel b/java/BUILD.bazel index 0ae6c1550..ea87b157d 100644 --- a/java/BUILD.bazel +++ b/java/BUILD.bazel @@ -2,6 +2,36 @@ package( default_visibility = ["//visibility:public"], ) +config_setting( + name = "darwin", + values = {"cpu": "darwin"}, + visibility = ["//visibility:public"], +) + +config_setting( + name = "darwin_x86_64", + values = {"cpu": "darwin_x86_64"}, + visibility = ["//visibility:public"], +) + +config_setting( + name = "windows", + values = {"cpu": "x64_windows"}, + visibility = ["//visibility:public"], +) + +config_setting( + name = "windows_msvc", + values = {"cpu": "x64_windows_msvc"}, + visibility = ["//visibility:public"], +) + +config_setting( + name = "windows_msys", + values = {"cpu": "x64_windows_msys"}, + visibility = ["//visibility:public"], +) + # >>> JNI headers genrule( @@ -14,11 +44,11 @@ genrule( genrule( name = "copy_link_jni_md_header", srcs = select({ - "@org_brotli//:darwin": ["@openjdk_macosx_jni_md_h//file"], - "@org_brotli//:darwin_x86_64": ["@openjdk_macosx_jni_md_h//file"], - "@org_brotli//:windows_msys": ["@openjdk_windows_jni_md_h//file"], - "@org_brotli//:windows_msvc": ["@openjdk_windows_jni_md_h//file"], - "@org_brotli//:windows": ["@openjdk_windows_jni_md_h//file"], + ":darwin": ["@openjdk_macosx_jni_md_h//file"], + ":darwin_x86_64": ["@openjdk_macosx_jni_md_h//file"], + ":windows_msys": ["@openjdk_windows_jni_md_h//file"], + ":windows_msvc": ["@openjdk_windows_jni_md_h//file"], + ":windows": ["@openjdk_windows_jni_md_h//file"], "//conditions:default": ["@openjdk_solaris_jni_md_h//file"], }), outs = ["jni/jni_md.h"], diff --git a/java/org/brotli/integration/BUILD.bazel b/java/org/brotli/integration/BUILD.bazel index 5b773251a..6a23eb0f1 100644 --- a/java/org/brotli/integration/BUILD.bazel +++ b/java/org/brotli/integration/BUILD.bazel @@ -37,8 +37,8 @@ java_binary( java_test( name = "bundle_checker_data_test", - args = ["org/brotli/integration/test_data.zip"], - data = ["test_data.zip"], + args = ["$(location :test_data)"], + data = [":test_data"], main_class = "org.brotli.integration.BundleChecker", use_testrunner = 0, runtime_deps = [":bundle_checker"], @@ -48,26 +48,27 @@ java_test( name = "bundle_checker_fuzz_test", args = [ "-s", - "org/brotli/integration/fuzz_data.zip", + "$(location :fuzz_data)", ], - data = ["fuzz_data.zip"], + data = [":fuzz_data"], main_class = "org.brotli.integration.BundleChecker", use_testrunner = 0, runtime_deps = [":bundle_checker"], ) +filegroup( + name = "fuzz_data", + srcs = ["fuzz_data.zip"], + visibility = ["//visibility:private"], +) filegroup( name = "test_data", srcs = ["test_data.zip"], - visibility = [ - "//org/brotli/wrapper/dec:__pkg__", - ], + visibility = ["@org_brotli_java//org/brotli/wrapper/dec:__pkg__"], ) filegroup( name = "test_corpus", srcs = ["test_corpus.zip"], - visibility = [ - "//org/brotli/wrapper/enc:__pkg__", - ], + visibility = ["@org_brotli_java//org/brotli/wrapper/enc:__pkg__"], ) diff --git a/java/org/brotli/integration/BrotliJniTestBase.java b/java/org/brotli/integration/BrotliJniTestBase.java index c272f4226..f20d4db15 100644 --- a/java/org/brotli/integration/BrotliJniTestBase.java +++ b/java/org/brotli/integration/BrotliJniTestBase.java @@ -10,4 +10,13 @@ public class BrotliJniTestBase { System.load(new java.io.File(jniLibrary).getAbsolutePath()); } } + + /** + * Makes sure this class is initialized. + * + * Invoking this is an alternative to extending this class. + */ + public static void init() { + // Do nothing, just force `` execution, if necessary. + } } diff --git a/java/org/brotli/integration/BundleChecker.java b/java/org/brotli/integration/BundleChecker.java index e3ddb33b0..29d2fb100 100644 --- a/java/org/brotli/integration/BundleChecker.java +++ b/java/org/brotli/integration/BundleChecker.java @@ -106,7 +106,9 @@ public static void main(String[] args) throws FileNotFoundException { throw new RuntimeException("Usage: BundleChecker [-s] ..."); } for (int i = argsOffset; i < args.length; ++i) { - new BundleChecker(new FileInputStream(args[i]), new AtomicInteger(0), sanityCheck).run(); + String bundleArg = args[i]; + String bundlePath = new java.io.File(bundleArg).getAbsolutePath(); + new BundleChecker(new FileInputStream(bundlePath), new AtomicInteger(0), sanityCheck).run(); } } } diff --git a/java/org/brotli/wrapper/common/BUILD.bazel b/java/org/brotli/wrapper/common/BUILD.bazel index eeaa47491..9a493ceba 100644 --- a/java/org/brotli/wrapper/common/BUILD.bazel +++ b/java/org/brotli/wrapper/common/BUILD.bazel @@ -9,7 +9,7 @@ filegroup( filegroup( name = "brotli_jni_no_dictionary_data", - srcs = ["//:brotli_jni_no_dictionary_data.dll"], + srcs = ["@org_brotli_java//:brotli_jni_no_dictionary_data.dll"], ) java_library( diff --git a/java/org/brotli/wrapper/dec/BUILD.bazel b/java/org/brotli/wrapper/dec/BUILD.bazel index ca902f7eb..f57e361cb 100644 --- a/java/org/brotli/wrapper/dec/BUILD.bazel +++ b/java/org/brotli/wrapper/dec/BUILD.bazel @@ -36,7 +36,7 @@ java_library( filegroup( name = "brotli_jni", - srcs = ["//:brotli_jni.dll"], + srcs = ["@org_brotli_java//:brotli_jni.dll"], ) filegroup( diff --git a/java/org/brotli/wrapper/enc/BUILD.bazel b/java/org/brotli/wrapper/enc/BUILD.bazel index b8500c78f..3a3d92cab 100644 --- a/java/org/brotli/wrapper/enc/BUILD.bazel +++ b/java/org/brotli/wrapper/enc/BUILD.bazel @@ -9,7 +9,7 @@ filegroup( filegroup( name = "brotli_jni", - srcs = ["//:brotli_jni.dll"], + srcs = ["@org_brotli_java//:brotli_jni.dll"], ) java_library( diff --git a/java/org/brotli/wrapper/enc/EncoderTest.java b/java/org/brotli/wrapper/enc/EncoderTest.java index 18ed6470a..8c8fc4b13 100644 --- a/java/org/brotli/wrapper/enc/EncoderTest.java +++ b/java/org/brotli/wrapper/enc/EncoderTest.java @@ -6,6 +6,7 @@ import org.brotli.integration.BundleHelper; import org.brotli.wrapper.dec.BrotliInputStream; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -17,13 +18,14 @@ /** Tests for {@link org.brotli.wrapper.enc.Encoder}. */ @RunWith(AllTests.class) -public class EncoderTest extends BrotliJniTestBase { +public class EncoderTest extends TestCase { static InputStream getBundle() throws IOException { return new FileInputStream(System.getProperty("TEST_BUNDLE")); } /** Creates a test suite. */ public static TestSuite suite() throws IOException { + BrotliJniTestBase.init(); TestSuite suite = new TestSuite(); InputStream bundle = getBundle(); try {