pkgsrc-wip/pkg_summary-utils/files/pkg_cmp_summary
Aleksey Cheusov 7ad7a55f22 version -> 0.15.0
Major changes

     pkg_grep_summary: in order to support summaries for multi-variant
     packages it is strongly recommented to use 'fvalue' variable in
     condition, not $2. Man page and README update accordingly.

     pkg_cmp_summary: -m option added for comparing summaries for
     multi-variant packages
     (PKGPATH=category/name:variable_assignments format).

pkg_cmp_summary -m implies -p
2008-09-07 18:17:38 +00:00

186 lines
4.1 KiB
Text
Executable file

#!/usr/bin/env runawk
# Copyright (c) 2007-2008 Aleksey Cheusov <vle@gmx.net>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
############################################################
#use "pkgsrc-dewey.awk"
############################################################
function usage (){
printf "\
pkg_cmp_summary - compares two summary files\n\
usage: pkg_cmp_summary -h\n\
pkg_cmp_summary [OPTIONS] summary1 summary2\n\
OPTIONS:\n\
-h|--help display this help\n\
-p|--with-pkgpath use PKGPATH:PKGBASE pair for identifing a package\n\
-c|--use-checksum also use CVS_CHECKSUM field in comparing packages\n\
-m|--multi support multi-variant packages, that is packages\n\
with building options in PKGPATH section\n\
" > "/dev/stderr"
}
BEGIN {
skip = 0
for (i = 1; i <= ARGC; ++i){
if (ARGV [i] ~ /^(-h|--help)$/){
usage()
exit 0
}else if (ARGV [i] ~ /^(-p|--with-pkgpath)$/){
with_pkgpath = 1
ARGV [i] = ""
++skip
}else if (ARGV [i] ~ /^(-c|--use-checksum)$/){
use_checksum = 1
ARGV [i] = ""
++skip
}else if (ARGV [i] ~ /^(-m|--multi)$/){
with_multivar = 1
with_pkgpath = 1
ARGV [i] = ""
++skip
}
}
if (ARGC-skip != 3){
usage()
exit 1
}
file1 = ARGV [1 + skip]
}
function trim (s){
sub(/^[ \t]+/, "", s)
sub(/[ \t]+$/, "", s)
return s
}
$0 ~ /^PKGNAME=/ {
pkgname = trim(substr($0, 9))
next
}
use_checksum && $0 ~ /^CVS_CHECKSUM=/ {
checksum = trim(substr($0, 14))
next
}
with_pkgpath && $0 ~ /^PKGPATH=/ {
pkgpath = trim(substr($0, 9))
full_pkgpath = pkgpath
if (with_multivar && pkgpath ~ /:/){
sub(/:.*$/, "", pkgpath)
}
next
}
NF == 0 {
# ver
ver = pkgname
sub(/^.*-/, "", ver)
# pkgbase
sub(/-[^-]+$/, "", pkgname)
# option PKGPATH
if (with_pkgpath){
pkgbase = pkgpath " " pkgname
full_pkgbase = full_pkgpath " " pkgname
}else{
pkgbase = pkgname
full_pkgbase = pkgname
}
# current checksum
curr_checksum = checksum
# cleaning...
pkgname = pkgpath = checksum = ""
#
if (FILENAME == file1){
# first file!
if (pkgbase in names){
duplicates [pkgbase] += 1
}else{
names [pkgbase] = ver
if (with_multivar && pkgpath != full_pkgpath){
full_pkgpaths [pkgbase] = full_pkgbase
}
if (use_checksum){
checksums [pkgbase] = curr_checksum
}
}
}else{
# second file!
present [pkgbase] = 0
if (pkgbase in duplicates){
next
}
if (! (pkgbase in names)){
print "+", full_pkgbase, ver
next
}
ver1 = names [pkgbase]
res = dewey_cmp(ver1, ver)
if (use_checksum && res == "="){
prev_checksum = checksums [pkgbase]
if (prev_checksum != "" &&
curr_checksum != "" &&
prev_checksum != curr_checksum)
{
res = "!"
}
}
print res, full_pkgbase, ver1, ver
}
next
}
END {
for (pkgbase in names){
if (! (pkgbase in present)){
if (pkgbase in full_pkgpaths)
print "-", full_pkgpaths [pkgbase], names [pkgbase]
else
print "-", pkgbase, names [pkgbase]
delete duplicates [pkgbase]
}else if (pkgbase in duplicates){
print duplicates [pkgbase]+1, pkgbase
}
}
}