Skip to content

Commit 56e43c3

Browse files
committed
⬆️ xshell
1 parent 5e85158 commit 56e43c3

File tree

14 files changed

+247
-212
lines changed

14 files changed

+247
-212
lines changed

Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide_db/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ limit = { path = "../limit", version = "0.0.0" }
3535
[dev-dependencies]
3636
test_utils = { path = "../test_utils" }
3737
sourcegen = { path = "../sourcegen" }
38-
xshell = "0.1"
38+
xshell = "0.2.0"
3939
expect-test = "1.2.0-pre.1"

crates/ide_db/src/tests/sourcegen_lints.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ use std::{borrow::Cow, fs, path::Path};
44
use itertools::Itertools;
55
use stdx::format_to;
66
use test_utils::project_root;
7-
use xshell::cmd;
7+
use xshell::{cmd, Shell};
88

99
/// This clones rustc repo, and so is not worth to keep up-to-date. We update
1010
/// manually by un-ignoring the test from time to time.
1111
#[test]
1212
#[ignore]
1313
fn sourcegen_lint_completions() {
14+
let sh = &Shell::new().unwrap();
15+
1416
let rust_repo = project_root().join("./target/rust");
1517
if !rust_repo.exists() {
16-
cmd!("git clone --depth=1 https://github.com/rust-lang/rust {rust_repo}").run().unwrap();
18+
cmd!(sh, "git clone --depth=1 https://github.com/rust-lang/rust {rust_repo}")
19+
.run()
20+
.unwrap();
1721
}
1822

1923
let mut contents = String::from(
@@ -30,16 +34,19 @@ pub struct LintGroup {
3034
",
3135
);
3236

33-
generate_lint_descriptor(&mut contents);
37+
generate_lint_descriptor(sh, &mut contents);
3438
contents.push('\n');
3539

3640
generate_feature_descriptor(&mut contents, &rust_repo.join("src/doc/unstable-book/src"));
3741
contents.push('\n');
3842

3943
let lints_json = project_root().join("./target/clippy_lints.json");
40-
cmd!("curl https://rust-lang.github.io/rust-clippy/master/lints.json --output {lints_json}")
41-
.run()
42-
.unwrap();
44+
cmd!(
45+
sh,
46+
"curl https://rust-lang.github.io/rust-clippy/master/lints.json --output {lints_json}"
47+
)
48+
.run()
49+
.unwrap();
4350
generate_descriptor_clippy(&mut contents, &lints_json);
4451

4552
let contents = sourcegen::add_preamble("sourcegen_lints", sourcegen::reformat(contents));
@@ -48,10 +55,10 @@ pub struct LintGroup {
4855
sourcegen::ensure_file_contents(destination.as_path(), &contents);
4956
}
5057

51-
fn generate_lint_descriptor(buf: &mut String) {
58+
fn generate_lint_descriptor(sh: &Shell, buf: &mut String) {
5259
// FIXME: rustdoc currently requires an input file for -Whelp cc https://github.com/rust-lang/rust/pull/88831
5360
let file = project_root().join(file!());
54-
let stdout = cmd!("rustdoc -W help {file}").read().unwrap();
61+
let stdout = cmd!(sh, "rustdoc -W help {file}").read().unwrap();
5562
let start_lints = stdout.find("---- ------- -------").unwrap();
5663
let start_lint_groups = stdout.find("---- ---------").unwrap();
5764
let start_lints_rustdoc =

crates/rust-analyzer/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jemallocator = { version = "0.4.1", package = "tikv-jemallocator", optional = tr
7575
[dev-dependencies]
7676
expect-test = "1.2.0-pre.1"
7777
jod-thread = "0.1.0"
78-
xshell = "0.1"
78+
xshell = "0.2.0"
7979

8080
test_utils = { path = "../test_utils" }
8181
sourcegen = { path = "../sourcegen" }

crates/rust-analyzer/tests/slow-tests/tidy.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,43 @@ use std::{
33
path::{Path, PathBuf},
44
};
55

6-
use xshell::{cmd, pushd, pushenv, read_file};
6+
use xshell::{cmd, Shell};
77

88
#[test]
99
fn check_code_formatting() {
10-
let _dir = pushd(sourcegen::project_root()).unwrap();
11-
let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
10+
let sh = &Shell::new().unwrap();
11+
sh.change_dir(sourcegen::project_root());
12+
sh.set_var("RUSTUP_TOOLCHAIN", "stable");
1213

13-
let out = cmd!("rustfmt --version").read().unwrap();
14+
let out = cmd!(sh, "rustfmt --version").read().unwrap();
1415
if !out.contains("stable") {
1516
panic!(
1617
"Failed to run rustfmt from toolchain 'stable'. \
1718
Please run `rustup component add rustfmt --toolchain stable` to install it.",
1819
)
1920
}
2021

21-
let res = cmd!("cargo fmt -- --check").run();
22+
let res = cmd!(sh, "cargo fmt -- --check").run();
2223
if res.is_err() {
23-
let _ = cmd!("cargo fmt").run();
24+
let _ = cmd!(sh, "cargo fmt").run();
2425
}
2526
res.unwrap()
2627
}
2728

2829
#[test]
2930
fn check_lsp_extensions_docs() {
31+
let sh = &Shell::new().unwrap();
32+
3033
let expected_hash = {
31-
let lsp_ext_rs =
32-
read_file(sourcegen::project_root().join("crates/rust-analyzer/src/lsp_ext.rs"))
33-
.unwrap();
34+
let lsp_ext_rs = sh
35+
.read_file(sourcegen::project_root().join("crates/rust-analyzer/src/lsp_ext.rs"))
36+
.unwrap();
3437
stable_hash(lsp_ext_rs.as_str())
3538
};
3639

3740
let actual_hash = {
3841
let lsp_extensions_md =
39-
read_file(sourcegen::project_root().join("docs/dev/lsp-extensions.md")).unwrap();
42+
sh.read_file(sourcegen::project_root().join("docs/dev/lsp-extensions.md")).unwrap();
4043
let text = lsp_extensions_md
4144
.lines()
4245
.find_map(|line| line.strip_prefix("lsp_ext.rs hash:"))
@@ -62,6 +65,8 @@ Please adjust docs/dev/lsp-extensions.md.
6265

6366
#[test]
6467
fn files_are_tidy() {
68+
let sh = &Shell::new().unwrap();
69+
6570
let files = sourcegen::list_files(&sourcegen::project_root().join("crates"));
6671

6772
let mut tidy_docs = TidyDocs::default();
@@ -70,7 +75,7 @@ fn files_are_tidy() {
7075
let extension = path.extension().unwrap_or_default().to_str().unwrap_or_default();
7176
match extension {
7277
"rs" => {
73-
let text = read_file(&path).unwrap();
78+
let text = sh.read_file(&path).unwrap();
7479
check_todo(&path, &text);
7580
check_dbg(&path, &text);
7681
check_test_attrs(&path, &text);
@@ -80,7 +85,7 @@ fn files_are_tidy() {
8085
tidy_marks.visit(&path, &text);
8186
}
8287
"toml" => {
83-
let text = read_file(&path).unwrap();
88+
let text = sh.read_file(&path).unwrap();
8489
check_cargo_toml(&path, text);
8590
}
8691
_ => (),
@@ -139,8 +144,10 @@ fn check_cargo_toml(path: &Path, text: String) {
139144

140145
#[test]
141146
fn check_merge_commits() {
142-
let bors = cmd!("git rev-list --merges --author 'bors\\[bot\\]' HEAD~19..").read().unwrap();
143-
let all = cmd!("git rev-list --merges HEAD~19..").read().unwrap();
147+
let sh = &Shell::new().unwrap();
148+
149+
let bors = cmd!(sh, "git rev-list --merges --author 'bors\\[bot\\]' HEAD~19..").read().unwrap();
150+
let all = cmd!(sh, "git rev-list --merges HEAD~19..").read().unwrap();
144151
if bors != all {
145152
panic!(
146153
"
@@ -213,6 +220,8 @@ See https://github.com/rust-lang/rust-clippy/issues/5537 for discussion.
213220

214221
#[test]
215222
fn check_licenses() {
223+
let sh = &Shell::new().unwrap();
224+
216225
let expected = "
217226
0BSD OR MIT OR Apache-2.0
218227
Apache-2.0
@@ -235,7 +244,7 @@ Zlib OR Apache-2.0 OR MIT
235244
.filter(|it| !it.is_empty())
236245
.collect::<Vec<_>>();
237246

238-
let meta = cmd!("cargo metadata --format-version 1").read().unwrap();
247+
let meta = cmd!(sh, "cargo metadata --format-version 1").read().unwrap();
239248
let mut licenses = meta
240249
.split(|c| c == ',' || c == '{' || c == '}')
241250
.filter(|it| it.contains(r#""license""#))

crates/sourcegen/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ rust-version = "1.57"
1010
doctest = false
1111

1212
[dependencies]
13-
xshell = "0.1"
13+
xshell = "0.2.0"

crates/sourcegen/src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
path::{Path, PathBuf},
1212
};
1313

14-
use xshell::{cmd, pushenv};
14+
use xshell::{cmd, Shell};
1515

1616
pub fn list_rust_files(dir: &Path) -> Vec<PathBuf> {
1717
let mut res = list_files(dir);
@@ -133,8 +133,8 @@ impl fmt::Display for Location {
133133
}
134134
}
135135

136-
fn ensure_rustfmt() {
137-
let version = cmd!("rustfmt --version").read().unwrap_or_default();
136+
fn ensure_rustfmt(sh: &Shell) {
137+
let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default();
138138
if !version.contains("stable") {
139139
panic!(
140140
"Failed to run rustfmt from toolchain 'stable'. \
@@ -144,10 +144,11 @@ fn ensure_rustfmt() {
144144
}
145145

146146
pub fn reformat(text: String) -> String {
147-
let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
148-
ensure_rustfmt();
147+
let sh = Shell::new().unwrap();
148+
sh.set_var("RUSTUP_TOOLCHAIN", "stable");
149+
ensure_rustfmt(&sh);
149150
let rustfmt_toml = project_root().join("rustfmt.toml");
150-
let mut stdout = cmd!("rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
151+
let mut stdout = cmd!(sh, "rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
151152
.stdin(text)
152153
.read()
153154
.unwrap();

xtask/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ rust-version = "1.57"
1010
anyhow = "1.0.26"
1111
flate2 = "1.0"
1212
write-json = "0.1.0"
13-
xshell = "0.1"
13+
xshell = "0.2.0"
1414
xflags = "0.2.1"
1515
# Avoid adding more dependencies to this crate

xtask/src/dist.rs

+30-27
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@ use std::{
55
path::{Path, PathBuf},
66
};
77

8-
use anyhow::Result;
98
use flate2::{write::GzEncoder, Compression};
10-
use xshell::{cmd, cp, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file};
9+
use xshell::{cmd, Shell};
1110

1211
use crate::{date_iso, flags, project_root};
1312

1413
impl flags::Dist {
15-
pub(crate) fn run(self) -> Result<()> {
16-
let stable =
17-
std::env::var("GITHUB_REF").unwrap_or_default().as_str() == "refs/heads/release";
14+
pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
15+
let stable = sh.var("GITHUB_REF").unwrap_or_default().as_str() == "refs/heads/release";
1816

1917
let project_root = project_root();
2018
let target = Target::get(&project_root);
2119
let dist = project_root.join("dist");
22-
rm_rf(&dist)?;
23-
mkdir_p(&dist)?;
20+
sh.remove_path(&dist)?;
21+
sh.create_dir(&dist)?;
2422

2523
let release_channel = if stable { "stable" } else { "nightly" };
26-
dist_server(release_channel, &target)?;
24+
dist_server(sh, release_channel, &target)?;
2725

2826
if let Some(patch_version) = self.client_patch_version {
2927
let version = if stable {
@@ -32,58 +30,63 @@ impl flags::Dist {
3230
// A hack to make VS Code prefer nightly over stable.
3331
format!("0.3.{}", patch_version)
3432
};
35-
let release_tag = if stable { date_iso()? } else { "nightly".to_string() };
36-
dist_client(&version, &release_tag, &target)?;
33+
let release_tag = if stable { date_iso(sh)? } else { "nightly".to_string() };
34+
dist_client(sh, &version, &release_tag, &target)?;
3735
}
3836
Ok(())
3937
}
4038
}
4139

42-
fn dist_client(version: &str, release_tag: &str, target: &Target) -> Result<()> {
40+
fn dist_client(
41+
sh: &Shell,
42+
version: &str,
43+
release_tag: &str,
44+
target: &Target,
45+
) -> anyhow::Result<()> {
4346
let bundle_path = Path::new("editors").join("code").join("server");
44-
mkdir_p(&bundle_path)?;
45-
cp(&target.server_path, &bundle_path)?;
47+
sh.create_dir(&bundle_path)?;
48+
sh.copy_file(&target.server_path, &bundle_path)?;
4649
if let Some(symbols_path) = &target.symbols_path {
47-
cp(symbols_path, &bundle_path)?;
50+
sh.copy_file(symbols_path, &bundle_path)?;
4851
}
4952

50-
let _d = pushd("./editors/code")?;
53+
let _d = sh.push_dir("./editors/code");
5154

52-
let mut patch = Patch::new("./package.json")?;
55+
let mut patch = Patch::new(sh, "./package.json")?;
5356
patch
5457
.replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version))
5558
.replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag))
5659
.replace(r#""$generated-start": {},"#, "")
5760
.replace(",\n \"$generated-end\": {}", "")
5861
.replace(r#""enabledApiProposals": [],"#, r#""#);
59-
patch.commit()?;
62+
patch.commit(sh)?;
6063

6164
Ok(())
6265
}
6366

64-
fn dist_server(release_channel: &str, target: &Target) -> Result<()> {
65-
let _e = pushenv("RUST_ANALYZER_CHANNEL", release_channel);
66-
let _e = pushenv("CARGO_PROFILE_RELEASE_LTO", "thin");
67+
fn dist_server(sh: &Shell, release_channel: &str, target: &Target) -> anyhow::Result<()> {
68+
let _e = sh.push_env("RUST_ANALYZER_CHANNEL", release_channel);
69+
let _e = sh.push_env("CARGO_PROFILE_RELEASE_LTO", "thin");
6770

6871
// Uncomment to enable debug info for releases. Note that:
6972
// * debug info is split on windows and macs, so it does nothing for those platforms,
7073
// * on Linux, this blows up the binary size from 8MB to 43MB, which is unreasonable.
71-
// let _e = pushenv("CARGO_PROFILE_RELEASE_DEBUG", "1");
74+
// let _e = sh.push_env("CARGO_PROFILE_RELEASE_DEBUG", "1");
7275

7376
if target.name.contains("-linux-") {
7477
env::set_var("CC", "clang");
7578
}
7679

7780
let target_name = &target.name;
78-
cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} --release").run()?;
81+
cmd!(sh, "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} --release").run()?;
7982

8083
let dst = Path::new("dist").join(&target.artifact_name);
8184
gzip(&target.server_path, &dst.with_extension("gz"))?;
8285

8386
Ok(())
8487
}
8588

86-
fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
89+
fn gzip(src_path: &Path, dest_path: &Path) -> anyhow::Result<()> {
8790
let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best());
8891
let mut input = io::BufReader::new(File::open(src_path)?);
8992
io::copy(&mut input, &mut encoder)?;
@@ -133,9 +136,9 @@ struct Patch {
133136
}
134137

135138
impl Patch {
136-
fn new(path: impl Into<PathBuf>) -> Result<Patch> {
139+
fn new(sh: &Shell, path: impl Into<PathBuf>) -> anyhow::Result<Patch> {
137140
let path = path.into();
138-
let contents = read_file(&path)?;
141+
let contents = sh.read_file(&path)?;
139142
Ok(Patch { path, original_contents: contents.clone(), contents })
140143
}
141144

@@ -145,8 +148,8 @@ impl Patch {
145148
self
146149
}
147150

148-
fn commit(&self) -> Result<()> {
149-
write_file(&self.path, &self.contents)?;
151+
fn commit(&self, sh: &Shell) -> anyhow::Result<()> {
152+
sh.write_file(&self.path, &self.contents)?;
150153
Ok(())
151154
}
152155
}

0 commit comments

Comments
 (0)