aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndřej Čertík <ondrej@certik.us>2020-01-27 23:30:58 -0700
committerGitHub <noreply@github.com>2020-01-27 23:30:58 -0700
commit21020c2f60a2a0f07bc4ef2506004ed5a361793b (patch)
tree58f1c368dedb755b626403ae8f812bd1d485e8ef
parentdd739aaf983ccd25bd7033fb2700d5ca81053bd1 (diff)
parentb530b48950267b1ba1151a272182eab88cb59400 (diff)
downloadfpm-21020c2f60a2a0f07bc4ef2506004ed5a361793b.tar.gz
fpm-21020c2f60a2a0f07bc4ef2506004ed5a361793b.zip
Merge pull request #26 from certik/target
Build in a target directory
-rw-r--r--src/main.rs28
-rw-r--r--tests/cli.rs4
2 files changed, 26 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index eeb118b..be71598 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -31,6 +31,7 @@ fn collect_source_files() -> Vec<String> {
}
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,18 @@ add_executable(p1 main.f90 {})
}
}
-fn run() {
- let output = std::process::Command::new("build/p1")
+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 = p1_bin(target_dir)
+ .current_dir(target_dir)
.output().unwrap();
println!("status: {}", output.status);
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
@@ -108,7 +124,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");
}
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()