2012-08-22 19:25:57 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# NAME:
|
|
|
|
# meta2deps.sh - extract useful info from .meta files
|
|
|
|
#
|
|
|
|
# SYNOPSIS:
|
|
|
|
# meta2deps.sh SB="SB" "meta" ...
|
2020-11-24 21:45:38 +00:00
|
|
|
#
|
2012-08-22 19:25:57 +00:00
|
|
|
# DESCRIPTION:
|
|
|
|
# This script looks each "meta" file and extracts the
|
|
|
|
# information needed to deduce build and src dependencies.
|
2020-11-24 21:45:38 +00:00
|
|
|
#
|
2012-08-22 19:25:57 +00:00
|
|
|
# To do this, we extract the 'CWD' record as well as all the
|
|
|
|
# syscall traces which describe 'R'ead, 'C'hdir and 'E'xec
|
|
|
|
# syscalls.
|
|
|
|
#
|
|
|
|
# The typical meta file looks like::
|
|
|
|
#.nf
|
|
|
|
#
|
|
|
|
# # Meta data file "path"
|
|
|
|
# CMD "command-line"
|
|
|
|
# CWD "cwd"
|
|
|
|
# TARGET "target"
|
|
|
|
# -- command output --
|
|
|
|
# -- filemon acquired metadata --
|
|
|
|
# # buildmon version 2
|
|
|
|
# V 2
|
|
|
|
# E "pid" "path"
|
|
|
|
# R "pid" "path"
|
|
|
|
# C "pid" "cwd"
|
|
|
|
# R "pid" "path"
|
|
|
|
# X "pid" "status"
|
|
|
|
#.fi
|
|
|
|
#
|
|
|
|
# The fact that all the syscall entry lines start with a single
|
|
|
|
# character make these files quite easy to process using sed(1).
|
|
|
|
#
|
|
|
|
# To simplify the logic the 'CWD' line is made to look like a
|
|
|
|
# normal 'C'hdir entry, and "cwd" is remembered so that it can
|
|
|
|
# be prefixed to any "path" which is not absolute.
|
|
|
|
#
|
|
|
|
# If the "path" being read ends in '.srcrel' it is the content
|
|
|
|
# of (actually the first line of) that file that we are
|
|
|
|
# interested in.
|
|
|
|
#
|
|
|
|
# Any "path" which lies outside of the sandbox "SB" is generally
|
|
|
|
# not of interest and is ignored.
|
|
|
|
#
|
|
|
|
# The output, is a set of absolute paths with "SB" like:
|
|
|
|
#.nf
|
|
|
|
#
|
|
|
|
# $SB/obj-i386/bsd/include
|
2016-12-23 02:57:00 +00:00
|
|
|
# $SB/obj-i386/bsd/lib/csu/i386
|
2012-08-22 19:25:57 +00:00
|
|
|
# $SB/obj-i386/bsd/lib/libc
|
|
|
|
# $SB/src/bsd/include
|
|
|
|
# $SB/src/bsd/sys/i386/include
|
|
|
|
# $SB/src/bsd/sys/sys
|
|
|
|
# $SB/src/pan-release/rtsock
|
|
|
|
# $SB/src/pfe-shared/include/jnx
|
|
|
|
#.fi
|
|
|
|
#
|
|
|
|
# Which can then be further processed by 'gendirdeps.mk'
|
|
|
|
#
|
|
|
|
# If we are passed 'DPDEPS='"dpdeps", then for each src file
|
|
|
|
# outside of "CURDIR" we read, we output a line like:
|
|
|
|
#.nf
|
|
|
|
#
|
|
|
|
# DPDEPS_$path += $RELDIR
|
|
|
|
#.fi
|
|
|
|
#
|
|
|
|
# with "$path" geting turned into reldir's, so that we can end
|
|
|
|
# up with a list of all the directories which depend on each src
|
|
|
|
# file in another directory. This can allow for efficient yet
|
|
|
|
# complete testing of changes.
|
|
|
|
|
|
|
|
|
|
|
|
# RCSid:
|
2016-12-23 02:57:00 +00:00
|
|
|
# $FreeBSD$
|
2020-11-24 21:45:38 +00:00
|
|
|
# $Id: meta2deps.sh,v 1.14 2020/10/02 03:11:17 sjg Exp $
|
2012-08-22 19:25:57 +00:00
|
|
|
|
2015-06-13 19:20:56 +00:00
|
|
|
# Copyright (c) 2010-2013, Juniper Networks, Inc.
|
|
|
|
# All rights reserved.
|
2020-11-24 21:45:38 +00:00
|
|
|
#
|
2012-08-22 19:25:57 +00:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
2020-11-24 21:45:38 +00:00
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
2012-08-22 19:25:57 +00:00
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
2020-11-24 21:45:38 +00:00
|
|
|
# notice, this list of conditions and the following disclaimer.
|
2012-08-22 19:25:57 +00:00
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
2020-11-24 21:45:38 +00:00
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
2012-08-22 19:25:57 +00:00
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
|
|
|
|
# OWNER 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
|
2020-11-24 21:45:38 +00:00
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2012-08-22 19:25:57 +00:00
|
|
|
|
|
|
|
meta2src() {
|
|
|
|
cat /dev/null "$@" |
|
|
|
|
sed -n '/^R .*\.[chyl]$/s,^..[0-9]* ,,p' |
|
|
|
|
sort -u
|
|
|
|
}
|
2020-11-24 21:45:38 +00:00
|
|
|
|
2012-08-22 19:25:57 +00:00
|
|
|
meta2dirs() {
|
|
|
|
cat /dev/null "$@" |
|
|
|
|
sed -n '/^R .*\/.*\.[a-z0-9][^\/]*$/s,^..[0-9]* \(.*\)/[^/]*$,\1,p' |
|
|
|
|
sort -u
|
|
|
|
}
|
|
|
|
|
2013-05-11 05:10:31 +00:00
|
|
|
add_list() {
|
|
|
|
sep=' '
|
|
|
|
suffix=
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
"|") sep="$1"; shift;;
|
|
|
|
-s) suffix="$2"; shift 2;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
name=$1
|
|
|
|
shift
|
|
|
|
eval list="\$$name"
|
|
|
|
for top in "$@"
|
|
|
|
do
|
|
|
|
case "$sep$list$sep" in
|
|
|
|
*"$sep$top$suffix$sep"*) continue;;
|
|
|
|
esac
|
|
|
|
list="${list:+$list$sep}$top$suffix"
|
|
|
|
done
|
|
|
|
eval "$name=\"$list\""
|
|
|
|
}
|
|
|
|
|
2015-06-13 19:20:56 +00:00
|
|
|
_excludes_f() {
|
|
|
|
egrep -v "$EXCLUDES"
|
|
|
|
}
|
|
|
|
|
2020-11-24 21:45:38 +00:00
|
|
|
error() {
|
|
|
|
echo "ERROR: $@" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:25:57 +00:00
|
|
|
meta2deps() {
|
|
|
|
DPDEPS=
|
2013-05-11 05:10:31 +00:00
|
|
|
SRCTOPS=$SRCTOP
|
|
|
|
OBJROOTS=
|
2015-06-13 19:20:56 +00:00
|
|
|
EXCLUDES=
|
2012-08-22 19:25:57 +00:00
|
|
|
while :
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
*=*) eval export "$1"; shift;;
|
2013-05-11 05:10:31 +00:00
|
|
|
-a) MACHINE_ARCH=$2; shift 2;;
|
|
|
|
-m) MACHINE=$2; shift 2;;
|
|
|
|
-C) CURDIR=$2; shift 2;;
|
|
|
|
-H) HOST_TARGET=$2; shift 2;;
|
|
|
|
-S) add_list SRCTOPS $2; shift 2;;
|
|
|
|
-O) add_list OBJROOTS $2; shift 2;;
|
2015-06-13 19:20:56 +00:00
|
|
|
-X) add_list EXCLUDES '|' $2; shift 2;;
|
2013-05-11 05:10:31 +00:00
|
|
|
-R) RELDIR=$2; shift 2;;
|
|
|
|
-T) TARGET_SPEC=$2; shift 2;;
|
2012-08-22 19:25:57 +00:00
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2013-05-11 05:10:31 +00:00
|
|
|
_th= _o=
|
|
|
|
case "$MACHINE" in
|
|
|
|
host) _ht=$HOST_TARGET;;
|
|
|
|
esac
|
2020-11-24 21:45:38 +00:00
|
|
|
|
2013-05-11 05:10:31 +00:00
|
|
|
for o in $OBJROOTS
|
|
|
|
do
|
|
|
|
case "$MACHINE,/$o/" in
|
|
|
|
host,*$HOST_TARGET*) ;;
|
|
|
|
*$MACHINE*|*${TARGET_SPEC:-$MACHINE}*) ;;
|
|
|
|
*) add_list _o $o; continue;;
|
|
|
|
esac
|
|
|
|
for x in $_ht $TARGET_SPEC $MACHINE
|
|
|
|
do
|
|
|
|
case "$o" in
|
|
|
|
"") continue;;
|
|
|
|
*/$x/) add_list _o ${o%$x/}; o=;;
|
|
|
|
*/$x) add_list _o ${o%$x}; o=;;
|
|
|
|
*$x/) add_list _o ${o%$x/}; o=;;
|
|
|
|
*$x) add_list _o ${o%$x}; o=;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
done
|
|
|
|
OBJROOTS="$_o"
|
|
|
|
|
|
|
|
case "$OBJTOP" in
|
|
|
|
"")
|
|
|
|
for o in $OBJROOTS
|
|
|
|
do
|
|
|
|
OBJTOP=$o${TARGET_SPEC:-$MACHINE}
|
|
|
|
break
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
src_re=
|
|
|
|
obj_re=
|
|
|
|
add_list '|' -s '/*' src_re $SRCTOPS
|
|
|
|
add_list '|' -s '*' obj_re $OBJROOTS
|
2020-11-24 21:45:38 +00:00
|
|
|
|
2012-08-22 19:25:57 +00:00
|
|
|
[ -z "$RELDIR" ] && unset DPDEPS
|
|
|
|
tf=/tmp/m2d$$-$USER
|
|
|
|
rm -f $tf.*
|
|
|
|
trap 'rm -f $tf.*; trap 0' 0
|
|
|
|
|
|
|
|
> $tf.dirdep
|
|
|
|
> $tf.qual
|
|
|
|
> $tf.srcdep
|
|
|
|
> $tf.srcrel
|
|
|
|
> $tf.dpdeps
|
|
|
|
|
|
|
|
seenit=
|
|
|
|
seensrc=
|
|
|
|
lpid=
|
2015-06-13 19:20:56 +00:00
|
|
|
case "$EXCLUDES" in
|
|
|
|
"") _excludes=cat;;
|
|
|
|
*) _excludes=_excludes_f;;
|
|
|
|
esac
|
|
|
|
# handle @list files
|
|
|
|
case "$@" in
|
|
|
|
*@[!.]*)
|
|
|
|
for f in "$@"
|
|
|
|
do
|
|
|
|
case "$f" in
|
|
|
|
*.meta) cat $f;;
|
|
|
|
@*) xargs cat < ${f#@};;
|
|
|
|
*) cat $f;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*) cat /dev/null "$@";;
|
|
|
|
esac 2> /dev/null |
|
2020-11-24 21:45:38 +00:00
|
|
|
sed -e 's,^CWD,C C,;/^[CREFLMV] /!d' -e "s,',,g" |
|
|
|
|
$_excludes | ( version=no
|
2012-08-22 19:25:57 +00:00
|
|
|
while read op pid path junk
|
|
|
|
do
|
|
|
|
: op=$op pid=$pid path=$path
|
|
|
|
# we track cwd and ldir (of interest) per pid
|
|
|
|
# CWD is bmake's cwd
|
|
|
|
case "$lpid,$pid" in
|
|
|
|
,C) CWD=$path cwd=$path ldir=$path
|
|
|
|
if [ -z "$SB" ]; then
|
|
|
|
SB=`echo $CWD | sed 's,/obj.*,,'`
|
|
|
|
fi
|
|
|
|
SRCTOP=${SRCTOP:-$SB/src}
|
2020-11-24 21:45:38 +00:00
|
|
|
case "$verion" in
|
|
|
|
no) ;; # ignore
|
|
|
|
0) error "no filemon data";;
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
version=0
|
2012-08-22 19:25:57 +00:00
|
|
|
continue
|
|
|
|
;;
|
|
|
|
$pid,$pid) ;;
|
|
|
|
*)
|
|
|
|
case "$lpid" in
|
|
|
|
"") ;;
|
2016-12-23 02:57:00 +00:00
|
|
|
*) eval ldir_$lpid=$ldir;;
|
2012-08-22 19:25:57 +00:00
|
|
|
esac
|
|
|
|
eval ldir=\${ldir_$pid:-$CWD} cwd=\${cwd_$pid:-$CWD}
|
|
|
|
lpid=$pid
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "$op,$path" in
|
2020-11-24 21:45:38 +00:00
|
|
|
V,*) version=$path; continue;;
|
2013-05-11 05:10:31 +00:00
|
|
|
W,*srcrel|*.dirdep) continue;;
|
2012-08-22 19:25:57 +00:00
|
|
|
C,*)
|
|
|
|
case "$path" in
|
|
|
|
/*) cwd=$path;;
|
|
|
|
*) cwd=`cd $cwd/$path 2> /dev/null && /bin/pwd`;;
|
|
|
|
esac
|
|
|
|
# watch out for temp dirs that no longer exist
|
|
|
|
test -d ${cwd:-/dev/null/no/such} || cwd=$CWD
|
2016-12-23 02:57:00 +00:00
|
|
|
eval cwd_$pid=$cwd
|
2012-08-22 19:25:57 +00:00
|
|
|
continue
|
|
|
|
;;
|
2020-11-24 21:45:38 +00:00
|
|
|
F,*) # $path is new pid
|
2016-12-23 02:57:00 +00:00
|
|
|
eval cwd_$path=$cwd ldir_$path=$ldir
|
2012-08-22 19:25:57 +00:00
|
|
|
continue
|
2020-11-24 21:45:38 +00:00
|
|
|
;;
|
2012-08-22 19:25:57 +00:00
|
|
|
*) dir=${path%/*}
|
|
|
|
case "$path" in
|
2013-05-11 05:10:31 +00:00
|
|
|
$src_re|$obj_re) ;;
|
2012-08-22 19:25:57 +00:00
|
|
|
/*/stage/*) ;;
|
|
|
|
/*) continue;;
|
|
|
|
*) for path in $ldir/$path $cwd/$path
|
|
|
|
do
|
|
|
|
test -e $path && break
|
|
|
|
done
|
|
|
|
dir=${path%/*}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
# avoid repeating ourselves...
|
|
|
|
case "$DPDEPS,$seensrc," in
|
|
|
|
,*)
|
|
|
|
case ",$seenit," in
|
|
|
|
*,$dir,*) continue;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*,$path,*) continue;;
|
|
|
|
esac
|
|
|
|
# canonicalize if needed
|
|
|
|
case "/$dir/" in
|
|
|
|
*/../*|*/./*)
|
|
|
|
rdir=$dir
|
|
|
|
dir=`cd $dir 2> /dev/null && /bin/pwd`
|
|
|
|
seen="$rdir,$dir"
|
|
|
|
;;
|
|
|
|
*) seen=$dir;;
|
|
|
|
esac
|
|
|
|
case "$dir" in
|
2016-03-02 20:06:24 +00:00
|
|
|
${CURDIR:-.}|"") continue;;
|
2013-05-11 05:10:31 +00:00
|
|
|
$src_re)
|
2012-08-22 19:25:57 +00:00
|
|
|
# avoid repeating ourselves...
|
|
|
|
case "$DPDEPS,$seensrc," in
|
|
|
|
,*)
|
|
|
|
case ",$seenit," in
|
|
|
|
*,$dir,*) continue;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
case ",$seenit," in
|
|
|
|
*,$dir,*) continue;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ -d $path ]; then
|
|
|
|
case "$path" in
|
|
|
|
*/..) ldir=${dir%/*};;
|
|
|
|
*) ldir=$path;;
|
|
|
|
esac
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
[ -f $path ] || continue
|
|
|
|
case "$dir" in
|
|
|
|
$CWD) continue;; # ignore
|
2013-05-11 05:10:31 +00:00
|
|
|
$src_re)
|
2012-08-22 19:25:57 +00:00
|
|
|
seenit="$seenit,$seen"
|
|
|
|
echo $dir >> $tf.srcdep
|
|
|
|
case "$DPDEPS,$reldir,$seensrc," in
|
|
|
|
,*) ;;
|
|
|
|
*) seensrc="$seensrc,$path"
|
|
|
|
echo "DPDEPS_$dir/${path##*/} += $RELDIR" >> $tf.dpdeps
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
# if there is a .dirdep we cannot skip
|
|
|
|
# just because we've seen the dir before.
|
|
|
|
if [ -s $path.dirdep ]; then
|
|
|
|
# this file contains:
|
|
|
|
# '# ${RELDIR}.<machine>'
|
|
|
|
echo $path.dirdep >> $tf.qual
|
|
|
|
continue
|
|
|
|
elif [ -s $dir.dirdep ]; then
|
|
|
|
echo $dir.dirdep >> $tf.qual
|
|
|
|
seenit="$seenit,$seen"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
seenit="$seenit,$seen"
|
|
|
|
case "$dir" in
|
2013-05-11 05:10:31 +00:00
|
|
|
$obj_re)
|
2012-08-22 19:25:57 +00:00
|
|
|
echo $dir;;
|
|
|
|
esac
|
|
|
|
done > $tf.dirdep
|
2020-11-24 21:45:38 +00:00
|
|
|
case "$version" in
|
|
|
|
0) error "no filemon data";;
|
|
|
|
esac ) || exit 1
|
2012-08-22 19:25:57 +00:00
|
|
|
_nl=echo
|
|
|
|
for f in $tf.dirdep $tf.qual $tf.srcdep
|
|
|
|
do
|
|
|
|
[ -s $f ] || continue
|
|
|
|
case $f in
|
|
|
|
*qual) # a list of .dirdep files
|
2015-06-13 19:20:56 +00:00
|
|
|
# we can prefix everything with $OBJTOP to
|
2012-08-22 19:25:57 +00:00
|
|
|
# tell gendirdeps.mk that these are
|
|
|
|
# DIRDEP entries, since they are already
|
|
|
|
# qualified with .<machine> as needed.
|
|
|
|
# We strip .$MACHINE though
|
|
|
|
xargs cat < $f | sort -u |
|
2013-05-11 05:10:31 +00:00
|
|
|
sed "s,^# ,,;s,^,$OBJTOP/,;s,\.${TARGET_SPEC:-$MACHINE}\$,,;s,\.$MACHINE\$,,"
|
2012-08-22 19:25:57 +00:00
|
|
|
;;
|
|
|
|
*) sort -u $f;;
|
|
|
|
esac
|
|
|
|
_nl=:
|
|
|
|
done
|
|
|
|
if [ -s $tf.dpdeps ]; then
|
|
|
|
case "$DPDEPS" in
|
|
|
|
*/*) ;;
|
|
|
|
*) echo > $DPDEPS;; # the echo is needed!
|
|
|
|
esac
|
|
|
|
sort -u $tf.dpdeps |
|
|
|
|
sed "s,${SRCTOP}/,,;s,${SB_BACKING_SB:-$SB}/src/,," >> $DPDEPS
|
|
|
|
fi
|
|
|
|
# ensure we produce _something_ else egrep -v gets upset
|
|
|
|
$_nl
|
|
|
|
}
|
|
|
|
|
|
|
|
case /$0 in
|
|
|
|
*/meta2dep*) meta2deps "$@";;
|
|
|
|
*/meta2dirs*) meta2dirs "$@";;
|
|
|
|
*/meta2src*) meta2src "$@";;
|
|
|
|
esac
|