checkout_files: Added drivers/net/ethernet/hisilicon/Kconfig
[compat-rdma/compat-rdma.git] / scripts / admin_rdma.sh
1 #!/bin/bash
2 #
3 # Copyright 2012 Mellanox Technologies Ltd.
4 # Copyright 2007, 2008, 2010    Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
5 #
6 # Use this to create compat-rdma-2.6
7
8 # Usage: you should have the latest pull of linux-2.6.git
9 #
10
11 GIT_URL="git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git"
12 GIT_COMPAT_URL="git://github.com/mcgrof/compat.git"
13
14 FILES="ofed_scripts/checkout_files"
15 SRC=${SRC:-'.'}
16
17 # Pretty colors
18 GREEN="\033[01;32m"
19 YELLOW="\033[01;33m"
20 NORMAL="\033[00m"
21 BLUE="\033[34m"
22 RED="\033[31m"
23 PURPLE="\033[35m"
24 CYAN="\033[36m"
25 UNDERLINE="\033[02m"
26
27 CODE_METRICS=code-metrics.txt
28
29 usage() {
30         printf "Usage: $0 [ refresh] [ --help | -h | -s | -n | -p | -c ]\n"
31
32         printf "${GREEN}%10s${NORMAL} - will update your all your patch offsets using quilt\n" "refresh"
33         printf "${GREEN}%10s${NORMAL} - get and apply pending-stable/ fixes purging old files there\n" "-s"
34         printf "${GREEN}%10s${NORMAL} - apply the patches linux-next-cherry-picks directory\n" "-n"
35         printf "${GREEN}%10s${NORMAL} - apply the patches on the linux-next-pending directory\n" "-p"
36         printf "${GREEN}%10s${NORMAL} - apply the patches on the crap directory\n" "-c"
37 }
38
39 # Execute command w/ echo and exit if it fail
40 ex()
41 {
42         echo "$@"
43         if ! "$@"; then
44                 printf "\nFailed executing $@\n\n"
45                 exit 1
46         fi
47 }
48
49 brag_backport() {
50         COMPAT_FILES_CODE=$(find ./ -type f -name  \*.[ch] | egrep  "^./compat/|include/linux/compat" |
51                 xargs wc -l | tail -1 | awk '{print $1}')
52         let COMPAT_ALL_CHANGES=$2+$COMPAT_FILES_CODE
53         printf "${GREEN}%10s${NORMAL} - backport code changes\n" $2
54         printf "${GREEN}%10s${NORMAL} - backport code additions\n" $3
55         printf "${GREEN}%10s${NORMAL} - backport code deletions\n" $4
56         printf "${GREEN}%10s${NORMAL} - backport from compat module\n" $COMPAT_FILES_CODE
57         printf "${GREEN}%10s${NORMAL} - total backport code\n" $COMPAT_ALL_CHANGES
58         printf "${RED}%10s${NORMAL} - %% of code consists of backport work\n" \
59                 $(perl -e 'printf("%.4f", 100 * '$COMPAT_ALL_CHANGES' / '$1');')
60 }
61
62 nag_pending_stable() {
63         printf "${YELLOW}%10s${NORMAL} - Code changes brought in from pending-stable\n" $2
64         printf "${YELLOW}%10s${NORMAL} - Code additions brought in from pending-stable\n" $3
65         printf "${YELLOW}%10s${NORMAL} - Code deletions brought in from pending-stable\n" $4
66         printf "${RED}%10s${NORMAL} - %% of code being cherry picked from pending-stable\n" $(perl -e 'printf("%.4f", 100 * '$2' / '$1');')
67 }
68
69 nag_next_cherry_pick() {
70         printf "${YELLOW}%10s${NORMAL} - Code changes brought in from linux-next\n" $2
71         printf "${YELLOW}%10s${NORMAL} - Code additions brought in from linux-next\n" $3
72         printf "${YELLOW}%10s${NORMAL} - Code deletions brought in from linux-next\n" $4
73         printf "${RED}%10s${NORMAL} - %% of code being cherry picked from linux-next\n" $(perl -e 'printf("%.4f", 100 * '$2' / '$1');')
74 }
75
76 nag_pending() {
77         printf "${YELLOW}%10s${NORMAL} - Code changes posted but not yet merged\n" $2
78         printf "${YELLOW}%10s${NORMAL} - Code additions posted but not yet merged\n" $3
79         printf "${YELLOW}%10s${NORMAL} - Code deletions posted but not yet merged\n" $4
80         printf "${RED}%10s${NORMAL} - %% of code not yet merged\n" $(perl -e 'printf("%.4f", 100 * '$2' / '$1');')
81 }
82
83 nag_crap() {
84         printf "${RED}%10s${NORMAL} - Crap changes not yet posted\n" $2
85         printf "${RED}%10s${NORMAL} - Crap additions not yet posted\n" $3
86         printf "${RED}%10s${NORMAL} - Crap deletions not yet posted\n" $4
87         printf "${RED}%10s${NORMAL} - %% of crap code\n" $(perl -e 'printf("%.4f", 100 * '$2' / '$1');')
88 }
89
90 nagometer() {
91         CHANGES=0
92
93         ORIG_CODE=$2
94         ADD=$(grep -Hc ^+ $1/*.patch| awk -F":" 'BEGIN {sum=0} {sum += $2} END { print sum}')
95         DEL=$(grep -Hc ^- $1/*.patch| awk -F":" 'BEGIN {sum=0} {sum += $2} END { print sum}')
96         # Total code is irrelevant unless you take into account each part,
97         # easier to just compare against the original code.
98         # let TOTAL_CODE=$ORIG_CODE+$ADD-$DEL
99
100         let CHANGES=$ADD+$DEL
101
102         case $1 in
103         "patches")
104                 brag_backport $ORIG_CODE $CHANGES $ADD $DEL
105                 ;;
106         "pending-stable")
107                 nag_pending_stable $ORIG_CODE $CHANGES $ADD $DEL
108                 ;;
109         "linux-next-cherry-picks")
110                 nag_next_cherry_pick $ORIG_CODE $CHANGES $ADD $DEL
111                 ;;
112         "linux-next-pending")
113                 nag_pending $ORIG_CODE $CHANGES $ADD $DEL
114                 ;;
115         "crap")
116                 nag_crap $ORIG_CODE $CHANGES $ADD $DEL
117                 ;;
118         *)
119                 ;;
120         esac
121
122 }
123
124 EXTRA_PATCHES="patches crap"
125 REFRESH="n"
126 GET_STABLE_PENDING="n"
127 POSTFIX_RELEASE_TAG=""
128 if [ $# -ge 1 ]; then
129         if [ $# -gt 4 ]; then
130                 usage $0
131                 exit
132         fi
133         if [[ $1 = "-h" || $1 = "--help" ]]; then
134                 usage $0
135                 exit
136         fi
137         while [ $# -ne 0 ]; do
138                 if [[ "$1" = "-s" ]]; then
139                         GET_STABLE_PENDING="y"
140                         EXTRA_PATCHES="${EXTRA_PATCHES} pending-stable" 
141                         EXTRA_PATCHES="${EXTRA_PATCHES} pending-stable/backports/"
142                         POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}s"
143                         shift; continue;
144                 fi
145                 if [[ "$1" = "-n" ]]; then
146                         EXTRA_PATCHES="${EXTRA_PATCHES} linux-next-cherry-picks"
147                         POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}n"
148                         shift; continue;
149                 fi
150                 if [[ "$1" = "-p" ]]; then
151                         EXTRA_PATCHES="${EXTRA_PATCHES} linux-next-pending"
152                         POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}p"
153                         shift; continue;
154                 fi
155                 if [[ "$1" = "-c" ]]; then
156                         EXTRA_PATCHES="${EXTRA_PATCHES} crap"
157                         POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}c"
158                         shift; continue;
159                 fi
160                 if [[ "$1" = "refresh" ]]; then
161                         REFRESH="y"
162                         shift; continue;
163                 fi
164
165                 echo "Unexpected argument passed: $1"
166                 usage $0
167                 exit
168         done
169
170 fi
171
172 # User exported this variable
173 if [ -z $GIT_TREE ]; then
174         GIT_TREE="/home/$USER/linux-next/"
175         if [ ! -d $GIT_TREE ]; then
176                 echo "Please tell me where your linux-next git tree is."
177                 echo "You can do this by exporting its location as follows:"
178                 echo
179                 echo "  export GIT_TREE=/home/$USER/linux-next/"
180                 echo
181                 echo "If you do not have one you can clone the repository:"
182                 echo "  git clone $GIT_URL"
183                 exit 1
184         fi
185 else
186         echo "You said to use git tree at: $GIT_TREE for linux-next"
187 fi
188
189 if [ -z $GIT_COMPAT_TREE ]; then
190         GIT_COMPAT_TREE="/home/$USER/compat/"
191         if [ ! -d $GIT_COMPAT_TREE ]; then
192                 echo "Please tell me where your compat git tree is."
193                 echo "You can do this by exporting its location as follows:"
194                 echo
195                 echo "  export GIT_COMPAT_TREE=/home/$USER/compat/"
196                 echo
197                 echo "If you do not have one you can clone the repository:"
198                 echo "  git clone $GIT_COMPAT_URL"
199                 exit 1
200         fi
201 else
202         echo "You said to use git tree at: $GIT_COMPAT_TREE for compat"
203 fi
204
205 # Drivers that have their own directory
206
207 # Staging drivers
208 STAGING_DRIVERS=""
209
210
211 /bin/rm -rf $SRC/`cat $FILES | awk -F '/' '{print$1}' | sort -u`
212
213
214 while read line
215 do
216         ex mkdir -p $SRC/$(dirname $line)
217         ex cp -a $GIT_TREE/$line $SRC/$(dirname $line)
218 done < $FILES
219
220 if [ $SRC != '.' ]; then
221         ex cp -a [mM]akefile $SRC
222         ex cp -a configure $SRC
223 fi
224
225 # Compat stuff
226 COMPAT="compat"
227 # mkdir -p $COMPAT include/{linux,net,scsi}
228 mkdir -p $COMPAT include/{linux,net,uapi}
229 echo "Copying $GIT_COMPAT_TREE/ files..."
230 cp $GIT_COMPAT_TREE/compat/*.[ch] $COMPAT/
231 cp $GIT_COMPAT_TREE/compat/Makefile $COMPAT/
232 cp $GIT_COMPAT_TREE/compat/Kconfig $COMPAT/
233 cp $GIT_COMPAT_TREE/autogen.sh $COMPAT/
234 cp $GIT_COMPAT_TREE/configure.ac $COMPAT/
235 cp -a $GIT_COMPAT_TREE/build $COMPAT/
236 cp -a $GIT_COMPAT_TREE/config $COMPAT/
237 cp -a $GIT_COMPAT_TREE/scripts/ $COMPAT/
238 cp -a $GIT_COMPAT_TREE/include/linux/* include/linux/
239 cp -a $GIT_COMPAT_TREE/include/net/* include/net/
240 cp -a $GIT_COMPAT_TREE/include/scsi/* include/scsi/
241 cp -a $GIT_COMPAT_TREE/include/uapi/* include/uapi/
242 rm -f $COMPAT/*.mod.c
243
244 # Stable pending, if -n was passed
245 if [[ "$GET_STABLE_PENDING" = y ]]; then
246
247         if [ -z $NEXT_TREE ]; then
248                 NEXT_TREE="/home/$USER/linux-next/"
249                 if [ ! -d $NEXT_TREE ]; then
250                         echo "Please tell me where your linux-next git tree is."
251                         echo "You can do this by exporting its location as follows:"
252                         echo
253                         echo "  export NEXT_TREE=/home/$USER/linux-next/"
254                         echo
255                         echo "If you do not have one you can clone the repository:"
256                         echo "  git clone git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git"
257                         exit 1
258                 fi
259         else
260                 echo "You said to use git tree at: $NEXT_TREE for linux-next"
261         fi
262
263         LAST_DIR=$PWD
264         cd $GIT_TREE
265         if [ -f localversion* ]; then
266                 echo -e "You should be using a stable tree to use the -s option"
267                 exit 1
268         fi
269
270         # we now assume you are using a stable tree
271         cd $GIT_TREE
272         LAST_STABLE_UPDATE=$(git describe --abbrev=0)
273         cd $NEXT_TREE
274         PENDING_STABLE_DIR="pending-stable/"
275
276         rm -rf $PENDING_STABLE_DIR
277
278         git tag -l | grep $LAST_STABLE_UPDATE 2>&1 > /dev/null
279         if [[ $? -ne 0 ]]; then
280                 echo -e "${BLUE}Tag $LAST_STABLE_UPDATE not found on $NEXT_TREE tree: bailing out${NORMAL}"
281                 exit 1
282         fi
283         echo -e "${GREEN}Generating stable cherry picks... ${NORMAL}"
284         echo -e "\nUsing command on directory $PWD:"
285         echo -e "\ngit format-patch --grep=\"stable@vger.kernel.org\" -o $PENDING_STABLE_DIR ${LAST_STABLE_UPDATE}.. $WSTABLE"
286         git format-patch --grep="stable@vger.kernel.org" -o $PENDING_STABLE_DIR ${LAST_STABLE_UPDATE}.. $WSTABLE
287         if [ ! -d ${LAST_DIR}/${PENDING_STABLE_DIR} ]; then
288                 echo -e "Assumption that ${LAST_DIR}/${PENDING_STABLE_DIR} directory exists failed"
289                 exit 1
290         fi
291         echo -e "${GREEN}Purging old stable cherry picks... ${NORMAL}"
292         rm -f ${LAST_DIR}/${PENDING_STABLE_DIR}/*.patch
293         cp ${PENDING_STABLE_DIR}/*.patch ${LAST_DIR}/${PENDING_STABLE_DIR}/
294         if [ -f ${LAST_DIR}/${PENDING_STABLE_DIR}/.ignore ]; then
295                 for i in $(cat ${LAST_DIR}/${PENDING_STABLE_DIR}/.ignore) ; do
296                         echo -e "Skipping $i from generated stable patches..."
297                         rm -f ${LAST_DIR}/${PENDING_STABLE_DIR}/*$i*
298                 done
299         fi
300         echo -e "${GREEN}Updated stable cherry picks, review with git diff and update hunks with ./scripts/admin-update.sh -s refresh${NORMAL}"
301         cd $LAST_DIR
302 fi
303
304 # Refresh patches using quilt
305 patchRefresh() {
306         if [ -d patches.orig ] ; then
307                 rm -rf .pc patches/series
308         else
309                 mkdir patches.orig
310         fi
311
312         export QUILT_PATCHES=$1
313
314         mv -u $1/* patches.orig/
315
316         for i in patches.orig/*.patch; do
317                 if [ ! -f "$i" ]; then
318                         echo -e "${RED}No patches found in $1${NORMAL}"
319                         break;
320                 fi
321                 echo -e "${GREEN}Refresh backport patch${NORMAL}: ${BLUE}$i${NORMAL}"
322                 quilt import $i
323                 quilt push -f
324                 RET=$?
325                 if [[ $RET -ne 0 ]]; then
326                         echo -e "${RED}Refreshing $i failed${NORMAL}, update it"
327                         echo -e "use ${CYAN}quilt edit [filename]${NORMAL} to apply the failed part manually"
328                         echo -e "use ${CYAN}quilt refresh${NORMAL} after the files are corrected and rerun this script"
329                         cp patches.orig/README $1/README
330                         exit $RET
331                 fi
332                 QUILT_DIFF_OPTS="-p" quilt refresh -p ab --no-index --no-timestamp
333         done
334         quilt pop -a
335
336         cp patches.orig/README $1/README
337         rm -rf patches.orig .pc $1/series
338 }
339
340 cd $SRC
341
342 ORIG_CODE=$(find ./ -type f -name  \*.[ch] |
343         egrep -v "^./compat/|include/linux/compat" |
344         xargs wc -l | tail -1 | awk '{print $1}')
345 printf "\n${CYAN}compat-rdma code metrics${NORMAL}\n\n" > $CODE_METRICS
346 printf "${PURPLE}%10s${NORMAL} - Total upstream lines of code being pulled\n" $ORIG_CODE >> $CODE_METRICS
347
348 for dir in $EXTRA_PATCHES; do
349         LAST_ELEM=$dir
350 done
351
352 for dir in $EXTRA_PATCHES; do
353         if [[ ! -d $dir ]]; then
354                 echo -e "${RED}Patches: $dir empty, skipping...${NORMAL}\n"
355                 continue
356         fi
357         if [[ $LAST_ELEM = $dir && "$REFRESH" = y ]]; then
358                 patchRefresh $dir
359         fi
360
361         FOUND=$(find $dir/ -maxdepth 1 -name \*.patch | wc -l)
362         if [ $FOUND -eq 0 ]; then
363                 continue
364         fi
365         for i in $(ls -v $dir/*.patch); do
366                 echo -e "${GREEN}Applying backport patch${NORMAL}: ${BLUE}$i${NORMAL}"
367                 patch -p1 -N -t < $i
368                 RET=$?
369                 if [[ $RET -ne 0 ]]; then
370                         echo -e "${RED}Patching $i failed${NORMAL}, update it"
371                         exit $RET
372                 fi
373         done
374         nagometer $dir $ORIG_CODE >> $CODE_METRICS
375 done
376
377 DIR="$PWD"
378 cd $GIT_TREE
379 GIT_DESCRIBE=$($DIR/scripts/setlocalversion $GIT_TREE)
380 GIT_BRANCH=$(git branch --no-color |sed -n 's/^\* //p')
381 GIT_BRANCH=${GIT_BRANCH:-master}
382 GIT_REMOTE=$(git config branch.${GIT_BRANCH}.remote)
383 GIT_REMOTE=${GIT_REMOTE:-origin}
384 GIT_REMOTE_URL=$(git config remote.${GIT_REMOTE}.url)
385 GIT_REMOTE_URL=${GIT_REMOTE_URL:-unknown}
386
387 cd $GIT_COMPAT_TREE
388 git describe > $DIR/compat_base
389 cd $DIR
390
391 echo -e "${GREEN}Updated${NORMAL} from local tree: ${BLUE}${GIT_TREE}${NORMAL}"
392 echo -e "Origin remote URL: ${CYAN}${GIT_REMOTE_URL}${NORMAL}"
393 cd $DIR
394 if [ -d ./.git ]; then
395         if [[ ${POSTFIX_RELEASE_TAG} != "" ]]; then
396                 echo -e "$(./scripts/setlocalversion)-${POSTFIX_RELEASE_TAG}" > compat_version
397         else
398                 echo -e "$(./scripts/setlocalversion)" > compat_version
399         fi
400
401         cd $GIT_TREE
402         TREE_NAME=${GIT_REMOTE_URL##*/}
403
404         echo $TREE_NAME > $DIR/compat_base_tree
405         echo $GIT_DESCRIBE > $DIR/compat_base_tree_version
406
407         case $TREE_NAME in
408         "linux-next.git") # The linux-next integration testing tree
409                 echo -e "This is a ${RED}linux-next.git${NORMAL} compat-wireless release"
410                 ;;
411         "linux-stable.git") # Greg's all stable tree
412                 echo -e "This is a ${GREEN}linux-stable.git${NORMAL} compat-wireless release"
413                 ;;
414         "linux-2.6.git") # Linus' 2.6 tree
415                 echo -e "This is a ${GREEN}linux-2.6.git${NORMAL} compat-wireless release"
416                 ;;
417         *)
418                 ;;
419         esac
420
421         cd $DIR
422         echo -e "\nBase tree: ${GREEN}$(cat compat_base_tree)${NORMAL}" >> $CODE_METRICS
423         echo -e "Base tree version: ${PURPLE}$(cat compat_base_tree_version)${NORMAL}" >> $CODE_METRICS
424         echo -e "compat.git: ${CYAN}$(cat compat_base)${NORMAL}" >> $CODE_METRICS
425         echo -e "compat-rdma release: ${YELLOW}$(cat compat_version)${NORMAL}" >> $CODE_METRICS
426
427         cat $CODE_METRICS
428 fi