/[gentoo-x86]/eclass/java-vm-2.eclass
Gentoo

Contents of /eclass/java-vm-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.46 - (show annotations) (download)
Mon Jul 23 19:06:20 2012 UTC (2 years ago) by sera
Branch: MAIN
Changes since 1.45: +6 -4 lines
Add C to flags pass to pax-mark to ensure a header is created. Thanks to blueness. #427642

1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/java-vm-2.eclass,v 1.45 2012/07/18 16:54:55 sera Exp $
4
5 # @ECLASS: java-vm-2.eclass
6 # @MAINTAINER:
7 # java@gentoo.org
8 # @BLURB: Java Virtual Machine eclass
9 # @DESCRIPTION:
10 # This eclass provides functionality which assists with installing
11 # virtual machines, and ensures that they are recognized by java-config.
12
13 inherit eutils fdo-mime multilib pax-utils prefix
14
15 EXPORT_FUNCTIONS pkg_setup pkg_postinst pkg_prerm pkg_postrm
16
17 RDEPEND="
18 =dev-java/java-config-2*
19 || ( app-admin/eselect-java <dev-java/java-config-2.2 )"
20 DEPEND="${RDEPEND}"
21 has "${EAPI}" 0 1 && DEPEND="${DEPEND} >=sys-apps/portage-2.1"
22
23 export WANT_JAVA_CONFIG=2
24
25
26 # @ECLASS-VARIABLE: JAVA_VM_CONFIG_DIR
27 # @INTERNAL
28 # @DESCRIPTION:
29 # Where to place the vm env file.
30 JAVA_VM_CONFIG_DIR="/usr/share/java-config-2/vm"
31
32 # @ECLASS-VARIABLE: JAVA_VM_DIR
33 # @INTERNAL
34 # @DESCRIPTION:
35 # Base directory for vm links.
36 JAVA_VM_DIR="/usr/lib/jvm"
37
38 # @ECLASS-VARIABLE: JAVA_VM_SYSTEM
39 # @INTERNAL
40 # @DESCRIPTION:
41 # Link for system-vm
42 JAVA_VM_SYSTEM="/etc/java-config-2/current-system-vm"
43
44 # @ECLASS-VARIABLE: JAVA_VM_BUILD_ONLY
45 # @DESCRIPTION:
46 # Set to YES to mark a vm as build-only.
47 JAVA_VM_BUILD_ONLY="${JAVA_VM_BUILD_ONLY:-FALSE}"
48
49
50 # @FUNCTION: java-vm-2_pkg_setup
51 # @DESCRIPTION:
52 # default pkg_setup
53 #
54 # Initialize vm handle.
55
56 java-vm-2_pkg_setup() {
57 if [[ "${SLOT}" != "0" ]]; then
58 VMHANDLE=${PN}-${SLOT}
59 else
60 VMHANDLE=${PN}
61 fi
62 }
63
64
65 # @FUNCTION: java-vm-2_pkg_postinst
66 # @DESCRIPTION:
67 # default pkg_postinst
68 #
69 # Set the generation-2 system VM and Java plugin, if it isn't set or the
70 # setting is invalid. Also update mime database.
71
72 java-vm-2_pkg_postinst() {
73 # Note that we cannot rely on java-config here, as it will silently recognize
74 # e.g. icedtea6-bin as valid system VM if icedtea6 is set but invalid (e.g. due
75 # to the migration to icedtea-6)
76 if [[ ! -L "${ROOT}${JAVA_VM_SYSTEM}" ]]; then
77 java_set_default_vm_
78 else
79 local current_vm_path=$(readlink "${ROOT}${JAVA_VM_SYSTEM}")
80 local current_vm=$(basename "${ROOT}${current_vm_path}")
81 if [[ ! -L "${ROOT}${JAVA_VM_DIR}/${current_vm}" ]]; then
82 java_set_default_vm_
83 fi
84 fi
85
86 java-vm_check-nsplugin
87 java_mozilla_clean_
88 fdo-mime_desktop_database_update
89 }
90
91
92 # @FUNCTION: java-vm_check-nsplugin
93 # @INTERNAL
94 # @DESCRIPTION:
95 # Check if the nsplugin needs updating
96
97 java-vm_check-nsplugin() {
98 local libdir
99 if [[ ${VMHANDLE} =~ emul-linux-x86 ]]; then
100 libdir=lib32
101 else
102 libdir=lib
103 fi
104
105 has ${EAPI:-0} 0 1 2 && ! use prefix && EPREFIX=
106
107 # Install a default nsplugin if we don't already have one
108 if in_iuse nsplugin && use nsplugin; then
109 if [[ ! -f "${ROOT}${EPREFIX}"/usr/${libdir}/nsbrowser/plugins/javaplugin.so ]]; then
110 einfo "No system nsplugin currently set."
111 java-vm_set-nsplugin
112 else
113 einfo "System nsplugin is already set, not changing it."
114 fi
115 einfo "You can change nsplugin with eselect java-nsplugin."
116 fi
117 }
118
119
120 # @FUNCTION: java-vm_set-nsplugin
121 # @INTERNAL
122 # @DESCRIPTION:
123 # Set the nsplugin implemetation.
124
125 java-vm_set-nsplugin() {
126 local extra_args
127 if use amd64; then
128 if [[ ${VMHANDLE} =~ emul-linux-x86 ]]; then
129 extra_args="32bit"
130 else
131 extra_args="64bit"
132 fi
133 einfo "Setting ${extra_args} nsplugin to ${VMHANDLE}"
134 else
135 einfo "Setting nsplugin to ${VMHANDLE}..."
136 fi
137 eselect java-nsplugin set ${extra_args} ${VMHANDLE}
138 }
139
140
141 # @FUNCTION: java-vm-2_pkg_prerm
142 # @DESCRIPTION:
143 # default pkg_prerm
144 #
145 # Warn user if removing system-vm.
146
147 java-vm-2_pkg_prerm() {
148 # Although REPLACED_BY_VERSION is EAPI=4, we shouldn't need to check EAPI for this use case
149 if [[ "$(GENTOO_VM="" java-config -f 2>/dev/null)" == "${VMHANDLE}" && -z "${REPLACED_BY_VERSION}" ]]; then
150 ewarn "It appears you are removing your system-vm!"
151 ewarn "Please run java-config -L to list available VMs,"
152 ewarn "then use java-config -S to set a new system-vm!"
153 fi
154 }
155
156
157 # @FUNCTION: java-vm-2_pkg_postrm
158 # @DESCRIPTION:
159 # default pkg_postrm
160 #
161 # Update mime database.
162
163 java-vm-2_pkg_postrm() {
164 fdo-mime_desktop_database_update
165 }
166
167
168 # @FUNCTION: java_set_default_vm_
169 # @INTERNAL
170 # @DESCRIPTION:
171 # Set system-vm.
172
173 java_set_default_vm_() {
174 java-config-2 --set-system-vm="${VMHANDLE}"
175
176 einfo " ${P} set as the default system-vm."
177 }
178
179
180 # @FUNCTION: get_system_arch
181 # @DESCRIPTION:
182 # Get Java specific arch name.
183
184 get_system_arch() {
185 local sarch
186 sarch=$(echo ${ARCH} | sed -e s/[i]*.86/i386/ -e s/x86_64/amd64/ -e s/sun4u/sparc/ -e s/sparc64/sparc/ -e s/arm.*/arm/ -e s/sa110/arm/)
187 if [ -z "${sarch}" ]; then
188 sarch=$(uname -m | sed -e s/[i]*.86/i386/ -e s/x86_64/amd64/ -e s/sun4u/sparc/ -e s/sparc64/sparc/ -e s/arm.*/arm/ -e s/sa110/arm/)
189 fi
190 echo ${sarch}
191 }
192
193
194 # @FUNCTION: set_java_env
195 # @DESCRIPTION:
196 # Installs a vm env file.
197
198 # TODO rename to something more evident, like install_env_file
199 set_java_env() {
200 debug-print-function ${FUNCNAME} $*
201
202 if has ${EAPI:-0} 0 1 2 && ! use prefix ; then
203 ED="${D}"
204 EPREFIX=""
205 fi
206
207 local platform="$(get_system_arch)"
208 local env_file="${ED}${JAVA_VM_CONFIG_DIR}/${VMHANDLE}"
209 local old_env_file="${ED}/etc/env.d/java/20${P}"
210 if [[ ${1} ]]; then
211 local source_env_file="${1}"
212 else
213 local source_env_file="${FILESDIR}/${VMHANDLE}.env"
214 fi
215
216 if [[ ! -f ${source_env_file} ]]; then
217 die "Unable to find the env file: ${source_env_file}"
218 fi
219
220 dodir ${JAVA_VM_CONFIG_DIR}
221 sed \
222 -e "s/@P@/${P}/g" \
223 -e "s/@PN@/${PN}/g" \
224 -e "s/@PV@/${PV}/g" \
225 -e "s/@PF@/${PF}/g" \
226 -e "s/@SLOT@/${SLOT}/g" \
227 -e "s/@PLATFORM@/${platform}/g" \
228 -e "s/@LIBDIR@/$(get_libdir)/g" \
229 -e "/^LDPATH=.*lib\\/\\\"/s|\"\\(.*\\)\"|\"\\1${platform}/:\\1${platform}/server/\"|" \
230 < "${source_env_file}" \
231 > "${env_file}" || die "sed failed"
232
233 (
234 echo "VMHANDLE=\"${VMHANDLE}\""
235 echo "BUILD_ONLY=\"${JAVA_VM_BUILD_ONLY}\""
236 ) >> "${env_file}"
237
238 eprefixify ${env_file}
239
240 [[ -n ${JAVA_PROVIDE} ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" >> ${env_file}
241
242 local java_home=$(source "${env_file}"; echo ${JAVA_HOME})
243 [[ -z ${java_home} ]] && die "No JAVA_HOME defined in ${env_file}"
244
245 # Make the symlink
246 dodir "${JAVA_VM_DIR}"
247 dosym ${java_home#${EPREFIX}} ${JAVA_VM_DIR}/${VMHANDLE} \
248 || die "Failed to make VM symlink at ${JAVA_VM_DIR}/${VMHANDLE}"
249 }
250
251
252 # @FUNCTION: java-vm_set-pax-markings
253 # @DESCRIPTION:
254 # Set PaX markings on all JDK/JRE executables to allow code-generation on
255 # the heap by the JIT compiler.
256 #
257 # The markings need to be set prior to the first invocation of the the freshly
258 # built / installed VM. Be it before creating the Class Data Sharing archive or
259 # generating cacerts. Otherwise a PaX enabled kernel will kill the VM.
260 # Bug #215225 #389751
261 #
262 # @CODE
263 # Parameters:
264 # $1 - JDK/JRE base directory.
265 #
266 # Examples:
267 # java-vm_set-pax-markings "${S}"
268 # java-vm_set-pax-markings "${ED}"/opt/${P}
269 # @CODE
270
271 java-vm_set-pax-markings() {
272 debug-print-function ${FUNCNAME} "$*"
273 [[ $# -ne 1 ]] && die "${FUNCNAME}: takes exactly one argument"
274 [[ ! -f "${1}"/bin/java ]] \
275 && die "${FUNCNAME}: argument needs to be JDK/JRE base directory"
276
277 local executables=( "${1}"/bin/* )
278 [[ -d "${1}"/jre ]] && executables+=( "${1}"/jre/bin/* )
279
280 # Ensure a PaX header is created.
281 local pax_markings="C"
282 # Usally disabeling MPROTECT is sufficent.
283 local pax_markings+="m"
284 # On x86 for heap sizes over 700MB disable SEGMEXEC and PAGEEXEC as well.
285 use x86 && pax_markings+="sp"
286
287 pax-mark ${pax_markings} $(list-paxables "${executables[@]}")
288 }
289
290
291 # @FUNCTION: java-vm_revdep-mask
292 # @DESCRIPTION:
293 # Installs a revdep-rebuild control file which SEARCH_DIR_MASK set to the path
294 # where the VM is installed. Prevents pointless rebuilds - see bug #177925.
295 # Also gives a notice to the user.
296 #
297 # @CODE
298 # Parameters:
299 # $1 - Path of the VM (defaults to /opt/${P} if not set)
300 #
301 # Examples:
302 # java-vm_revdep-mask
303 # java-vm_revdep-mask /path/to/jdk/
304 #
305 # @CODE
306
307 java-vm_revdep-mask() {
308 if has ${EAPI:-0} 0 1 2 && ! use prefix; then
309 ED="${D}"
310 EPREFIX=
311 fi
312
313 local VMROOT="${1-"${EPREFIX}"/opt/${P}}"
314
315 dodir /etc/revdep-rebuild/
316 echo "SEARCH_DIRS_MASK=\"${VMROOT}\""> "${ED}/etc/revdep-rebuild/61-${VMHANDLE}"
317 }
318
319
320 # @FUNCTION: java-vm_sandbox-predict
321 # @DESCRIPTION:
322 # Install a sandbox control file. Specified paths won't cause a sandbox
323 # violation if opened read write but no write takes place. See bug 388937#c1
324 #
325 # @CODE
326 # Examples:
327 # java-vm_sandbox-predict /dev/random /proc/self/coredump_filter
328 # @CODE
329
330 java-vm_sandbox-predict() {
331 debug-print-function ${FUNCNAME} "$*"
332 [[ -z "${1}" ]] && die "${FUNCNAME} takes at least one argument"
333
334 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
335
336 local path path_arr=("$@")
337 # subshell this to prevent IFS bleeding out dependant on bash version.
338 # could use local, which *should* work, but that requires a lot of testing.
339 path=$(IFS=":"; echo "${path_arr[*]}")
340 dodir /etc/sandbox.d
341 echo "SANDBOX_PREDICT=\"${path}\"" > "${ED}/etc/sandbox.d/20${VMHANDLE}" \
342 || die "Failed to write sandbox control file"
343 }
344
345
346 # @FUNCTION: java_get_plugin_dir_
347 # @INTERNAL
348 # @DESCRIPTION:
349 # Get the java plugin dir.
350
351 java_get_plugin_dir_() {
352 has ${EAPI:-0} 0 1 2 && ! use prefix && EPREFIX=
353 echo "${EPREFIX}"/usr/$(get_libdir)/nsbrowser/plugins
354 }
355
356
357 # @FUNCTION: install_mozilla_plugin
358 # @DESCRIPTION:
359 # Register a netscape java-plugin.
360
361 install_mozilla_plugin() {
362 local plugin="${1}"
363 local variant="${2}"
364
365 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
366 if [[ ! -f "${ED}/${plugin}" ]]; then
367 die "Cannot find mozilla plugin at ${ED}/${plugin}"
368 fi
369
370 if [[ -n "${variant}" ]]; then
371 variant="-${variant}"
372 fi
373
374 local plugin_dir="/usr/share/java-config-2/nsplugin"
375 dodir "${plugin_dir}"
376 dosym "${plugin}" "${plugin_dir}/${VMHANDLE}${variant}-javaplugin.so"
377 }
378
379
380 # @FUNCTION: java_mozilla_clean_
381 # @INTERNAL
382 # @DESCRIPTION:
383 # Because previously some ebuilds installed symlinks outside of pkg_install
384 # and are left behind, which forces you to manualy remove them to select the
385 # jdk/jre you want to use for java
386
387 java_mozilla_clean_() {
388 local plugin_dir=$(java_get_plugin_dir_)
389 for file in ${plugin_dir}/javaplugin_*; do
390 rm -f ${file}
391 done
392 for file in ${plugin_dir}/libjavaplugin*; do
393 rm -f ${file}
394 done
395 }

  ViewVC Help
Powered by ViewVC 1.1.20