Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editors/code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"preview": true,
"private": true,
"icon": "icon.png",
"version": "0.1.0",
"//": "The real version is in release.yaml, this one just needs to be bigger",
"version": "0.2.0-dev",
"publisher": "matklad",
"repository": {
"url": "https://github.com/rust-analyzer/rust-analyzer.git",
Expand Down
56 changes: 0 additions & 56 deletions xtask/src/cmd.rs

This file was deleted.

116 changes: 45 additions & 71 deletions xtask/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use std::{env, path::PathBuf, str};

use anyhow::{Context, Result};
use anyhow::{bail, format_err, Context, Result};

use crate::cmd::{run, run_with_output, Cmd};
use crate::not_bash::{ls, pushd, rm, run};

// Latest stable, feel free to send a PR if this lags behind.
const REQUIRED_RUST_VERSION: u32 = 41;
Expand Down Expand Up @@ -55,7 +55,7 @@ fn fix_path_for_mac() -> Result<()> {
const ROOT_DIR: &str = "";
let home_dir = match env::var("HOME") {
Ok(home) => home,
Err(e) => anyhow::bail!("Failed getting HOME from environment with error: {}.", e),
Err(e) => bail!("Failed getting HOME from environment with error: {}.", e),
};

[ROOT_DIR, &home_dir]
Expand All @@ -69,7 +69,7 @@ fn fix_path_for_mac() -> Result<()> {
if !vscode_path.is_empty() {
let vars = match env::var_os("PATH") {
Some(path) => path,
None => anyhow::bail!("Could not get PATH variable from env."),
None => bail!("Could not get PATH variable from env."),
};

let mut paths = env::split_paths(&vars).collect::<Vec<_>>();
Expand All @@ -82,84 +82,61 @@ fn fix_path_for_mac() -> Result<()> {
}

fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
let npm_version = Cmd {
unix: r"npm --version",
windows: r"cmd.exe /c npm --version",
work_dir: "./editors/code",
}
.run();

if npm_version.is_err() {
eprintln!("\nERROR: `npm --version` failed, `npm` is required to build the VS Code plugin")
}
let _dir = pushd("./editors/code");

Cmd { unix: r"npm install", windows: r"cmd.exe /c npm install", work_dir: "./editors/code" }
.run()?;
Cmd {
unix: r"npm run package --scripts-prepend-node-path",
windows: r"cmd.exe /c npm run package",
work_dir: "./editors/code",
}
.run()?;
let find_code = |f: fn(&str) -> bool| -> Result<&'static str> {
["code", "code-insiders", "codium", "code-oss"]
.iter()
.copied()
.find(|bin| f(bin))
.ok_or_else(|| {
format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?")
})
};

let code_binary = ["code", "code-insiders", "codium", "code-oss"].iter().find(|bin| {
Cmd {
unix: &format!("{} --version", bin),
windows: &format!("cmd.exe /c {}.cmd --version", bin),
work_dir: "./editors/code",
}
.run()
.is_ok()
});
let installed_extensions;
if cfg!(unix) {
run!("npm --version").context("`npm` is required to build the VS Code plugin")?;
run!("npm install")?;

let code_binary = match code_binary {
Some(it) => it,
None => anyhow::bail!("Can't execute `code --version`. Perhaps it is not in $PATH?"),
};
let vsix_pkg = {
rm("*.vsix")?;
run!("npm run package --scripts-prepend-node-path")?;
ls("*.vsix")?.pop().unwrap()
};

Cmd {
unix: &format!(r"{} --install-extension ./rust-analyzer-0.1.0.vsix --force", code_binary),
windows: &format!(
r"cmd.exe /c {}.cmd --install-extension ./rust-analyzer-0.1.0.vsix --force",
code_binary
),
work_dir: "./editors/code",
}
.run()?;
let code = find_code(|bin| run!("{} --version", bin).is_ok())?;
run!("{} --install-extension {} --force", code, vsix_pkg.display())?;
installed_extensions = run!("{} --list-extensions", code; echo = false)?;
} else {
run!("cmd.exe /c npm --version")
.context("`npm` is required to build the VS Code plugin")?;
run!("cmd.exe /c npm install")?;

let vsix_pkg = {
rm("*.vsix")?;
run!("cmd.exe /c npm run package")?;
ls("*.vsix")?.pop().unwrap()
};

let installed_extensions = Cmd {
unix: &format!(r"{} --list-extensions", code_binary),
windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
work_dir: ".",
let code = find_code(|bin| run!("cmd.exe /c {}.cmd --version", bin).is_ok())?;
run!(r"cmd.exe /c {}.cmd --install-extension {} --force", code, vsix_pkg.display())?;
installed_extensions = run!("cmd.exe /c {}.cmd --list-extensions", code; echo = false)?;
}
.run_with_output()?;

if !installed_extensions.contains("rust-analyzer") {
anyhow::bail!(
bail!(
"Could not install the Visual Studio Code extension. \
Please make sure you have at least NodeJS 10.x together with the latest version of VS Code installed and try again."
);
}

if installed_extensions.contains("ra-lsp") {
Cmd {
unix: &format!(r"{} --uninstall-extension matklad.ra-lsp", code_binary),
windows: &format!(
r"cmd.exe /c {}.cmd --uninstall-extension matklad.ra-lsp",
code_binary
),
work_dir: "./editors/code",
}
.run()?;
}

Ok(())
}

fn install_server(opts: ServerOpt) -> Result<()> {
let mut old_rust = false;
if let Ok(stdout) = run_with_output("cargo --version", ".") {
println!("{}", stdout);
if let Ok(stdout) = run!("cargo --version") {
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
old_rust = true;
}
Expand All @@ -172,20 +149,17 @@ fn install_server(opts: ServerOpt) -> Result<()> {
)
}

let res = if opts.jemalloc {
run("cargo install --path crates/ra_lsp_server --locked --force --features jemalloc", ".")
} else {
run("cargo install --path crates/ra_lsp_server --locked --force", ".")
};
let jemalloc = if opts.jemalloc { "--features jemalloc" } else { "" };
let res = run!("cargo install --path crates/ra_lsp_server --locked --force {}", jemalloc);

if res.is_err() && old_rust {
eprintln!(
"\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
REQUIRED_RUST_VERSION,
)
);
}

res
res.map(drop)
}

fn check_version(version_output: &str, min_minor_version: u32) -> bool {
Expand Down
58 changes: 28 additions & 30 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! FIXME: write short doc here

mod cmd;
pub mod not_bash;
pub mod install;
pub mod pre_commit;

Expand All @@ -16,8 +16,8 @@ use std::{
};

use crate::{
cmd::{run, run_with_output},
codegen::Mode,
not_bash::{pushd, run},
};

pub use anyhow::Result;
Expand All @@ -38,9 +38,9 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> {
ensure_rustfmt()?;

if mode == Mode::Verify {
run(&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), ".")?;
run!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN)?;
} else {
run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?;
run!("rustup run {} -- cargo fmt", TOOLCHAIN)?;
}
Ok(())
}
Expand Down Expand Up @@ -70,8 +70,9 @@ fn ensure_rustfmt() -> Result<()> {
Ok(status) if status.success() => return Ok(()),
_ => (),
};
run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?;
run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".")
run!("rustup toolchain install {}", TOOLCHAIN)?;
run!("rustup component add rustfmt --toolchain {}", TOOLCHAIN)?;
Ok(())
}

pub fn run_clippy() -> Result<()> {
Expand All @@ -92,34 +93,31 @@ pub fn run_clippy() -> Result<()> {
"clippy::nonminimal_bool",
"clippy::redundant_pattern_matching",
];
run(
&format!(
"rustup run {} -- cargo clippy --all-features --all-targets -- -A {}",
TOOLCHAIN,
allowed_lints.join(" -A ")
),
".",
run!(
"rustup run {} -- cargo clippy --all-features --all-targets -- -A {}",
TOOLCHAIN,
allowed_lints.join(" -A ")
)?;
Ok(())
}

fn install_clippy() -> Result<()> {
run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?;
run(&format!("rustup component add clippy --toolchain {}", TOOLCHAIN), ".")
run!("rustup toolchain install {}", TOOLCHAIN)?;
run!("rustup component add clippy --toolchain {}", TOOLCHAIN)?;
Ok(())
}

pub fn run_fuzzer() -> Result<()> {
match Command::new("cargo")
.args(&["fuzz", "--help"])
.stderr(Stdio::null())
.stdout(Stdio::null())
.status()
{
Ok(status) if status.success() => (),
_ => run("cargo install cargo-fuzz", ".")?,
let _d = pushd("./crates/ra_syntax");
match run!("cargo fuzz --help") {
Ok(_) => (),
_ => {
run!("cargo install cargo-fuzz")?;
}
};

run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax")
run!("rustup run nightly -- cargo fuzz run parser")?;
Ok(())
}

/// Cleans the `./target` dir after the build such that only
Expand Down Expand Up @@ -161,15 +159,15 @@ fn rm_rf(path: &Path) -> Result<()> {
}

pub fn run_release() -> Result<()> {
run("git switch release", ".")?;
run("git fetch upstream", ".")?;
run("git reset --hard upstream/master", ".")?;
run("git push", ".")?;
run!("git switch release")?;
run!("git fetch upstream")?;
run!("git reset --hard upstream/master")?;
run!("git push")?;

let changelog_dir = project_root().join("../rust-analyzer.github.io/thisweek/_posts");

let today = run_with_output("date --iso", ".")?;
let commit = run_with_output("git rev-parse HEAD", ".")?;
let today = run!("date --iso")?;
let commit = run!("git rev-parse HEAD")?;
let changelog_n = fs::read_dir(changelog_dir.as_path())?.count();

let contents = format!(
Expand Down
Loading