mirror of
https://github.com/rust-lang/rust.git
synced 2026-01-24 23:17:31 +00:00
Use yarn instead of npm in tidy
This commit is contained in:
@@ -38,7 +38,7 @@ path = [
|
||||
"triagebot.toml",
|
||||
"typos.toml",
|
||||
"package.json",
|
||||
"package-lock.json",
|
||||
"yarn.lock",
|
||||
"x",
|
||||
"x.ps1",
|
||||
"x.py",
|
||||
|
||||
@@ -315,12 +315,12 @@
|
||||
# target when running tests, otherwise this can be omitted.
|
||||
#build.nodejs = "node"
|
||||
|
||||
# The npm executable to use. Note that this is used for rustdoc-gui tests,
|
||||
# otherwise this can be omitted.
|
||||
# The yarn executable to use. Note that this is used for rustdoc-gui tests and
|
||||
# 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.
|
||||
#build.npm = "npm"
|
||||
#build.yarn = "yarn"
|
||||
|
||||
# Python interpreter to use for various tasks throughout the build, notably
|
||||
# rustdoc tests, and some dist bits and pieces.
|
||||
|
||||
2821
package-lock.json
generated
2821
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -73,10 +73,10 @@ build/
|
||||
node_modules/
|
||||
.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`.
|
||||
package.json
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
|
||||
# Output of the dist-related steps like dist-std, dist-rustc, and dist-docs
|
||||
dist/
|
||||
|
||||
@@ -1199,11 +1199,11 @@ impl Step for PlainSourceTarball {
|
||||
"bootstrap.example.toml",
|
||||
"configure",
|
||||
"license-metadata.json",
|
||||
"package-lock.json",
|
||||
"package.json",
|
||||
"x",
|
||||
"x.ps1",
|
||||
"x.py",
|
||||
"yarn.lock",
|
||||
// tidy-alphabetical-end
|
||||
];
|
||||
let src_dirs = ["src", "compiler", "library", "tests", "LICENSES"];
|
||||
|
||||
@@ -1074,11 +1074,17 @@ impl Step for RustdocJSNotStd {
|
||||
|
||||
fn get_browser_ui_test_version_inner(
|
||||
builder: &Builder<'_>,
|
||||
npm: &Path,
|
||||
yarn: &Path,
|
||||
global: bool,
|
||||
) -> Option<String> {
|
||||
let mut command = command(npm);
|
||||
command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
|
||||
let mut command = command(yarn);
|
||||
command
|
||||
.arg("--cwd")
|
||||
.arg(&builder.build.out)
|
||||
.arg("list")
|
||||
.arg("--parseable")
|
||||
.arg("--long")
|
||||
.arg("--depth=0");
|
||||
if global {
|
||||
command.arg("--global");
|
||||
}
|
||||
@@ -1089,9 +1095,9 @@ fn get_browser_ui_test_version_inner(
|
||||
.map(|v| v.to_owned())
|
||||
}
|
||||
|
||||
fn get_browser_ui_test_version(builder: &Builder<'_>, npm: &Path) -> Option<String> {
|
||||
get_browser_ui_test_version_inner(builder, npm, false)
|
||||
.or_else(|| get_browser_ui_test_version_inner(builder, npm, true))
|
||||
fn get_browser_ui_test_version(builder: &Builder<'_>, yarn: &Path) -> Option<String> {
|
||||
get_browser_ui_test_version_inner(builder, yarn, false)
|
||||
.or_else(|| get_browser_ui_test_version_inner(builder, yarn, true))
|
||||
}
|
||||
|
||||
/// Run GUI tests on a given rustdoc.
|
||||
@@ -1115,7 +1121,7 @@ impl Step for RustdocGUI {
|
||||
&& builder.doc_tests != DocTests::Only
|
||||
&& builder
|
||||
.config
|
||||
.npm
|
||||
.yarn
|
||||
.as_ref()
|
||||
.map(|p| get_browser_ui_test_version(builder, p).is_some())
|
||||
.unwrap_or(false)
|
||||
@@ -1178,8 +1184,8 @@ impl Step for RustdocGUI {
|
||||
cmd.arg("--nodejs").arg(nodejs);
|
||||
}
|
||||
|
||||
if let Some(ref npm) = builder.config.npm {
|
||||
cmd.arg("--npm").arg(npm);
|
||||
if let Some(ref yarn) = builder.config.yarn {
|
||||
cmd.arg("--yarn").arg(yarn);
|
||||
}
|
||||
|
||||
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
|
||||
});
|
||||
cmd.arg(jobs.to_string());
|
||||
// pass the path to the npm command used for installing js deps.
|
||||
if let Some(npm) = &builder.config.npm {
|
||||
cmd.arg(npm);
|
||||
// pass the path to the yarn command used for installing js deps.
|
||||
if let Some(yarn) = &builder.config.yarn {
|
||||
cmd.arg(yarn);
|
||||
} else {
|
||||
cmd.arg("npm");
|
||||
cmd.arg("yarn");
|
||||
}
|
||||
if builder.is_verbose() {
|
||||
cmd.arg("--verbose");
|
||||
|
||||
@@ -271,7 +271,7 @@ pub struct Config {
|
||||
pub mandir: Option<PathBuf>,
|
||||
pub codegen_tests: bool,
|
||||
pub nodejs: Option<PathBuf>,
|
||||
pub npm: Option<PathBuf>,
|
||||
pub yarn: Option<PathBuf>,
|
||||
pub gdb: Option<PathBuf>,
|
||||
pub lldb: Option<PathBuf>,
|
||||
pub python: Option<PathBuf>,
|
||||
@@ -462,6 +462,8 @@ impl Config {
|
||||
gdb: build_gdb,
|
||||
lldb: build_lldb,
|
||||
nodejs: build_nodejs,
|
||||
|
||||
yarn: build_yarn,
|
||||
npm: build_npm,
|
||||
python: build_python,
|
||||
windows_rc: build_windows_rc,
|
||||
@@ -831,6 +833,12 @@ impl Config {
|
||||
.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);
|
||||
|
||||
// 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),
|
||||
ninja_in_file: llvm_ninja.unwrap_or(true),
|
||||
nodejs: build_nodejs.map(PathBuf::from),
|
||||
npm: build_npm.map(PathBuf::from),
|
||||
omit_git_hash,
|
||||
on_fail: flags_on_fail,
|
||||
optimized_compiler_builtins,
|
||||
@@ -1468,6 +1475,7 @@ impl Config {
|
||||
vendor,
|
||||
verbose_tests,
|
||||
windows_rc: build_windows_rc.map(PathBuf::from),
|
||||
yarn: build_yarn.map(PathBuf::from),
|
||||
// tidy-alphabetical-end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ define_config! {
|
||||
gdb: Option<String> = "gdb",
|
||||
lldb: Option<String> = "lldb",
|
||||
nodejs: Option<String> = "nodejs",
|
||||
npm: Option<String> = "npm",
|
||||
npm: Option<String> = "npm", // unused, present for compatibility
|
||||
yarn: Option<String> = "yarn",
|
||||
python: Option<String> = "python",
|
||||
windows_rc: Option<String> = "windows-rc",
|
||||
reuse: Option<String> = "reuse",
|
||||
|
||||
@@ -185,12 +185,12 @@ than building it.
|
||||
.or_else(|| cmd_finder.maybe_have("node"))
|
||||
.or_else(|| cmd_finder.maybe_have("nodejs"));
|
||||
|
||||
build.config.npm = build
|
||||
build.config.yarn = build
|
||||
.config
|
||||
.npm
|
||||
.yarn
|
||||
.take()
|
||||
.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
|
||||
.config
|
||||
|
||||
@@ -586,4 +586,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
|
||||
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.",
|
||||
},
|
||||
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).",
|
||||
},
|
||||
];
|
||||
|
||||
@@ -3,10 +3,8 @@ use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::{fs, io};
|
||||
|
||||
use crate::ci::CiEnv;
|
||||
|
||||
/// 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 copy_to_build = |p| {
|
||||
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_to_build("package.json")?;
|
||||
copy_to_build("package-lock.json")?;
|
||||
copy_to_build("yarn.lock")?;
|
||||
|
||||
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 {
|
||||
let mut cmd = Command::new(yarn);
|
||||
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"]);
|
||||
// make sure our `yarn.lock` file actually means something
|
||||
cmd.arg("--frozen");
|
||||
|
||||
cmd.current_dir(out_dir);
|
||||
let exit_status = cmd.spawn()?.wait()?;
|
||||
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!(
|
||||
"npm install returned exit code {exit_status}"
|
||||
"yarn install returned exit code {exit_status}"
|
||||
))));
|
||||
}
|
||||
Ok(nm_path)
|
||||
|
||||
@@ -5,7 +5,7 @@ use getopts::Options;
|
||||
|
||||
pub(crate) struct Config {
|
||||
pub(crate) nodejs: PathBuf,
|
||||
pub(crate) npm: PathBuf,
|
||||
pub(crate) yarn: PathBuf,
|
||||
pub(crate) rust_src: PathBuf,
|
||||
pub(crate) out_dir: PathBuf,
|
||||
pub(crate) initial_cargo: PathBuf,
|
||||
@@ -21,7 +21,7 @@ impl Config {
|
||||
pub(crate) fn from_args(args: Vec<String>) -> Self {
|
||||
let mut opts = Options::new();
|
||||
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("", "rust-src", "root source of the rust source", "PATH")
|
||||
.reqopt(
|
||||
@@ -51,14 +51,14 @@ impl Config {
|
||||
eprintln!("`nodejs` was not provided. If not available, please install it");
|
||||
std::process::exit(1);
|
||||
};
|
||||
let Some(npm) = matches.opt_str("npm").map(PathBuf::from) else {
|
||||
eprintln!("`npm` was not provided. If not available, please install it");
|
||||
let Some(yarn) = matches.opt_str("yarn").map(PathBuf::from) else {
|
||||
eprintln!("`yarn` was not provided. If not available, please install it");
|
||||
std::process::exit(1);
|
||||
};
|
||||
|
||||
Self {
|
||||
nodejs,
|
||||
npm,
|
||||
yarn,
|
||||
rust_src: matches.opt_str("rust-src").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(),
|
||||
|
||||
@@ -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");
|
||||
|
||||
let mut command = Command::new(&config.nodejs);
|
||||
|
||||
Reference in New Issue
Block a user