Skip to content

Commit 49a90d4

Browse files
committed
Switch from not_bash to xshell
1 parent f0412da commit 49a90d4

File tree

14 files changed

+181
-325
lines changed

14 files changed

+181
-325
lines changed

Cargo.lock

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xtask/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ quote = "1.0.2"
1818
ungrammar = "1.1.3"
1919
walkdir = "2.3.1"
2020
write-json = "0.1.0"
21-
fs-err = "2.3"
21+
xshell = "0.1"
2222
# Avoid adding more dependencies to this crate

xtask/src/codegen.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ use std::{
1515
fmt, mem,
1616
path::{Path, PathBuf},
1717
};
18+
use xshell::{cmd, pushenv, read_file, write_file};
1819

19-
use crate::{
20-
ensure_rustfmt,
21-
not_bash::{fs2, pushenv, run},
22-
project_root, Result,
23-
};
20+
use crate::{ensure_rustfmt, project_root, Result};
2421

2522
pub use self::{
2623
gen_assists_docs::{generate_assists_docs, generate_assists_tests},
@@ -57,7 +54,7 @@ impl CodegenCmd {
5754
/// A helper to update file on disk if it has changed.
5855
/// With verify = false,
5956
fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
60-
match fs2::read_to_string(path) {
57+
match read_file(path) {
6158
Ok(old_contents) if normalize(&old_contents) == normalize(contents) => {
6259
return Ok(());
6360
}
@@ -67,7 +64,7 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
6764
anyhow::bail!("`{}` is not up-to-date", path.display());
6865
}
6966
eprintln!("updating {}", path.display());
70-
fs2::write(path, contents)?;
67+
write_file(path, contents)?;
7168
return Ok(());
7269

7370
fn normalize(s: &str) -> String {
@@ -80,10 +77,10 @@ const PREAMBLE: &str = "Generated file, do not edit by hand, see `xtask/src/code
8077
fn reformat(text: &str) -> Result<String> {
8178
let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
8279
ensure_rustfmt()?;
83-
let stdout = run!(
84-
"rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display();
85-
<text.as_bytes()
86-
)?;
80+
let rustfmt_toml = project_root().join("rustfmt.toml");
81+
let stdout = cmd!("rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
82+
.stdin(text)
83+
.read()?;
8784
Ok(format!("//! {}\n\n{}\n", PREAMBLE, stdout))
8885
}
8986

xtask/src/codegen/gen_features.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ use std::path::{Path, PathBuf};
33

44
use quote::quote;
55
use walkdir::WalkDir;
6+
use xshell::{cmd, read_file};
67

7-
use crate::{
8-
codegen::{project_root, reformat, update, Mode, Result},
9-
not_bash::{fs2, run},
10-
};
8+
use crate::codegen::{project_root, reformat, update, Mode, Result};
119

1210
pub fn generate_features(mode: Mode) -> Result<()> {
1311
if !Path::new("./target/rust").exists() {
14-
run!("git clone https://github.com/rust-lang/rust ./target/rust")?;
12+
cmd!("git clone https://github.com/rust-lang/rust ./target/rust").run()?;
1513
}
1614

1715
let contents = generate_descriptor("./target/rust/src/doc/unstable-book/src".into())?;
@@ -34,7 +32,7 @@ fn generate_descriptor(src_dir: PathBuf) -> Result<String> {
3432
.map(|entry| {
3533
let path = entry.path();
3634
let feature_ident = path.file_stem().unwrap().to_str().unwrap().replace("-", "_");
37-
let doc = fs2::read_to_string(path).unwrap();
35+
let doc = read_file(path).unwrap();
3836

3937
quote! { LintCompletion { label: #feature_ident, description: #doc } }
4038
});

xtask/src/dist.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use flate2::{write::GzEncoder, Compression};
21
use std::{
32
env,
43
fs::File,
@@ -7,11 +6,10 @@ use std::{
76
};
87

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

11-
use crate::{
12-
not_bash::{date_iso, fs2, pushd, rm_rf, run},
13-
project_root,
14-
};
12+
use crate::{date_iso, project_root};
1513

1614
pub struct DistCmd {
1715
pub nightly: bool,
@@ -22,7 +20,7 @@ impl DistCmd {
2220
pub fn run(self) -> Result<()> {
2321
let dist = project_root().join("dist");
2422
rm_rf(&dist)?;
25-
fs2::create_dir_all(&dist)?;
23+
mkdir_p(&dist)?;
2624

2725
if let Some(version) = self.client_version {
2826
let release_tag = if self.nightly { "nightly".to_string() } else { date_iso()? };
@@ -34,7 +32,7 @@ impl DistCmd {
3432
}
3533

3634
fn dist_client(version: &str, release_tag: &str) -> Result<()> {
37-
let _d = pushd("./editors/code");
35+
let _d = pushd("./editors/code")?;
3836
let nightly = release_tag == "nightly";
3937

4038
let mut patch = Patch::new("./package.json")?;
@@ -54,20 +52,16 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
5452
}
5553
patch.commit()?;
5654

57-
run!("npm ci")?;
58-
run!("npx vsce package -o ../../dist/rust-analyzer.vsix")?;
55+
cmd!("npm ci").run()?;
56+
cmd!("npx vsce package -o ../../dist/rust-analyzer.vsix").run()?;
5957
Ok(())
6058
}
6159

6260
fn dist_server() -> Result<()> {
6361
if cfg!(target_os = "linux") {
6462
env::set_var("CC", "clang");
65-
run!(
66-
"cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release"
67-
)?;
68-
} else {
69-
run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?;
7063
}
64+
cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release").run()?;
7165

7266
let (src, dst) = if cfg!(target_os = "linux") {
7367
("./target/release/rust-analyzer", "./dist/rust-analyzer-linux")
@@ -82,7 +76,7 @@ fn dist_server() -> Result<()> {
8276
let src = Path::new(src);
8377
let dst = Path::new(dst);
8478

85-
fs2::copy(&src, &dst)?;
79+
cp(&src, &dst)?;
8680
gzip(&src, &dst.with_extension("gz"))?;
8781

8882
Ok(())
@@ -105,7 +99,7 @@ struct Patch {
10599
impl Patch {
106100
fn new(path: impl Into<PathBuf>) -> Result<Patch> {
107101
let path = path.into();
108-
let contents = fs2::read_to_string(&path)?;
102+
let contents = read_file(&path)?;
109103
Ok(Patch { path, original_contents: contents.clone(), contents })
110104
}
111105

@@ -115,13 +109,14 @@ impl Patch {
115109
self
116110
}
117111

118-
fn commit(&self) -> io::Result<()> {
119-
fs2::write(&self.path, &self.contents)
112+
fn commit(&self) -> Result<()> {
113+
write_file(&self.path, &self.contents)?;
114+
Ok(())
120115
}
121116
}
122117

123118
impl Drop for Patch {
124119
fn drop(&mut self) {
125-
fs2::write(&self.path, &self.original_contents).unwrap();
120+
write_file(&self.path, &self.original_contents).unwrap();
126121
}
127122
}

xtask/src/install.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use std::{env, path::PathBuf, str};
44

55
use anyhow::{bail, format_err, Context, Result};
6-
7-
use crate::not_bash::{pushd, run};
6+
use xshell::{cmd, pushd};
87

98
// Latest stable, feel free to send a PR if this lags behind.
109
const REQUIRED_RUST_VERSION: u32 = 47;
@@ -76,7 +75,7 @@ fn fix_path_for_mac() -> Result<()> {
7675
}
7776

7877
fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
79-
let _dir = pushd("./editors/code");
78+
let _dir = pushd("./editors/code")?;
8079

8180
let find_code = |f: fn(&str) -> bool| -> Result<&'static str> {
8281
["code", "code-insiders", "codium", "code-oss"]
@@ -89,24 +88,25 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
8988
};
9089

9190
let installed_extensions = if cfg!(unix) {
92-
run!("npm --version").context("`npm` is required to build the VS Code plugin")?;
93-
run!("npm install")?;
91+
cmd!("npm --version").run().context("`npm` is required to build the VS Code plugin")?;
92+
cmd!("npm install").run()?;
9493

95-
run!("npm run package --scripts-prepend-node-path")?;
94+
cmd!("npm run package --scripts-prepend-node-path").run()?;
9695

97-
let code = find_code(|bin| run!("{} --version", bin).is_ok())?;
98-
run!("{} --install-extension rust-analyzer.vsix --force", code)?;
99-
run!("{} --list-extensions", code; echo = false)?
96+
let code = find_code(|bin| cmd!("{bin} --version").read().is_ok())?;
97+
cmd!("{code} --install-extension rust-analyzer.vsix --force").run()?;
98+
cmd!("{code} --list-extensions").read()?
10099
} else {
101-
run!("cmd.exe /c npm --version")
100+
cmd!("cmd.exe /c npm --version")
101+
.run()
102102
.context("`npm` is required to build the VS Code plugin")?;
103-
run!("cmd.exe /c npm install")?;
103+
cmd!("cmd.exe /c npm install").run()?;
104104

105-
run!("cmd.exe /c npm run package")?;
105+
cmd!("cmd.exe /c npm run package").run()?;
106106

107-
let code = find_code(|bin| run!("cmd.exe /c {}.cmd --version", bin).is_ok())?;
108-
run!(r"cmd.exe /c {}.cmd --install-extension rust-analyzer.vsix --force", code)?;
109-
run!("cmd.exe /c {}.cmd --list-extensions", code; echo = false)?
107+
let code = find_code(|bin| cmd!("cmd.exe /c {bin}.cmd --version").read().is_ok())?;
108+
cmd!("cmd.exe /c {code}.cmd --install-extension rust-analyzer.vsix --force").run()?;
109+
cmd!("cmd.exe /c {code}.cmd --list-extensions").read()?
110110
};
111111

112112
if !installed_extensions.contains("rust-analyzer") {
@@ -122,7 +122,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
122122

123123
fn install_server(opts: ServerOpt) -> Result<()> {
124124
let mut old_rust = false;
125-
if let Ok(stdout) = run!("cargo --version") {
125+
if let Ok(stdout) = cmd!("cargo --version").read() {
126126
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
127127
old_rust = true;
128128
}
@@ -134,12 +134,13 @@ fn install_server(opts: ServerOpt) -> Result<()> {
134134
REQUIRED_RUST_VERSION,
135135
)
136136
}
137-
138-
let malloc_feature = match opts.malloc {
139-
Malloc::System => "",
140-
Malloc::Mimalloc => "--features mimalloc",
137+
let features = match opts.malloc {
138+
Malloc::System => &[][..],
139+
Malloc::Mimalloc => &["--features", "mimalloc"],
141140
};
142-
let res = run!("cargo install --path crates/rust-analyzer --locked --force {}", malloc_feature);
141+
142+
let cmd = cmd!("cargo install --path crates/rust-analyzer --locked --force {features...}");
143+
let res = cmd.run();
143144

144145
if res.is_err() && old_rust {
145146
eprintln!(
@@ -148,7 +149,8 @@ fn install_server(opts: ServerOpt) -> Result<()> {
148149
);
149150
}
150151

151-
res.map(drop)
152+
res?;
153+
Ok(())
152154
}
153155

154156
fn check_version(version_output: &str, min_minor_version: u32) -> bool {

0 commit comments

Comments
 (0)