]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/freeze/files/freeze
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / freeze / files / freeze
1 #!/bin/sh
2 #
3 # This script must be executed with the following environment variables
4 # and arguments:
5 #
6 # export FROZEN_DIR=<place to write conf files>
7 # export PKGDIR=<location of openembedded package source>
8 # export DISTRO=<distro being frozen>
9 # freeze {directories}
10 #
11 # where {directories} are one or more directories containing built
12 # packages.  If not given or empty FROZEN_DIR defaults to the directory
13 # on BBPATH containing conf/local.conf.  With no arguments $TMPDIR/work must
14 # be the location of the built packages.
15 #
16 # The output of the script consists of two files:
17 #       $FROZEN_DIR/$DISTRO-bbfiles.conf
18 #         defines BBFILES to a list of all the .bb files required
19 #
20 #       $FROZEN_DIR/$DISTRO-packages.conf
21 #         defines BBFILES to a list of the directories containing
22 #         those bb files.
23 #
24 # The output path definitions use ${PKGDIR} (literally)
25 #
26 # Check the arguments.
27 test -n "$DISTRO" || {
28         echo "FATAL: freeze: set \$DISTRO to the name of the distro to freeze" >&2
29         exit 1
30 }
31 test -r "$PKGDIR/packages/freeze/freeze.bb" || {
32         echo "FATAL: freeze: set \$PKGDIR to the directory containing OE packages" >&2
33         exit 1
34 }
35 if test -n "$FROZEN_DIR" -a -d "$FROZEN_DIR"
36 then
37         : # ok, given a directory
38 else
39         if test -n "$BBPATH"
40         then
41                 FROZEN_DIR=""
42                 for d in ${BBPATH//:/ }
43                 do
44                         if test -r "$d/conf/local.conf"
45                         then
46                                 FROZEN_DIR="$d/conf"
47                                 break
48                         elif test -z "$FROZEN_DIR" -a -d "$d"
49                         then
50                                 # default to the first existing directory on
51                                 # the path
52                                 FROZEN_DIR="$d"
53                         fi
54                 done
55         fi
56         if test -n "$FROZEN_DIR"
57         then
58                 echo "NOTE: freeze: \$FROZEN_DIR=\"$FROZEN_DIR\"" >&2
59                 echo "NOTE:         (defaulted from \$BBPATH=\"$BBPATH\")" >&2
60         else
61                 echo "FATAL: freeze: set \$FROZEN_DIR to the directory for the new .conf files" >&2
62                 exit 1
63         fi
64 fi
65 test -d "$1" || {
66         if test -d "$TMPDIR/work"
67         then
68                 set "$TMPDIR/work"
69         else
70                 echo "FATAL: freeze: give one or more directories containing built packages" >&2
71                 exit 1
72         fi
73 }
74 #
75 # First some helper functions
76 #
77 # output "$@" if there is exactly one argument (so this selectively
78 # outputs a file name if the pattern matches exactly one file).
79 output() {
80         if test $# -eq 1 -a -r "$1"
81         then
82                 echo '${PKGDIR}/packages/'"$1 \\"
83                 return 0
84         else
85                 return 1
86         fi
87 }
88 #
89 # Perform edit '$1' on '$2' and check to see if the result is a valid
90 # file name.  If '$1' is empty '$2' is checked with no edit
91 check() {
92         local nf
93         if test -n "$1"
94         then
95                 nf="$(echo "$2" | sed -n "$1")"
96                 test -n "$nf" && output */$nf.bb
97         else
98                 output */"$2.bb"
99         fi
100 }
101 #
102 # Output a note - because bitbake swallows the stderr stream and redirects to the
103 # log file, which never gets read, it is necessary to do something horrible here.
104 bberror(){
105         echo "ERROR:" "$@" >/dev/tty
106 }
107 bbnote(){
108         echo "NOTE:" "$@" >/dev/tty
109 }
110 #
111 # Say where the files go (this goes to the log file)
112 bbnote "frozen bbfiles.conf  --> $FROZEN_DIR/$DISTRO-bbfiles.conf" >&2
113 bbnote "frozen packages.conf --> $FROZEN_DIR/$DISTRO-packages.conf" >&2
114 #
115 # List the built packages, for each one find the corresponding bb file
116 # (from the packages directory).
117 for d in "$@"
118 do
119         (cd "$d"; ls) | while read x
120         do
121                 echo "$x" "$d/$x"
122         done
123 done | {
124         report=
125         while read d full
126         do
127                 if test ! -d "$full"
128                 then
129                         bberror "$full: not a directory, ignored" >&2
130                 elif echo "$d" | egrep '\-[^-][^-]*-[a-z][a-z]*[0-9][0-9.]*$'
131                 then
132                         :
133                 else
134                         bberror "$full: expected package-version-rev" >&2
135                         if test -z "$report"
136                         then
137                                 bberror "  name not recognised as a package and so ignored" >&2
138                                 report="$d"
139                         fi
140                 fi
141         done
142         if test -n "$report"
143         then
144                 bberror "$report: at least this directory was ignored" >&2
145                 bberror "  The output files may be wrong, some .bb files may be missing!" >&2
146         fi
147 } | sed 's/^\(.*\)-\([^-]*\)-\([^-]*\)$/\1 \2 \3/' | {
148         # the check commands need to be executed from the packages directory so they
149         # can use shell wildcarding to match the bb files
150         cd "$PKGDIR/packages"
151         # This would be several orders of magnitude easier if portmap did not have
152         # the version '5-7' (etc).  This is the only package with a '-' in the
153         # version number...
154         report=
155         while read p v r
156         do
157                 # Each package/version must be found in $PKGDIR/packages, this search
158                 # is a heuristic, note that there are never any '_' characters in the
159                 # work directory name.
160                 f="${p}_$v"
161                 check '' "$f" ||
162                 check 's/-/[-_]/gp' "$p-$v" ||
163                 check 's/_1\.0$//p' "$f" ||
164                 check 's/_\([0-9.]*\)cvs200[0-9]*$/_\1cvs/p' "$f" ||
165                 check 's/_\([0-9.]*\)+cvs200[0-9]*$/_\1+cvs/p' "$f" ||
166                 check 's/_0\.1cvs200[0-9]*$/_cvs/p' "$f" ||
167                 check 's/_\([0-9.]*\)+cvs200[0-9]*$/_cvs/p' "$f" ||
168                 check 's/_0\.1cvs\(200[0-9]*\)$/_\1/p' "$f" || 
169                 check 's/_\([0-9.]*\)+svn200[0-9]*$/_svn/p' "$f" || {
170                         bberror "($p,$v,$r): package not found" >&2
171                         if test -z "$report"
172                         then
173                                 report="($p,$v,$r)"
174                                 bberror "at least one package has not been found" >&2
175                         fi
176                 }
177         done
178         # in all cases add freeze and unfreeze
179         echo '${PKGDIR}/packages/freeze/freeze.bb '"\\"
180         echo '${PKGDIR}/packages/freeze/unfreeze.bb '"\\"
181         # check for a problem
182         if test -n "$report"
183         then
184                 bberror "At least $report was not found." >&2
185                 bberror "This can be ignored if the .bb file has been removed, however if not" >&2
186                 bberror "the frozen .conf output files are useless unless you fix them up" >&2
187         fi
188 } | sort | uniq | {
189         # the simple bb file list (package/bbfile.bb)
190         out="$FROZEN_DIR/$DISTRO-bbfiles.conf"
191         echo '# automatically generated by bitbake freeze' >"$out"
192         echo 'BBFILES := "\' >>"$out"
193         tee -a "$out"
194         echo '"' >>"$out"
195 } | sed 's!^\(.*\)/[^/]*\.bb \\$!\1/*.bb \\!' | uniq | {
196         # the package directories list (package)
197         out="$FROZEN_DIR/$DISTRO-packages.conf"
198         echo '# automatically generated by bitbake freeze' >"$out"
199         echo 'BBFILES := "\' >>"$out"
200         cat >>"$out"
201         echo '"' >>"$out"
202 }