Skip to content

Make install-tools command work from any directory in the workspace. #2725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
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
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
# We use this alias for task automation in the project.
# See README in xtask directory.
xtask = "run --package xtask --"

[env]
# To provide an anchor to the root of the workspace when working with paths.
# See https://github.com/rust-lang/cargo/issues/3946#issuecomment-973132993
CARGO_WORKSPACE_DIR = { value = "", relative = true }
14 changes: 11 additions & 3 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use anyhow::{anyhow, Ok, Result};
use clap::Parser;
use std::path::Path;
use std::{env, process::Command};

fn main() -> Result<()> {
Expand Down Expand Up @@ -54,6 +55,11 @@ fn execute_task() -> Result<()> {
fn install_tools() -> Result<()> {
println!("Installing project tools...");

let path_to_mdbook_exerciser =
Path::new(env!("CARGO_WORKSPACE_DIR")).join("mdbook-exerciser");
let path_to_mdbook_course =
Path::new(env!("CARGO_WORKSPACE_DIR")).join("mdbook-course");

let install_args = vec![
// The --locked flag is important for reproducible builds. It also
// avoids breakage due to skews between mdbook and mdbook-svgbob.
Expand All @@ -62,9 +68,11 @@ fn install_tools() -> Result<()> {
vec!["mdbook-pandoc", "--locked", "--version", "0.9.3"],
vec!["mdbook-i18n-helpers", "--locked", "--version", "0.3.5"],
vec!["i18n-report", "--locked", "--version", "0.2.0"],
// These packages are located in this repository
vec!["--path", "mdbook-exerciser", "--locked"],
vec!["--path", "mdbook-course", "--locked"],
// Mdbook-exerciser and mdbook-course are located in this repository.
// To make it possible to install them from any directory we need to
// specify their path from the workspace root.
vec!["--path", path_to_mdbook_exerciser.to_str().unwrap(), "--locked"],
vec!["--path", path_to_mdbook_course.to_str().unwrap(), "--locked"],
];

for args in &install_args {
Expand Down