2019-09-30 11:58:53 +03:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
|
2020-01-07 15:33:09 +01:00
|
|
|
mod cmd;
|
2020-01-07 14:42:56 +01:00
|
|
|
pub mod install;
|
|
|
|
|
pub mod pre_commit;
|
2020-01-07 15:33:51 +01:00
|
|
|
|
|
|
|
|
pub mod codegen;
|
2020-01-03 20:37:02 +01:00
|
|
|
mod ast_src;
|
2019-08-18 21:33:31 +03:00
|
|
|
|
2019-11-13 20:51:57 +01:00
|
|
|
use anyhow::Context;
|
2018-10-14 20:32:57 +06:00
|
|
|
use std::{
|
2020-01-07 16:01:41 +01:00
|
|
|
env, fs,
|
2020-01-10 11:23:11 +01:00
|
|
|
io::Write,
|
2018-10-16 00:54:27 +06:00
|
|
|
path::{Path, PathBuf},
|
2020-01-07 15:33:09 +01:00
|
|
|
process::{Command, Stdio},
|
2018-10-14 20:32:57 +06:00
|
|
|
};
|
|
|
|
|
|
2020-02-10 15:32:03 +01:00
|
|
|
use crate::{
|
|
|
|
|
cmd::{run, run_with_output},
|
|
|
|
|
codegen::Mode,
|
|
|
|
|
};
|
2019-08-18 21:34:55 +03:00
|
|
|
|
2020-01-07 15:33:09 +01:00
|
|
|
pub use anyhow::Result;
|
|
|
|
|
|
2019-01-24 07:58:38 -05:00
|
|
|
const TOOLCHAIN: &str = "stable";
|
2018-10-16 00:54:27 +06:00
|
|
|
|
|
|
|
|
pub fn project_root() -> PathBuf {
|
2019-11-01 22:20:44 +02: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-16 00:54:27 +06:00
|
|
|
}
|
2018-11-01 01:50:43 +06:00
|
|
|
|
|
|
|
|
pub fn run_rustfmt(mode: Mode) -> Result<()> {
|
2020-01-10 11:23:11 +01:00
|
|
|
ensure_rustfmt()?;
|
2018-10-31 23:57:38 +03:00
|
|
|
|
2019-10-23 18:13:40 +03:00
|
|
|
if mode == Mode::Verify {
|
2019-02-08 14:49:43 +03:00
|
|
|
run(&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), ".")?;
|
2018-11-01 01:50:43 +06:00
|
|
|
} else {
|
|
|
|
|
run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2018-10-31 23:57:38 +03:00
|
|
|
|
2020-01-10 11:23:11 +01:00
|
|
|
fn reformat(text: impl std::fmt::Display) -> Result<String> {
|
|
|
|
|
ensure_rustfmt()?;
|
|
|
|
|
let mut rustfmt = Command::new("rustup")
|
|
|
|
|
.args(&["run", TOOLCHAIN, "--", "rustfmt", "--config-path"])
|
|
|
|
|
.arg(project_root().join("rustfmt.toml"))
|
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
|
.spawn()?;
|
|
|
|
|
write!(rustfmt.stdin.take().unwrap(), "{}", text)?;
|
|
|
|
|
let output = rustfmt.wait_with_output()?;
|
|
|
|
|
let stdout = String::from_utf8(output.stdout)?;
|
2020-02-07 23:35:34 +02:00
|
|
|
let preamble = "Generated file, do not edit by hand, see `xtask/src/codegen`";
|
2020-01-10 11:23:11 +01:00
|
|
|
Ok(format!("//! {}\n\n{}", preamble, stdout))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn ensure_rustfmt() -> Result<()> {
|
|
|
|
|
match Command::new("rustup")
|
|
|
|
|
.args(&["run", TOOLCHAIN, "--", "cargo", "fmt", "--version"])
|
|
|
|
|
.stderr(Stdio::null())
|
|
|
|
|
.stdout(Stdio::null())
|
|
|
|
|
.status()
|
|
|
|
|
{
|
|
|
|
|
Ok(status) if status.success() => return Ok(()),
|
|
|
|
|
_ => (),
|
|
|
|
|
};
|
2019-12-08 23:13:56 +08:00
|
|
|
run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?;
|
2019-02-08 14:49:43 +03:00
|
|
|
run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".")
|
2018-10-31 23:57:38 +03:00
|
|
|
}
|
2018-12-09 10:29:13 +00:00
|
|
|
|
2019-06-03 09:43:06 -04: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 20:51:57 +01:00
|
|
|
_ => install_clippy().context("install clippy")?,
|
2019-06-03 09:43:06 -04:00
|
|
|
};
|
|
|
|
|
|
2019-06-04 02:24:47 -04:00
|
|
|
let allowed_lints = [
|
|
|
|
|
"clippy::collapsible_if",
|
|
|
|
|
"clippy::map_clone", // FIXME: remove when Iterator::copied stabilizes (1.36.0)
|
2019-06-04 18:05:38 -04:00
|
|
|
"clippy::needless_pass_by_value",
|
|
|
|
|
"clippy::nonminimal_bool",
|
|
|
|
|
"clippy::redundant_pattern_matching",
|
2019-06-04 02:24:47 -04:00
|
|
|
];
|
2019-06-03 09:43:06 -04:00
|
|
|
run(
|
|
|
|
|
&format!(
|
|
|
|
|
"rustup run {} -- cargo clippy --all-features --all-targets -- -A {}",
|
|
|
|
|
TOOLCHAIN,
|
|
|
|
|
allowed_lints.join(" -A ")
|
|
|
|
|
),
|
|
|
|
|
".",
|
|
|
|
|
)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 15:33:51 +01:00
|
|
|
fn install_clippy() -> Result<()> {
|
2019-12-08 23:13:56 +08:00
|
|
|
run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?;
|
2019-06-03 09:43:06 -04:00
|
|
|
run(&format!("rustup component add clippy --toolchain {}", TOOLCHAIN), ".")
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 13:14:06 +00: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 14:49:43 +03:00
|
|
|
run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax")
|
2018-12-31 13:14:06 +00:00
|
|
|
}
|
2020-01-07 16:01:41 +01:00
|
|
|
|
|
|
|
|
/// Cleans the `./target` dir after the build such that only
|
|
|
|
|
/// dependencies are cached on CI.
|
|
|
|
|
pub fn run_pre_cache() -> Result<()> {
|
|
|
|
|
let slow_tests_cookie = Path::new("./target/.slow_tests_cookie");
|
|
|
|
|
if !slow_tests_cookie.exists() {
|
|
|
|
|
panic!("slow tests were skipped on CI!")
|
|
|
|
|
}
|
|
|
|
|
rm_rf(slow_tests_cookie)?;
|
|
|
|
|
|
|
|
|
|
for entry in Path::new("./target/debug").read_dir()? {
|
|
|
|
|
let entry = entry?;
|
|
|
|
|
if entry.file_type().map(|it| it.is_file()).ok() == Some(true) {
|
|
|
|
|
// Can't delete yourself on windows :-(
|
|
|
|
|
if !entry.path().ends_with("xtask.exe") {
|
|
|
|
|
rm_rf(&entry.path())?
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs::remove_file("./target/.rustc_info.json")?;
|
|
|
|
|
let to_delete = ["ra_", "heavy_test"];
|
|
|
|
|
for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() {
|
|
|
|
|
for entry in Path::new(dir).read_dir()? {
|
|
|
|
|
let entry = entry?;
|
|
|
|
|
if to_delete.iter().any(|&it| entry.path().display().to_string().contains(it)) {
|
|
|
|
|
rm_rf(&entry.path())?
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn rm_rf(path: &Path) -> Result<()> {
|
|
|
|
|
if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) }
|
|
|
|
|
.with_context(|| format!("failed to remove {:?}", path))
|
|
|
|
|
}
|
2020-02-10 15:32:03 +01:00
|
|
|
|
|
|
|
|
pub fn run_release() -> Result<()> {
|
|
|
|
|
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 changelog_n = fs::read_dir(changelog_dir.as_path())?.count();
|
|
|
|
|
|
|
|
|
|
let contents = format!(
|
|
|
|
|
"\
|
|
|
|
|
= Changelog #{}
|
|
|
|
|
:sectanchors:
|
|
|
|
|
:page-layout: post
|
|
|
|
|
|
|
|
|
|
Commit: commit:{}[] +
|
|
|
|
|
Release: release:{}[]
|
|
|
|
|
|
|
|
|
|
== New Features
|
|
|
|
|
|
|
|
|
|
* pr:[] .
|
|
|
|
|
|
|
|
|
|
== Fixes
|
|
|
|
|
|
|
|
|
|
== Internal Improvements
|
|
|
|
|
",
|
|
|
|
|
changelog_n, commit, today
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n));
|
|
|
|
|
fs::write(&path, &contents)?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|