From 23b392704074de5ae55354b3e9d630d792d77c48 Mon Sep 17 00:00:00 2001 From: Simon Mavi Stewart Date: Tue, 24 Jan 2023 17:17:00 +0000 Subject: [PATCH 1/3] Add test to ensure generated docs and files are up to date This also removes a need on the root build file to depend on stardoc. --- BUILD | 38 +++------------------------- scripts/BUILD | 54 ++++++++++++++++++++++++++++++++++++---- scripts/generate_docs.sh | 8 ------ tests/bazel_run_tests.sh | 45 +++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 47 deletions(-) delete mode 100755 scripts/generate_docs.sh diff --git a/BUILD b/BUILD index 3e8b8d966..cb7908c09 100644 --- a/BUILD +++ b/BUILD @@ -1,7 +1,9 @@ -load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -exports_files(["defs.bzl"]) +exports_files([ + "defs.bzl", + "specs.bzl", +]) licenses(["notice"]) # Apache 2.0 @@ -13,33 +15,6 @@ exports_files( visibility = ["//scripts:__pkg__"], ) -stardoc( - name = "defs", - out = "defs.md", - input = "defs.bzl", - symbol_names = [ - "javadoc", - "java_export", - "maven_bom", - "maven_install", - ], - visibility = ["//scripts:__pkg__"], - deps = ["//:implementation"], -) - -stardoc( - name = "specs", - out = "specs.md", - input = "specs.bzl", - symbol_names = [ - "maven.artifact", - "maven.repository", - "maven.exclusion", - ], - visibility = ["//scripts:__pkg__"], - deps = ["//:implementation"], -) - bzl_library( name = "implementation", srcs = [ @@ -84,8 +59,3 @@ alias( name = "mirror_coursier", actual = "//scripts:mirror_coursier", ) - -alias( - name = "generate_api_reference", - actual = "//scripts:generate_api_reference", -) diff --git a/scripts/BUILD b/scripts/BUILD index d25ce1924..72542c0ca 100644 --- a/scripts/BUILD +++ b/scripts/BUILD @@ -1,6 +1,10 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") +load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc") load("//private:versions.bzl", "COURSIER_CLI_HTTP_FILE_NAME") load("//private/rules:artifact.bzl", "artifact") -load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") + +exports_files([ +]) genrule( name = "buildifier-bin", @@ -25,16 +29,16 @@ genrule( name = "generate_base_docs", srcs = [ "//:docs/includes/main_functions_header.md", - "//:defs.md", + "defs.md", "//:docs/includes/spec_functions_header.md", - "//:specs.md", + "specs.md", ], outs = ["generate_base_docs.md"], cmd = """cat \ $(location //:docs/includes/main_functions_header.md) \ - $(location //:defs.md) \ + $(location :defs.md) \ $(location //:docs/includes/spec_functions_header.md) \ - $(location //:specs.md) > $@""", + $(location :specs.md) > $@""", ) genrule( @@ -46,12 +50,52 @@ genrule( visibility = ["//:__pkg__"], ) +sh_binary( + name = "generate-docs", + srcs = [ + "copy-prebuilts.sh", + ], + args = [ + "docs", + "$(location :generate_api_reference)", + "api.md", + ], + data = [ + ":generate_api_reference", + ], +) + nodejs_binary( name = "doctoc", data = ["@npm//doctoc"], entry_point = {"@npm//:node_modules/doctoc": "doctoc.js"}, ) +stardoc( + name = "defs", + out = "defs.md", + input = "//:defs.bzl", + symbol_names = [ + "javadoc", + "java_export", + "maven_bom", + "maven_install", + ], + deps = ["//:implementation"], +) + +stardoc( + name = "specs", + out = "specs.md", + input = "//:specs.bzl", + symbol_names = [ + "maven.artifact", + "maven.repository", + "maven.exclusion", + ], + deps = ["//:implementation"], +) + java_binary( name = "google-java-format", jvm_flags = [ diff --git a/scripts/generate_docs.sh b/scripts/generate_docs.sh deleted file mode 100755 index 88181de06..000000000 --- a/scripts/generate_docs.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -bazel build //scripts:generate_api_reference && \ - cp bazel-bin/scripts/api.md docs/api.md && \ - chmod u+rw docs/api.md && \ - chmod a-x docs/api.md diff --git a/tests/bazel_run_tests.sh b/tests/bazel_run_tests.sh index e08d8370c..50069d58f 100755 --- a/tests/bazel_run_tests.sh +++ b/tests/bazel_run_tests.sh @@ -5,6 +5,33 @@ # # Add a new test to the TESTS array and send all output to TEST_LOG +function test_docs_are_up_to_date() { + before_docs="$(git status)" + bazel run //scripts:generate-docs >> "$TEST_LOG" 2>&1 + after_docs="$(git status)" + expect_same "$before_docs" "$after_docs" +} + +function test_formatting_is_okay() { + before_format="$(git status)" + bazel run //scripts:format >> "$TEST_LOG" 2>&1 + after_format="$(git status)" + expect_same "$before_format" "$after_format" +} + +function test_prebuilts_are_up_to_date() { + temp=$(mktemp -d) + cp private/tools/prebuilt/*.jar "$temp" + bazel run //scripts:refresh-prebuilts >> "$TEST_LOG" 2>&1 + + for i in private/tools/prebuilt/*.jar; do + file_name=$(basename $i) + before="$(jar tvf "$temp/$file_name" | grep -v build-data.properties)" + after="$(jar tvf "private/tools/prebuilt/$file_name" | grep -v build-data.properties)" + expect_same "$before" "$after" + done +} + function test_dependency_aggregation() { bazel query --notool_deps 'deps(@regression_testing//:com_sun_xml_bind_jaxb_ri)' >> "$TEST_LOG" 2>&1 @@ -112,6 +139,10 @@ function test_v1_lock_file_format() { } TESTS=( + "test_formatting_is_okay" + "test_prebuilts_are_up_to_date" + "test_docs_are_up_to_date" + "test_dependency_aggregation" "test_duplicate_version_warning" "test_duplicate_version_warning_same_version" @@ -160,6 +191,20 @@ function expect_not_log() { return 1 } +function expect_same() { + local before="$1" + local after="$2" + + if [ "$before" != "$after" ]; then + diff <(echo "$before") <(echo "$after") >> "$TEST_LOG" 2>&1 + + printf "FAILED\n" + cat $TEST_LOG + DUMPED_TEST_LOG=1 + return 1 + fi +} + function exit_handler() { local exit_code=$? if [ $exit_code != "0" ] && [ $DUMPED_TEST_LOG == "0" ]; then From d663875bd87ff58938a4abaf340eab2e94ead05d Mon Sep 17 00:00:00 2001 From: Simon Mavi Stewart Date: Thu, 23 Feb 2023 12:10:15 +0000 Subject: [PATCH 2/3] Try a different way of checking whether the prebuilts have changed --- tests/bazel_run_tests.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/bazel_run_tests.sh b/tests/bazel_run_tests.sh index 50069d58f..7d7526579 100755 --- a/tests/bazel_run_tests.sh +++ b/tests/bazel_run_tests.sh @@ -5,13 +5,6 @@ # # Add a new test to the TESTS array and send all output to TEST_LOG -function test_docs_are_up_to_date() { - before_docs="$(git status)" - bazel run //scripts:generate-docs >> "$TEST_LOG" 2>&1 - after_docs="$(git status)" - expect_same "$before_docs" "$after_docs" -} - function test_formatting_is_okay() { before_format="$(git status)" bazel run //scripts:format >> "$TEST_LOG" 2>&1 @@ -26,12 +19,29 @@ function test_prebuilts_are_up_to_date() { for i in private/tools/prebuilt/*.jar; do file_name=$(basename $i) - before="$(jar tvf "$temp/$file_name" | grep -v build-data.properties)" - after="$(jar tvf "private/tools/prebuilt/$file_name" | grep -v build-data.properties)" - expect_same "$before" "$after" + + echo "Comparing $file_name" >> "$TEST_LOG" + + different="$(comm -3 <(jar tvf "$temp/$file_name" | grep -v build-data.properties) <(jar tvf "private/tools/prebuilt/$file_name" | grep -v build-data.properties))" + + if [ -n "$different" ]; then + echo "$different" >> "$TEST_LOG" 2>&1 + + printf "FAILED\n" + cat $TEST_LOG + DUMPED_TEST_LOG=1 + return 1 + fi done } +function test_docs_are_up_to_date() { + before_docs="$(git status)" + bazel run //scripts:generate-docs >> "$TEST_LOG" 2>&1 + after_docs="$(git status)" + expect_same "$before_docs" "$after_docs" +} + function test_dependency_aggregation() { bazel query --notool_deps 'deps(@regression_testing//:com_sun_xml_bind_jaxb_ri)' >> "$TEST_LOG" 2>&1 From 19999a8e956b9575270395e04baf7aafa342d1af Mon Sep 17 00:00:00 2001 From: Simon Mavi Stewart Date: Thu, 23 Feb 2023 12:14:40 +0000 Subject: [PATCH 3/3] `comm` wants lexographic sorting on Linux --- tests/bazel_run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bazel_run_tests.sh b/tests/bazel_run_tests.sh index 7d7526579..98ad27c40 100755 --- a/tests/bazel_run_tests.sh +++ b/tests/bazel_run_tests.sh @@ -22,7 +22,7 @@ function test_prebuilts_are_up_to_date() { echo "Comparing $file_name" >> "$TEST_LOG" - different="$(comm -3 <(jar tvf "$temp/$file_name" | grep -v build-data.properties) <(jar tvf "private/tools/prebuilt/$file_name" | grep -v build-data.properties))" + different="$(comm -3 <(jar tvf "$temp/$file_name" | grep -v build-data.properties | sort) <(jar tvf "private/tools/prebuilt/$file_name" | grep -v build-data.properties | sort))" if [ -n "$different" ]; then echo "$different" >> "$TEST_LOG" 2>&1