diff --git a/common/hooks/post-install/05-generate-gitrevs.sh b/common/hooks/post-install/05-generate-gitrevs.sh new file mode 100644 index 00000000000..2804e0e4541 --- /dev/null +++ b/common/hooks/post-install/05-generate-gitrevs.sh @@ -0,0 +1,39 @@ +# This hook generates a file in ${wrksrc}/.xbps_git_revs with the last +# commit sha1 (in short mode) for all files of a source pkg. + +hook() { + local GITREVS_FILE=${wrksrc}/.xbps_${sourcepkg}_git_revs + local _revs= _out= f= _filerev= _files= + + # If XBPS_USE_GIT_REVS is disabled in conf file don't continue. + if [ -z $XBPS_USE_GIT_REVS ]; then + return + fi + # If the file exists don't regenerate it again. + if [ -s ${GITREVS_FILE} ]; then + return + fi + # Get the git revisions from this source pkg. + cd ${XBPS_SRCPKGDIR} + _files=$(git ls-files ${sourcepkg}) + [ -z "${_files}" ] && return + + for f in ${_files}; do + _filerev=$(git rev-list --abbrev-commit HEAD $f | head -n1) + [ -z "${_filerev}" ] && continue + _out="${f} ${_filerev}" + if [ -z "${_revs}" ]; then + _revs="${_out}" + else + _revs="${_revs} ${_out}" + fi + done + + set -- ${_revs} + while [ $# -gt 0 ]; do + local _file=$1; local _rev=$2 + echo "${_file}: ${_rev}" + echo "${_file}: ${_rev}" >> ${GITREVS_FILE} + shift 2 + done +} diff --git a/common/hooks/pre-pkg/00-gen-pkg.sh b/common/hooks/pre-pkg/00-gen-pkg.sh index 2fccc9e2cfb..f6e41a0a5ba 100644 --- a/common/hooks/pre-pkg/00-gen-pkg.sh +++ b/common/hooks/pre-pkg/00-gen-pkg.sh @@ -40,6 +40,9 @@ genpkg() { if [ -s ${PKGDESTDIR}/shlib-requires ]; then _shrequires="$(cat ${PKGDESTDIR}/shlib-requires)" fi + if [ -s ${wrksrc}/.xbps_${sourcepkg}_git_revs ]; then + _gitrevs="$(cat ${wrksrc}/.xbps_${sourcepkg}_git_revs)" + fi if [ -n "$provides" ]; then local _provides= @@ -92,7 +95,7 @@ genpkg() { --built-with "xbps-src-${XBPS_SRC_VERSION}" \ --build-options "${PKG_BUILD_OPTIONS}" \ --pkgver "${pkgver}" --quiet \ - --source-revisions "$(cat ${PKG_GITREVS_FILE:-/dev/null} 2>/dev/null)" \ + --source-revisions "${_gitrevs}" \ --shlib-provides "${_shprovides}" \ --shlib-requires "${_shrequires}" \ ${_preserve} ${_sourcerevs} ${PKGDESTDIR}