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..98ad27c40 100755 --- a/tests/bazel_run_tests.sh +++ b/tests/bazel_run_tests.sh @@ -5,6 +5,43 @@ # # Add a new test to the TESTS array and send all output to TEST_LOG +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) + + echo "Comparing $file_name" >> "$TEST_LOG" + + 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 + + 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 @@ -112,6 +149,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 +201,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