2019-09-30 03:58:53 -05:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2020-01-07 08:33:09 -06:00
|
|
|
mod cmd;
|
2020-01-07 07:42:56 -06:00
|
|
|
pub mod install;
|
|
|
|
pub mod pre_commit;
|
2020-01-07 08:33:51 -06:00
|
|
|
|
|
|
|
pub mod codegen;
|
2020-01-03 13:37:02 -06:00
|
|
|
mod ast_src;
|
2019-08-18 13:33:31 -05:00
|
|
|
|
2019-11-13 13:51:57 -06:00
|
|
|
use anyhow::Context;
|
2018-10-14 09:32:57 -05:00
|
|
|
use std::{
|
2020-01-07 07:42:56 -06:00
|
|
|
env,
|
2018-10-15 13:54:27 -05:00
|
|
|
path::{Path, PathBuf},
|
2020-01-07 08:33:09 -06:00
|
|
|
process::{Command, Stdio},
|
2018-10-14 09:32:57 -05:00
|
|
|
};
|
|
|
|
|
2020-01-07 08:33:51 -06:00
|
|
|
use crate::{cmd::run, codegen::Mode};
|
2019-08-18 13:34:55 -05:00
|
|
|
|
2020-01-07 08:33:09 -06:00
|
|
|
pub use anyhow::Result;
|
|
|
|
|
2019-01-24 06:58:38 -06:00
|
|
|
const TOOLCHAIN: &str = "stable";
|
2018-10-15 13:54:27 -05:00
|
|
|
|
|
|
|
pub fn project_root() -> PathBuf {
|
2019-11-01 15:20:44 -05:00
|
|
|
Path::new(
|
|
|
|
&env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| env!("CARGO_MANIFEST_DIR").to_owned()),
|
|
|
|
)
|
|
|
|
.ancestors()
|
|
|
|
.nth(1)
|
|
|
|
.unwrap()
|
|
|
|
.to_path_buf()
|
2018-10-15 13:54:27 -05:00
|
|
|
}
|
2018-10-31 14:50:43 -05:00
|
|
|
|
|
|
|
pub fn run_rustfmt(mode: Mode) -> Result<()> {
|
2018-10-31 15:57:38 -05:00
|
|
|
match Command::new("rustup")
|
|
|
|
.args(&["run", TOOLCHAIN, "--", "cargo", "fmt", "--version"])
|
|
|
|
.stderr(Stdio::null())
|
|
|
|
.stdout(Stdio::null())
|
|
|
|
.status()
|
|
|
|
{
|
|
|
|
Ok(status) if status.success() => (),
|
2019-11-13 13:51:57 -06:00
|
|
|
_ => install_rustfmt().context("install rustfmt")?,
|
2018-10-31 15:57:38 -05:00
|
|
|
};
|
|
|
|
|
2019-10-23 10:13:40 -05:00
|
|
|
if mode == Mode::Verify {
|
2019-02-08 05:49:43 -06:00
|
|
|
run(&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), ".")?;
|
2018-10-31 14:50:43 -05:00
|
|
|
} else {
|
|
|
|
run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2018-10-31 15:57:38 -05:00
|
|
|
|
2020-01-07 07:42:56 -06:00
|
|
|
fn install_rustfmt() -> Result<()> {
|
2019-12-08 09:13:56 -06:00
|
|
|
run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?;
|
2019-02-08 05:49:43 -06:00
|
|
|
run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".")
|
2018-10-31 15:57:38 -05:00
|
|
|
}
|
2018-12-09 04:29:13 -06:00
|
|
|
|
2019-06-03 08:43:06 -05:00
|
|
|
pub fn run_clippy() -> Result<()> {
|
|
|
|
match Command::new("rustup")
|
|
|
|
.args(&["run", TOOLCHAIN, "--", "cargo", "clippy", "--version"])
|
|
|
|
.stderr(Stdio::null())
|
|
|
|
.stdout(Stdio::null())
|
|
|
|
.status()
|
|
|
|
{
|
|
|
|
Ok(status) if status.success() => (),
|
2019-11-13 13:51:57 -06:00
|
|
|
_ => install_clippy().context("install clippy")?,
|
2019-06-03 08:43:06 -05:00
|
|
|
};
|
|
|
|
|
2019-06-04 01:24:47 -05:00
|
|
|
let allowed_lints = [
|
|
|
|
"clippy::collapsible_if",
|
|
|
|
"clippy::map_clone", // FIXME: remove when Iterator::copied stabilizes (1.36.0)
|
2019-06-04 17:05:38 -05:00
|
|
|
"clippy::needless_pass_by_value",
|
|
|
|
"clippy::nonminimal_bool",
|
|
|
|
"clippy::redundant_pattern_matching",
|
2019-06-04 01:24:47 -05:00
|
|
|
];
|
2019-06-03 08:43:06 -05:00
|
|
|
run(
|
|
|
|
&format!(
|
|
|
|
"rustup run {} -- cargo clippy --all-features --all-targets -- -A {}",
|
|
|
|
TOOLCHAIN,
|
|
|
|
allowed_lints.join(" -A ")
|
|
|
|
),
|
|
|
|
".",
|
|
|
|
)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-01-07 08:33:51 -06:00
|
|
|
fn install_clippy() -> Result<()> {
|
2019-12-08 09:13:56 -06:00
|
|
|
run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?;
|
2019-06-03 08:43:06 -05:00
|
|
|
run(&format!("rustup component add clippy --toolchain {}", TOOLCHAIN), ".")
|
|
|
|
}
|
|
|
|
|
2018-12-31 07:14:06 -06:00
|
|
|
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", ".")?,
|
|
|
|
};
|
|
|
|
|
2019-02-08 05:49:43 -06:00
|
|
|
run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax")
|
2018-12-31 07:14:06 -06:00
|
|
|
}
|