Mercurial > mxe-octave
annotate tools/patch-tool-mxe @ 2491:14be80e4c69f
Patch tool: Adding some progress messages to long processes.
author | Ryan Pavlik <rpavlik@iastate.edu> |
---|---|
date | Mon, 07 May 2012 12:45:03 -0500 |
parents | 0db1b21402e9 |
children | b48e499007b7 |
rev | line source |
---|---|
2358
14b3f5ea78ae
Cleanup coding style via "make cleanup-style"
Volker Grabsch <vog@notjusthosting.com>
parents:
2353
diff
changeset
|
1 #!/usr/bin/env bash |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
2 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
3 # Tool for converting between MXE patch files and git repos |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
4 # Imports and exports patch files in "git format-patch" format. |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
5 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
6 cmd=$1 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
7 pkg=$2 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
8 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
9 setupEnv() { |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
10 # MXE directory |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
11 export mxedir=$(cd $(dirname $0) && cd .. && pwd) |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
12 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
13 # directory for unpacked tarballs/git repos |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
14 export gitsdir=${mxedir}/gits |
2486
a866a8b8beab
patch-tool: use relative directories
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2485
diff
changeset
|
15 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
16 mkdir -p ${gitsdir} |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
17 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
18 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
19 # John Doe <John Doe@acme.org> |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
20 export author=`git var GIT_AUTHOR_IDENT | sed 's/^\(.* [<].*[>]\).*$/\1/'` |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
21 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
22 export pkg_version=$(sed -n "s/^.* id=\"${pkg}-version\">\([^<]*\)<.*$/\1/p" "${mxedir}/index.html") |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
23 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
24 export pkg_short_version=`echo $pkg_version | sed s/'\(.*\)\.[^.]*$'/'\1'/` |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
25 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
26 export pkg_subdir=`grep '^$(PKG)_SUBDIR' $mxedir/src/$pkg.mk | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
27 sed 's/.*:= \(.*\)/\1/' | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
28 sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
29 sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
30 sed s/'$(PKG)'/$pkg/;` |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
31 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
32 export pkg_file=`grep '^$(PKG)_FILE' $mxedir/src/$pkg.mk | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
33 sed 's/.*:= \(.*\)/\1/' | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
34 sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
35 sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
36 sed s/'$($(PKG)_SUBDIR)'/$pkg_subdir/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
37 sed s/'$(PKG)'/$pkg/;` |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
38 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
39 #echo $pkg |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
40 #echo $pkg_version |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
41 #echo $pkg_subdir |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
42 #echo $pkg_file |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
43 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
44 } |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
45 # init |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
46 function init_git { |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
47 setupEnv |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
48 cd $gitsdir |
2491
14be80e4c69f
Patch tool: Adding some progress messages to long processes.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2490
diff
changeset
|
49 |
14be80e4c69f
Patch tool: Adding some progress messages to long processes.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2490
diff
changeset
|
50 echo "Checking for cached $pkg_file" |
2490
0db1b21402e9
patch tool: Check for package file, and if it's not there, use makefile to grab it.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2489
diff
changeset
|
51 if [ ! -f $mxedir/pkg/$pkg_file ]; then |
0db1b21402e9
patch tool: Check for package file, and if it's not there, use makefile to grab it.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2489
diff
changeset
|
52 make -C "$mxedir" download-$pkg |
2491
14be80e4c69f
Patch tool: Adding some progress messages to long processes.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2490
diff
changeset
|
53 echo "Building the mxe Makefile target 'download-$pkg' to get missing file" |
2490
0db1b21402e9
patch tool: Check for package file, and if it's not there, use makefile to grab it.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2489
diff
changeset
|
54 if [ ! $? -eq 0 ]; then |
0db1b21402e9
patch tool: Check for package file, and if it's not there, use makefile to grab it.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2489
diff
changeset
|
55 echo "Could not build target download-$pkg - cancelling init." >&2 |
0db1b21402e9
patch tool: Check for package file, and if it's not there, use makefile to grab it.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2489
diff
changeset
|
56 exit 1 |
0db1b21402e9
patch tool: Check for package file, and if it's not there, use makefile to grab it.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2489
diff
changeset
|
57 fi |
0db1b21402e9
patch tool: Check for package file, and if it's not there, use makefile to grab it.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2489
diff
changeset
|
58 fi |
2491
14be80e4c69f
Patch tool: Adding some progress messages to long processes.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2490
diff
changeset
|
59 |
14be80e4c69f
Patch tool: Adding some progress messages to long processes.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2490
diff
changeset
|
60 echo "Unpacking archive..." |
2334
0ac3f45e790f
Improve indentation
Volker Grabsch <vog@notjusthosting.com>
parents:
2333
diff
changeset
|
61 echo $pkg_file | grep "\.tar\.gz" >> /dev/null && tar xf $mxedir/pkg/$pkg_file |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
62 echo $pkg_file | grep "\.tar\.bz2" >> /dev/null && tar xf $mxedir/pkg/$pkg_file |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
63 echo $pkg_file | grep "\.tar\.xz" >> /dev/null && xz -dc $mxedir/pkg/$pkg_file | tar xf - |
2334
0ac3f45e790f
Improve indentation
Volker Grabsch <vog@notjusthosting.com>
parents:
2333
diff
changeset
|
64 echo $pkg_file | grep "\.zip" >> /dev/null && unzip $mxedir/pkg/$pkg_file >> /dev/null |
2491
14be80e4c69f
Patch tool: Adding some progress messages to long processes.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2490
diff
changeset
|
65 |
14be80e4c69f
Patch tool: Adding some progress messages to long processes.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2490
diff
changeset
|
66 echo "Initializing repo and adding all as first commit" |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
67 cd $gitsdir/$pkg_subdir && \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
68 (git init; git add -A; git commit -m "init") > /dev/null |
2491
14be80e4c69f
Patch tool: Adding some progress messages to long processes.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2490
diff
changeset
|
69 |
14be80e4c69f
Patch tool: Adding some progress messages to long processes.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2490
diff
changeset
|
70 echo "Tagging distribution tarball state" |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
71 git tag dist |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
72 } |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
73 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
74 function export_patch { |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
75 setupEnv |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
76 cd $gitsdir/$pkg_subdir && \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
77 ( |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
78 echo 'This file is part of MXE.' |
2353
99516e73b368
Move doc/index.html -> index.html
Volker Grabsch <vog@notjusthosting.com>
parents:
2334
diff
changeset
|
79 echo 'See index.html for further information.' |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
80 echo '' |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
81 echo 'Contains ad hoc patches for cross building.' |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
82 echo '' |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
83 git format-patch -p --stdout dist..HEAD | \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
84 sed 's/^From: .*/From: MXE/g;' |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
85 ) > $mxedir/src/$pkg-1-fixes.patch |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
86 } |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
87 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
88 function import_patch { |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
89 setupEnv |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
90 cd $gitsdir/$pkg_subdir && \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
91 cat $mxedir/src/$pkg-1-fixes.patch | \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
92 sed '/^From/,$ !d' | \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
93 sed s/'^From: .*'/"From: $author"/'g;' | \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
94 git am --keep-cr |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
95 } |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
96 |
2488
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
97 case "$cmd" in |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
98 init) |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
99 init_git $pkg |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
100 ;; |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
101 import) |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
102 import_patch $pkg |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
103 ;; |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
104 export) |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
105 export_patch $pkg |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
106 ;; |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
107 *) |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
108 echo "Unrecognized command '${cmd}'" >&2 |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
109 cat <<EOS |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
110 Usage: $0 COMMAND PACKAGENAME |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
111 where COMMAND is one of: |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
112 init - create a git directory for the package with the raw source |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
113 import - apply the "pkgname-1-fixes.patch" patch commits |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
114 export - create/replace the "pkgname-1-fixes.patch" patch with a patch of all commits since init. |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
115 EOS |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
116 exit 1 |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
117 ;; |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
118 esac |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
119 |