pkgsrc-wip/pkg_summary-utils/files/pkg_lint_summary.in
2010-03-12 21:38:22 +00:00

156 lines
3.7 KiB
Text
Executable file

#!/usr/bin/env runawk
# Copyright (c) 2010 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.
############################################################
#env "LC_ALL=C"
#use "pkgsrc-dewey.awk"
#use "power_getopt.awk"
#use "psu_funcs.awk"
#use "has_prefix.awk"
#use "exitnow.awk"
############################################################
#.begin-str help
# pkg_lint_summary - does sanity check for summaries
# usage: pkg_cmp_summary -h
# pkg_cmp_summary [OPTIONS] [files...]
# OPTIONS:
# -h|--help display this help
# -l checks REQUIRES/PROVIDES fields
# -d checks DEPENDS fields (they present and
# versions are correct)
#.end-str
############################################################
BEGIN {
prefix = ENVIRON ["PREFIX"]
if (prefix == "")
prefix = "@@prefix@@"
opt_l = getarg("l")
opt_d = getarg("d")
cnt = 0
if (!opt_l && !opt_d){
print "One of the following options should be applied: -l, -d" \
> "/dev/stderr"
exitnow(1)
}
}
/^PKGNAME=/{
pkgname = substr($0, 9)
pkgbase = pkgname2pkgbase(pkgname)
pkgver = pkgname2version(pkgname)
}
/^PKGPATH=/{
pkgpath = substr($0, 9)
}
NF == 0 {
for (i=1; i < 10000 && ((pkgbase SUBSEP i) in pkg2ver); ++i){
pkg2ver [pkgbase, i] = pkgver
}
pkg2ver [pkgbase] = 1
}
opt_l {
if (/^REQUIRES=/){
requires1 = substr($0, 10)
if (!(requires1 in provides2pkg))
requires [++requires_cnt] = requires1
}else if (/^PROVIDES=/){
provides1 = substr($0, 10)
provides2pkg [provides1] = 1
}else if (NF == 0){
pkg = (pkgpath " " pkgname)
for (i=1; i <= requires_cnt; ++i){
# print "r:", requires [i], pkg
req = requires [i]
reqd_libs [req] = 1
reqd_libs2where [req, ++reqd_libs2cnt [req]] = pkg
}
requires_cnt = 0
}
}
opt_d {
if (/^DEPENDS=/) {
cnt=split(substr($0, 9), arr, / /)
for (i=1; i <= cnt; ++i){
deps [++deps_cnt] = arr [i]
}
}else if (NF == 0){
for (i=1; i <= deps_cnt; ++i){
if (! (i in deps))
break
# print pkgpath, pkgbase, i, "->", deps [i]
depends [pkgpath, pkgbase, i] = deps [i]
}
deps_cnt = 0
}
}
NF == 0 {
pkgname = pkgpath = pkgver = ""
}
function check_ver (ver, condition){
}
END {
ex = 0
if (opt_l){
for (p in reqd_libs){
if (! (p in provides2pkg)){
if (has_prefix(p, prefix)){
for (i=1; i <= reqd_libs2cnt [p]; ++i){
print "l: not_found " p, reqd_libs2where [p, i]
ex = 1
}
}
}
}
}
if (opt_d){
for (d in depends){
dep = depends [d]
pkgdep=pkgname2pkgbase(dep)
# pkgver=pkgname2version(dep)
split(d, arr, SUBSEP)
if (! (pkgdep in pkg2ver)){
print "d: not_found", pkgdep, "<-", arr [1], arr [2]
ex = 1
}
# print arr[2]
# print d, dep, pkgdep, pkgver
}
}
exitnow(ex)
}