Skip to content

Commit 291c2b0

Browse files
egithinjiEric Githinji
and
Eric Githinji
authored
Make install-tools command work from any directory in the workspace. (#2725)
This fixes #2708 by creating a CARGO_WORKSPACE_DIR env variable to act as an anchor path, allowing the installation of mdbook-exerciser and mdbook-course to succeed from any directory within the repository. Based on the approach mentioned here: rust-lang/cargo#3946 (comment) --------- Co-authored-by: Eric Githinji <[email protected]>
1 parent d0d8168 commit 291c2b0

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.cargo/config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
# We use this alias for task automation in the project.
33
# See README in xtask directory.
44
xtask = "run --package xtask --"
5+
6+
[env]
7+
# To provide an anchor to the root of the workspace when working with paths.
8+
# See https://github.com/rust-lang/cargo/issues/3946#issuecomment-973132993
9+
CARGO_WORKSPACE_DIR = { value = "", relative = true }

xtask/src/main.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
2222
use anyhow::{anyhow, Ok, Result};
2323
use clap::Parser;
24+
use std::path::Path;
2425
use std::{env, process::Command};
2526

2627
fn main() -> Result<()> {
@@ -54,6 +55,11 @@ fn execute_task() -> Result<()> {
5455
fn install_tools() -> Result<()> {
5556
println!("Installing project tools...");
5657

58+
let path_to_mdbook_exerciser =
59+
Path::new(env!("CARGO_WORKSPACE_DIR")).join("mdbook-exerciser");
60+
let path_to_mdbook_course =
61+
Path::new(env!("CARGO_WORKSPACE_DIR")).join("mdbook-course");
62+
5763
let install_args = vec![
5864
// The --locked flag is important for reproducible builds. It also
5965
// avoids breakage due to skews between mdbook and mdbook-svgbob.
@@ -62,9 +68,11 @@ fn install_tools() -> Result<()> {
6268
vec!["mdbook-pandoc", "--locked", "--version", "0.9.3"],
6369
vec!["mdbook-i18n-helpers", "--locked", "--version", "0.3.5"],
6470
vec!["i18n-report", "--locked", "--version", "0.2.0"],
65-
// These packages are located in this repository
66-
vec!["--path", "mdbook-exerciser", "--locked"],
67-
vec!["--path", "mdbook-course", "--locked"],
71+
// Mdbook-exerciser and mdbook-course are located in this repository.
72+
// To make it possible to install them from any directory we need to
73+
// specify their path from the workspace root.
74+
vec!["--path", path_to_mdbook_exerciser.to_str().unwrap(), "--locked"],
75+
vec!["--path", path_to_mdbook_course.to_str().unwrap(), "--locked"],
6876
];
6977

7078
for args in &install_args {

0 commit comments

Comments
 (0)