difftreelog
ci scripts to fetch golang/cpp testsuites
in: master
1 file changed
xtask/src/main.rsdiffbeforeafterboth1use anyhow::Result;2use clap::Parser;3use xshell::{cmd, Shell};45mod 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 = env!("TARGET_PLATFORM"))]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 /// Build and run test file from `bindings/c`30 TestCBindings {31 #[arg(long, default_value = env!("TARGET_PLATFORM"))]32 target: String,33 /// Which bindings file to build and run34 #[arg(long, default_value = "libjsonnet_test_file")]35 test_file: String,36 args: Vec<String>,37 },38}3940fn main() -> Result<()> {41 let sh = Shell::new()?;42 match Opts::parse() {43 Opts::Sourcegen => sourcegen::generate_ungrammar(),44 Opts::Profile {45 hyperfine,46 callgrind,47 cachegrind,48 args,49 target,50 } => {51 let out = sh.create_temp_dir()?;5253 // build-std54 cmd!(55 sh,56 "cargo build -Zbuild-std --target={target} --profile releasedebug"57 )58 .run()?;59 let built = format!("./target/{target}/releasedebug/jrsonnet");60 let bench_cmd = format!("{built} {}", args.join(" "));61 if hyperfine {62 cmd!(sh, "hyperfine {bench_cmd}").run()?;63 }64 if callgrind {65 let args = args.clone();66 let mut callgrind_out = out.path().to_owned();67 callgrind_out.push("callgrind.out.1");68 cmd!(sh, "valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --callgrind-out-file={callgrind_out} {built} {args...}").run()?;69 cmd!(sh, "kcachegrind {callgrind_out}").run()?;70 }71 if cachegrind {72 let mut cachegrind_out = out.path().to_owned();73 cachegrind_out.push("cachegrind.out.1");74 cmd!(sh, "valgrind --tool=cachegrind --cachegrind-out-file={cachegrind_out} {built} {args...}").run()?;75 cmd!(sh, "kcachegrind {cachegrind_out}").run()?;76 }7778 Ok(())79 }80 Opts::Lint { fix } => {81 let fmt_check = if fix { None } else { Some("--check") };82 cmd!(sh, "cargo fmt {fmt_check...}").run()?;83 Ok(())84 }85 Opts::TestCBindings {86 target,87 test_file,88 args,89 } => {90 cmd!(91 sh,92 "cargo build -p libjsonnet --target={target} --release --no-default-features --features=interop-common,interop-threading"93 )94 .run()?;95 let built = format!("./target/{target}/release/libjsonnet.a");96 let c_bindings = "./bindings/c/";97 cmd!(sh, "cp {built} {c_bindings}").run()?;98 sh.change_dir(c_bindings);99100 // TODO: Pass target to gcc?101 cmd!(sh, "gcc -c {test_file}.c").run()?;102 cmd!(sh, "gcc -o {test_file} -lc -lm {test_file}.o libjsonnet.a").run()?;103 let sh = Shell::new()?;104105 cmd!(sh, "{c_bindings}{test_file} {args...}").run()?;106107 Ok(())108 }109 }110}1use anyhow::Result;2use clap::Parser;3use xshell::{cmd, Shell};45mod 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 = env!("TARGET_PLATFORM"))]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 /// Build and run test file from `bindings/c`30 TestCBindings {31 #[arg(long, default_value = env!("TARGET_PLATFORM"))]32 target: String,33 /// Which bindings file to build and run34 #[arg(long, default_value = "libjsonnet_test_file")]35 test_file: String,36 args: Vec<String>,37 },38 /// Update C++/Golang golden testsuites from git39 UpdateTestsuites,40}4142fn main() -> Result<()> {43 let sh = Shell::new()?;44 match Opts::parse() {45 Opts::Sourcegen => sourcegen::generate_ungrammar(),46 Opts::Profile {47 hyperfine,48 callgrind,49 cachegrind,50 args,51 target,52 } => {53 let out = sh.create_temp_dir()?;5455 // build-std56 cmd!(57 sh,58 "cargo build -Zbuild-std --target={target} --profile releasedebug"59 )60 .run()?;61 let built = format!("./target/{target}/releasedebug/jrsonnet");62 let bench_cmd = format!("{built} {}", args.join(" "));63 if hyperfine {64 cmd!(sh, "hyperfine {bench_cmd}").run()?;65 }66 if callgrind {67 let args = args.clone();68 let mut callgrind_out = out.path().to_owned();69 callgrind_out.push("callgrind.out.1");70 cmd!(sh, "valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --callgrind-out-file={callgrind_out} {built} {args...}").run()?;71 cmd!(sh, "kcachegrind {callgrind_out}").run()?;72 }73 if cachegrind {74 let mut cachegrind_out = out.path().to_owned();75 cachegrind_out.push("cachegrind.out.1");76 cmd!(sh, "valgrind --tool=cachegrind --cachegrind-out-file={cachegrind_out} {built} {args...}").run()?;77 cmd!(sh, "kcachegrind {cachegrind_out}").run()?;78 }7980 Ok(())81 }82 Opts::Lint { fix } => {83 let fmt_check = if fix { None } else { Some("--check") };84 cmd!(sh, "cargo fmt {fmt_check...}").run()?;85 Ok(())86 }87 Opts::TestCBindings {88 target,89 test_file,90 args,91 } => {92 cmd!(93 sh,94 "cargo build -p libjsonnet --target={target} --release --no-default-features --features=interop-common,interop-threading"95 )96 .run()?;97 let built = format!("./target/{target}/release/libjsonnet.a");98 let c_bindings = "./bindings/c/";99 cmd!(sh, "cp {built} {c_bindings}").run()?;100 sh.change_dir(c_bindings);101102 // TODO: Pass target to gcc?103 cmd!(sh, "gcc -c {test_file}.c").run()?;104 cmd!(sh, "gcc -o {test_file} -lc -lm {test_file}.o libjsonnet.a").run()?;105 let sh = Shell::new()?;106107 cmd!(sh, "{c_bindings}{test_file} {args...}").run()?;108109 Ok(())110 }111 Opts::UpdateTestsuites => {112 let _pushd = sh.push_dir("tests");113 let git_dir = sh.create_temp_dir()?;114 let git_dir_path = git_dir.path();115 cmd!(116 sh,117 "git clone https://github.com/google/jsonnet.git --depth=1 {git_dir_path}/jsonnet"118 )119 .run()?;120 cmd!(121 sh,122 "git clone https://github.com/google/go-jsonnet.git --depth=1 {git_dir_path}/go-jsonnet"123 )124 .run()?;125 sh.remove_path("cpp_test_suite")?;126 sh.remove_path("go_testdata")?;127 cmd!(sh, "mv {git_dir_path}/jsonnet/test_suite cpp_test_suite").run()?;128 cmd!(sh, "mv {git_dir_path}/go-jsonnet/testdata go_testdata").run()?;129130 Ok(())131 }132 }133}