Use yarn instead of npm in tidy

This commit is contained in:
binarycat 2025-11-07 14:20:20 -06:00 committed by Yotam Ofek
parent 89fe96197d
commit 8acea59362
14 changed files with 1980 additions and 2871 deletions

View file

@ -38,7 +38,7 @@ path = [
"triagebot.toml", "triagebot.toml",
"typos.toml", "typos.toml",
"package.json", "package.json",
"package-lock.json", "yarn.lock",
"x", "x",
"x.ps1", "x.ps1",
"x.py", "x.py",

View file

@ -315,12 +315,12 @@
# target when running tests, otherwise this can be omitted. # target when running tests, otherwise this can be omitted.
#build.nodejs = "node" #build.nodejs = "node"
# The npm executable to use. Note that this is used for rustdoc-gui tests, # The yarn executable to use. Note that this is used for rustdoc-gui tests and
# otherwise this can be omitted. # tidy js extra-checks, otherwise this can be omitted.
# #
# Under Windows this should be `npm.cmd` or path to it (verified on nodejs v18.06), or # Under Windows this should be `yarn.cmd` or path to it (verified on nodejs v18.06), or
# error will be emitted. # error will be emitted.
#build.npm = "npm" #build.yarn = "yarn"
# Python interpreter to use for various tasks throughout the build, notably # Python interpreter to use for various tasks throughout the build, notably
# rustdoc tests, and some dist bits and pieces. # rustdoc tests, and some dist bits and pieces.

2821
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -73,10 +73,10 @@ build/
node_modules/ node_modules/
.bin/ .bin/
# Copy of package.json and package-lock.json, because npm requires these # Copy of package.json and yarn.lock, because yarn requires these
# to be in the same directory as `node_modules`. # to be in the same directory as `node_modules`.
package.json package.json
package-lock.json yarn.lock
# Output of the dist-related steps like dist-std, dist-rustc, and dist-docs # Output of the dist-related steps like dist-std, dist-rustc, and dist-docs
dist/ dist/

View file

@ -1199,11 +1199,11 @@ impl Step for PlainSourceTarball {
"bootstrap.example.toml", "bootstrap.example.toml",
"configure", "configure",
"license-metadata.json", "license-metadata.json",
"package-lock.json",
"package.json", "package.json",
"x", "x",
"x.ps1", "x.ps1",
"x.py", "x.py",
"yarn.lock",
// tidy-alphabetical-end // tidy-alphabetical-end
]; ];
let src_dirs = ["src", "compiler", "library", "tests", "LICENSES"]; let src_dirs = ["src", "compiler", "library", "tests", "LICENSES"];

View file

@ -1074,11 +1074,17 @@ impl Step for RustdocJSNotStd {
fn get_browser_ui_test_version_inner( fn get_browser_ui_test_version_inner(
builder: &Builder<'_>, builder: &Builder<'_>,
npm: &Path, yarn: &Path,
global: bool, global: bool,
) -> Option<String> { ) -> Option<String> {
let mut command = command(npm); let mut command = command(yarn);
command.arg("list").arg("--parseable").arg("--long").arg("--depth=0"); command
.arg("--cwd")
.arg(&builder.build.out)
.arg("list")
.arg("--parseable")
.arg("--long")
.arg("--depth=0");
if global { if global {
command.arg("--global"); command.arg("--global");
} }
@ -1089,9 +1095,9 @@ fn get_browser_ui_test_version_inner(
.map(|v| v.to_owned()) .map(|v| v.to_owned())
} }
fn get_browser_ui_test_version(builder: &Builder<'_>, npm: &Path) -> Option<String> { fn get_browser_ui_test_version(builder: &Builder<'_>, yarn: &Path) -> Option<String> {
get_browser_ui_test_version_inner(builder, npm, false) get_browser_ui_test_version_inner(builder, yarn, false)
.or_else(|| get_browser_ui_test_version_inner(builder, npm, true)) .or_else(|| get_browser_ui_test_version_inner(builder, yarn, true))
} }
/// Run GUI tests on a given rustdoc. /// Run GUI tests on a given rustdoc.
@ -1115,7 +1121,7 @@ impl Step for RustdocGUI {
&& builder.doc_tests != DocTests::Only && builder.doc_tests != DocTests::Only
&& builder && builder
.config .config
.npm .yarn
.as_ref() .as_ref()
.map(|p| get_browser_ui_test_version(builder, p).is_some()) .map(|p| get_browser_ui_test_version(builder, p).is_some())
.unwrap_or(false) .unwrap_or(false)
@ -1178,8 +1184,8 @@ impl Step for RustdocGUI {
cmd.arg("--nodejs").arg(nodejs); cmd.arg("--nodejs").arg(nodejs);
} }
if let Some(ref npm) = builder.config.npm { if let Some(ref yarn) = builder.config.yarn {
cmd.arg("--npm").arg(npm); cmd.arg("--yarn").arg(yarn);
} }
let _time = helpers::timeit(builder); let _time = helpers::timeit(builder);
@ -1222,11 +1228,11 @@ impl Step for Tidy {
8 * std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32 8 * std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32
}); });
cmd.arg(jobs.to_string()); cmd.arg(jobs.to_string());
// pass the path to the npm command used for installing js deps. // pass the path to the yarn command used for installing js deps.
if let Some(npm) = &builder.config.npm { if let Some(yarn) = &builder.config.yarn {
cmd.arg(npm); cmd.arg(yarn);
} else { } else {
cmd.arg("npm"); cmd.arg("yarn");
} }
if builder.is_verbose() { if builder.is_verbose() {
cmd.arg("--verbose"); cmd.arg("--verbose");

View file

@ -271,7 +271,7 @@ pub struct Config {
pub mandir: Option<PathBuf>, pub mandir: Option<PathBuf>,
pub codegen_tests: bool, pub codegen_tests: bool,
pub nodejs: Option<PathBuf>, pub nodejs: Option<PathBuf>,
pub npm: Option<PathBuf>, pub yarn: Option<PathBuf>,
pub gdb: Option<PathBuf>, pub gdb: Option<PathBuf>,
pub lldb: Option<PathBuf>, pub lldb: Option<PathBuf>,
pub python: Option<PathBuf>, pub python: Option<PathBuf>,
@ -462,6 +462,8 @@ impl Config {
gdb: build_gdb, gdb: build_gdb,
lldb: build_lldb, lldb: build_lldb,
nodejs: build_nodejs, nodejs: build_nodejs,
yarn: build_yarn,
npm: build_npm, npm: build_npm,
python: build_python, python: build_python,
windows_rc: build_windows_rc, windows_rc: build_windows_rc,
@ -831,6 +833,12 @@ impl Config {
.to_owned(); .to_owned();
} }
if build_npm.is_some() {
println!(
"WARNING: `build.npm` set in bootstrap.toml, this option no longer has any effect. . Use `build.yarn` instead to provide a path to a `yarn` binary."
);
}
let mut lld_enabled = rust_lld_enabled.unwrap_or(false); let mut lld_enabled = rust_lld_enabled.unwrap_or(false);
// Linux targets for which the user explicitly overrode the used linker // Linux targets for which the user explicitly overrode the used linker
@ -1382,7 +1390,6 @@ impl Config {
musl_root: rust_musl_root.map(PathBuf::from), musl_root: rust_musl_root.map(PathBuf::from),
ninja_in_file: llvm_ninja.unwrap_or(true), ninja_in_file: llvm_ninja.unwrap_or(true),
nodejs: build_nodejs.map(PathBuf::from), nodejs: build_nodejs.map(PathBuf::from),
npm: build_npm.map(PathBuf::from),
omit_git_hash, omit_git_hash,
on_fail: flags_on_fail, on_fail: flags_on_fail,
optimized_compiler_builtins, optimized_compiler_builtins,
@ -1468,6 +1475,7 @@ impl Config {
vendor, vendor,
verbose_tests, verbose_tests,
windows_rc: build_windows_rc.map(PathBuf::from), windows_rc: build_windows_rc.map(PathBuf::from),
yarn: build_yarn.map(PathBuf::from),
// tidy-alphabetical-end // tidy-alphabetical-end
} }
} }

View file

@ -35,7 +35,8 @@ define_config! {
gdb: Option<String> = "gdb", gdb: Option<String> = "gdb",
lldb: Option<String> = "lldb", lldb: Option<String> = "lldb",
nodejs: Option<String> = "nodejs", nodejs: Option<String> = "nodejs",
npm: Option<String> = "npm", npm: Option<String> = "npm", // unused, present for compatibility
yarn: Option<String> = "yarn",
python: Option<String> = "python", python: Option<String> = "python",
windows_rc: Option<String> = "windows-rc", windows_rc: Option<String> = "windows-rc",
reuse: Option<String> = "reuse", reuse: Option<String> = "reuse",

View file

@ -185,12 +185,12 @@ than building it.
.or_else(|| cmd_finder.maybe_have("node")) .or_else(|| cmd_finder.maybe_have("node"))
.or_else(|| cmd_finder.maybe_have("nodejs")); .or_else(|| cmd_finder.maybe_have("nodejs"));
build.config.npm = build build.config.yarn = build
.config .config
.npm .yarn
.take() .take()
.map(|p| cmd_finder.must_have(p)) .map(|p| cmd_finder.must_have(p))
.or_else(|| cmd_finder.maybe_have("npm")); .or_else(|| cmd_finder.maybe_have("yarn"));
build.config.gdb = build build.config.gdb = build
.config .config

View file

@ -586,4 +586,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Warning, severity: ChangeSeverity::Warning,
summary: "Flags from `*FLAGS*` (such as `RUSTFLAGS`) env. vars. now have precedence over rustflags set by bootstrap. Before, it was the other way around.", summary: "Flags from `*FLAGS*` (such as `RUSTFLAGS`) env. vars. now have precedence over rustflags set by bootstrap. Before, it was the other way around.",
}, },
ChangeInfo {
change_id: 148763,
severity: ChangeSeverity::Info,
summary: "`yarn` is now used instead of `npm` to install dependencies for some extra tidy checks. Use `build.yarn` to manually specify the path to `yarn` (`build.npm` is no longer used).",
},
]; ];

View file

@ -3,10 +3,8 @@ use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use std::{fs, io}; use std::{fs, io};
use crate::ci::CiEnv;
/// Install all the npm deps, and return the path of `node_modules`. /// Install all the npm deps, and return the path of `node_modules`.
pub fn install(src_root_path: &Path, out_dir: &Path, npm: &Path) -> Result<PathBuf, io::Error> { pub fn install(src_root_path: &Path, out_dir: &Path, yarn: &Path) -> Result<PathBuf, io::Error> {
let nm_path = out_dir.join("node_modules"); let nm_path = out_dir.join("node_modules");
let copy_to_build = |p| { let copy_to_build = |p| {
fs::copy(src_root_path.join(p), out_dir.join(p)).map_err(|e| { fs::copy(src_root_path.join(p), out_dir.join(p)).map_err(|e| {
@ -16,25 +14,19 @@ pub fn install(src_root_path: &Path, out_dir: &Path, npm: &Path) -> Result<PathB
}; };
// copy stuff to the output directory to make node_modules get put there. // copy stuff to the output directory to make node_modules get put there.
copy_to_build("package.json")?; copy_to_build("package.json")?;
copy_to_build("package-lock.json")?; copy_to_build("yarn.lock")?;
let mut cmd = Command::new(yarn);
cmd.arg("install");
// make sure our `yarn.lock` file actually means something
cmd.arg("--frozen");
let mut cmd = Command::new(npm);
if CiEnv::is_ci() {
// `npm ci` redownloads every time and thus is too slow for local development.
cmd.arg("ci");
} else {
cmd.arg("install");
}
// disable a bunch of things we don't want.
// this makes tidy output less noisy, and also significantly improves runtime
// of repeated tidy invocations.
cmd.args(&["--audit=false", "--save=false", "--fund=false"]);
cmd.current_dir(out_dir); cmd.current_dir(out_dir);
let exit_status = cmd.spawn()?.wait()?; let exit_status = cmd.spawn()?.wait()?;
if !exit_status.success() { if !exit_status.success() {
eprintln!("npm install did not exit successfully"); eprintln!("yarn install did not exit successfully");
return Err(io::Error::other(Box::<dyn Error + Send + Sync>::from(format!( return Err(io::Error::other(Box::<dyn Error + Send + Sync>::from(format!(
"npm install returned exit code {exit_status}" "yarn install returned exit code {exit_status}"
)))); ))));
} }
Ok(nm_path) Ok(nm_path)

View file

@ -5,7 +5,7 @@ use getopts::Options;
pub(crate) struct Config { pub(crate) struct Config {
pub(crate) nodejs: PathBuf, pub(crate) nodejs: PathBuf,
pub(crate) npm: PathBuf, pub(crate) yarn: PathBuf,
pub(crate) rust_src: PathBuf, pub(crate) rust_src: PathBuf,
pub(crate) out_dir: PathBuf, pub(crate) out_dir: PathBuf,
pub(crate) initial_cargo: PathBuf, pub(crate) initial_cargo: PathBuf,
@ -21,7 +21,7 @@ impl Config {
pub(crate) fn from_args(args: Vec<String>) -> Self { pub(crate) fn from_args(args: Vec<String>) -> Self {
let mut opts = Options::new(); let mut opts = Options::new();
opts.optopt("", "nodejs", "absolute path of nodejs", "PATH") opts.optopt("", "nodejs", "absolute path of nodejs", "PATH")
.optopt("", "npm", "absolute path of npm", "PATH") .optopt("", "yarn", "absolute path of yarn", "PATH")
.reqopt("", "out-dir", "output path of doc compilation", "PATH") .reqopt("", "out-dir", "output path of doc compilation", "PATH")
.reqopt("", "rust-src", "root source of the rust source", "PATH") .reqopt("", "rust-src", "root source of the rust source", "PATH")
.reqopt( .reqopt(
@ -51,14 +51,14 @@ impl Config {
eprintln!("`nodejs` was not provided. If not available, please install it"); eprintln!("`nodejs` was not provided. If not available, please install it");
std::process::exit(1); std::process::exit(1);
}; };
let Some(npm) = matches.opt_str("npm").map(PathBuf::from) else { let Some(yarn) = matches.opt_str("yarn").map(PathBuf::from) else {
eprintln!("`npm` was not provided. If not available, please install it"); eprintln!("`yarn` was not provided. If not available, please install it");
std::process::exit(1); std::process::exit(1);
}; };
Self { Self {
nodejs, nodejs,
npm, yarn,
rust_src: matches.opt_str("rust-src").map(PathBuf::from).unwrap(), rust_src: matches.opt_str("rust-src").map(PathBuf::from).unwrap(),
out_dir: matches.opt_str("out-dir").map(PathBuf::from).unwrap(), out_dir: matches.opt_str("out-dir").map(PathBuf::from).unwrap(),
initial_cargo: matches.opt_str("initial-cargo").map(PathBuf::from).unwrap(), initial_cargo: matches.opt_str("initial-cargo").map(PathBuf::from).unwrap(),

View file

@ -59,7 +59,7 @@ fn main() -> Result<(), ()> {
} }
} }
let local_node_modules = npm::install(&config.rust_src, &config.out_dir, &config.npm) let local_node_modules = npm::install(&config.rust_src, &config.out_dir, &config.yarn)
.expect("unable to install browser-ui-test"); .expect("unable to install browser-ui-test");
let mut command = Command::new(&config.nodejs); let mut command = Command::new(&config.nodejs);

1918
yarn.lock Normal file

File diff suppressed because it is too large Load diff