Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ Both module attributes are optional. `module_name` defaults to the target name.
`module_path` defaults to the target's full Bazel package path, preserving
nested project structure; a target in the root package falls back to its target
name. Use either attribute to override its derived value. Module paths must be
portable relative paths and unique within an aggregate. Only HTML `dokka`
targets can be aggregated.
portable relative paths, unique within an aggregate, and must not collide with
Dokka's root assets or index files. Only HTML `dokka` targets can be aggregated.

The aggregate rule uses the same precedence and consumes the selected
configuration's `offline_mode`, `plugins`, and `plugins_configuration` settings.
Expand Down
18 changes: 18 additions & 0 deletions dokka/private/multi_module.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
load(":providers.bzl", "DokkaConfigInfo", "DokkaInfo")

_DOKKA_TOOLCHAIN_TYPE = Label("//dokka:toolchain_type")
_DOKKA_RESERVED_ROOT_ENTRIES = [
"images",
"index.html",
"navigation.html",
"package-list",
"scripts",
"styles",
"ui-kit",
]
_WINDOWS_INVALID_PATH_CHARACTERS = ["<", ">", ":", "\"", "|", "?", "*"]

def _validate_module_path(module_path, label):
Expand All @@ -27,6 +36,15 @@ def _validate_module_path(module_path, label):
).format(label, module_path),
)

root_entry = segments[0].lower()
if root_entry in _DOKKA_RESERVED_ROOT_ENTRIES:
fail(
(
"Dokka target {} has invalid module_path '{}': first segment '{}' is reserved " +
"by Dokka's aggregate output."
).format(label, module_path, segments[0]),
)

def _dokka_multi_module_impl(ctx):
modules = []
module_paths = {}
Expand Down
13 changes: 13 additions & 0 deletions tests/rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ dokka(
tags = ["manual"],
)

dokka(
name = "reserved_module_path_fixture",
srcs = ["Fixture.kt"],
module_path = "scripts/api",
tags = ["manual"],
)

dokka_multi_module(
name = "multi_module_fixture",
config = ":shared_config",
Expand Down Expand Up @@ -135,6 +142,12 @@ dokka_multi_module(
tags = ["manual"],
)

dokka_multi_module(
name = "reserved_path_aggregate_fixture",
modules = [":reserved_module_path_fixture"],
tags = ["manual"],
)

dokka_multi_module(
name = "non_html_aggregate_fixture",
modules = [":analysis_fixture"],
Expand Down
14 changes: 14 additions & 0 deletions tests/rules/dokka_analysis_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ def _invalid_module_path_test_impl(ctx):
asserts.expect_failure(env, "has invalid module_path '../invalid'")
return analysistest.end(env)

def _reserved_module_path_test_impl(ctx):
env = analysistest.begin(ctx)
asserts.expect_failure(env, "first segment 'scripts' is reserved")
return analysistest.end(env)

def _non_html_module_test_impl(ctx):
env = analysistest.begin(ctx)
asserts.expect_failure(env, "only accepts HTML `dokka` targets")
Expand All @@ -405,6 +410,10 @@ _invalid_module_path_test = analysistest.make(
_invalid_module_path_test_impl,
expect_failure = True,
)
_reserved_module_path_test = analysistest.make(
_reserved_module_path_test_impl,
expect_failure = True,
)
_non_html_module_test = analysistest.make(
_non_html_module_test_impl,
expect_failure = True,
Expand Down Expand Up @@ -444,6 +453,10 @@ def dokka_analysis_test_suite(name):
name = name + "_invalid_module_path",
target_under_test = ":invalid_path_aggregate_fixture",
)
_reserved_module_path_test(
name = name + "_reserved_module_path",
target_under_test = ":reserved_path_aggregate_fixture",
)
_non_html_module_test(
name = name + "_non_html_module",
target_under_test = ":non_html_aggregate_fixture",
Expand All @@ -458,6 +471,7 @@ def dokka_analysis_test_suite(name):
":" + name + "_invalid_module_path",
":" + name + "_multi_module",
":" + name + "_non_html_module",
":" + name + "_reserved_module_path",
":" + name + "_reusable_config",
],
)