scripts: objdiff: remove unnecessary code
[deliverable/linux.git] / scripts / objdiff
1 #!/bin/bash
2
3 # objdiff - a small script for validating that a commit or series of commits
4 # didn't change object code.
5 #
6 # Copyright 2014, Jason Cooper <jason@lakedaemon.net>
7 #
8 # Licensed under the terms of the GNU GPL version 2
9
10 # usage example:
11 #
12 # $ git checkout COMMIT_A
13 # $ <your fancy build command here>
14 # $ ./scripts/objdiff record path/to/*.o
15 #
16 # $ git checkout COMMIT_B
17 # $ <your fancy build command here>
18 # $ ./scripts/objdiff record path/to/*.o
19 #
20 # $ ./scripts/objdiff diff COMMIT_A COMMIT_B
21 # $
22
23 # And to clean up (everything is in .tmp_objdiff/*)
24 # $ ./scripts/objdiff clean all
25 #
26 # Note: 'make mrproper' will also remove .tmp_objdiff
27
28 SRCTREE=$(git rev-parse --show-toplevel 2>/dev/null)
29
30 if [ -z "$SRCTREE" ]; then
31 echo >&2 "ERROR: Not a git repository."
32 exit 1
33 fi
34
35 TMPD=$SRCTREE/.tmp_objdiff
36
37 usage() {
38 echo >&2 "Usage: $0 <command> <args>"
39 echo >&2 " record <list of object files>"
40 echo >&2 " diff <commitA> <commitB>"
41 echo >&2 " clean all | <commit>"
42 exit 1
43 }
44
45 dorecord() {
46 [ $# -eq 0 ] && usage
47
48 FILES="$*"
49
50 CMT="`git rev-parse --short HEAD`"
51
52 OBJDUMP="${CROSS_COMPILE}objdump"
53 OBJDIFFD="$TMPD/$CMT"
54
55 for f in $FILES; do
56 dn="${f%/*}"
57 bn="${f##*/}"
58
59 [ ! -d "$OBJDIFFD/$dn" ] && mkdir -p "$OBJDIFFD/$dn"
60
61 # remove addresses for a more clear diff
62 # 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"
65 done
66 }
67
68 dodiff() {
69 [ $# -ne 2 ] && [ $# -ne 0 ] && usage
70
71 if [ $# -eq 0 ]; then
72 SRC="`git rev-parse --short HEAD^`"
73 DST="`git rev-parse --short HEAD`"
74 else
75 SRC="`git rev-parse --short $1`"
76 DST="`git rev-parse --short $2`"
77 fi
78
79 DIFF="`which colordiff`"
80
81 if [ ${#DIFF} -eq 0 ] || [ ! -x "$DIFF" ]; then
82 DIFF="`which diff`"
83 fi
84
85 SRCD="$TMPD/$SRC"
86 DSTD="$TMPD/$DST"
87
88 if [ ! -d "$SRCD" ]; then
89 echo >&2 "ERROR: $SRCD doesn't exist"
90 exit 1
91 fi
92
93 if [ ! -d "$DSTD" ]; then
94 echo >&2 "ERROR: $DSTD doesn't exist"
95 exit 1
96 fi
97
98 $DIFF -Nurd $SRCD $DSTD
99 }
100
101 doclean() {
102 [ $# -eq 0 ] && usage
103 [ $# -gt 1 ] && usage
104
105 if [ "x$1" = "xall" ]; then
106 rm -rf $TMPD/*
107 else
108 CMT="`git rev-parse --short $1`"
109
110 if [ -d "$TMPD/$CMT" ]; then
111 rm -rf $TMPD/$CMT
112 else
113 echo >&2 "$CMT not found"
114 fi
115 fi
116 }
117
118 [ $# -eq 0 ] && usage
119
120 case "$1" in
121 record)
122 shift
123 dorecord $*
124 ;;
125 diff)
126 shift
127 dodiff $*
128 ;;
129 clean)
130 shift
131 doclean $*
132 ;;
133 *)
134 echo >&2 "Unrecognized command '$1'"
135 exit 1
136 ;;
137 esac
This page took 0.037514 seconds and 6 git commands to generate.