eclass: remove unused bzr.eclass
[gentoo.git] / eclass / mozlinguas-v2.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: mozlinguas-v2.eclass
5 # @MAINTAINER:
6 # mozilla@gentoo.org
7 # @AUTHOR:
8 # Nirbheek Chauhan <nirbheek@gentoo.org>
9 # Ian Stakenvicius <axs@gentoo.org>
10 # @SUPPORTED_EAPIS: 2 3 4 5 6
11 # @BLURB: Handle language packs for mozilla products
12 # @DESCRIPTION:
13 # Sets IUSE according to MOZ_LANGS (language packs available). Also exports
14 # src_unpack, src_compile and src_install for use in ebuilds, and provides
15 # supporting functions for langpack generation and installation.
16
17 inherit mozextension
18
19 case "${EAPI:-0}" in
20         0|1)
21                 die "EAPI ${EAPI:-0} does not support the '->' SRC_URI operator";;
22         2|3|4|5|6)
23                 EXPORT_FUNCTIONS src_unpack src_compile src_install;;
24         *)
25                 die "EAPI ${EAPI} is not supported, contact eclass maintainers";;
26 esac
27
28 # @ECLASS-VARIABLE: MOZ_LANGS
29 # @DESCRIPTION:
30 # Array containing the list of language pack xpis available for
31 # this release. The list can be updated with scripts/get_langs.sh from the
32 # mozilla overlay.
33 : ${MOZ_LANGS:=()}
34
35 # @ECLASS-VARIABLE: MOZ_PV
36 # @DESCRIPTION:
37 # Ebuild package version converted to equivalent upstream version.
38 # Defaults to ${PV}, and should be overridden for alphas, betas, and RCs
39 : ${MOZ_PV:="${PV}"}
40
41 # @ECLASS-VARIABLE: MOZ_PN
42 # @DESCRIPTION:
43 # Ebuild package name converted to equivalent upstream name.
44 # Defaults to ${PN}, and should be overridden for binary ebuilds.
45 : ${MOZ_PN:="${PN}"}
46
47 # @ECLASS-VARIABLE: MOZ_P
48 # @DESCRIPTION:
49 # Ebuild package name + version converted to upstream equivalent.
50 # Defaults to ${MOZ_PN}-${MOZ_PV}
51 : ${MOZ_P:="${MOZ_PN}-${MOZ_PV}"}
52
53 # @ECLASS-VARIABLE: MOZ_FTP_URI
54 # @DESCRIPTION:
55 # The ftp URI prefix for the release tarballs and language packs.
56 : ${MOZ_FTP_URI:=""}
57
58 # @ECLASS-VARIABLE: MOZ_HTTP_URI
59 # @DESCRIPTION:
60 # The http URI prefix for the release tarballs and language packs.
61 : ${MOZ_HTTP_URI:=""}
62
63 # @ECLASS-VARIABLE: MOZ_LANGPACK_HTTP_URI
64 # @DESCRIPTION:
65 # An alternative http URI if it differs from official mozilla URI.
66 # Defaults to whatever MOZ_HTTP_URI was set to.
67 : ${MOZ_LANGPACK_HTTP_URI:=${MOZ_HTTP_URI}}
68
69 # @ECLASS-VARIABLE: MOZ_LANGPACK_PREFIX
70 # @DESCRIPTION:
71 # The relative path till the lang code in the langpack file URI.
72 # Defaults to ${MOZ_PV}/linux-i686/xpi/
73 : ${MOZ_LANGPACK_PREFIX:="${MOZ_PV}/linux-i686/xpi/"}
74
75 # @ECLASS-VARIABLE: MOZ_LANGPACK_SUFFIX
76 # @DESCRIPTION:
77 # The suffix after the lang code in the langpack file URI.
78 # Defaults to '.xpi'
79 : ${MOZ_LANGPACK_SUFFIX:=".xpi"}
80
81 # @ECLASS-VARIABLE: MOZ_LANGPACK_UNOFFICIAL
82 # @DESCRIPTION:
83 # The status of the langpack, used to differentiate within
84 # Manifests and on Gentoo mirrors as to when the langpacks are
85 # generated officially by Mozilla or if they were generated
86 # unofficially by others (ie the Gentoo mozilla team).  When
87 # this var is set, the distfile will have a .unofficial.xpi
88 # suffix.
89 : ${MOZ_LANGPACK_UNOFFICIAL:=""}
90
91 # @ECLASS-VARIABLE: MOZ_GENERATE_LANGPACKS
92 # @DESCRIPTION:
93 # This flag specifies whether or not the langpacks should be
94 # generated directly during the build process, rather than
95 # being downloaded and installed from upstream pre-built
96 # extensions.  Primarily it supports pre-release builds.
97 # Defaults to empty.
98 : ${MOZ_GENERATE_LANGPACKS:=""}
99
100 # @ECLASS-VARIABLE: MOZ_L10N_SOURCEDIR
101 # @DESCRIPTION:
102 # The path that l10n sources can be found at, once unpacked.
103 # Defaults to ${WORKDIR}/l10n-sources
104 : ${MOZ_L10N_SOURCEDIR:="${WORKDIR}/l10n-sources"}
105
106 # @ECLASS-VARIABLE: MOZ_L10N_URI_PREFIX
107 # @DESCRIPTION:
108 # The full URI prefix of the distfile for each l10n locale.  The
109 # AB_CD and MOZ_L10N_URI_SUFFIX will be appended to this to complete the
110 # SRC_URI when MOZ_GENERATE_LANGPACKS is set.  If empty, nothing will
111 # be added to SRC_URI.
112 # Defaults to empty.
113 : ${MOZ_L10N_URI_PREFIX:=""}
114
115 # @ECLASS-VARIABLE: MOZ_L10N_URI_SUFFIX
116 # @DESCRIPTION:
117 # The suffix of l10n source distfiles.
118 # Defaults to '.tar.xz'
119 : ${MOZ_L10N_URI_SUFFIX:=".tar.xz"}
120
121 # @ECLASS-VARIABLE: MOZ_FORCE_UPSTREAM_L10N
122 # @DESCRIPTION:
123 # Set this to use upstream langpaks even if the package normally
124 # shouldn't (ie it is an alpha or beta package)
125 : ${MOZ_FORCE_UPSTREAM_L10N:=""}
126
127 # @ECLASS-VARIABLE: MOZ_TOO_REGIONALIZED_FOR_L10N
128 # @INTERNAL
129 # @DESCRIPTION:
130 # Upstream identifiers that should not contain region subtags in L10N
131 MOZ_TOO_REGIONALIZED_FOR_L10N=( fy-NL ga-IE gu-IN hi-IN hy-AM nb-NO nn-NO pa-IN sv-SE )
132
133 # @ECLASS-VARIABLE: MOZ_INSTALL_L10N_XPIFILE
134 # @DESCRIPTION:
135 # Install langpacks as .xpi file instead of unpacked directory.
136 # Leave unset to install unpacked
137 : ${MOZ_INSTALL_L10N_XPIFILE:=""}
138
139 # Add l10n_* to IUSE according to available language packs
140 # No language packs for alphas and betas
141 if ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] ; then
142         if ! [[ ${PV} =~ alpha|beta ]] || { [[ ${PN} == seamonkey ]] && ! [[ ${PV} =~ alpha ]] ; } || [[ -n ${MOZ_FORCE_UPSTREAM_L10N} ]] ; then
143         [[ -z ${MOZ_FTP_URI} ]] && [[ -z ${MOZ_LANGPACK_HTTP_URI} ]] && die "No URI set to download langpacks, please set one of MOZ_{FTP,HTTP_LANGPACK}_URI"
144         for x in "${MOZ_LANGS[@]}" ; do
145                 # en and en_US are handled internally
146                 if [[ ${x} == en ]] || [[ ${x} == en-US ]]; then
147                         continue
148                 fi
149                 # strip region subtag if $x is in the list
150                 if has ${x} "${MOZ_TOO_REGIONALIZED_FOR_L10N[@]}" ; then
151                         xflag=${x%%-*}
152                 else
153                         xflag=${x}
154                 fi
155                 SRC_URI+=" l10n_${xflag/[_@]/-}? ("
156                 [[ -n ${MOZ_FTP_URI} ]] && SRC_URI+="
157                         ${MOZ_FTP_URI}/${MOZ_LANGPACK_PREFIX}${x}${MOZ_LANGPACK_SUFFIX} -> ${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
158                 [[ -n ${MOZ_LANGPACK_HTTP_URI} ]] && SRC_URI+="
159                         ${MOZ_LANGPACK_HTTP_URI}/${MOZ_LANGPACK_PREFIX}${x}${MOZ_LANGPACK_SUFFIX} -> ${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
160                 SRC_URI+=" )"
161                 IUSE+=" l10n_${xflag/[_@]/-}"
162                 # We used to do some magic if specific/generic locales were missing, but
163                 # we stopped doing that due to bug 325195.
164         done
165         fi
166 else
167         for x in "${MOZ_LANGS[@]}" ; do
168                 # en and en_US are handled internally
169                 if [[ ${x} == en ]] || [[ ${x} == en-US ]]; then
170                         continue
171                 fi
172                 # strip region subtag if $x is in the list
173                 if has ${x} "${MOZ_TOO_REGIONALIZED_FOR_L10N[@]}" ; then
174                         xflag=${x%%-*}
175                 else
176                         xflag=${x}
177                 fi
178 # Do NOT grab l10n sources from hg tip at this time, since it is a moving target
179 #               if [[ ${PV} =~ alpha ]]; then
180 #                       # Please note that this URI is not deterministic - digest breakage could occur
181 #                       SRC_URI+=" l10n_${xflag/[_@]/-}? ( http://hg.mozilla.org/releases/l10n/mozilla-aurora/ach/archive/tip.tar.bz2 -> ${MOZ_P}-l10n-${x}.tar.bz2 )"
182 #               elif [[ ${PV} =~ beta ]] && ! [[ ${PN} == seamonkey ]]; then
183 #                       # Please note that this URI is not deterministic - digest breakage could occur
184 #                       SRC_URI+=" l10n_${xflag/[_@]/-}? ( http://hg.mozilla.org/releases/l10n/mozilla-beta/ach/archive/tip.tar.bz2 -> ${MOZ_P}-l10n-${x}.tar.bz2 )"
185 #               elif [[ -n ${MOZ_L10N_URI_PREFIX} ]]; then
186                 if [[ -n ${MOZ_L10N_URI_PREFIX} ]]; then
187                         SRC_URI+=" l10n_${xflag/[_@]/-}? ( ${MOZ_L10N_URI_PREFIX}${x}${MOZ_L10N_URI_SUFFIX} )"
188                 fi
189                 IUSE+=" l10n_${xflag/[_@]/-}"
190         done
191 fi
192 unset x xflag
193
194 # @FUNCTION: mozlinguas_export
195 # @INTERNAL
196 # @DESCRIPTION:
197 # Generate the list of language packs called "mozlinguas"
198 # This list is used to unpack and install the xpi language packs
199 mozlinguas_export() {
200         if [[ ${PN} == seamonkey ]] ; then
201                 [[ ${PV} =~ alpha ]] && ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] && return
202         else
203                 [[ ${PV} =~ alpha|beta ]] && ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] && return
204         fi
205         local lingua lflag
206         mozlinguas=()
207         # Set mozlinguas based on the enabled l10n_* USE flags.
208         for lingua in "${MOZ_LANGS[@]}"; do
209                 # strip region subtag if $x is in the list
210                 if has ${lingua} en en-US; then
211                         # For mozilla products, en and en_US are handled internally
212                         continue
213                 elif has ${lingua} "${MOZ_TOO_REGIONALIZED_FOR_L10N[@]}" ; then
214                         lflag=${lingua%%-*}
215                 else
216                         lflag=${lingua}
217                 fi
218                 use l10n_${lflag/[_@]/-} && mozlinguas+=( ${lingua} )
219         done
220         # Compatibility code - Check LINGUAS and warn if anything set there isn't enabled via l10n
221         for lingua in ${LINGUAS}; do
222                 if has ${lingua//[_@]/-} en en-US; then
223                         # For mozilla products, en and en_US are handled internally
224                         continue
225                 # If this language is supported by ${P},
226                 elif has ${lingua} "${MOZ_LANGS[@]//-/_}"; then
227                         # Warn the language is missing, if it isn't already there
228                         has ${lingua//[_@]/-} "${mozlinguas[@]//[_@]/-}" || \
229                                 ewarn "LINGUAS value ${lingua} is not enabled using L10N use flags"
230                         continue
231                 # For each short lingua that isn't in MOZ_LANGS,
232                 # We used to add *all* long MOZ_LANGS to the mozlinguas list,
233                 # but we stopped doing that due to bug 325195.
234                 else
235                         :
236                 fi
237                 einfo "Sorry, but ${P} does not support the ${lingua} locale in LINGUAS"
238         done
239 }
240
241 # @FUNCTION: mozlinguas_src_unpack
242 # @DESCRIPTION:
243 # Unpack xpi language packs according to the user's LINGUAS settings
244 mozlinguas_src_unpack() {
245         local x
246         if ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
247                 mozlinguas_export
248                 for x in "${mozlinguas[@]}"; do
249                         # FIXME: Add support for unpacking xpis to portage
250                         xpi_unpack "${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
251                 done
252                 if [[ "${mozlinguas[*]}" != "" && "${mozlinguas[*]}" != "en" ]]; then
253                         einfo "Selected language packs (first will be default): ${mozlinguas[*]}"
254                 fi
255         fi
256 }
257 # For the phase function export
258 mozlinguas-v2_src_unpack() {
259         mozlinguas_src_unpack
260 }
261
262
263 # @FUNCTION: mozlinguas_mozconfig
264 # @DESCRIPTION:
265 # if applicable, add the necessary flag to .mozconfig to support
266 # the generation of locales.  Note that this function requires
267 # mozconfig_annontate to already be declared via an inherit of
268 # mozconfig or mozcoreconf.
269 mozlinguas_mozconfig() {
270         if [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
271                 if declare -f mozconfig_annotate >/dev/null ; then
272                         mozconfig_annotate 'for building locales' --with-l10n-base=${MOZ_L10N_SOURCEDIR}
273                 else
274                         die "Could not configure l10n-base, mozconfig_annotate not declared -- missing inherit?"
275                 fi
276         fi
277 }
278
279 # @FUNCTION: mozlinguas_src_compile
280 # @DESCRIPTION:
281 # if applicable, build the selected locales.
282 mozlinguas_src_compile() {
283         if [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
284                 # leverage BUILD_OBJ_DIR if set otherwise assume PWD.
285                 local x y targets=( "langpack" ) localedir="${BUILD_OBJ_DIR:-.}"
286                 case ${PN} in
287                         *firefox)
288                                 localedir+="/browser/locales"
289                                 ;;
290                         seamonkey)
291                                 localedir+="/suite/locales"
292                                 ;;
293                         *thunderbird)
294                                 localedir+="/mail/locales"
295                                 targets+=( "calendar-langpack" )
296                                 ;;
297                         *) die "Building locales for ${PN} is not supported."
298                 esac
299                 pushd "${localedir}" > /dev/null || die
300                 mozlinguas_export
301                 for x in "${mozlinguas[@]}"; do for y in "${targets[@]}"; do
302                         emake ${y}-${x} LOCALE_MERGEDIR="./${y}-${x}"
303                 done; done
304                 popd > /dev/null || die
305         fi
306 }
307
308 # For the phase function export
309 mozlinguas-v2_src_compile() {
310         mozlinguas_src_compile
311 }
312
313 # @FUNCTION: mozlinguas_xpistage_langpacks
314 # @DESCRIPTION:
315 # Add extra langpacks to the xpi-stage dir for prebuilt plugins
316 #
317 # First argument is the path to the extension
318 # Second argument is the prefix of the source (same as first if unspecified)
319 # Remaining arguments are the modules in the extension that are localized
320 #  (basename of first if unspecified)
321 #
322 # Example - installing extra langpacks for lightning:
323 # src_install() {
324 #       ... # general installation steps
325 #       mozlinguas_xpistage_langpacks \
326 #               "${BUILD_OBJ_DIR}"/dist/xpi-stage/lightning \
327 #               "${WORKDIR}"/lightning \
328 #               lightning calendar
329 #       ... # proceed with installation from the xpi-stage dir
330 # }
331
332 mozlinguas_xpistage_langpacks() {
333         local l c modpath="${1}" srcprefix="${1}" modules=( "${1##*/}" )
334         shift
335         if [[ -n ${1} ]] ; then srcprefix="${1}" ; shift ; fi
336         if [[ -n ${1} ]] ; then modules=( $@ ) ; fi
337
338         mozlinguas_export
339         mkdir -p "${modpath}/chrome" || die
340         for l in "${mozlinguas[@]}"; do for c in "${modules[@]}" ; do
341                 if [[ -e "${srcprefix}-${l}/chrome/${c}-${l}" ]]; then
342                         cp -RLp -t "${modpath}/chrome" "${srcprefix}-${l}/chrome/${c}-${l}" || die
343                         grep "locale ${c} ${l} chrome/" "${srcprefix}-${l}/chrome.manifest" \
344                                 >>"${modpath}/chrome.manifest" || die
345                 elif [[ -e "${srcprefix}/chrome/${c}-${l}" ]]; then
346                         cp -RLp -t "${modpath}/chrome" "${srcprefix}/chrome/${c}-${l}" || die
347                         grep "locale ${c} ${l} chrome/" "${srcprefix}/chrome.manifest" \
348                                 >>"${modpath}/chrome.manifest" || die
349                 else
350                         ewarn "Locale ${l} was not found for ${c}, skipping."
351                 fi
352         done; done
353 }
354
355 # @FUNCTION: mozlinguas-v2_src_install
356 # @DESCRIPTION:
357 # Install xpi language packs according to the user's L10N settings
358 # NOTE - uses ${BUILD_OBJ_DIR} or PWD if unset, for source-generated langpacks
359 mozlinguas_src_install() {
360         local x
361         mozlinguas_export
362         if [[ -n ${MOZ_GENERATE_LANGPACKS} ]] && [[ -n ${mozlinguas[*]} ]]; then
363                 local repopath="${WORKDIR}/${PN}-generated-langpacks"
364                 mkdir -p "${repopath}" || die
365                 pushd "${BUILD_OBJ_DIR:-.}"/dist/*/xpi > /dev/null || die
366                 for x in "${mozlinguas[@]}"; do
367                         cp "${MOZ_P}.${x}.langpack.xpi" \
368                         "${repopath}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi" || die
369                         xpi_unpack "${repopath}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
370                 done
371                 popd > /dev/null || die
372         fi
373
374         for x in "${mozlinguas[@]}"; do
375                 if [[ -n ${MOZ_INSTALL_L10N_XPIFILE} ]]; then
376                         xpi_copy "${WORKDIR}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}"
377                 else
378                         xpi_install "${WORKDIR}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}"
379                 fi
380         done
381 }
382
383 # For the phase function export
384 mozlinguas-v2_src_install() {
385         mozlinguas_src_install
386 }