From caa6c664d92c6cadb7cc25f50eb8b21ef304c364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Sat, 18 Jan 2020 10:15:58 -0700 Subject: Build in a target directory --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index eeb118b..fec41a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,7 @@ fn collect_source_files() -> Vec { } fn build(target_dir: &Path) { + let target = PathBuf::from(target_dir); println!("TARGET_DIR: {}", target_dir.to_str().unwrap()); let value = std::fs::read_to_string("fpm.toml") .unwrap() @@ -41,7 +42,7 @@ fn build(target_dir: &Path) { for file in &files { println!("File: {}", file); if !file.ends_with("main.f90") { - files2 = files2 + " " + &file.replace("\\", "/"); + files2 = files2 + " ../" + &file.replace("\\", "/"); } } println!("Files: {:?}", files); @@ -52,9 +53,12 @@ enable_language(Fortran) project(p1) -add_executable(p1 main.f90 {}) +add_executable(p1 ../main.f90 {}) ", files2); - std::fs::write("CMakeLists.txt", s).unwrap(); + let mut cmakelists = target; + cmakelists.push("CMakeLists.txt"); + std::fs::create_dir_all(target_dir).unwrap(); + std::fs::write(cmakelists.to_str().unwrap(), s).unwrap(); let mut args: Vec<&str> = vec![]; if cfg!(windows) { @@ -65,6 +69,7 @@ add_executable(p1 main.f90 {}) println!("[+] cmake {:?}", args); let output = std::process::Command::new("cmake") .args(&args) + .current_dir(target_dir) .env("FC", "gfortran") .output().unwrap(); println!("status: {}", output.status); @@ -79,6 +84,7 @@ add_executable(p1 main.f90 {}) println!("[+] cmake {:?}", args); let output = std::process::Command::new("cmake") .args(&args) + .current_dir(target_dir) .output().unwrap(); println!("status: {}", output.status); println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); @@ -88,8 +94,9 @@ add_executable(p1 main.f90 {}) } } -fn run() { +fn run(target_dir: &Path) { let output = std::process::Command::new("build/p1") + .current_dir(target_dir) .output().unwrap(); println!("status: {}", output.status); println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); @@ -108,7 +115,7 @@ fn main() { } else if args.command == "run" { println!("Command: run"); build(args.target_dir.as_path()); - run(); + run(args.target_dir.as_path()); } else { panic!("Unknown command"); } -- cgit v1.2.3 From eef71c890651062a4bcd97d053654ef9ed270f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Mon, 27 Jan 2020 22:59:31 -0700 Subject: Test "fpm run" in the same directory as fpm build --- tests/cli.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/cli.rs b/tests/cli.rs index 4ddc675..b099721 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -72,6 +72,8 @@ fn test_1() { let mut run = fpm_bin(); run.arg("run") + .arg("--target-dir") + .arg("build-test") .current_dir("tests/1"); run.assert() .success2() @@ -92,6 +94,8 @@ fn test_2() { let mut run = fpm_bin(); run.arg("run") + .arg("--target-dir") + .arg("build-test") .current_dir("tests/2"); run.assert() .success2() -- cgit v1.2.3 From b530b48950267b1ba1151a272182eab88cb59400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Mon, 27 Jan 2020 23:24:20 -0700 Subject: Use absolute path to p1 --- src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index fec41a3..be71598 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,8 +94,17 @@ add_executable(p1 ../main.f90 {}) } } +fn p1_bin(target_dir: &Path) -> std::process::Command { + let mut fpm_bin_relative: std::path::PathBuf = target_dir.to_path_buf(); + fpm_bin_relative.push("build"); + fpm_bin_relative.push("p1"); + fpm_bin_relative.set_extension(std::env::consts::EXE_EXTENSION); + let fpm_bin_absolute = std::fs::canonicalize(fpm_bin_relative).unwrap(); + std::process::Command::new(fpm_bin_absolute.to_str().unwrap()) +} + fn run(target_dir: &Path) { - let output = std::process::Command::new("build/p1") + let output = p1_bin(target_dir) .current_dir(target_dir) .output().unwrap(); println!("status: {}", output.status); -- cgit v1.2.3