From 9eeff4412c8352c21b829f50f3ced1c05e5e2836 Mon Sep 17 00:00:00 2001 From: Justin Karneges Date: Tue, 21 Nov 2023 13:55:34 -0800 Subject: [PATCH] write configuration .pri files from build.rs and use them --- build.rs | 52 +++++++++++++++++++++++++++++++++++++++-- postbuild/postbuild.pro | 2 +- src/cpp/cpp/cpp.pro | 4 ++-- src/cpp/tests/tests.pro | 4 ++-- src/rust/rust.pro | 2 -- 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/build.rs b/build.rs index 173bc8b0..9062eb8d 100644 --- a/build.rs +++ b/build.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::env; use std::error::Error; use std::fs; -use std::io::{BufRead, BufReader}; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use std::process::Command; use std::thread; @@ -51,6 +51,33 @@ fn check_version( Ok(()) } +fn write_cpp_conf_pri(path: &Path) -> Result<(), Box> { + let mut f = fs::File::create(path)?; + + writeln!(&mut f)?; + + Ok(()) +} + +fn write_postbuild_conf_pri( + path: &Path, + bin_dir: &str, + lib_dir: &str, + config_dir: &str, + run_dir: &str, + log_dir: &str, +) -> Result<(), Box> { + let mut f = fs::File::create(path)?; + + writeln!(&mut f, "BINDIR = {}", bin_dir)?; + writeln!(&mut f, "LIBDIR = {}", lib_dir)?; + writeln!(&mut f, "CONFIGDIR = {}", config_dir)?; + writeln!(&mut f, "RUNDIR = {}", run_dir)?; + writeln!(&mut f, "LOGDIR = {}", log_dir)?; + + Ok(()) +} + fn main() -> Result<(), Box> { let qt_host_bins = { let pkg = "Qt5Core"; @@ -97,7 +124,14 @@ fn main() -> Result<(), Box> { let f = fs::File::open("conf.pri")?; let reader = BufReader::new(f); - const CONF_VARS: &[&str] = &["CONFIGDIR", "LIBDIR", "MAKETOOL"]; + const CONF_VARS: &[&str] = &[ + "BINDIR", + "CONFIGDIR", + "LIBDIR", + "LOGDIR", + "RUNDIR", + "MAKETOOL", + ]; for line in reader.lines() { let line = line?; @@ -116,8 +150,11 @@ fn main() -> Result<(), Box> { conf }; + let bin_dir = conf.get("BINDIR").unwrap(); let config_dir = conf.get("CONFIGDIR").unwrap(); let lib_dir = conf.get("LIBDIR").unwrap(); + let log_dir = conf.get("LOGDIR").unwrap(); + let run_dir = conf.get("RUNDIR").unwrap(); let maketool = fs::canonicalize(conf.get("MAKETOOL").unwrap())?; let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?); @@ -128,6 +165,17 @@ fn main() -> Result<(), Box> { fs::create_dir_all(cpp_lib_dir.join(Path::new(dir)))?; } + write_cpp_conf_pri(&cpp_lib_dir.join(Path::new("conf.pri")))?; + + write_postbuild_conf_pri( + &Path::new("target").join(Path::new("postbuild_conf.pri")), + bin_dir, + lib_dir, + config_dir, + run_dir, + log_dir, + )?; + if !cpp_src_dir.join("Makefile").try_exists()? { assert!(Command::new(&qmake_path) .args(["-o", "Makefile", "cpp.pro"]) diff --git a/postbuild/postbuild.pro b/postbuild/postbuild.pro index 13fd3fa2..8a6ce4ff 100644 --- a/postbuild/postbuild.pro +++ b/postbuild/postbuild.pro @@ -1,7 +1,7 @@ TEMPLATE = aux CONFIG -= debug_and_release debug -include($$OUT_PWD/../conf.pri) +include($$OUT_PWD/../target/postbuild_conf.pri) root_dir = $$PWD/.. bin_dir = $$root_dir/bin diff --git a/src/cpp/cpp/cpp.pro b/src/cpp/cpp/cpp.pro index ef8ee7cc..2fd2a390 100644 --- a/src/cpp/cpp/cpp.pro +++ b/src/cpp/cpp/cpp.pro @@ -1,6 +1,6 @@ TEMPLATE = lib CONFIG -= app_bundle -CONFIG += staticlib +CONFIG += staticlib c++11 QT -= gui QT += network TARGET = pushpin-cpp @@ -11,5 +11,5 @@ cpp_build_dir = $$OUT_PWD/../../../target/cpp MOC_DIR = $$cpp_build_dir/moc OBJECTS_DIR = $$cpp_build_dir/obj -include($$OUT_PWD/../../../conf.pri) +include($$OUT_PWD/../../../target/cpp/conf.pri) include(cpp.pri) diff --git a/src/cpp/tests/tests.pro b/src/cpp/tests/tests.pro index 3505b44a..7a3503f7 100644 --- a/src/cpp/tests/tests.pro +++ b/src/cpp/tests/tests.pro @@ -1,6 +1,6 @@ TEMPLATE = lib CONFIG -= app_bundle -CONFIG += staticlib +CONFIG += staticlib c++11 QT -= gui QT *= network testlib TARGET = pushpin-cpptest @@ -15,7 +15,7 @@ SRC_DIR = $$PWD/.. QZMQ_DIR = $$SRC_DIR/qzmq RUST_DIR = $$SRC_DIR/../rust -include($$PWD/../../../conf.pri) +include($$PWD/../../../target/cpp/conf.pri) INCLUDEPATH += $$SRC_DIR INCLUDEPATH += $$SRC_DIR/proxy diff --git a/src/rust/rust.pro b/src/rust/rust.pro index 6a5ac3b0..f4d80010 100644 --- a/src/rust/rust.pro +++ b/src/rust/rust.pro @@ -1,8 +1,6 @@ TEMPLATE = aux CONFIG -= debug_and_release debug -include($$OUT_PWD/../../conf.pri) - root_dir = $$PWD/../.. CONFIG(debug, debug|release) {