aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Rostovtsev <arostovtsev@google.com>2023-08-04 15:24:30 -0400
committerGitHub <noreply@github.com>2023-08-04 15:24:30 -0400
commitabe8c1d1bbbe874e594ce0fc41f16b1566f1891a (patch)
treedf29260016dad382f8e90466597de883dabceaae
parent799f388ecdb790e6d7f6bf6eebaa2c0befb807fe (diff)
downloadstardoc-abe8c1d1bbbe874e594ce0fc41f16b1566f1891a.tar.gz
List maven artifacts in MODULE.bazel to avoid rules_jvm_external pin warning (#176)
Since we no longer have a single source of truth for maven artifacts, we need a consistency test. Use some old-school sed to extract the STARDOC_MAVEN_ARTIFACTS list from MODULE.bazel and deps.bzl, and add a test to ensure they are consistent. And - for good measure - add a similar test to ensure the version number in version.bzl and MODULE.bazel is consistent too. Fixes #174
-rw-r--r--BUILD15
-rw-r--r--MODULE.bazel14
-rw-r--r--deps.bzl2
-rw-r--r--test/BUILD49
4 files changed, 73 insertions, 7 deletions
diff --git a/BUILD b/BUILD
index 85e0841..9f3f897 100644
--- a/BUILD
+++ b/BUILD
@@ -10,10 +10,17 @@ license(
licenses(["notice"])
-exports_files([
- "LICENSE",
- "WORKSPACE",
-])
+# Inputs for distro transformations and consistency tests.
+exports_files(
+ [
+ "LICENSE",
+ "WORKSPACE",
+ "MODULE.bazel",
+ "deps.bzl",
+ "version.bzl",
+ ],
+ visibility = ["//:__subpackages__"],
+)
filegroup(
name = "stardoc_rule_doc",
diff --git a/MODULE.bazel b/MODULE.bazel
index d344cba..5aca9ec 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -10,14 +10,24 @@ bazel_dep(name = "rules_jvm_external", version = "4.5")
bazel_dep(name = "rules_license", version = "0.0.7")
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
+# Maven artifacts required by Stardoc; keep consistent with deps.bzl
+STARDOC_MAVEN_ARTIFACTS = [
+ "com.beust:jcommander:1.82",
+ "com.google.escapevelocity:escapevelocity:1.1",
+ "com.google.guava:guava:31.1-jre",
+ "com.google.truth:truth:1.1.3",
+ "junit:junit:4.13.2",
+]
+
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
name = "stardoc_maven",
- # We don't yet specify the maven coordinates in the MODULE.bazel to avoid duplicating information.
- # Always respect the maven_install.json file generated by rules_jvm_external from the WORKSPACE file.
+ artifacts = STARDOC_MAVEN_ARTIFACTS,
+ fail_if_repin_required = True,
lock_file = "//:maven_install.json",
repositories = [
"https://repo1.maven.org/maven2",
],
+ strict_visibility = True,
)
use_repo(maven, "stardoc_maven")
diff --git a/deps.bzl b/deps.bzl
index 4d77a6b..65bf7b9 100644
--- a/deps.bzl
+++ b/deps.bzl
@@ -17,7 +17,7 @@
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@rules_jvm_external//:defs.bzl", "maven_install")
-# Maven artifacts required by Stardoc
+# Maven artifacts required by Stardoc; keep consistent with MODULE.bazel
STARDOC_MAVEN_ARTIFACTS = [
"com.beust:jcommander:1.82",
"com.google.escapevelocity:escapevelocity:1.1",
diff --git a/test/BUILD b/test/BUILD
index be7077f..c4f59e3 100644
--- a/test/BUILD
+++ b/test/BUILD
@@ -1,4 +1,5 @@
load(":stardoc_test.bzl", "self_gen_test", "stardoc_test")
+load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
package(default_applicable_licenses = ["//:license"])
@@ -281,3 +282,51 @@ sh_test(
"@local_repository_test//:output.md",
],
)
+
+# Consistency tests for WORKSPACE-related .bzl files vs. MODULE.bazel
+
+genrule(
+ name = "stardoc_maven_artifacts_in_deps_bzl",
+ srcs = ["//:deps.bzl"],
+ outs = ["stardoc_maven_artifacts_in_deps_bzl.txt"],
+ # Remove all lines except those from 'STARDOC_MAVEN_ARTIFACTS = [' to next ']'
+ cmd = "sed -e '/STARDOC_MAVEN_ARTIFACTS = \\[/,/\\]/!d' $< >$@",
+)
+
+genrule(
+ name = "stardoc_maven_artifacts_in_module_bazel",
+ srcs = ["//:MODULE.bazel"],
+ outs = ["stardoc_maven_artifacts_in_module_bazel.txt"],
+ # Remove all lines except those from 'STARDOC_MAVEN_ARTIFACTS = [' to next ']'
+ cmd = "sed -e '/STARDOC_MAVEN_ARTIFACTS = \\[/,/\\]/!d' $< >$@",
+)
+
+diff_test(
+ name = "stardoc_maven_artifacts_consistency_test",
+ failure_message = "STARDOC_MAVEN_ARTIFACTS in deps.bzl and MODULE.bazel are inconsistent",
+ file1 = "stardoc_maven_artifacts_in_deps_bzl",
+ file2 = "stardoc_maven_artifacts_in_module_bazel",
+)
+
+genrule(
+ name = "stardoc_version_in_version_bzl",
+ srcs = ["//:version.bzl"],
+ outs = ["stardoc_version_in_version_bzl.txt"],
+ # Find first line starting containing 'version = ' and extract the string value
+ cmd = "grep -m 1 'version = ' $< | sed -e 's/.*version = \\(\".*\"\\).*/\\1/' >$@",
+)
+
+genrule(
+ name = "stardoc_version_in_module_bazel",
+ srcs = ["//:MODULE.bazel"],
+ outs = ["stardoc_version_in_module_bazel.txt"],
+ # Find first line starting containing 'version = ' and extract the string value
+ cmd = "grep -m 1 'version = ' $< | sed -e 's/.*version = \\(\".*\"\\).*/\\1/' >$@",
+)
+
+diff_test(
+ name = "stardoc_version_consistency_test",
+ failure_message = "version in version.bzl and MODULE.bazel is inconsistent",
+ file1 = "stardoc_version_in_version_bzl",
+ file2 = "stardoc_version_in_module_bazel",
+)