Skip to content

Commit c4e5fd5

Browse files
psurplyjlrivasp
authored andcommitted
lib: add build script option to select products to include
The build script now uses the CRASHLOG_PRODUCTS environment variable to select which project(s) to include in the embedded collateral tree. Example: $ CRASHLOG_COLLATERAL_TREE=./collateral CRASHLOG_PRODUCTS=LNL,LNC,SKT cargo build Signed-off-by: Surply, Pierre <[email protected]>
1 parent 4457030 commit c4e5fd5

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

lib/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,27 @@
5858
- Windows: `target/release/intel_crashlog.dll`
5959
- Linux: `target/release/libintel_crashlog.so`
6060

61+
### Product Support
62+
63+
The product-specific support is provided by the collateral tree.
64+
The files included in the collateral tree can be embedded in the crate/library
65+
when the `embedded_collateral_tree` feature is enabled.
66+
67+
This can be configure at build-time using the following environment variables:
68+
69+
- `CRASHLOG_COLLATERAL_TREE`: Path to the collateral tree in the file system.
70+
If not set, the build script will embed the files located in the
71+
[collateral](collateral) folder.
72+
- `CRASHLOG_PRODUCTS`: Comma-separated list of products (Three-Letter Acronyms)
73+
to include in the embedded tree. If not set or empty, all the available
74+
product supports found in the collateral tree are included.
75+
76+
Example:
77+
78+
```
79+
$ CRASHLOG_COLLATERAL_TREE=./collateral CRASHLOG_PRODUCTS=LNL,LNC,SKT cargo build
80+
```
81+
6182
### Building Documentation
6283

6384
Generate the HTML documentation with:

lib/build.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ use std::env;
88

99
#[cfg(feature = "embedded_collateral_tree")]
1010
use std::{
11+
collections::BTreeSet,
1112
fs::File,
1213
io::Write,
1314
path::{Path, PathBuf},
1415
};
1516

17+
const COLLATERAL_PATH_VAR: &str = "CRASHLOG_COLLATERAL_TREE";
18+
const PRODUCTS_VAR: &str = "CRASHLOG_PRODUCTS";
19+
1620
#[cfg(feature = "ffi")]
1721
fn generate_headers() {
1822
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
19-
println!("cargo:rerun-if-changed=src/ffi.rs");
23+
cargo_emit::rerun_if_changed!("src/ffi.rs");
2024

2125
for (language, header) in [
2226
(cbindgen::Language::C, "target/include/intel_crashlog.h"),
@@ -51,10 +55,22 @@ fn generate_headers() {
5155

5256
#[cfg(feature = "embedded_collateral_tree")]
5357
fn embed_collateral_tree() {
58+
cargo_emit::rerun_if_env_changed!(COLLATERAL_PATH_VAR);
59+
cargo_emit::rerun_if_env_changed!(PRODUCTS_VAR);
60+
5461
let collateral_tree =
55-
env::var("CRASHLOG_COLLATERAL_TREE").unwrap_or_else(|_| "collateral".to_string());
62+
env::var(COLLATERAL_PATH_VAR).unwrap_or_else(|_| "collateral".to_string());
63+
5664
cargo_emit::rerun_if_changed!(collateral_tree);
57-
cargo_emit::warning!("Embedding collateral tree: {}", collateral_tree);
65+
66+
let requested_products: BTreeSet<String> = env::var(PRODUCTS_VAR)
67+
.unwrap_or_else(|_| String::new())
68+
.split(",")
69+
.filter(|s| !s.is_empty())
70+
.map(|s| s.trim().to_owned())
71+
.collect();
72+
73+
let mut included_products = BTreeSet::new();
5874

5975
let out_dir = env::var_os("OUT_DIR").unwrap();
6076
let dest_path = Path::new(&out_dir).join("embedded_collateral_tree.rs");
@@ -63,6 +79,15 @@ fn embed_collateral_tree() {
6379
let tree_path = std::path::absolute(Path::new(&collateral_tree)).unwrap();
6480
file.write_all("{\n".as_ref()).unwrap();
6581
for (product, variant, stepping, security, fullpath) in visit_collateral_tree(&tree_path) {
82+
// Check if product must be included in the collateral tree
83+
if !requested_products.is_empty() && !requested_products.contains(&product) {
84+
continue;
85+
}
86+
87+
if product != "all" {
88+
included_products.insert(product.clone());
89+
}
90+
6691
let path = fullpath
6792
.strip_prefix(
6893
tree_path
@@ -94,6 +119,23 @@ fn embed_collateral_tree() {
94119
.unwrap();
95120
}
96121
file.write_all("}\n".as_ref()).unwrap();
122+
123+
for requested_product in requested_products {
124+
if !included_products.contains(&requested_product) {
125+
cargo_emit::warning!("Requested unknown Crash Log product: {}", requested_product);
126+
}
127+
}
128+
129+
if !included_products.is_empty() {
130+
cargo_emit::warning!(
131+
"Embedding Crash Log support for the following product(s): {}",
132+
included_products
133+
.iter()
134+
.map(|s| s.as_str())
135+
.collect::<Vec<_>>()
136+
.join(", ")
137+
);
138+
}
97139
}
98140

99141
#[cfg(feature = "embedded_collateral_tree")]

0 commit comments

Comments
 (0)