Skip to content

Commit

Permalink
Force NUM_JOBS to fixed value if SOURCE_DATE_EPOCH is defined
Browse files Browse the repository at this point in the history
Fixes #80
  • Loading branch information
lukaslueg committed Feb 16, 2025
1 parent a967ab7 commit 7ee42a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/environment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::util::ArrayDisplay;
use crate::{fmt_option_str, write_str_variable, write_variable};
use std::{collections, env, ffi, fmt, fs, io, process};
use std::{borrow, collections, env, ffi, fmt, fs, io, process};

pub struct EnvironmentMap(collections::HashMap<String, String>);

Expand Down Expand Up @@ -115,7 +115,11 @@ impl EnvironmentMap {
w,
"NUM_JOBS",
"u32",
env::var("NUM_JOBS").unwrap(),
if env::var(crate::SOURCE_DATE_EPOCH).is_ok() {
borrow::Cow::Borrowed("1")
} else {
borrow::Cow::Owned(env::var("NUM_JOBS").unwrap())
},
"The parallelism that was specified during compilation."
);
write_variable!(
Expand Down
2 changes: 1 addition & 1 deletion src/krono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn strptime(s: &str) -> chrono::DateTime<chrono::offset::Utc> {
}

fn get_source_date_epoch_from_env() -> Option<chrono::DateTime<chrono::offset::Utc>> {
match std::env::var("SOURCE_DATE_EPOCH") {
match std::env::var(crate::SOURCE_DATE_EPOCH) {
Ok(val) => {
let ts = match val.parse::<i64>() {
Ok(ts) => ts,
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ pub use environment::CIPlatform;
#[allow(dead_code)]
type _READMETEST = ();

/// If `SOURCE_DATE_EPOCH` is defined, it's value is used instead of
/// `chrono::..::now()` as `BUILT_TIME_UTC`.
/// The presence of `SOURCE_DATE_EPOCH` also soft-indicates that a
/// reproducible build is desired, which we may or may not be able
/// to honor.
const SOURCE_DATE_EPOCH: &str = "SOURCE_DATE_EPOCH";

macro_rules! write_variable {
($writer:expr, $name:expr, $datatype:expr, $value:expr, $doc:expr) => {
writeln!(
Expand Down
1 change: 1 addition & 0 deletions tests/testbox_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ mod built_info {
fn main() {
assert_eq!(built::util::strptime(built_info::BUILT_TIME_UTC).to_rfc2822(),
"Sat, 25 May 2024 12:15:59 +0000");
assert_eq!(built_info::NUM_JOBS, 1);
println!("builttestsuccess");
}"#,
);
Expand Down

0 comments on commit 7ee42a5

Please sign in to comment.