Skip to content

Commit

Permalink
Expose build time to package build scriptlets via $RPM_BUILD_TIME
Browse files Browse the repository at this point in the history
This is useful for consistently setting timestamps within build
scriptlets, in particular when doing reproducable builds.
  • Loading branch information
pmatilai committed Feb 27, 2024
1 parent a478cb8 commit 08100d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static rpm_time_t getBuildTime(void)
char *srcdate;
time_t epoch;
char *endptr;
char *timestr = NULL;

srcdate = getenv("SOURCE_DATE_EPOCH");
if (srcdate && rpmExpandNumeric("%{?use_source_date_epoch_as_buildtime}")) {
Expand All @@ -40,6 +41,10 @@ static rpm_time_t getBuildTime(void)
} else
buildTime = (uint32_t) time(NULL);

rasprintf(&timestr, "%u", buildTime);
setenv("RPM_BUILD_TIME", timestr, 1);
free(timestr);

return buildTime;
}

Expand Down
1 change: 1 addition & 0 deletions docs/manual/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ RPM_ARCH | Architecture of the package
RPM_BUILD_DIR | The build directory of the package
RPM_BUILD_NCPUS |
RPM_BUILD_ROOT | The buildroot directory of the package
RPM_BUILD_TIME | The build time of the package
RPM_DOC_DIR | The special documentation directory of the package
RPM_LD_FLAGS | Linker flags
RPM_OPT_FLAGS | Compiler flags
Expand Down

0 comments on commit 08100d0

Please # to comment.