Gentoo Archives: gentoo-commits

From: Ian Stakenvicius <axs@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/mozilla:master commit in: scripts/
Date: Tue, 03 May 2016 15:34:27
Message-Id: 1462289648.1a33c33d296ff49a382d50c857d7a20c6b6ae758.axs@gentoo
1 commit: 1a33c33d296ff49a382d50c857d7a20c6b6ae758
2 Author: Ian Stakenvicius <axs <AT> gentoo <DOT> org>
3 AuthorDate: Tue May 3 15:34:08 2016 +0000
4 Commit: Ian Stakenvicius <axs <AT> gentoo <DOT> org>
5 CommitDate: Tue May 3 15:34:08 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/mozilla.git/commit/?id=1a33c33d
7
8 Add script to help automate rolling of langpacks for mozilla packages
9
10 scripts/generate_langpacks.sh | 217 ++++++++++++++++++++++++++++++++++++++++++
11 1 file changed, 217 insertions(+)
12
13 diff --git a/scripts/generate_langpacks.sh b/scripts/generate_langpacks.sh
14 new file mode 100755
15 index 0000000..5032cdd
16 --- /dev/null
17 +++ b/scripts/generate_langpacks.sh
18 @@ -0,0 +1,217 @@
19 +#!/bin/bash
20 +
21 +#
22 +# Langpack generator for mozilla packages
23 +# hacked together by Ian Stakenvicius <axs@g.o>, spring 2016
24 +#
25 +# Call this script, providing a path to the ebuild you want to generate the langpacks for as argument1
26 +#
27 +
28 +# source make.conf to get PORTAGE_TMPDIR etc.
29 +if [[ -e /etc/make.conf ]]; then
30 + . /etc/make.conf
31 +elif [[ -e /etc/portage/make.conf ]]; then
32 + . /etc/portage/make.conf
33 +fi
34 +
35 +: ${L10N_STAGING_DIR:=/var/cache/mozl10n}
36 +: ${LANGPACK_DESTDIR:=${L10N_STAGING_DIR}}
37 +: ${PORTAGE_TMPDIR:=/var/tmp/portage}
38 +: ${PORTDIR:=/usr/portage}
39 +
40 +ebuild=${1}
41 +
42 +if [[ ${ebuild/.ebuild/} == ${ebuild} ]]; then
43 + echo "Must specify the full path to the ebuild as arg.1"
44 +fi
45 +
46 +if ! grep mozlinguas_mozconfig ${ebuild} &>/dev/null ; then
47 + if ! grep mozlinguas_mozconfig ${ebuild%/*}/../../eclass/$(grep -o 'mozconfig-v[^ ]*' ${ebuild}).eclass &>/dev/null ; then
48 + if ! grep mozlinguas_mozconfig ${PORTDIR}/eclass/$(grep -o 'mozconfig-v[^ ]*' ${ebuild}).eclass &>/dev/null ; then
49 + echo ""
50 + echo "WARNING -- this script will not work unless 'mozlinguas_mozconfig' is called sometime during"
51 + echo "src_configure between mozconfig_init and mozconfig_final. A rough check did not find this call."
52 + echo "Press any key to continue or CTRL-C to abort."
53 + read target
54 + fi
55 + fi
56 +fi
57 +
58 +echo ""
59 +echo "Using ${L10N_STAGING_DIR} for l10n repository cache"
60 +echo "Using ${LANGPACK_DESTDIR} to store generated langpacks"
61 +echo ""
62 +
63 +target=${ebuild##*/}
64 +target=${target%.ebuild}
65 +uctarget=${target^^*}
66 +uctarget=${uctarget//-/_}
67 +
68 +l10nrepo="mozilla-release"
69 +if [[ ${uctarget/_BETA/} != ${uctarget} ]]; then
70 + l10nrepo="mozilla-beta"
71 + uctarget=${uctarget/_BETA/b}
72 +fi
73 +
74 +l10n_releasedir="${LANGPACK_DESTDIR%/}/l10n-${target}"
75 +
76 +# if the mozlangs.cached file in l10n_releasedir doesn't exist, then
77 +# create it and checkout all the upstream l10n repositories using mercurial,
78 +# based on the list of locales in MOZ_LANGS in the ebuild. If the directory
79 +# already exists, then assume everything has been checked out and
80 +# proceed.
81 +if ! [[ -e ${l10n_releasedir}/mozlangs.cached ]]; then
82 + mkdir -p ${l10n_releasedir}
83 +
84 + # source the ebuild so that MOZ_LANGS is available
85 + cat ${ebuild} |grep -A 5 'MOZ_LANGS' >${l10n_releasedir}/mozlangs
86 + . ${l10n_releasedir}/mozlangs
87 +
88 + for abcd in "${MOZ_LANGS[@]}" ; do
89 + if [[ ! -d ${L10N_STAGING_DIR%/}/${l10nrepo}/${abcd} ]]; then
90 + mkdir -p ${L10N_STAGING_DIR%/}/${l10nrepo}
91 + cd ${L10N_STAGING_DIR%/}/${l10nrepo}
92 + hg clone "http://hg.mozilla.org/releases/l10n/${l10nrepo}/${abcd}"
93 + fi
94 + if [[ -d ${L10N_STAGING_DIR%/}/${l10nrepo}/${abcd} ]]; then
95 + cd ${L10N_STAGING_DIR%/}/${l10nrepo}/${abcd}
96 + hg pull
97 + if hg tags |grep ${uctarget//\./_}_RELEASE &>/dev/null; then
98 + rev="-r ${uctarget//\./_}_RELEASE"
99 + elif hg branches |grep ${uctarget//\./} &>/dev/null; then
100 + rev="-r $(hg branches |grep ${uctarget//\./})"
101 + else
102 + echo "*** WARNING: ${abcd} has no branch or tag matching ${target}, using HEAD"
103 + rev=
104 + fi
105 + hg archive ${rev} -t files ${l10n_releasedir}/src/${abcd}
106 + fi
107 + done
108 + cp ${l10n_releasedir}/mozlangs{,.cached}
109 +else
110 + . ${l10n_releasedir}/mozlangs.cached
111 +fi
112 +
113 +# set some variables based on what package it is
114 +# so the langpacks can be rolled
115 +# note -- this sets $S to BUILD_OBJ_DIR, getting the path
116 +# from the actual ebuild would likely be more stable long-term
117 +case "${target}" in
118 +*thunderbird*)
119 + category=mail-client
120 + langpack_targets=( langpack calendar-langpack )
121 + locale_buildpath=mail/locales
122 + if grep 'S=.*comm-esr' ${ebuild} &>/dev/null; then
123 + S=${PORTAGE_TMPDIR%/}/${category}/${target}/work/comm-esr*/tbird
124 + else
125 + S=${PORTAGE_TMPDIR%/}/${category}/${target}/work/thunderbird-*/tbird
126 + fi
127 + ;;
128 +*firefox*)
129 + category=www-client
130 + langpack_targets=( langpack )
131 + locale_buildpath=browser/locales
132 + if grep 'S=.*mozilla-esr' ${ebuild} &>/dev/null; then
133 + S=${PORTAGE_TMPDIR%/}/${category}/${target}/work/mozilla-esr*/ff
134 + else
135 + S=${PORTAGE_TMPDIR%/}/${category}/${target}/work/firefox-*/ff
136 + fi
137 + ;;
138 +*seamonkey*)
139 + category=www-client
140 + langpack_targets=( langpack )
141 + locale_buildpath=suite/locales
142 + if grep 'S=.*comm-release' ${ebuild} &>/dev/null; then
143 + S=${PORTAGE_TMPDIR%/}/${category}/${target}/work/comm-release*/seamonk
144 + else
145 + S=${PORTAGE_TMPDIR%/}/${category}/${target}/work/seamonkey-*/seamonk
146 + fi
147 + ;;
148 +esac
149 +
150 +
151 +# compile a build, with the necessary flags to set up the use of the checked out langpacks
152 +MOZ_GENERATE_LANGPACKS=1 MOZ_L10N_SOURCEDIR="${l10n_releasedir}/src" ebuild ${ebuild} clean compile
153 +
154 +if ! [[ -d ${S} ]]; then
155 + die "Need a fully compiled package before langpack generation can be performed"
156 +fi
157 +
158 +
159 +function package_lightning {
160 + cd ${S}/dist/xpi-stage
161 + cp -rL lightning stage-lightning
162 + for ech in lightning-*; do
163 + if [[ -d $ech ]]; then
164 + abcd=${ech/lightning-/}
165 + if [[ -d ${ech}/chrome/calendar-${abcd} ]]; then
166 + cp -t stage-lightning/chrome -rL ${ech}/chrome/{calendar,lightning}-${abcd}
167 + grep '^locale ' ${ech}/chrome.manifest |tee -a stage-lightning/chrome.manifest
168 + else
169 + echo "${abcd} does not have any locale files"
170 + fi
171 + fi
172 + done
173 + cd stage-lightning
174 + find . -type f -name .mkdir.done -delete
175 + vers=$(cat install.rdf |grep 'em:version' |sed -e 's#^.*>\([0-9\.]*\)<.*$#\1#')
176 +
177 + # roll a .xpi that mimicks what upstream would roll if they ever did it again
178 + zip -9 -r ${l10n_releasedir}/lightning-${vers}.xpi *
179 +
180 + # make a tarball, as it may be more suitable to extract that instead of using a
181 + # faked upstream package
182 + cd ..
183 + mv stage-lightning lightning-${vers}
184 + tar -Jcf ${l10n_releasedir}/lightning-${vers}.tar.xz lightning-${vers}
185 +}
186 +
187 +function package_gdata_provider {
188 + cd ${S}/dist/xpi-stage
189 + cp -rL gdata-provider stage-gdata-provider
190 + for ech in gdata-provider-*; do
191 + if [[ -d $ech ]]; then
192 + abcd=${ech/gdata-provider-/}
193 + if [[ -d ${ech}/chrome/gdata-provider-${abcd} ]]; then
194 + cp -t stage-gdata-provider/chrome -rL ${ech}/chrome/gdata-provider-${abcd}
195 + grep '^locale ' ${ech}/chrome.manifest |tee -a stage-gdata-provider/chrome.manifest
196 + else
197 + echo "${abcd} does not have any locale files"
198 + fi
199 + fi
200 + done
201 + cd stage-gdata-provider
202 + find . -type f -name .mkdir.done -delete
203 + vers=$(cat install.rdf |grep 'em:version' |sed -e 's#^.*>\([0-9\.]*\)<.*$#\1#')
204 +
205 + # roll a .xpi that mimicks what upstream would roll if they ever did it again
206 + zip -9 -r ${l10n_releasedir}/gdata-provider-${vers}.xpi *
207 +
208 + # make a tarball, as it may be more suitable to extract that instead of using a
209 + # faked upstream package
210 + cd ..
211 + mv stage-gdata-provider gdata-provider-${vers}
212 + tar -Jcf ${l10n_releasedir}/gdata-provider-${vers}.tar.xz gdata-provider-${vers}
213 +}
214 +
215 +# run the locales
216 +for langpack_op in "${langpack_targets[@]}"; do
217 + cd ${S}/${locale_buildpath}
218 + for ech_l10n in ${l10n_releasedir}/* ; do
219 + if [[ -d ${ech_l10n} ]]; then
220 + abcd=${ech_l10n##*/}
221 + # Need to set LOCALE_MERGEDIR to someplace that doesnt exist -- odd but whatever
222 + make ${langpack_op}-${abcd} LOCALE_MERGEDIR=./${abcd}
223 + fi
224 + done
225 +
226 + # get the langpacks
227 + cp -t ${l10n_releasedir}/ ${S}/dist/linux-*/xpi/*lang*
228 +
229 + # package lightning and gdata-provider if calendar was a target
230 + if ! [[ ${langpack_op/calendar/} == ${langpack_op} ]]; then
231 + package_lightning
232 + package_gdata_provider
233 + fi
234 +
235 +done