/[gentoo-x86]/eclass/mozlinguas.eclass
Gentoo

Contents of /eclass/mozlinguas.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations) (download)
Thu Jul 16 17:42:19 2015 UTC (2 weeks, 1 day ago) by axs
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +2 -1 lines
minor update within mozlinguas.eclass

1 axs 1.9 # Copyright 1999-2015 Gentoo Foundation
2 nirbheek 1.1 # Distributed under the terms of the GNU General Public License v2
3 axs 1.10 # $Header: /var/cvsroot/gentoo-x86/eclass/mozlinguas.eclass,v 1.9 2015/07/16 17:31:04 axs Exp $
4 nirbheek 1.1
5     # @ECLASS: mozlinguas.eclass
6     # @MAINTAINER:
7     # mozilla@gentoo.org
8     # @AUTHOR:
9     # Nirbheek Chauhan <nirbheek@gentoo.org>
10 axs 1.9 # Ian Stakenvicius <axs@gentoo.org>
11 nirbheek 1.1 # @BLURB: Handle language packs for mozilla products
12     # @DESCRIPTION:
13     # Sets IUSE according to MOZ_LANGS (language packs available). Also exports
14 axs 1.9 # src_unpack, src_compile and src_install for use in ebuilds, and provides
15     # supporting functions for langpack generation and installation.
16 nirbheek 1.1
17 axs 1.8 inherit mozextension
18 nirbheek 1.1
19     case "${EAPI:-0}" in
20     0|1)
21     die "EAPI ${EAPI:-0} does not support the '->' SRC_URI operator";;
22 axs 1.5 2|3|4|5)
23 axs 1.9 EXPORT_FUNCTIONS src_unpack src_compile src_install;;
24 nirbheek 1.1 *)
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 axs 1.9 # @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 nirbheek 1.1 # @ECLASS-VARIABLE: MOZ_LANGPACK_PREFIX
64     # @DESCRIPTION:
65     # The relative path till the lang code in the langpack file URI.
66     # Defaults to ${MOZ_PV}/linux-i686/xpi/
67     : ${MOZ_LANGPACK_PREFIX:="${MOZ_PV}/linux-i686/xpi/"}
68    
69     # @ECLASS-VARIABLE: MOZ_LANGPACK_SUFFIX
70     # @DESCRIPTION:
71     # The suffix after the lang code in the langpack file URI.
72     # Defaults to '.xpi'
73     : ${MOZ_LANGPACK_SUFFIX:=".xpi"}
74    
75 axs 1.9 # @ECLASS-VARIABLE: MOZ_LANGPACK_UNOFFICIAL
76     # @DESCRIPTION:
77     # The status of the langpack, used to differentiate within
78     # Manifests and on Gentoo mirrors as to when the langpacks are
79     # generated officially by Mozilla or if they were generated
80     # unofficially by others (ie the Gentoo mozilla team). When
81     # this var is set, the distfile will have a .unofficial.xpi
82     # suffix.
83     : ${MOZ_LANGPACK_UNOFFICIAL:=""}
84    
85     # @ECLASS-VARIABLE: MOZ_GENERATE_LANGPACKS
86     # @DESCRIPTION:
87     # This flag specifies whether or not the langpacks should be
88     # generated directly during the build process, rather than
89     # being downloaded and installed from upstream pre-built
90     # extensions. Primarily it supports pre-release builds.
91     # Defaults to empty.
92     : ${MOZ_GENERATE_LANGPACKS:=""}
93    
94     # @ECLASS-VARIABLE: MOZ_L10N_SOURCEDIR
95     # @DESCRIPTION:
96     # The path that l10n sources can be found at, once unpacked.
97     # Defaults to ${WORKDIR}/l10n-sources
98     : ${MOZ_L10N_SOURCEDIR:="${WORKDIR}/l10n-sources"}
99    
100     # @ECLASS-VARIABLE: MOZ_L10N_URI_PREFIX
101     # @DESCRIPTION:
102     # The full URI prefix of the distfile for each l10n locale. The
103     # AB_CD and MOZ_L10N_URI_SUFFIX will be appended to this to complete the
104     # SRC_URI when MOZ_GENERATE_LANGPACKS is set. If empty, nothing will
105     # be added to SRC_URI.
106     # Defaults to empty.
107     : ${MOZ_L10N_URI_PREFIX:=""}
108    
109     # @ECLASS-VARIABLE: MOZ_L10N_URI_SUFFIX
110     # @DESCRIPTION:
111     # The suffix of l10n source distfiles.
112     # Defaults to '.tar.xz'
113     : ${MOZ_L10N_URI_SUFFIX:=".tar.xz"}
114    
115 nirbheek 1.1 # Add linguas_* to IUSE according to available language packs
116     # No language packs for alphas and betas
117 axs 1.9 if ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] ; then
118     if ! [[ ${PV} =~ alpha|beta ]] || { [[ ${PN} == seamonkey ]] && ! [[ ${PV} =~ alpha ]] ; } ; then
119     [[ -z ${MOZ_FTP_URI} ]] && [[ -z ${MOZ_HTTP_URI} ]] && die "No URI set to download langpacks, please set one of MOZ_{FTP,HTTP}_URI"
120 nirbheek 1.1 for x in "${MOZ_LANGS[@]}" ; do
121     # en and en_US are handled internally
122     if [[ ${x} == en ]] || [[ ${x} == en-US ]]; then
123     continue
124     fi
125 axs 1.9 SRC_URI+=" linguas_${x/-/_}? ("
126     [[ -n ${MOZ_FTP_URI} ]] && SRC_URI+="
127     ${MOZ_FTP_URI}/${MOZ_LANGPACK_PREFIX}${x}${MOZ_LANGPACK_SUFFIX} -> ${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
128     [[ -n ${MOZ_HTTP_URI} ]] && SRC_URI+="
129     ${MOZ_HTTP_URI}/${MOZ_LANGPACK_PREFIX}${x}${MOZ_LANGPACK_SUFFIX} -> ${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
130     SRC_URI+=" )"
131 nirbheek 1.1 IUSE+=" linguas_${x/-/_}"
132     # We used to do some magic if specific/generic locales were missing, but
133     # we stopped doing that due to bug 325195.
134     done
135 axs 1.9 fi
136     else
137     for x in "${MOZ_LANGS[@]}" ; do
138     # en and en_US are handled internally
139     if [[ ${x} == en ]] || [[ ${x} == en-US ]]; then
140     continue
141     fi
142     # Do NOT grab l10n sources from hg tip at this time, since it is a moving target
143     # if [[ ${PV} =~ alpha ]]; then
144     # # Please note that this URI is not deterministic - digest breakage could occur
145     # SRC_URI+=" linguas_${x/-/_}? ( http://hg.mozilla.org/releases/l10n/mozilla-aurora/ach/archive/tip.tar.bz2 -> ${MOZ_P}-l10n-${x}.tar.bz2 )"
146     # elif [[ ${PV} =~ beta ]] && ! [[ ${PN} == seamonkey ]]; then
147     # # Please note that this URI is not deterministic - digest breakage could occur
148     # SRC_URI+=" linguas_${x/-/_}? ( http://hg.mozilla.org/releases/l10n/mozilla-beta/ach/archive/tip.tar.bz2 -> ${MOZ_P}-l10n-${x}.tar.bz2 )"
149     # elif [[ -n ${MOZ_L10N_URI_PREFIX} ]]; then
150     if [[ -n ${MOZ_L10N_URI_PREFIX} ]]; then
151     SRC_URI+=" linguas_${x/-/_}? ( ${MOZ_L10N_URI_PREFIX}${x}${MOZ_L10N_URI_SUFFIX} )"
152     fi
153     IUSE+=" linguas_${x/-/_}"
154     done
155 nirbheek 1.1 fi
156     unset x
157    
158     # @FUNCTION: mozlinguas_export
159     # @INTERNAL
160     # @DESCRIPTION:
161     # Generate the list of language packs called "mozlinguas"
162     # This list is used to unpack and install the xpi language packs
163     mozlinguas_export() {
164 polynomial-c 1.2 if [[ ${PN} == seamonkey ]] ; then
165 axs 1.9 [[ ${PV} =~ alpha ]] && ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] && return
166 polynomial-c 1.2 else
167 axs 1.9 [[ ${PV} =~ alpha|beta ]] && ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] && return
168 polynomial-c 1.2 fi
169 nirbheek 1.1 local lingua
170     mozlinguas=()
171     for lingua in ${LINGUAS}; do
172     if has ${lingua} en en_US; then
173     # For mozilla products, en and en_US are handled internally
174     continue
175     # If this language is supported by ${P},
176     elif has ${lingua} "${MOZ_LANGS[@]//-/_}"; then
177     # Add the language to mozlinguas, if it isn't already there
178     has ${lingua//_/-} "${mozlinguas[@]}" || mozlinguas+=(${lingua//_/-})
179     continue
180     # For each short lingua that isn't in MOZ_LANGS,
181     # We used to add *all* long MOZ_LANGS to the mozlinguas list,
182     # but we stopped doing that due to bug 325195.
183     else
184     :
185     fi
186     ewarn "Sorry, but ${P} does not support the ${lingua} locale"
187     done
188     }
189    
190     # @FUNCTION: mozlinguas_src_unpack
191     # @DESCRIPTION:
192     # Unpack xpi language packs according to the user's LINGUAS settings
193     mozlinguas_src_unpack() {
194     local x
195 axs 1.9 if ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
196     mozlinguas_export
197     for x in "${mozlinguas[@]}"; do
198     # FIXME: Add support for unpacking xpis to portage
199     xpi_unpack "${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
200     done
201     if [[ "${mozlinguas[*]}" != "" && "${mozlinguas[*]}" != "en" ]]; then
202     einfo "Selected language packs (first will be default): ${mozlinguas[*]}"
203     fi
204     fi
205     }
206    
207     # @FUNCTION: mozlinguas_mozconfig
208     # @DESCRIPTION:
209     # if applicable, add the necessary flag to .mozconfig to support
210     # the generation of locales. Note that this function requires
211     # mozconfig_annontate to already be declared via an inherit of
212     # mozconfig or mozcoreconf.
213     mozlinguas_mozconfig() {
214     if [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
215     if declare -f mozconfig_annotate >/dev/null ; then
216     mozconfig_annotate 'for building locales' --with-l10n-base=${MOZ_L10N_SOURCEDIR}
217     else
218     die "Could not configure l10n-base, mozconfig_annotate not declared -- missing inherit?"
219     fi
220     fi
221     }
222    
223     # @FUNCTION: mozlinguas_src_compile
224     # @DESCRIPTION:
225     # if applicable, build the selected locales.
226     mozlinguas_src_compile() {
227     if [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
228     # leverage BUILD_OBJ_DIR if set otherwise assume PWD.
229     local x y targets=( "langpack" ) localedir="${BUILD_OBJ_DIR:-.}"
230     case ${PN} in
231     *firefox)
232     localedir+="/browser/locales"
233     ;;
234     seamonkey)
235     localedir+="/suite/locales"
236     ;;
237     *thunderbird)
238     localedir+="/mail/locales"
239     targets+=( "calendar-langpack" )
240     ;;
241     *) die "Building locales for ${PN} is not supported."
242     esac
243     pushd "${localedir}" > /dev/null || die
244     mozlinguas_export
245     for x in "${mozlinguas[@]}"; do for y in "${targets[@]}"; do
246     emake ${y}-${x} LOCALE_MERGEDIR="./${y}-${x}"
247     done; done
248     popd > /dev/null || die
249     fi
250     }
251    
252     # @FUNCTION: mozlinguas_xpistage_langpacks
253     # @DESCRIPTION:
254     # Add extra langpacks to the xpi-stage dir for prebuilt plugins
255     #
256     # First argument is the path to the extension
257     # Second argument is the prefix of the source (same as first if unspecified)
258     # Remaining arguments are the modules in the extension that are localized
259     # (basename of first if unspecified)
260     #
261     # Example - installing extra langpacks for lightning:
262     # src_install() {
263     # ... # general installation steps
264     # mozlinguas_xpistage_langpacks \
265     # "${BUILD_OBJ_DIR}"/dist/xpi-stage/lightning \
266     # "${WORKDIR}"/lightning \
267     # lightning calendar
268     # ... # proceed with installation from the xpi-stage dir
269     # }
270    
271     mozlinguas_xpistage_langpacks() {
272     local l c modpath="${1}" srcprefix="${1}" modules=( "${1##*/}" )
273     shift
274     if [[ -n ${1} ]] ; then srcprefix="${1}" ; shift ; fi
275     if [[ -n ${1} ]] ; then modules=( $@ ) ; fi
276    
277 axs 1.8 mozlinguas_export
278 axs 1.10 mkdir -p "${modpath}/chrome" || die
279 axs 1.9 for l in "${mozlinguas[@]}"; do for c in "${modules[@]}" ; do
280     if [[ -e "${srcprefix}-${l}/chrome/${c}-${l}" ]]; then
281     cp -RLp -t "${modpath}/chrome" "${srcprefix}-${l}/chrome/${c}-${l}" || die
282     grep "locale ${c} ${l} chrome/" "${srcprefix}-${l}/chrome.manifest" \
283     >>"${modpath}/chrome.manifest" || die
284     elif [[ -e "${srcprefix}/chrome/${c}-${l}" ]]; then
285     cp -RLp -t "${modpath}/chrome" "${srcprefix}/chrome/${c}-${l}" || die
286     grep "locale ${c} ${l} chrome/" "${srcprefix}/chrome.manifest" \
287     >>"${modpath}/chrome.manifest" || die
288     else
289     ewarn "Locale ${l} was not found for ${c}, skipping."
290     fi
291     done; done
292 axs 1.7 }
293    
294 nirbheek 1.1 # @FUNCTION: mozlinguas_src_install
295     # @DESCRIPTION:
296     # Install xpi language packs according to the user's LINGUAS settings
297 axs 1.9 # NOTE - uses ${BUILD_OBJ_DIR} or PWD if unset, for source-generated langpacks
298 nirbheek 1.1 mozlinguas_src_install() {
299     local x
300     mozlinguas_export
301 axs 1.9 if [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
302     local repopath="${WORKDIR}/${PN}-generated-langpacks"
303     mkdir -p "${repopath}"
304     pushd "${BUILD_OBJ_DIR:-.}"/dist/*/xpi > /dev/null || die
305     for x in "${mozlinguas[@]}"; do
306     cp "${MOZ_P}.${x}.langpack.xpi" \
307     "${repopath}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi" || die
308     xpi_unpack "${repopath}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
309     done
310     popd > /dev/null || die
311     fi
312 nirbheek 1.1 for x in "${mozlinguas[@]}"; do
313 axs 1.9 xpi_install "${WORKDIR}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}"
314 nirbheek 1.1 done
315     }

  ViewVC Help
Powered by ViewVC 1.1.20