Skip to content

uudoc: use SOURCE_DATE_EPOCH if set in build environment - #14982

Open
kpcyrd wants to merge 1 commit into
uutils:mainfrom
kpcyrd:source-date-epoch
Open

kpcyrd wants to merge 1 commit into
uutils:mainfrom
kpcyrd:source-date-epoch

Conversation

@kpcyrd

@kpcyrd kpcyrd commented Sep 30, 2026

Copy link
Copy Markdown

I noticed the Arch Linux reproducible builds environment flags all man pages as non-reproducible, unless the package is built on the same day:

│ ├── usr/share/man/man1/uu-b2sum.1.gz
│ │ ├── uu-b2sum.1
│ │ │ @@ -1,10 +1,10 @@
│ │ │  .ie \n(.g .ds Aq \(aq
│ │ │  .el .ds Aq '
│ │ │ -.TH B2SUM 1 "2026-09-17"
│ │ │ +.TH B2SUM 1 "2026-09-29"
│ │ │  .SH NAME
│ │ │  b2sum \- Print or check the BLAKE2b checksums
│ │ │  .SH SYNOPSIS
│ │ │  \fBb2sum\fR [OPTIONS] [FILE]...
│ │ │  .SH DESCRIPTION
│ │ │  Print or check the BLAKE2b checksums
│ │ │  .SH OPTIONS

With this patch the uudoc binary checks if the SOURCE_DATE_EPOCH environment variable is set, then prefers this value if present. This value is guaranteed to be present in the Arch Linux build environment, Debian, and others.

I've added a test that runs uudoc with SOURCE_DATE_EPOCH set and checks the timestamp is set accordingly.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Invalid epoch values silently fall back to the current date, defeating reproducibility.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Uses SOURCE_DATE_EPOCH to make generated manpage dates reproducible.

Changes:

  • Converts the epoch to a UTC date.
  • Adds an integration test for deterministic output.
File Description
src/​bin/​uudoc.rs Selects the manpage date from the environment.
tests/​uudoc/​mod.rs Verifies epoch-based manpage dates.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/bin/uudoc.rs Outdated
Comment thread src/bin/uudoc.rs Outdated
Comment on lines +172 to +180
let now = env::var("SOURCE_DATE_EPOCH")
.ok()
.and_then(|source_date_epoch| {
let timestamp = source_date_epoch.parse().ok()?;
let timestamp = Timestamp::new(timestamp, 0).ok()?;
let datetime = timestamp.to_zoned(TimeZone::UTC);
Some(datetime)
})
.unwrap_or_else(Zoned::now);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let now = env::var("SOURCE_DATE_EPOCH")
.ok()
.and_then(|source_date_epoch| {
let timestamp = source_date_epoch.parse().ok()?;
let timestamp = Timestamp::new(timestamp, 0).ok()?;
let datetime = timestamp.to_zoned(TimeZone::UTC);
Some(datetime)
})
.unwrap_or_else(Zoned::now);
let now = env::var("SOURCE_DATE_EPOCH")
.ok()
.and_then(|s| s.parse().ok())
.and_then(|s| Timestamp::new(s, 0).ok())
.map(|t| t.to_zoned(TimeZone::UTC))
.unwrap_or_else(Zoned::now);

seems like it would read easier with combinators

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied, thanks!

@oech3

oech3 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

We can just remove build date instead of freezing it. No?

@xtqqczze

Copy link
Copy Markdown
Collaborator

I think SOURCE_DATE_EPOCH is the technically correct approach.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 13:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new option chain triggers an enabled Clippy warning that CI treats as an error.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread src/bin/uudoc.rs Outdated
Comment thread src/bin/uudoc.rs Outdated
// Convert to string for processing
let manpage = String::from_utf8(buffer).expect("Invalid UTF-8 in manpage");

// Use SOURCE_DATE_EPOCH if set

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Use SOURCE_DATE_EPOCH if set
// Use `SOURCE_DATE_EPOCH` for reproducible builds if set and valid; otherwise use the current time.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/id/setgid is no longer failing!

Copilot AI balanced review requested due to automatic review settings September 30, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation is focused, cross-platform, and covered by a regression test.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Comment thread src/bin/uudoc.rs Outdated

use std::{
collections::HashMap,
env,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error[E0425]: cannot find value `uumain` in module `env`
   --> /home/runner/work/coreutils/coreutils/target/debug/build/coreutils-09b66ed593f1a000/out/uutils_map.rs:185:23
    |
185 |         ("env", (env::uumain, env::uu_app)),
    |                       ^^^^^^ not found in `env`

error[E0425]: cannot find value `uu_app` in module `env`
   --> /home/runner/work/coreutils/coreutils/target/debug/build/coreutils-09b66ed593f1a000/out/uutils_map.rs:185:36
    |
185 |         ("env", (env::uumain, env::uu_app)),
    |                                    ^^^^^^ not found in `env`

I'm not sure why, but this import needs to be removed and the call should use the fully qualified std::env::var instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@kpcyrd
kpcyrd force-pushed the source-date-epoch branch from 96295d7 to 90bdb1c Compare October 1, 2026 10:10
Copilot AI balanced review requested due to automatic review settings October 1, 2026 10:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation is focused, correct, and adequately tested.

Review effort: Balanced
Findings: None

@xtqqczze
xtqqczze requested a review from sylvestre October 1, 2026 10:19

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants