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
24 changes: 18 additions & 6 deletions extensions/mdbook/private/mdbook.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def _map_inputs(file):
def _mdbook_impl(ctx):
output = ctx.actions.declare_directory(ctx.label.name)

book = ctx.file.book
if book == None:
book = ctx.actions.declare_file("{}.book.toml".format(ctx.label.name))
ctx.actions.write(
output = book,
content = "",
)

toolchain = ctx.toolchains["@rules_rust_mdbook//:toolchain_type"]

plugin_paths = depset([
Expand All @@ -33,7 +41,7 @@ def _mdbook_impl(ctx):
path_sep = ";" if is_windows else ":"
plugin_path = path_sep.join(plugin_paths.to_list())

inputs = depset([ctx.file.book] + ctx.files.srcs)
inputs = depset([book] + ctx.files.srcs)

inputs_map_args = ctx.actions.args()
inputs_map_args.use_param_file("%s", use_always = True)
Expand All @@ -45,7 +53,8 @@ def _mdbook_impl(ctx):
args.add(output.path)
args.add(toolchain.mdbook)
args.add("build")
args.add("${{pwd}}/{}".format(ctx.file.book.dirname))
book_dir = "/".join(_src_dest_path(book).split("/")[:-1])
args.add("${{pwd}}/{}".format(book_dir))

ctx.actions.run(
mnemonic = "MdBookBuild",
Expand All @@ -64,7 +73,7 @@ def _mdbook_impl(ctx):
),
MdBookInfo(
srcs = depset(ctx.files.srcs),
config = ctx.file.book,
config = book,
plugins = depset(ctx.files.plugins),
),
]
Expand All @@ -74,9 +83,11 @@ mdbook = rule(
doc = "Rules to create book from markdown files using `mdBook`.",
attrs = {
"book": attr.label(
doc = "The `book.toml` file.",
doc = (
"The optional `book.toml` file. An empty default configuration is " +
"used when omitted."
),
allow_single_file = ["book.toml"],
mandatory = True,
),
"plugins": attr.label_list(
doc = (
Expand Down Expand Up @@ -121,7 +132,8 @@ def _mdbook_server_impl(ctx):
workspace_name = ctx.workspace_name

args.add("--mdbook={}".format(_rlocationpath(toolchain.mdbook, workspace_name)))
args.add("--config={}".format(_src_dest_path(book_info.config)))
config_dest = _src_dest_path(book_info.config)
args.add("--config={}".format(config_dest))
args.add("--hostname={}".format(ctx.attr.hostname))
args.add("--port={}".format(ctx.attr.port))

Expand Down
12 changes: 12 additions & 0 deletions extensions/mdbook/test/default_config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//:defs.bzl", "mdbook")

mdbook(
name = "default_config",
srcs = glob(["src/**/*.md"]),
)

build_test(
name = "default_config_test",
targets = [":default_config"],
)
3 changes: 3 additions & 0 deletions extensions/mdbook/test/default_config/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Summary

- [Chapter 1](./chapter_1.md)
3 changes: 3 additions & 0 deletions extensions/mdbook/test/default_config/src/chapter_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Chapter 1

This book uses mdBook's default configuration.
Loading