Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write configuration .pri files from build.rs and use them #47797

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)?;

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<dyn Error>> {
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<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