From 79b29a17c50d27bb089747a0b1ac23cf62db24c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Thu, 20 Feb 2020 15:02:34 -0700 Subject: Reuse the FC env variable if present --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index be71598..b3195c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use structopt::StructOpt; use toml::Value; use std::path::{Path, PathBuf}; +use std::env; #[derive(Debug, StructOpt)] struct Cli { @@ -67,10 +68,16 @@ add_executable(p1 ../main.f90 {}) }; args.extend(vec!["-B", "build", "."]); println!("[+] cmake {:?}", args); + let env_fc = env::var("FC"); + let fc : String = if env_fc.is_err() { + "gfortran".to_string() + } else { + env_fc.unwrap() + }; let output = std::process::Command::new("cmake") .args(&args) .current_dir(target_dir) - .env("FC", "gfortran") + .env("FC", fc) .output().unwrap(); println!("status: {}", output.status); println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); -- cgit v1.2.3 From 8281c302054e479ba4d938971a426721f409ca23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Thu, 20 Feb 2020 15:08:14 -0700 Subject: Simplify the code --- src/main.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index b3195c7..340c1d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,11 +68,9 @@ add_executable(p1 ../main.f90 {}) }; args.extend(vec!["-B", "build", "."]); println!("[+] cmake {:?}", args); - let env_fc = env::var("FC"); - let fc : String = if env_fc.is_err() { - "gfortran".to_string() - } else { - env_fc.unwrap() + let fc : String = match env::var("FC") { + Ok(val) => val, + Err(_) => "gfortran".to_string(), }; let output = std::process::Command::new("cmake") .args(&args) -- cgit v1.2.3