History

scripts: objdiff: improve path flexibility for record command

Prior to this commit, scripts/objdiff expected to be run at the top directory and only the relative path of objects. This commit provides more flexibility in terms of object path: [1] scripts/objdiff can be run in any directory For example, $ scripts/objdiff record init/main.o and $ cd init; ../scripts/objdiff record main.o produce the same result. [2] Support absolute path for objects $ scripts/objdiff record /home/foo/bar/linux/init/main.o work as well.

Masahiro Yamada committed 12 years ago

Commit 18165ef1 parent 1ecc8e41 file · +16 −6Browse files

Showing the changes to scripts/objdiff (1 of 1 file). Show all

Unified · Split

scripts/objdiff+16−6
@@ -25,7 +25,7 @@ · 24 unmodified lines
2525 #
2626 # Note: 'make mrproper' will also remove .tmp_objdiff
2727
28−SRCTREE=$(git rev-parse --show-toplevel 2>/dev/null)
28+SRCTREE=$(cd $(git rev-parse --show-toplevel 2>/dev/null); pwd)
2929
3030 if [ -z "$SRCTREE" ]; then
3131 echo >&2 "ERROR: Not a git repository."
@@ -42,6 +42,18 @@ usage() { · 10 unmodified lines
4242 exit 1
4343 }
4444
45+get_output_dir() {
46+ dir=${1%/*}
47+
48+ if [ "$dir" = "$1" ]; then
49+ dir=.
50+ fi
51+
52+ dir=$(cd $dir; pwd)
53+
54+ echo $TMPD/$CMT${dir#$SRCTREE}
55+}
56+
4557 dorecord() {
4658 [ $# -eq 0 ] && usage
4759
@@ -50,18 +62,16 @@ dorecord() { · 2 unmodified lines
5062 CMT="`git rev-parse --short HEAD`"
5163
5264 OBJDUMP="${CROSS_COMPILE}objdump"
53− OBJDIFFD="$TMPD/$CMT"
5465
5566 for f in $FILES; do
56− dn="${f%/*}"
67+ dir=$(get_output_dir $f)
5768 bn="${f##*/}"
5869
59− [ ! -d "$OBJDIFFD/$dn" ] && mkdir -p "$OBJDIFFD/$dn"
70+ [ ! -d "$dir" ] && mkdir -p $dir
6071
6172 # remove addresses for a more clear diff
6273 # http://dummdida.tumblr.com/post/60924060451/binary-diff-between-libc-from-scientificlinux-and
63− $OBJDUMP -D "$f" | sed "s/^[[:space:]]\+[0-9a-f]\+//" \
64− >"$OBJDIFFD/$dn/$bn"
74+ $OBJDUMP -D $f | sed "s/^[[:space:]]\+[0-9a-f]\+//" > $dir/$bn
6575 done
6676 }
6777