Skip to content

Commit

Permalink
Add BUILDER_SOURCE_DATE_FROM_SPEC_MTIME
Browse files Browse the repository at this point in the history
BUILDER_SOURCE_DATE_FROM_SPEC_MTIME can be set to use the mtime of the
spec file as the SOURCE_DATE_EPOCH. This is useful for vendor packages.
  • Loading branch information
wojas committed Jun 25, 2021
1 parent 883c275 commit 6455890
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -91,7 +91,7 @@ usage() {
echo " -V VERSION - Override version (default: run gen-version)"
echo " -R RELEASE - Override release tag (default: '1pdns', do not include %{dist} here)"
echo " -m MODULES - Build only specific components (comma separated; warning: this disables install tests)"
echo " -e EPOCH - Set a specific Epoch for packages"
echo " -e EPOCH - Set a specific Epoch for RPM packages"
echo " -b VALUE - Docker cache buster, set to 'always', 'daily', 'weekly' or a literal value."
echo " -p PACKAGENAME - Build only spec files that have this string in their name (warning: this disables install tests)"
echo " -q - Be more quiet. Build error details are still printed on build error."
Expand Down
2 changes: 1 addition & 1 deletion demo/builder-support/dockerfiles/Dockerfile.rpmbuild
Expand Up @@ -36,7 +36,7 @@ RUN mkdir /cache/new
# Only vendor specs can safely use the builder cache for these reasons.
@IF [ ! -z "$M_all$M_vendor" ]
COPY builder-support/vendor-specs/ builder-support/vendor-specs/
RUN BUILDER_CACHE_THIS=1 builder/helpers/build-specs.sh builder-support/vendor-specs/*.spec
RUN BUILDER_CACHE_THIS=1 BUILDER_SOURCE_DATE_FROM_SPEC_MTIME=1 builder/helpers/build-specs.sh builder-support/vendor-specs/*.spec
@ENDIF

# You can override these build args for faster Python builds
Expand Down
10 changes: 10 additions & 0 deletions helpers/build-specs.sh
Expand Up @@ -113,11 +113,21 @@ for spec in "${specs[@]}"; do
sed -i "/Name:/a Epoch: ${BUILDER_EPOCH}" "$spec"
fi

# Use the modification time of the spec file as the SOURCE_DATE_EPOCH if
# BUILDER_SOURCE_DATE_FROM_SPEC_MTIME is set. This is useful for vendor packages
# that have independent versioning.
if [ -n "${BUILDER_SOURCE_DATE_FROM_SPEC_MTIME}" ]; then
SOURCE_DATE_EPOCH=$(stat -c '%Y' "$spec")
export SOURCE_DATE_EPOCH
fi

# Download sources
spectool -g -R "$spec"

# Build the rpm and record which files are new
rpm_file_list > /tmp/rpms-before
# NOTE: source_date_epoch_from_changelog is always overriden by SOURCE_DATE_EPOCH if that is set.
# See https://fossies.org/linux/rpm/build/build.c#l_298
rpmbuild \
--define "_sdistdir /sdist" \
--define "_buildhost reproducible" \
Expand Down

0 comments on commit 6455890

Please sign in to comment.