Skip to content

Commit

Permalink
Merge #260
Browse files Browse the repository at this point in the history
260: Pass data dir to detect script r=MikailBag a=MikailBag

bors r+

Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
  • Loading branch information
bors[bot] and MikailBag authored Feb 21, 2020
2 parents 03e9f9a + bce09d4 commit 064c41a
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/soft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ fn run_under_trace(
script_path: &Path,
data_path: &Path,
detect_out: &DetectScriptOutput,
work_dir: &Path
) -> anyhow::Result<Vec<u8>> {
let current_dir = tempfile::TempDir::new().context("failed to create temp dir")?;
println!("running in {}", current_dir.path().display());
let log_out_file = current_dir.path().join("__jjs_trace.json");
println!("running in {}", work_dir.display());
let log_out_file = work_dir.join("__jjs_trace.json");
let data_path = data_path.canonicalize().context("data dir not exists")?;
println!("script will use data from {}", data_path.display());
let mut cmd = Command::new("lxtrace");
cmd.current_dir(current_dir.path())
cmd.current_dir(work_dir)
// machine-readable
.arg("--json")
// redirect to file, so it will not mix with script output
Expand Down Expand Up @@ -184,7 +184,11 @@ impl std::str::FromStr for DetectScriptOutput {
}
}

fn run_detect_script(tpl: &TemplateInfo) -> anyhow::Result<Option<DetectScriptOutput>> {
fn run_detect_script(
tpl: &TemplateInfo,
data_dir: &Path,
work_dir: &Path,
) -> anyhow::Result<Option<DetectScriptOutput>> {
let detect_script_path = tpl.dir.join("detect.sh");
if !detect_script_path.exists() {
bail!("detect.sh script missing");
Expand All @@ -194,6 +198,8 @@ fn run_detect_script(tpl: &TemplateInfo) -> anyhow::Result<Option<DetectScriptOu
let status = std::process::Command::new("bash")
.arg(&detect_script_path)
.arg(out_file_path.path())
.current_dir(work_dir)
.env("DATA", data_dir)
.status()
.context("failed to execute detect.sh script")?;
let script_out =
Expand Down Expand Up @@ -247,7 +253,10 @@ fn process_toolchain_template(
mut event_log: Option<&mut dyn std::io::Write>,
out_dir: &Path,
) -> anyhow::Result<()> {
let detect_out = match run_detect_script(&tpl)? {

let work_dir = tempfile::TempDir::new().context("failed to create temp dir")?;
let data_dir = tpl.dir.join("data");
let detect_out = match run_detect_script(&tpl, &data_dir, work_dir.path())? {
Some(dso) => dso,
None => {
println!("Skipping toolchain {}: not available", &tpl.name);
Expand All @@ -260,10 +269,9 @@ fn process_toolchain_template(
.read_dir()?
.map(|item| item.map_err(|err| anyhow::Error::new(err).context("failed to read script")))
.collect();
let current_dir = tpl.dir.join("data");
for script in scripts? {
println!("running {}", script.path().display());
let out = run_under_trace(&script.path(), &current_dir, &detect_out)
let out = run_under_trace(&script.path(), &data_dir, &detect_out, work_dir.path())
.context("failed to collect trace")?;
let scanner = serde_json::Deserializer::from_slice(&out).into_iter();
let mut cnt = 0;
Expand Down

0 comments on commit 064c41a

Please sign in to comment.