Changeset View
Changeset View
Standalone View
Standalone View
head/share/mk/meta2deps.sh
#!/bin/sh | #!/bin/sh | ||||
# NAME: | # NAME: | ||||
# meta2deps.sh - extract useful info from .meta files | # meta2deps.sh - extract useful info from .meta files | ||||
# | # | ||||
# SYNOPSIS: | # SYNOPSIS: | ||||
# meta2deps.sh SB="SB" "meta" ... | # meta2deps.sh SB="SB" "meta" ... | ||||
# | # | ||||
# DESCRIPTION: | # DESCRIPTION: | ||||
# This script looks each "meta" file and extracts the | # This script looks each "meta" file and extracts the | ||||
# information needed to deduce build and src dependencies. | # information needed to deduce build and src dependencies. | ||||
# | # | ||||
# To do this, we extract the 'CWD' record as well as all the | # To do this, we extract the 'CWD' record as well as all the | ||||
# syscall traces which describe 'R'ead, 'C'hdir and 'E'xec | # syscall traces which describe 'R'ead, 'C'hdir and 'E'xec | ||||
# syscalls. | # syscalls. | ||||
# | # | ||||
# The typical meta file looks like:: | # The typical meta file looks like:: | ||||
#.nf | #.nf | ||||
# | # | ||||
# # Meta data file "path" | # # Meta data file "path" | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
# with "$path" geting turned into reldir's, so that we can end | # 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 | # up with a list of all the directories which depend on each src | ||||
# file in another directory. This can allow for efficient yet | # file in another directory. This can allow for efficient yet | ||||
# complete testing of changes. | # complete testing of changes. | ||||
# RCSid: | # RCSid: | ||||
# $FreeBSD$ | # $FreeBSD$ | ||||
# $Id: meta2deps.sh,v 1.12 2016/12/13 20:44:16 sjg Exp $ | # $Id: meta2deps.sh,v 1.14 2020/10/02 03:11:17 sjg Exp $ | ||||
# Copyright (c) 2010-2013, Juniper Networks, Inc. | # Copyright (c) 2010-2013, Juniper Networks, Inc. | ||||
# All rights reserved. | # All rights reserved. | ||||
# | # | ||||
# Redistribution and use in source and binary forms, with or without | # Redistribution and use in source and binary forms, with or without | ||||
# modification, are permitted provided that the following conditions | # modification, are permitted provided that the following conditions | ||||
# are met: | # are met: | ||||
# 1. Redistributions of source code must retain the above copyright | # 1. Redistributions of source code must retain the above copyright | ||||
# notice, this list of conditions and the following disclaimer. | # notice, this list of conditions and the following disclaimer. | ||||
# 2. Redistributions in binary form must reproduce the above copyright | # 2. Redistributions in binary form must reproduce the above copyright | ||||
# notice, this list of conditions and the following disclaimer in the | # notice, this list of conditions and the following disclaimer in the | ||||
# documentation and/or other materials provided with the distribution. | # documentation and/or other materials provided with the distribution. | ||||
# | # | ||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
meta2src() { | meta2src() { | ||||
cat /dev/null "$@" | | cat /dev/null "$@" | | ||||
sed -n '/^R .*\.[chyl]$/s,^..[0-9]* ,,p' | | sed -n '/^R .*\.[chyl]$/s,^..[0-9]* ,,p' | | ||||
sort -u | sort -u | ||||
} | } | ||||
meta2dirs() { | meta2dirs() { | ||||
cat /dev/null "$@" | | cat /dev/null "$@" | | ||||
sed -n '/^R .*\/.*\.[a-z0-9][^\/]*$/s,^..[0-9]* \(.*\)/[^/]*$,\1,p' | | sed -n '/^R .*\/.*\.[a-z0-9][^\/]*$/s,^..[0-9]* \(.*\)/[^/]*$,\1,p' | | ||||
sort -u | sort -u | ||||
} | } | ||||
add_list() { | add_list() { | ||||
sep=' ' | sep=' ' | ||||
Show All 18 Lines | list="${list:+$list$sep}$top$suffix" | ||||
done | done | ||||
eval "$name=\"$list\"" | eval "$name=\"$list\"" | ||||
} | } | ||||
_excludes_f() { | _excludes_f() { | ||||
egrep -v "$EXCLUDES" | egrep -v "$EXCLUDES" | ||||
} | } | ||||
error() { | |||||
echo "ERROR: $@" >&2 | |||||
exit 1 | |||||
} | |||||
meta2deps() { | meta2deps() { | ||||
DPDEPS= | DPDEPS= | ||||
SRCTOPS=$SRCTOP | SRCTOPS=$SRCTOP | ||||
OBJROOTS= | OBJROOTS= | ||||
EXCLUDES= | EXCLUDES= | ||||
while : | while : | ||||
do | do | ||||
case "$1" in | case "$1" in | ||||
Show All 10 Lines | meta2deps() { | ||||
*) break;; | *) break;; | ||||
esac | esac | ||||
done | done | ||||
_th= _o= | _th= _o= | ||||
case "$MACHINE" in | case "$MACHINE" in | ||||
host) _ht=$HOST_TARGET;; | host) _ht=$HOST_TARGET;; | ||||
esac | esac | ||||
for o in $OBJROOTS | for o in $OBJROOTS | ||||
do | do | ||||
case "$MACHINE,/$o/" in | case "$MACHINE,/$o/" in | ||||
host,*$HOST_TARGET*) ;; | host,*$HOST_TARGET*) ;; | ||||
*$MACHINE*|*${TARGET_SPEC:-$MACHINE}*) ;; | *$MACHINE*|*${TARGET_SPEC:-$MACHINE}*) ;; | ||||
*) add_list _o $o; continue;; | *) add_list _o $o; continue;; | ||||
esac | esac | ||||
for x in $_ht $TARGET_SPEC $MACHINE | for x in $_ht $TARGET_SPEC $MACHINE | ||||
Show All 17 Lines | do | ||||
break | break | ||||
done | done | ||||
;; | ;; | ||||
esac | esac | ||||
src_re= | src_re= | ||||
obj_re= | obj_re= | ||||
add_list '|' -s '/*' src_re $SRCTOPS | add_list '|' -s '/*' src_re $SRCTOPS | ||||
add_list '|' -s '*' obj_re $OBJROOTS | add_list '|' -s '*' obj_re $OBJROOTS | ||||
[ -z "$RELDIR" ] && unset DPDEPS | [ -z "$RELDIR" ] && unset DPDEPS | ||||
tf=/tmp/m2d$$-$USER | tf=/tmp/m2d$$-$USER | ||||
rm -f $tf.* | rm -f $tf.* | ||||
trap 'rm -f $tf.*; trap 0' 0 | trap 'rm -f $tf.*; trap 0' 0 | ||||
> $tf.dirdep | > $tf.dirdep | ||||
> $tf.qual | > $tf.qual | ||||
> $tf.srcdep | > $tf.srcdep | ||||
Show All 16 Lines | do | ||||
*.meta) cat $f;; | *.meta) cat $f;; | ||||
@*) xargs cat < ${f#@};; | @*) xargs cat < ${f#@};; | ||||
*) cat $f;; | *) cat $f;; | ||||
esac | esac | ||||
done | done | ||||
;; | ;; | ||||
*) cat /dev/null "$@";; | *) cat /dev/null "$@";; | ||||
esac 2> /dev/null | | esac 2> /dev/null | | ||||
sed -e 's,^CWD,C C,;/^[CREFLM] /!d' -e "s,',,g" | | sed -e 's,^CWD,C C,;/^[CREFLMV] /!d' -e "s,',,g" | | ||||
$_excludes | | $_excludes | ( version=no | ||||
while read op pid path junk | while read op pid path junk | ||||
do | do | ||||
: op=$op pid=$pid path=$path | : op=$op pid=$pid path=$path | ||||
# we track cwd and ldir (of interest) per pid | # we track cwd and ldir (of interest) per pid | ||||
# CWD is bmake's cwd | # CWD is bmake's cwd | ||||
case "$lpid,$pid" in | case "$lpid,$pid" in | ||||
,C) CWD=$path cwd=$path ldir=$path | ,C) CWD=$path cwd=$path ldir=$path | ||||
if [ -z "$SB" ]; then | if [ -z "$SB" ]; then | ||||
SB=`echo $CWD | sed 's,/obj.*,,'` | SB=`echo $CWD | sed 's,/obj.*,,'` | ||||
fi | fi | ||||
SRCTOP=${SRCTOP:-$SB/src} | SRCTOP=${SRCTOP:-$SB/src} | ||||
case "$verion" in | |||||
no) ;; # ignore | |||||
0) error "no filemon data";; | |||||
*) ;; | |||||
esac | |||||
version=0 | |||||
continue | continue | ||||
;; | ;; | ||||
$pid,$pid) ;; | $pid,$pid) ;; | ||||
*) | *) | ||||
case "$lpid" in | case "$lpid" in | ||||
"") ;; | "") ;; | ||||
*) eval ldir_$lpid=$ldir;; | *) eval ldir_$lpid=$ldir;; | ||||
esac | esac | ||||
eval ldir=\${ldir_$pid:-$CWD} cwd=\${cwd_$pid:-$CWD} | eval ldir=\${ldir_$pid:-$CWD} cwd=\${cwd_$pid:-$CWD} | ||||
lpid=$pid | lpid=$pid | ||||
;; | ;; | ||||
esac | esac | ||||
case "$op,$path" in | case "$op,$path" in | ||||
V,*) version=$path; continue;; | |||||
W,*srcrel|*.dirdep) continue;; | W,*srcrel|*.dirdep) continue;; | ||||
C,*) | C,*) | ||||
case "$path" in | case "$path" in | ||||
/*) cwd=$path;; | /*) cwd=$path;; | ||||
*) cwd=`cd $cwd/$path 2> /dev/null && /bin/pwd`;; | *) cwd=`cd $cwd/$path 2> /dev/null && /bin/pwd`;; | ||||
esac | esac | ||||
# watch out for temp dirs that no longer exist | # watch out for temp dirs that no longer exist | ||||
test -d ${cwd:-/dev/null/no/such} || cwd=$CWD | test -d ${cwd:-/dev/null/no/such} || cwd=$CWD | ||||
eval cwd_$pid=$cwd | eval cwd_$pid=$cwd | ||||
continue | continue | ||||
;; | ;; | ||||
F,*) # $path is new pid | F,*) # $path is new pid | ||||
eval cwd_$path=$cwd ldir_$path=$ldir | eval cwd_$path=$cwd ldir_$path=$ldir | ||||
continue | continue | ||||
;; | ;; | ||||
*) dir=${path%/*} | *) dir=${path%/*} | ||||
case "$path" in | case "$path" in | ||||
$src_re|$obj_re) ;; | $src_re|$obj_re) ;; | ||||
/*/stage/*) ;; | /*/stage/*) ;; | ||||
/*) continue;; | /*) continue;; | ||||
*) for path in $ldir/$path $cwd/$path | *) for path in $ldir/$path $cwd/$path | ||||
do | do | ||||
test -e $path && break | test -e $path && break | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | elif [ -s $dir.dirdep ]; then | ||||
continue | continue | ||||
fi | fi | ||||
seenit="$seenit,$seen" | seenit="$seenit,$seen" | ||||
case "$dir" in | case "$dir" in | ||||
$obj_re) | $obj_re) | ||||
echo $dir;; | echo $dir;; | ||||
esac | esac | ||||
done > $tf.dirdep | done > $tf.dirdep | ||||
case "$version" in | |||||
0) error "no filemon data";; | |||||
esac ) || exit 1 | |||||
_nl=echo | _nl=echo | ||||
for f in $tf.dirdep $tf.qual $tf.srcdep | for f in $tf.dirdep $tf.qual $tf.srcdep | ||||
do | do | ||||
[ -s $f ] || continue | [ -s $f ] || continue | ||||
case $f in | case $f in | ||||
*qual) # a list of .dirdep files | *qual) # a list of .dirdep files | ||||
# we can prefix everything with $OBJTOP to | # we can prefix everything with $OBJTOP to | ||||
# tell gendirdeps.mk that these are | # tell gendirdeps.mk that these are | ||||
Show All 27 Lines |