Skip to content

Commit

Permalink
write configuration .pri files from build.rs and use them
Browse files Browse the repository at this point in the history
  • Loading branch information
jkarneges committed Nov 21, 2023
1 parent 9bccceb commit 2060513
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
52 changes: 50 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,6 +51,33 @@ fn check_version(
Ok(())
}

fn write_cpp_conf_pri(path: &Path) -> Result<(), Box<dyn Error>> {
let mut f = fs::File::create(path)?;

write!(&mut f, "\n")?;

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<dyn Error>> {
let mut f = fs::File::create(path)?;

write!(&mut f, "BINDIR = {}\n", bin_dir)?;
write!(&mut f, "LIBDIR = {}\n", lib_dir)?;
write!(&mut f, "CONFIGDIR = {}\n", config_dir)?;
write!(&mut f, "RUNDIR = {}\n", run_dir)?;
write!(&mut f, "LOGDIR = {}\n", log_dir)?;

Ok(())
}

fn main() -> Result<(), Box<dyn Error>> {
let qt_host_bins = {
let pkg = "Qt5Core";
Expand Down Expand Up @@ -97,7 +124,14 @@ fn main() -> Result<(), Box<dyn Error>> {
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?;
Expand All @@ -116,8 +150,11 @@ fn main() -> Result<(), Box<dyn Error>> {
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")?);
Expand All @@ -128,6 +165,17 @@ fn main() -> Result<(), Box<dyn Error>> {
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"])
Expand Down
2 changes: 1 addition & 1 deletion postbuild/postbuild.pro
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/cpp/cpp.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = lib
CONFIG -= app_bundle
CONFIG += staticlib
CONFIG += staticlib c++11
QT -= gui
QT += network
TARGET = pushpin-cpp
Expand All @@ -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)
4 changes: 2 additions & 2 deletions src/cpp/tests/tests.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = lib
CONFIG -= app_bundle
CONFIG += staticlib
CONFIG += staticlib c++11
QT -= gui
QT *= network testlib
TARGET = pushpin-cpptest
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/rust/rust.pro
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
TEMPLATE = aux
CONFIG -= debug_and_release debug

include($$OUT_PWD/../../conf.pri)

root_dir = $$PWD/../..

CONFIG(debug, debug|release) {
Expand Down

0 comments on commit 2060513

Please sign in to comment.