summaryrefslogtreecommitdiff
path: root/mk/checksum
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2007-08-14 19:08:18 +0000
committerjlam <jlam@pkgsrc.org>2007-08-14 19:08:18 +0000
commita78cac15b03f657e62edf2f8b242d9ab2101ebc4 (patch)
tree6a33bc420a88a701f0bfd26738911f754e21bf28 /mk/checksum
parent9999f553d9d020b78da9bbb17fe761a757d9d89f (diff)
downloadpkgsrc-a78cac15b03f657e62edf2f8b242d9ab2101ebc4.tar.gz
Move the code that generates distinfo to a standalone AWK script.
Diffstat (limited to 'mk/checksum')
-rw-r--r--mk/checksum/bsd.checksum.mk6
-rw-r--r--mk/checksum/checksum.mk104
-rw-r--r--mk/checksum/distinfo.awk358
3 files changed, 410 insertions, 58 deletions
diff --git a/mk/checksum/bsd.checksum.mk b/mk/checksum/bsd.checksum.mk
index 7f142406197..47604bd6b1f 100644
--- a/mk/checksum/bsd.checksum.mk
+++ b/mk/checksum/bsd.checksum.mk
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.checksum.mk,v 1.5 2007/03/07 01:06:11 rillig Exp $
+# $NetBSD: bsd.checksum.mk,v 1.6 2007/08/14 19:08:18 jlam Exp $
#
# This Makefile fragment is included by bsd.pkg.mk and defines the
# relevant variables and targets for the "checksum" phase.
@@ -33,8 +33,8 @@
.PHONY: checksum makesum makepatchsum mps mdi makedistinfo distinfo
-checksum makesum: fetch
-makedistinfo distinfo mdi: makepatchsum makesum
+checksum distinfo makesum: fetch
+makedistinfo mdi: distinfo
mps: makepatchsum
.if defined(NO_CHECKSUM)
diff --git a/mk/checksum/checksum.mk b/mk/checksum/checksum.mk
index 8a01e258d92..490575ed562 100644
--- a/mk/checksum/checksum.mk
+++ b/mk/checksum/checksum.mk
@@ -1,4 +1,4 @@
-# $NetBSD: checksum.mk,v 1.4 2007/03/07 01:06:11 rillig Exp $
+# $NetBSD: checksum.mk,v 1.5 2007/08/14 19:08:18 jlam Exp $
#
# See bsd.checksum.mk for helpful comments.
#
@@ -40,39 +40,51 @@ ${_COOKIE.checksum}:
fi
.endfor
-makesum:
- ${_PKG_SILENT}${_PKG_DEBUG}set -e; \
+_DISTINFO_CMD= ${SETENV} DIGEST=${TOOLS_DIGEST:Q} SED=${TOOLS_SED:Q} \
+ TEST=${TOOLS_TEST:Q} WC=${TOOLS_WC:Q} \
+ ${AWK} -f ${PKGSRCDIR}/mk/checksum/distinfo.awk --
+
+.if exists(${DISTDIR})
+_DISTINFO_ARGS_COMMON+= -d ${DISTDIR}
+.endif
+.if exists(${DISTINFO_FILE})
+_DISTINFO_ARGS_COMMON+= -f ${DISTINFO_FILE}
+.endif
+.if defined(_DIGEST_ALGORITHMS) && !empty(_DIGEST_ALGORITHMS)
+_DISTINFO_ARGS_COMMON+= ${_DIGEST_ALGORITHMS:S/^/-a /}
+.endif
+.if defined(_PATCH_DIGEST_ALGORITHMS) && !empty(_PATCH_DIGEST_ALGORITHMS)
+_DISTINFO_ARGS_COMMON+= ${_PATCH_DIGEST_ALGORITHMS:S/^/-p /}
+.endif
+
+.if defined(_CKSUMFILES) && !empty(_CKSUMFILES)
+_DISTINFO_ARGS_DISTSUM+= ${_CKSUMFILES:S/^/-c /}
+.endif
+.if defined(_IGNOREFILES) && !empty(_IGNOREFILES)
+_DISTINFO_ARGS_DISTSUM+= ${_IGNOREFILES:S/^/-i /}
+.endif
+
+_DISTINFO_ARGS_PATCHSUM+= ${PATCHDIR}/patch-*
+
+distinfo:
+ ${RUN}set -e; \
newfile=${DISTINFO_FILE}.$$$$; \
- if ${TEST} -f ${DISTINFO_FILE}; then \
- { ${GREP} '^.NetBSD' ${DISTINFO_FILE} || \
- ${ECHO} "$$""NetBSD""$$"; } > $$newfile; \
+ if ${_DISTINFO_CMD} ${_DISTINFO_ARGS_COMMON} \
+ ${_DISTINFO_ARGS_DISTSUM} \
+ ${_DISTINFO_ARGS_PATCHSUM} > $$newfile; \
+ then \
+ ${RM} -f $$newfile; \
+ ${ECHO_MSG} "=> distinfo: unchanged."; \
else \
- ${ECHO} "$$""NetBSD""$$" > $$newfile; \
- fi; \
- ${ECHO} "" >> $$newfile; \
- cd ${DISTDIR}; \
- for sumfile in "" ${_CKSUMFILES}; do \
- ${TEST} -n "$$sumfile" || continue; \
- for a in "" ${_DIGEST_ALGORITHMS}; do \
- ${TEST} -n "$$a" || continue; \
- ${TOOLS_DIGEST} $$a $$sumfile >> $$newfile; \
- done; \
- ${WC} -c $$sumfile | \
- ${AWK} '{ print "Size (" $$2 ") = " $$1 " bytes" }' \
- >> $$newfile; \
- done; \
- for ignore in "" ${_IGNOREFILES}; do \
- ${TEST} -n "$$ignore" || continue; \
- for a in "" ${_DIGEST_ALGORITHMS}; do \
- ${TEST} -n "$$a" || continue; \
- ${ECHO} "$$a ($$ignore) = IGNORE" >> $$newfile; \
- done; \
- done; \
- if ${TEST} -f ${DISTINFO_FILE}; then \
- ${AWK} '$$2 ~ /\(patch-[a-z0-9]+\)/ { print $$0 }' \
- < ${DISTINFO_FILE} >> $$newfile; \
- fi; \
- if ${CMP} -s $$newfile ${DISTINFO_FILE}; then \
+ ${MV} -f $$newfile ${DISTINFO_FILE}; \
+ fi
+
+makesum:
+ ${RUN}set -e; \
+ newfile=${DISTINFO_FILE}.$$$$; \
+ if ${_DISTINFO_CMD} ${_DISTINFO_ARGS_COMMON} \
+ ${_DISTINFO_ARGS_DISTSUM} > $$newfile; \
+ then \
${RM} -f $$newfile; \
${ECHO_MSG} "=> distinfo: distfiles part unchanged."; \
else \
@@ -80,31 +92,13 @@ makesum:
fi
makepatchsum:
- ${_PKG_SILENT}${_PKG_DEBUG}set -e; \
+ ${RUN}set -e; \
newfile=${DISTINFO_FILE}.$$$$; \
- if ${TEST} -f ${DISTINFO_FILE}; then \
- ${AWK} '$$2 !~ /\(patch-[a-z0-9]+\)/ { print $$0 }' \
- < ${DISTINFO_FILE} >> $$newfile; \
- else \
- ${ECHO} "$$""NetBSD""$$" > $$newfile; \
- ${ECHO} "" >> $$newfile; \
- fi; \
- if ${TEST} -d ${PATCHDIR}; then \
- ( cd ${PATCHDIR}; \
- for sumfile in "" patch-*; do \
- case "$$sumfile" in \
- ""|"patch-*") continue ;; \
- patch-local-*|*.orig|*.rej|*~) continue ;; \
- esac; \
- for a in "" ${_PATCH_DIGEST_ALGORITHMS}; do \
- ${TEST} -n "$$a" || continue; \
- ${ECHO} "$$a ($$sumfile) = `${SED} -e '/\$$NetBSD.*/d' $$sumfile | ${TOOLS_DIGEST} $$a`" >> $$newfile; \
- done; \
- done ); \
- fi; \
- if ${CMP} -s $$newfile ${DISTINFO_FILE}; then \
+ if ${_DISTINFO_CMD} ${_DISTINFO_ARGS_COMMON} \
+ ${_DISTINFO_ARGS_PATCHSUM} > $$newfile; \
+ then \
${RM} -f $$newfile; \
${ECHO_MSG} "=> distinfo: patches part unchanged."; \
else \
- ${MV} $$newfile ${DISTINFO_FILE}; \
+ ${MV} -f $$newfile ${DISTINFO_FILE}; \
fi
diff --git a/mk/checksum/distinfo.awk b/mk/checksum/distinfo.awk
new file mode 100644
index 00000000000..f8ba3144003
--- /dev/null
+++ b/mk/checksum/distinfo.awk
@@ -0,0 +1,358 @@
+#!/usr/bin/awk -f
+#
+# $NetBSD: distinfo.awk,v 1.1 2007/08/14 19:08:18 jlam Exp $
+#
+# Copyright (c) 2007 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by the NetBSD
+# Foundation, Inc. and its contributors.
+# 4. Neither the name of The NetBSD Foundation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+###########################################################################
+#
+# NAME
+# distinfo.awk -- print distinfo information to standard output
+#
+# SYNOPSIS
+# distinfo.awk -- [options] [patch ...]
+#
+# DESCRIPTION
+# distinfo.awk generates distinfo information for the named
+# cksumfiles, ignorefiles and patches. The format of a distinfo
+# file is:
+#
+# 1. NetBSD RCS ID header
+# 2. a blank line
+# 3. digests and size information for each cksumfile and ignorefile
+# 4. digests for patches
+#
+# For example:
+#
+# $NetBSD: distinfo.awk,v 1.1 2007/08/14 19:08:18 jlam Exp $
+#
+# SHA1 (make-3.81.tar.gz) = cd4fa5a3184176492bf0799593a8f250a728210c
+# RMD160 (make-3.81.tar.gz) = a713a72875cb9a29568677c98022465c6f55cbbf
+# Size (make-3.81.tar.gz) = 1564560 bytes
+# SHA1 (patch-aa) = ba88ee2175c7c2258fc647b3654b2f725cf75a50
+# SHA1 (patch-ac) = de18956fde66fa3fc61a991bb3e6724d9c5b1eac
+# SHA1 (patch-af) = 067cac366694ce33e5bc52ef937603ae17d3bc2e
+#
+# OPTIONS
+# The following command line arguments are supported.
+#
+# -- This is a mandatory option and must always be the
+# first option specified.
+#
+# -a algorithm Generate a digest for the specified distfiles
+# using the named digest algorithm. If this option
+# is given more than once, then digests are
+# generated using each algorithm in the order
+# given.
+#
+# -c cksumfile Generate distinfo information for the named
+# cksumfile. If this option is given more than
+# once, then generate information for each
+# cksumfile in alphabetical order.
+#
+# -d distdir Directory under which cksumfiles and ignorefiles
+# are found.
+#
+# -f distinfo Path to an existing distinfo file. If this
+# option is given, then it is used to provide the
+# distinfo information for either cksumfiles and
+# ignorefiles or patches, depending on which
+# are not given on the command line. Also, using
+# this option causes the return code to be 0 if
+# the generated distinfo information matches the
+# contents of the existing distinfo file, or
+# non-zero otherwise.
+#
+# -i ignorefile Generate distinfo information to ignore checksum
+# verification for ignorefile. If this option is
+# given more than once, then generate information
+# for each ignore file in alphabetical order.
+#
+# -p algorithm Generate a digest for the patches using the named
+# digest algorithm. If this option is given more
+# than once, then digests are generated using each
+# algorithm in the order given.
+#
+# patch ... Generate distinfo information for the named
+# patches in alphabetical order.
+#
+###########################################################################
+
+BEGIN {
+ DIGEST = ENVIRON["DIGEST"] ? ENVIRON["DIGEST"] : "digest"
+ SED = ENVIRON["SED"] ? ENVIRON["SED"] : "sed"
+ TEST = ENVIRON["TEST"] ? ENVIRON["TEST"] : "test"
+ WC = ENVIRON["WC"] ? ENVIRON["WC"] : "wc"
+
+ self = "distinfo.awk"
+ ARGSTART = 1
+ A = 0 # size of algorithms array
+ D = 0 # size of distfiles array
+ L = 0 # size of lines array
+ P = 0 # size of patch_algorithms array
+ N = 0 # size of patchfiles array
+ F = 0 # size of distinfo_lines array
+
+ distdir = "."
+ distinfo = ""
+ exitcode = 0
+
+ parse_options()
+
+ if (length(distdir) > 0) {
+ cmd = TEST " -d " distdir
+ if (system(cmd) != 0) {
+ print self ": " distdir " not found"
+ exitcode = 128
+ }
+ }
+ if (length(distinfo) > 0) {
+ cmd = TEST " -f " distinfo
+ if (system(cmd) != 0) {
+ print self ": " distinfo " not found"
+ exitcode = 128
+ }
+ while(getline < distinfo) { distinfo_lines[F++] = $0 }
+ close(distinfo)
+ }
+
+ if (exitcode > 0) exit(exitcode)
+
+ if (length(distinfo) == 0) { # no distinfo file
+ header()
+ distsum()
+ patchsum()
+ exitcode = 1
+ } else {
+ if (D > 0 && N > 0) { # distfiles & patches
+ header()
+ distsum()
+ patchsum()
+ } else if (D > 0 && N == 0) { # distfiles only
+ header()
+ distsum()
+ #
+ # Grab the patch distinfo lines from the existing
+ # distinfo file.
+ #
+ for (l = 0; l < F; l++) {
+ file = distinfo_lines[l]
+ sub("^[^(]*[(]", "", file)
+ sub("[)][^)]*$", "", file)
+ if (is_patch(file))
+ lines[L++] = distinfo_lines[l]
+ }
+ } else if (D == 0 && N > 0) { # patches only
+ #
+ # Grab the non-patch distinfo lines from the
+ # existing distinfo file.
+ #
+ for (l = 0; l < F; l++) {
+ file = distinfo_lines[l]
+ sub("^[^(]*[(]", "", file)
+ sub("[)][^)]*$", "", file)
+ if (!is_patch(file))
+ lines[L++] = distinfo_lines[l]
+ }
+ patchsum()
+ }
+ exitcode = is_same_distinfo() ? 0 : 1
+ }
+
+ # Print the new distinfo content to standard output.
+ for (l = 0; l < L; l++) { print lines[l] }
+
+ exit(exitcode)
+}
+
+function insertion_sort(a, nelem, temp, i, j) {
+ for (i = 1; i < nelem; ++i) {
+ for (j = i; a[j-1] > a[j]; --j) {
+ temp = a[j]
+ a[j] = a[j-1]
+ a[j-1] = temp
+ }
+ }
+ return
+}
+
+function parse_options( option) {
+ while (ARGSTART < ARGC) {
+ option = ARGV[ARGSTART]
+ if (option == "-a") {
+ algorithms[A++] = ARGV[ARGSTART + 1]
+ ARGSTART += 2
+ } else if (option == "-c") {
+ distfiles[D++] = ARGV[ARGSTART + 1]
+ cksumfiles[ARGV[ARGSTART + 1]] = 1
+ ARGSTART += 2
+ } else if (option == "-d") {
+ distdir = ARGV[ARGSTART + 1]
+ ARGSTART += 2
+ } else if (option == "-f") {
+ distinfo = ARGV[ARGSTART + 1]
+ ARGSTART += 2
+ } else if (option == "-i") {
+ distfiles[D++] = ARGV[ARGSTART + 1]
+ ignorefiles[ARGV[ARGSTART + 1]] = 1
+ ARGSTART += 2
+ } else if (option == "-p") {
+ patch_algorithms[P++] = ARGV[ARGSTART + 1]
+ ARGSTART += 2
+ } else if (option == "--") {
+ ARGSTART++
+ break
+ } else if (match(option, /^-.*/) != 0) {
+ option = substr(option, RSTART + 1, RLENGTH)
+ print self ": unknown option -- " option > "/dev/stderr"
+ print "usage: " self " -- [-a alg] [-c file] [-d distdir] [-f distinfo] [-i ignore] [-p alg] [patch ...]" > "/dev/stderr"
+ exit 1
+ } else {
+ break
+ }
+ }
+ while (ARGSTART < ARGC) {
+ patchfiles[N++] = ARGV[ARGSTART++]
+ }
+
+ # Sort each of the resulting arrays.
+ #insertion_sort(algorithms, A)
+ #insertion_sort(patch_algorithms, P)
+ insertion_sort(distfiles, D)
+ insertion_sort(patchfiles, N)
+}
+
+###
+### header()
+### Pull the NetBSD RCS ID file from the existing distinfo file
+### if it's available, otherwise generate a new one.
+###
+function header() {
+ if (length(distinfo) > 0) {
+ cmd = SED " 1q " distinfo
+ cmd | getline; close(cmd)
+ if ($0 ~ /^[$]NetBSD/) {
+ lines[L++] = $0
+ lines[L++] = ""
+ return
+ }
+ }
+ lines[L++] = "$NetBSD: distinfo.awk,v 1.1 2007/08/14 19:08:18 jlam Exp $"
+ lines[L++] = ""
+}
+
+###
+### is_patch(file)
+### Return 1 if the file is a valid patch name, or 0 otherwise.
+###
+function is_patch(file) {
+ if (file ~ /^patch-local-|[.]orig$|[.]rej$|~$/) return 0
+ if (file ~ /^patch-.*/) return 1
+ return 0
+}
+
+###
+### distsum()
+### Generate digests using the ones named in the algorithms
+### array, and size information for each cksumfile. Generate
+### an IGNORE line for each ignorefile.
+###
+function distsum( alg, file, cmd, a, i) {
+ for (i = 0; i < D; i++) {
+ file = distfiles[i]
+ cmd = "cd " distdir " && " TEST " -f " file
+ if (system(cmd) != 0) continue
+ for (a = 0; a < A; a++) {
+ alg = algorithms[a]
+ if (cksumfiles[file] == 1) {
+ cmd = "cd " distdir " && " DIGEST " " alg " " file
+ cmd | getline lines[L++]; close(cmd)
+ } else if (ignorefiles[file] == 1) {
+ lines[L++] = alg " (" file ") = IGNORE"
+ }
+ }
+ if (cksumfiles[file] == 1) {
+ cmd = "cd " distdir " && " WC " -c " file
+ cmd | getline; close(cmd)
+ sub("^[ ]+", ""); sub("[ ].*", "")
+ lines[L++] = "Size (" file ") = " $0 " bytes"
+ }
+ }
+}
+
+###
+### patchsum()
+### Generate digests using the ones named in patch_algorithms
+### for each patch.
+###
+function patchsum( alg, dir, file, patch, cmd, a, i) {
+ for (i = 0; i < N; i++) {
+ patch = patchfiles[i]
+ dir = patch; sub("/[^/]*$", "", dir)
+ file = patch; sub("^.*/", "", file)
+ cmd = TEST " -f " patch
+ if ((system(cmd) != 0) || !is_patch(file)) continue
+ for (a = 0; a < P; a++) {
+ alg = patch_algorithms[a]
+ cmd = SED " 1q " patch
+ cmd | getline; close(cmd)
+ if ($0 ~ /^[$]NetBSD/) {
+ cmd = SED " 1d " patch " | " DIGEST " " alg
+ cmd | getline; close(cmd)
+ sub("^", alg " (" file ") = ")
+ lines[L++] = $0
+ } else {
+ cmd = "cd " dir " && " DIGEST " " alg " " file
+ cmd | getline lines[L++]; close(cmd)
+ }
+ }
+ }
+}
+
+###
+### is_same_distinfo()
+### Return 1 if the distinfo_lines and lines array match
+### (so the new distinfo content and the old distinfo
+### content match), and zero otherwise.
+###
+function is_same_distinfo( l) {
+ if (L != F) { return 0 }
+ for (l = 0; l < L; l++) {
+ if (distinfo_lines[l] != lines[l])
+ return 0
+ }
+ return 1
+}