difftreelog
ci add pre-commit hook
in: master
5 files changed
.envrcdiffbeforeafterboth1RED='\033[0;31m'2RESET='\033[0m'31use flake4use flake56if ! diff .github/hooks/pre-commit .git/hooks/pre-commit >/dev/null; then7echo -e "${RED}Hooks are updated, read .github/hooks/pre-commit, and then install it with cp .github/hooks/pre-commit .git/hooks/pre-commit${RESET}"8fi29.github/hooks/pre-commitdiffbeforeafterbothno changes
flake.nixdiffbeforeafterboth116 };116 };117 };117 };118 devShells.default = craneLib.devShell {118 devShells.default = craneLib.devShell {119 nativeBuildInputs = with pkgs; [119 packages = with pkgs; [120 alejandra120 alejandra121 cargo-edit121 cargo-edit122 cargo-asm122 cargo-asm126 lld126 lld127 hyperfine127 hyperfine128 graphviz128 graphviz129 ];129 ] ++ lib.optionals (!stdenv.isDarwin) [130 valgrind131 kcachegrind132 ];130 };133 };131 }134 }132 );135 );xtask/Cargo.tomldiffbeforeafterboth15quote.workspace = true15quote.workspace = true16ungrammar.workspace = true16ungrammar.workspace = true17xshell.workspace = true17xshell.workspace = true18clap = {workspace = true, features = ["derive"]}1819xtask/src/main.rsdiffbeforeafterboth1use anyhow::Result;1use anyhow::Result;2use clap::Parser;3use xshell::{cmd, Shell};243mod sourcegen;5mod sourcegen;67#[derive(Parser)]8enum Opts {9 /// Generate files for rowan parser10 Sourcegen,11 /// Profile file execution12 Profile {13 #[arg(long, default_value = "true")]14 hyperfine: bool,15 #[arg(long)]16 callgrind: bool,17 #[arg(long)]18 cachegrind: bool,19 #[arg(long, default_value = "x86_64-unknown-linux-gnu")]20 target: String,21 args: Vec<String>,22 },23 /// Run all lints enforced by this repo24 Lint {25 /// Also fix found issues when possible.26 #[arg(long)]27 fix: bool,28 },29}4305fn main() -> Result<()> {31fn main() -> Result<()> {32 let sh = Shell::new()?;33 match Opts::parse() {6 sourcegen::generate_ungrammar()34 Opts::Sourcegen => sourcegen::generate_ungrammar(),35 Opts::Profile {36 hyperfine,37 callgrind,38 cachegrind,39 args,40 target,41 } => {42 let out = sh.create_temp_dir()?;4344 // build-std45 cmd!(46 sh,47 "cargo build -Zbuild-std --target={target} --profile releasedebug"48 )49 .run()?;50 let built = format!("./target/{target}/releasedebug/jrsonnet");51 let bench_cmd = format!("{built} {}", args.join(" "));52 if hyperfine {53 cmd!(sh, "hyperfine {bench_cmd}").run()?;54 }55 if callgrind {56 let args = args.clone();57 let mut callgrind_out = out.path().to_owned();58 callgrind_out.push("callgrind.out.1");59 cmd!(sh, "valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --callgrind-out-file={callgrind_out} {built} {args...}").run()?;60 cmd!(sh, "kcachegrind {callgrind_out}").run()?;61 }62 if cachegrind {63 let mut cachegrind_out = out.path().to_owned();64 cachegrind_out.push("cachegrind.out.1");65 cmd!(sh, "valgrind --tool=cachegrind --cachegrind-out-file={cachegrind_out} {built} {args...}").run()?;66 cmd!(sh, "kcachegrind {cachegrind_out}").run()?;67 }6869 Ok(())70 }71 Opts::Lint { fix } => {72 let fmt_check = if fix { None } else { Some("--check") };73 cmd!(sh, "cargo fmt {fmt_check...}").run()?;74 Ok(())75 }76 }7}77}878