support for environment variables in package.env

Vlastimil Babka <[email protected]>
Newsgroups gmane.linux.gentoo.java
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The need for this came with swt. To use embedded seamonkey/xulrunner
browser in apps using swt, the apps have to be started with
MOZILLA_FIVE_HOME variable pointing to /usr/lib/{seamonkey,xulrunner}/
according to what swt was built against. Currently there are two apps in
java-experimental that need this - zekr and rssowl.

So the idea is:
- - swt records MOZILLA_FIVE_HOME into its package.env via eclass
function, that also adds ENV_VARS="MOZILLA_FIVE_HOME" (space-separated
list) there to mark this variable(s) for exporting - I just copied this
idea from VM's env.d files we use
- - gjl looks for ENV_VARS in package and all deps transitively, and
exports the variables defined in them in the same package.env

Which means new java-config release and eclass change. Any package
exporting vars (a swt revbump) should RDEPEND on such new java-config
until it's stabled and we can force it in eclass, to ensure gjl will
pick the variable(s).

I've implemented this today (with my weak python foo :), so here are the
patches for review (inline):

Index: java-utils-2.eclass
===================================================================
RCS file: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v
retrieving revision 1.84
diff -u -B -r1.84 java-utils-2.eclass
- --- java-utils-2.eclass 6 May 2007 09:47:36 -0000       1.84
+++ java-utils-2.eclass 19 May 2007 00:02:58 -0000
@@ -1120,7 +1120,33 @@
                java-pkg_record-jar_ "${pkgs}" "${jar}"
        fi

- -       java-pkg_do_write_
+       java-pkg_do_write_
+}
+
+#
-
------------------------------------------------------------------------------
+# @ebuild-function java-pkg_register-environment-variable
+#
+# Register an arbitrary environment variable into package.env. The gjl
launcher
+# for this package or any package depending on this will export it into
+# environement before executing java command.
+# Must only be called in src_install phase.
+#
+# @param $1 - variable name
+# @param $2 - variable value
+#
-
------------------------------------------------------------------------------
+JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
+JAVA_PKG_EXTRA_ENV_VARS=""
+java-pkg_register-environment-variable() {
+       debug-print-function ${FUNCNAME} $*
+
+       java-pkg_check-phase install
+
+       [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
+
+       echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
+       JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
+
+       java-pkg_do_write_
 }

 # This function reads stdin, and based on that input, figures out how to
@@ -2143,6 +2169,14 @@
                echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
                [[ -n ${GENTOO_COMPILER} ]] && echo
"MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"

+               # extra env variables
+               if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
+                       cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}"
|| die
+                       # nested echo to remove leading/trailing spaces
+                       echo "ENV_VARS=\"$(echo
${JAVA_PKG_EXTRA_ENV_VARS})\"" \
+                               >> "${JAVA_PKG_ENV}" || die
+               fi
+
                # Strip unnecessary leading and trailing colons
                # TODO try to cleanup if possible
                sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i
"${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"

Index: src/java_config/EnvironmentManager.py
===================================================================
- --- src/java_config/EnvironmentManager.py       (revision 4675)
+++ src/java_config/EnvironmentManager.py       (working copy)
@@ -308,6 +308,43 @@

         return path

+    def add_pkg_env(self, pkg, env):
+        env_vars = pkg.query("ENV_VARS")
+        if (env_vars):
+            for var in env_vars.split(' '):
+                val = pkg.query(var)
+                assert val
+                if (not env.has_key(var)):
+                    env[var] = val
+
+    def build_dep_env(self, pkgs, missing_deps):
+        env = {}
+
+        unresolved = Set()
+        resolved = Set()
+
+        for p in pkgs[:]:
+            pkg = self.get_package(p)
+            if pkg:
+                pkgs.remove(p)
+                unresolved.add(pkg)
+
+        while len(unresolved) > 0:
+            pkg = unresolved.pop()
+            resolved.add(pkg)
+
+            self.add_pkg_env(pkg, env)
+
+            for dep in pkg.deps():
+                p = self.get_package(dep[-1])
+
+                if p:
+                    if p not in resolved:
+                        unresolved.add(p)
+                else:
+                    missing_deps.add(dep[-1])
+        return env
+
     def set_classpath(self, targets, pkgs):
         classpath = self.build_classpath(pkgs)

Index: src/gjl
===================================================================
- --- src/gjl     (revision 4676)
+++ src/gjl     (working copy)
@@ -120,6 +120,10 @@
     else:
         return None

+def get_env(package):
+    env = manager.build_dep_env([package.name()], Set())
+    return env
+
 def get_jar(pkg, gjar):
     jars = pkg.classpath()
     if jars:
@@ -173,7 +177,10 @@
     if options.get_args:
         args = get_args(pkg)
         if args:
- -            print 'gjl_args="%s"' % ( args )
+            print 'gjl_args="%s";' % ( args )
+        env = get_env(pkg)
+        for k, v in env.iteritems():
+            print 'export %s="%s";' % ( k, v )

     if options.jar:
         jar = get_jar(pkg, options.jar)

- --- swt-3.2.2.ebuild    2007-04-28 14:07:38.000000000 +0200
+++ swt-3.2.2-r1.ebuild 2007-05-19 01:46:59.000000000 +0200
@@ -98,6 +98,17 @@
        epatch "${FILESDIR}/${PN}-3.2.1-fbsd.patch"
 }

+get_gecko() {
+       local gecko
+       # Wasn't able to succesfully run test with this
+       #
http://overlays.gentoo.org/proj/java/browser/testcases/dev-java/swt
+       #use firefox && local gecko="firefox"
+       use seamonkey && gecko="seamonkey"
+       use xulrunner && gecko="xulrunner"
+
+       echo ${gecko}
+}
+
 src_compile() {
        # Drop jikes support as it seems to be unfriendly with SWT
        java-pkg_filter-compiler jikes
@@ -146,12 +157,7 @@
                ${make} make_gnome || die "Failed to build GNOME VFS
support"
        fi

- -       # Wasn't able to succesfully run test with this
- -       #
http://overlays.gentoo.org/proj/java/browser/testcases/dev-java/swt
- -       #use firefox && local gecko="firefox"
- -       use seamonkey && local gecko="seamonkey"
- -       use xulrunner && local gecko="xulrunner"
- -
+       local gecko="$(get_gecko)"
        if [[ ${gecko} ]]; then
                einfo "Building the Mozilla component"
                #local idir="$(pkg-config ${gecko}-xpcom
- --variable=includedir)"
@@ -189,6 +195,10 @@
        java-pkg_sointo /usr/$(get_libdir)
        java-pkg_doso *.so

+       local gecko="$(get_gecko)"
+       [[ -n "${gecko}" ]] && java-pkg_register-environment-variable \
+               MOZILLA_FIVE_HOME "/usr/$(get_libdir)/${gecko}/"
+
        dohtml about.html || die
 }


New swt's package.env:

DESCRIPTION="GTK based SWT Library"
GENERATION="2"
CLASSPATH="/usr/share/swt-3/lib/swt.jar"
LIBRARY_PATH="/usr/lib"
VM=">=virtual/jre-1.4"
TARGET="1.4"
SOURCE="1.4"
MERGE_VM="sun-jdk-1.6.0.02"
MERGE_COMPILER="ecj-3.2"
MOZILLA_FIVE_HOME="/usr/lib/seamonkey/"
ENV_VARS="MOZILLA_FIVE_HOME"

Tested and works with rssowl, might try zekr later, removing it's
dolauncher --pre stuff that simulates this behaviour.
- --
Vlastimil Babka (Caster)
Gentoo/Java
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGTj/btbrAj05h3oQRAsMtAKCR6nRPhOSS5rg/GbEYymGt7bvzIACghCkO
rcz/OiakLwkUR2RmAZs8O04=
=ujnj
-----END PGP SIGNATURE-----
-- 
[email protected] mailing list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.