Bug #365439: Add set_unless_changed() and unset_unless_changed().
authorArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>
Sun, 1 May 2011 01:21:57 +0000 (03:21 +0200)
committerArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>
Sun, 1 May 2011 01:21:57 +0000 (03:21 +0200)
bin/ebuild.sh
bin/isolated-functions.sh
man/portage.5

index c79d4c3d03ded25b70496a2b26ed66f89161545a..e652cb55b81d21955351dcb4ebfa9d733f4ae73e 100755 (executable)
@@ -1639,6 +1639,34 @@ _ebuild_phase_funcs() {
        esac
 }
 
+# Set given variable unless this variable has been already set (e.g. during emerge
+# invocation) to a value different than value set in make.conf.
+set_unless_changed() {
+       if [[ $# -ne 2 ]]; then
+               die "${FUNCNAME}() requires 2 arguments: VARIABLE VALUE"
+       fi
+
+       local variable="$1" value="$2"
+
+       if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
+               eval "${variable}=\"${value}\""
+       fi
+}
+
+# Unset given variable unless this variable has been set (e.g. during emerge
+# invocation) to a value different than value set in make.conf.
+unset_unless_changed() {
+       if [[ $# -ne 1 ]]; then
+               die "${FUNCNAME}() requires 1 argument: VARIABLE"
+       fi
+
+       local variable="$1"
+
+       if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
+               unset ${variable}
+       fi
+}
+
 PORTAGE_BASHRCS_SOURCED=0
 
 # @FUNCTION: source_all_bashrcs
index 2f144a084057cb1c599ebe03caaf7d59caf9db12..24443ac1b89dc3d01c2e4a780d6d154a00c14973 100644 (file)
@@ -585,8 +585,8 @@ save_ebuild_env() {
                        dyn_preinst dyn_help debug-print debug-print-function \
                        debug-print-section inherit EXPORT_FUNCTIONS remove_path_entry \
                        save_ebuild_env filter_readonly_variables preprocess_ebuild_env \
-                       source_all_bashrcs ebuild_main \
-                       ebuild_phase ebuild_phase_with_hooks \
+                       set_unless_changed unset_unless_changed source_all_bashrcs \
+                       ebuild_main ebuild_phase ebuild_phase_with_hooks \
                        _ebuild_arg_to_phase _ebuild_phase_funcs default \
                        _pipestatus \
                        ${QA_INTERCEPTORS}
index fc51481d139096170c9bc56f0475e46d0c928607..a210e8d2dc685713cc347a969d914961ed3de39d 100644 (file)
@@ -1,4 +1,4 @@
-.TH "PORTAGE" "5" "Feb 2011" "Portage VERSION" "Portage"
+.TH "PORTAGE" "5" "May 2011" "Portage VERSION" "Portage"
 .SH NAME
 portage \- the heart of Gentoo
 .SH "DESCRIPTION"
@@ -674,8 +674,22 @@ In this directory additional package\-specific bashrc files can be created.
 Note that if package\-specific environment variable settings are all that's
 needed, then \fB/etc/portage/package.env\fR should be used instead of the
 bashrc approach that is described here.
-Portage will source all of them after \fB/etc/portage/bashrc\fR in the following
-order:
+
+set_unless_changed and unset_unless_changed functions can be used to set or
+unset given variables only if these variable have not been set to values
+different than values set in make.conf. This functionality can be useful for
+temporary overriding of these variables during emerge invocation. Variables
+set in the usual VARIABLE=VALUE style will unconditionally override variables
+set during emerge invocation.
+
+.I Syntax:
+.nf
+set_unless_changed VARIABLE VALUE
+unset_unless_changed VALUE
+.fi
+
+Portage will source all of these bashrc files after \fB/etc/portage/bashrc\fR
+in the following order:
 .nr step 1 1
 .IP \n[step]. 3
 /etc/portage/env/${CATEGORY}/${PN}