1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-06 01:27:27 +02:00

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:
https://github.com/rust-lang/cargo/issues/3946#issuecomment-973132993

---------

Co-authored-by: Eric Githinji <egithinji@google.com>
This commit is contained in:
Eric Githinji 2025-05-06 09:55:55 +03:00 committed by GitHub
parent d0d8168c56
commit 291c2b08e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -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 }

View File

@ -21,6 +21,7 @@
use anyhow::{anyhow, Ok, Result};
use clap::Parser;
use std::path::Path;
use std::{env, process::Command};
fn main() -> Result<()> {
@ -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.
@ -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 {