git.delta.rocks / jrsonnet / refs/commits / ea44e4495023

difftreelog

ci add pre-commit hook

Yaroslav Bolyukin2024-06-18parent: #8d39c73.patch.diff
in: master

5 files changed

modified.envrcdiffbeforeafterboth
1RED='\033[0;31m'
2RESET='\033[0m'
3
1use flake4use flake
5
6if ! diff .github/hooks/pre-commit .git/hooks/pre-commit >/dev/null; then
7echo -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}"
8fi
29
added.github/hooks/pre-commitdiffbeforeafterboth

no changes

modifiedflake.nixdiffbeforeafterboth
116 };116 };
117 };117 };
118 devShells.default = craneLib.devShell {118 devShells.default = craneLib.devShell {
119 nativeBuildInputs = with pkgs; [119 packages = with pkgs; [
120 alejandra120 alejandra
121 cargo-edit121 cargo-edit
122 cargo-asm122 cargo-asm
126 lld126 lld
127 hyperfine127 hyperfine
128 graphviz128 graphviz
129 ];129 ] ++ lib.optionals (!stdenv.isDarwin) [
130 valgrind
131 kcachegrind
132 ];
130 };133 };
131 }134 }
132 );135 );
modifiedxtask/Cargo.tomldiffbeforeafterboth
15quote.workspace = true15quote.workspace = true
16ungrammar.workspace = true16ungrammar.workspace = true
17xshell.workspace = true17xshell.workspace = true
18clap = {workspace = true, features = ["derive"]}
1819
modifiedxtask/src/main.rsdiffbeforeafterboth
1use anyhow::Result;1use anyhow::Result;
2use clap::Parser;
3use xshell::{cmd, Shell};
24
3mod sourcegen;5mod sourcegen;
6
7#[derive(Parser)]
8enum Opts {
9 /// Generate files for rowan parser
10 Sourcegen,
11 /// Profile file execution
12 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 repo
24 Lint {
25 /// Also fix found issues when possible.
26 #[arg(long)]
27 fix: bool,
28 },
29}
430
5fn 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()?;
43
44 // build-std
45 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 }
68
69 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