Skip to content

Commit 01da420

Browse files
authored
Merge pull request #2792 from ehuss/remove-relative-renderer-command
Remove legacy relative renderer command paths
2 parents 534725c + df037d1 commit 01da420

File tree

2 files changed

+7
-51
lines changed

2 files changed

+7
-51
lines changed

crates/mdbook-driver/src/builtin_renderers/mod.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl CmdRenderer {
5050
CmdRenderer { name, cmd }
5151
}
5252

53-
fn compose_command(&self, root: &Path, destination: &Path) -> Result<Command> {
53+
fn compose_command(&self, root: &Path) -> Result<Command> {
5454
let mut words = Shlex::new(&self.cmd);
5555
let exe = match words.next() {
5656
Some(e) => PathBuf::from(e),
@@ -61,30 +61,8 @@ impl CmdRenderer {
6161
// Search PATH for the executable.
6262
exe
6363
} else {
64-
// Relative paths are preferred to be relative to the book root.
65-
let abs_exe = root.join(&exe);
66-
if abs_exe.exists() {
67-
abs_exe
68-
} else {
69-
// Historically paths were relative to the destination, but
70-
// this is not the preferred way.
71-
let legacy_path = destination.join(&exe);
72-
if legacy_path.exists() {
73-
warn!(
74-
"Renderer command `{}` uses a path relative to the \
75-
renderer output directory `{}`. This was previously \
76-
accepted, but has been deprecated. Relative executable \
77-
paths should be relative to the book root.",
78-
exe.display(),
79-
destination.display()
80-
);
81-
legacy_path
82-
} else {
83-
// Let this bubble through to later be handled by
84-
// handle_render_command_error.
85-
abs_exe
86-
}
87-
}
64+
// Relative path is relative to book root.
65+
root.join(&exe)
8866
};
8967

9068
let mut cmd = Command::new(exe);
@@ -143,7 +121,7 @@ impl Renderer for CmdRenderer {
143121
let _ = fs::create_dir_all(&ctx.destination);
144122

145123
let mut child = match self
146-
.compose_command(&ctx.root, &ctx.destination)?
124+
.compose_command(&ctx.root)?
147125
.stdin(Stdio::piped())
148126
.stdout(Stdio::inherit())
149127
.stderr(Stdio::inherit())

tests/testsuite/renderer.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,10 @@ fn backends_receive_render_context_via_stdin() {
211211
RenderContext::from_json(f).unwrap();
212212
}
213213

214-
// Legacy relative renderer paths.
215-
//
216-
// https://github.com/rust-lang/mdBook/pull/1418
214+
// Verifies that a relative path for the renderer command is relative to the
215+
// book root.
217216
#[test]
218-
fn legacy_relative_command_path() {
217+
fn relative_command_path() {
219218
let mut test = BookTest::init(|_| {});
220219
test.rust_program(
221220
"renderers/myrenderer",
@@ -228,7 +227,6 @@ fn legacy_relative_command_path() {
228227
}
229228
"#,
230229
)
231-
// Test with a modern path, relative to the book directory.
232230
.change_file(
233231
"book.toml",
234232
"[output.myrenderer]\n\
@@ -240,26 +238,6 @@ fn legacy_relative_command_path() {
240238
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the myrenderer backend
241239
[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "myrenderer" renderer
242240
243-
"#]]);
244-
})
245-
.check_file("book/output", "test");
246-
std::fs::remove_file(test.dir.join("book/output")).unwrap();
247-
// Test with legacy path, relative to the output directory.
248-
test.change_file(
249-
"book.toml",
250-
&format!(
251-
"[output.myrenderer]\n\
252-
command = '../renderers/myrenderer{exe}'\n",
253-
exe = std::env::consts::EXE_SUFFIX
254-
),
255-
)
256-
.run("build", |cmd| {
257-
cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
258-
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
259-
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the myrenderer backend
260-
[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "myrenderer" renderer
261-
[TIMESTAMP] [WARN] (mdbook_driver::builtin_renderers): Renderer command `../renderers/myrenderer[EXE]` uses a path relative to the renderer output directory `[ROOT]/book`. This was previously accepted, but has been deprecated. Relative executable paths should be relative to the book root.
262-
263241
"#]]);
264242
})
265243
.check_file("book/output", "test");

0 commit comments

Comments
 (0)