diff --git a/BUILD.bazel b/BUILD.bazel index be5d222..b5cc00c 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,4 +1,3 @@ -load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test") load( "@rules_java//toolchains:default_java_toolchain.bzl", "DEFAULT_TOOLCHAIN_CONFIGURATION", @@ -13,12 +12,3 @@ default_java_toolchain( source_version = "21", target_version = "21", ) - -buildifier( - name = "buildifier", -) - -buildifier_test( - name = "buildifier_check", - mode = "check", -) diff --git a/MODULE.bazel b/MODULE.bazel index a2690f2..434dc26 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,9 +1,13 @@ module(name = "rules_twirl") bazel_dep(name = "bazel_skylib", version = "1.7.1") -bazel_dep(name = "buildifier_prebuilt", version = "7.3.1") + +bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True) + bazel_dep(name = "rules_java", version = "7.11.1") -bazel_dep(name = "rules_pkg", version = "1.0.1") + +bazel_dep(name = "rules_pkg", version = "1.0.1", dev_dependency = True) + bazel_dep(name = "rules_jvm_external", version = "6.4") bazel_dep(name = "rules_scala_annex") @@ -16,7 +20,7 @@ archive_override( urls = ["https://github.com/lucidsoftware/rules_scala/archive/refs/tags/{}.zip".format(rules_scala_annex_version)], ) -bazel_dep(name = "stardoc", version = "0.7.1") +bazel_dep(name = "stardoc", version = "0.7.1", dev_dependency = True) register_toolchains( "//:repository_default_toolchain_21_definition", diff --git a/dev/BUILD.bazel b/dev/BUILD.bazel new file mode 100644 index 0000000..f003367 --- /dev/null +++ b/dev/BUILD.bazel @@ -0,0 +1,10 @@ +load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test") + +buildifier( + name = "buildifier", +) + +buildifier_test( + name = "buildifier_check", + mode = "check", +) diff --git a/dev/stardoc/BUILD.bazel b/dev/stardoc/BUILD.bazel new file mode 100644 index 0000000..c2e1e5c --- /dev/null +++ b/dev/stardoc/BUILD.bazel @@ -0,0 +1,29 @@ +# Borrowed from lucidsoftware/rules_scala + +load("@bazel_skylib//lib:paths.bzl", "paths") +load("@rules_pkg//pkg:pkg.bzl", "pkg_tar") +load("@stardoc//stardoc:stardoc.bzl", "stardoc") + +bzl_files = ["//twirl:twirl.bzl"] + +[ + stardoc( + name = paths.replace_extension(file, "_doc").removeprefix("//twirl:").replace("/", "_"), + out = paths.replace_extension(file, ".md").removeprefix("//twirl:").replace("/", "_"), + input = file, + symbol_names = ["twirl_templates"], + deps = [ + "//twirl:bzl_internal", + ], + ) + for file in bzl_files +] + +pkg_tar( + name = "docs", + srcs = [ + paths.replace_extension(file, ".md").removeprefix("//twirl:").replace("/", "_") + for file in bzl_files + ], + mode = "0644", +) diff --git a/scripts/format.sh b/scripts/format.sh index f20b051..7dcd629 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -3,7 +3,7 @@ set -euo pipefail if [ "$#" -eq 0 ] || [ "$1" != check ]; then - bazel run buildifier + bazel run //dev:buildifier else - bazel run buildifier_check + bazel run //dev:buildifier_check fi diff --git a/scripts/gen-docs.sh b/scripts/gen-docs.sh index 74f7f2e..905ec2a 100755 --- a/scripts/gen-docs.sh +++ b/scripts/gen-docs.sh @@ -2,7 +2,7 @@ # # Regenerates stardoc for the rules # -# Borrowed from higherkindness/rules_scala +# Borrowed from lucidsoftware/rules_scala # set -euxo pipefail @@ -11,8 +11,8 @@ cd "$(dirname "$0")/.." rm -fr docs/stardoc mkdir -p docs/stardoc -bazel build twirl:docs -tar xf "$(bazel info bazel-bin)/twirl/docs.tar" -C docs/stardoc +bazel build //dev/stardoc:docs +tar xf "$(bazel info bazel-bin)/dev/stardoc/docs.tar" -C docs/stardoc find docs/stardoc -size 0 -print0 | while read path; do rm $path done diff --git a/twirl/BUILD.bazel b/twirl/BUILD.bazel index 140c02a..32f571e 100644 --- a/twirl/BUILD.bazel +++ b/twirl/BUILD.bazel @@ -1,29 +1,8 @@ -# Borrowed from higherkindness/rules_scala +# Borrowed from lucidsoftware/rules_scala load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("@bazel_skylib//lib:paths.bzl", "paths") -load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes") -load("@rules_pkg//pkg:tar.bzl", "pkg_tar") -load("@stardoc//stardoc:stardoc.bzl", "stardoc") -[ - stardoc( - name = paths.replace_extension(file, "_doc").replace("/", "_"), - out = paths.replace_extension(file, ".md").replace("/", "_"), - input = file, - symbol_names = ["twirl_templates"], - deps = [ - "//twirl:bzl_internal", - ], - ) - for file in glob(["**/*.bzl"]) -] - -pkg_tar( - name = "docs", - srcs = [paths.replace_extension(file, ".md").replace("/", "_") for file in glob(["**/*.bzl"])], - mode = "0644", -) +exports_files(["twirl.bzl"]) bzl_library( name = "bzl_internal",