[RFC] support for optional dependencies in package.env
Vlastimil Babka <[email protected]>
| Newsgroups | gmane.linux.gentoo.java |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 https://bugs.gentoo.org/show_bug.cgi?id=176182 Useful for jdbc providers (or my bsf attempt) etc. Package doesn't depend (in ebuild DEPEND nor RDEPEND nor PDEPEND) on another but can use if it it's on classpath. So we add new java-pkg_register-optional-dependency to eclass, which will record given package to OPTIONAL_DEPEND in package.env. gjl will process it if it's installed, and ignore if not (no errors about missing package). - -- Vlastimil Babka (Caster) Gentoo/Java -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGWhhctbrAj05h3oQRAtnXAJ9IlzqsxMfioyGhvY3Yg8/BVSeOowCdELkZ N3kfQ9KX23cvaJHTzzIKbn4= =GRI1 -----END PGP SIGNATURE-----
java-utils-2.eclass.patch
(text/x-patch, 5.3 KB)
Index: java-utils-2.eclass
===================================================================
RCS file: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v
retrieving revision 1.87
diff -u -B -r1.87 java-utils-2.eclass
--- java-utils-2.eclass 27 May 2007 11:09:11 -0000 1.87
+++ java-utils-2.eclass 27 May 2007 23:43:05 -0000
@@ -1078,7 +1078,6 @@
# Intended for binary packages where you don't need to symlink the jars or get
# their classpath during build. As such, the dependencies only need to be
# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
-# Get the classpath provided by any number of packages.
#
# @param $1 - comma-separated list of packages, or a single package
# @param $2 - if param $1 is a single package, optionally specify the jar
@@ -1123,6 +1122,57 @@
}
# ------------------------------------------------------------------------------
+# @ebuild-function java-pkg_register-optional-dependency
+#
+# Registers optional runtime dependency on a package, list of packages, or a
+# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
+# called in src_install phase.
+# Intended for packages that can use other packages when those are in classpath.
+# Will be put on classpath by launcher if they are installed. Typical case are
+# JDBC implementations for various databases. It's better than having USE flag
+# for each implementation triggering hard dependency.
+#
+# @param $1 - comma-separated list of packages, or a single package
+# @param $2 - if param $1 is a single package, optionally specify the jar
+# to depend on
+#
+# Example: Record the optional dependency on whole xerces-2 and xalan,
+# java-pkg_register-optional-dependency xerces-2,xalan
+# Example: Record the dependency on ant.jar from ant-core
+# java-pkg_register-optional-dependency ant-core ant.jar
+#
+# Note: Passing both list of packages as the first parameter AND specifying the
+# jar as the second is not allowed and will cause the function to die. We assume
+# that there's more chance one passes such combination as a mistake, than that
+# there are more packages providing identically named jar without class
+# collisions.
+# ------------------------------------------------------------------------------
+java-pkg_register-optional-dependency() {
+ debug-print-function ${FUNCNAME} $*
+
+ java-pkg_check-phase install
+
+ [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
+
+ local pkgs="${1}"
+ local jar="${2}"
+
+ [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
+
+ if [[ -z "${jar}" ]]; then
+ for pkg in ${pkgs//,/ }; do
+ java-pkg_record-optional-jar_ "${pkg}"
+ done
+ else
+ [[ ${pkgs} == *,* ]] && \
+ die "${FUNCNAME} called with both package list and jar name"
+ java-pkg_record-optional-jar_ "${pkgs}" "${jar}"
+ fi
+
+ java-pkg_do_write_
+}
+
+# ------------------------------------------------------------------------------
# @ebuild-function java-pkg_register-environment-variable
#
# Register an arbitrary environment variable into package.env. The gjl launcher
@@ -2145,7 +2195,8 @@
# Create directory for package.env
dodir "${JAVA_PKG_SHAREPATH}"
if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
- "${JAVA_PKG_DEPEND_FILE}" ]]; then
+ "${JAVA_PKG_DEPEND_FILE}" || -f \
+ "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
# Create package.env
(
echo "DESCRIPTION=\"${DESCRIPTION}\""
@@ -2155,7 +2206,9 @@
[[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
[[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
[[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
- && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND_FILE} | uniq | tr '\n' ':')\""
+ && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
+ [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
+ && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
) > "${JAVA_PKG_ENV}"
@@ -2188,8 +2241,8 @@
# TODO try to cleanup if possible
sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
else
- debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY or"
- debug-print "JAVA_PKG_DEPEND_FILE not defined so can't"
+ debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
+ debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
debug-print "write package.env."
fi
}
@@ -2216,6 +2269,27 @@
}
# ------------------------------------------------------------------------------
+# @internal-function java-pkg_record-optional-jar_
+#
+# Record an optional dependency to the package.env OPTIONAL_DEPEND line.
+#
+# ------------------------------------------------------------------------------
+JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
+
+java-pkg_record-optional-jar_() {
+ debug-print-function ${FUNCNAME} $*
+
+ local pkg=${1} jar=${2} append
+ if [[ -z "${jar}" ]]; then
+ append="${pkg}"
+ else
+ append="$(basename ${jar})@${pkg}"
+ fi
+
+ echo ${append} >> ${JAVA_PKG_OPTIONAL_DEPEND_FILE}
+}
+
+# ------------------------------------------------------------------------------
# @internal-function java-pkg_append_
#
# Appends a value to a variable
java-config.patch
(text/x-patch, 1.8 KB)
Index: Package.py
===================================================================
--- Package.py (revision 4849)
+++ Package.py (working copy)
@@ -60,6 +60,16 @@
return [dep.split("@") for dep in depstr.split(":")]
else:
return []
+
+ def opt_deps(self):
+ """
+ Return all packages this package optionally depends on
+ """
+ depstr = self.query("OPTIONAL_DEPEND")
+ if depstr:
+ return [dep.split("@") for dep in depstr.split(":")]
+ else:
+ return []
def provides(self):
"""
Index: EnvironmentManager.py
===================================================================
--- EnvironmentManager.py (revision 4849)
+++ EnvironmentManager.py (working copy)
@@ -263,6 +263,19 @@
def build_classpath(self, pkgs):
return self.build_path(pkgs, "CLASSPATH")
+ def get_pkg_deps(self, pkg):
+ """
+ Returns list of package's deps and optional deps.
+ Filters out optional deps that are not present.
+ """
+ deps = pkg.deps();
+ for opt_dep in pkg.opt_deps():
+ p = self.get_package(opt_dep[-1])
+ if p:
+ deps.append(opt_dep)
+
+ return deps
+
def add_dep_classpath(self, pkg, dep, classpath):
pkg_cp = pkg.classpath()
if pkg_cp:
@@ -295,7 +308,7 @@
lpath = pkg.query(query)
self.add_path_elements(lpath, path)
- for dep in pkg.deps():
+ for dep in self.get_pkg_deps(pkg):
p = self.get_package(dep[-1])
if p:
@@ -344,7 +357,7 @@
self.add_pkg_env_vars(pkg, env)
- for dep in pkg.deps():
+ for dep in pkg.self.get_pkg_deps(pkg):
p = self.get_package(dep[-1])
if p: