egencache: handle empty --portdir-overlay
[portage.git] / bin / save-ebuild-env.sh
1 #!/bin/bash
2 # Copyright 1999-2013 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # @FUNCTION: __save_ebuild_env
6 # @DESCRIPTION:
7 # echo the current environment to stdout, filtering out redundant info.
8 #
9 # --exclude-init-phases causes pkg_nofetch and src_* phase functions to
10 # be excluded from the output. These function are not needed for installation
11 # or removal of the packages, and can therefore be safely excluded.
12 #
13 __save_ebuild_env() {
14         (
15         if has --exclude-init-phases $* ; then
16                 unset S _E_DOCDESTTREE_ _E_EXEDESTTREE_ \
17                         PORTAGE_DOCOMPRESS PORTAGE_DOCOMPRESS_SKIP
18                 if [[ -n $PYTHONPATH &&
19                         ${PYTHONPATH%%:*} -ef $PORTAGE_PYM_PATH ]] ; then
20                         if [[ $PYTHONPATH == *:* ]] ; then
21                                 export PYTHONPATH=${PYTHONPATH#*:}
22                         else
23                                 unset PYTHONPATH
24                         fi
25                 fi
26         fi
27
28         # misc variables inherited from the calling environment
29         unset COLORTERM DISPLAY EDITOR LESS LESSOPEN LOGNAME LS_COLORS PAGER \
30                 TERM TERMCAP USER ftp_proxy http_proxy no_proxy
31
32         # other variables inherited from the calling environment
33         unset CVS_RSH ECHANGELOG_USER GPG_AGENT_INFO \
34         SSH_AGENT_PID SSH_AUTH_SOCK STY WINDOW XAUTHORITY
35
36         # CCACHE and DISTCC config
37         unset ${!CCACHE_*} ${!DISTCC_*}
38
39         # There's no need to bloat environment.bz2 with internally defined
40         # functions and variables, so filter them out if possible.
41
42         for x in pkg_setup pkg_nofetch src_unpack src_prepare src_configure \
43                 src_compile src_test src_install pkg_preinst pkg_postinst \
44                 pkg_prerm pkg_postrm ; do
45                 unset -f default_$x __eapi{0,1,2,3,4}_$x
46         done
47         unset x
48
49         unset -f assert __assert_sigpipe_ok \
50                 __dump_trace die \
51                 __quiet_mode __vecho __elog_base eqawarn elog \
52                 einfo einfon ewarn eerror ebegin __eend eend KV_major \
53                 KV_minor KV_micro KV_to_int get_KV __1 __1 has \
54                 __has_phase_defined_up_to \
55                 hasv hasq __qa_source __qa_call \
56                 addread addwrite adddeny addpredict __sb_append_var \
57                 use usev useq has_version portageq \
58                 best_version use_with use_enable register_die_hook \
59                 keepdir unpack __strip_duplicate_slashes econf einstall \
60                 __dyn_setup __dyn_unpack __dyn_clean \
61                 into insinto exeinto docinto \
62                 insopts diropts exeopts libopts docompress \
63                 __abort_handler __abort_prepare __abort_configure __abort_compile \
64                 __abort_test __abort_install __dyn_prepare __dyn_configure \
65                 __dyn_compile __dyn_test __dyn_install \
66                 __dyn_pretend __dyn_help \
67                 debug-print debug-print-function \
68                 debug-print-section __helpers_die inherit EXPORT_FUNCTIONS \
69                 nonfatal register_success_hook \
70                 __hasg __hasgq \
71                 __save_ebuild_env __set_colors __filter_readonly_variables \
72                 __preprocess_ebuild_env \
73                 __repo_key __source_all_bashrcs \
74                 __ebuild_main __ebuild_phase __ebuild_phase_with_hooks \
75                 __ebuild_arg_to_phase __ebuild_phase_funcs default \
76                 __unpack_tar __unset_colors \
77                 ${QA_INTERCEPTORS}
78
79         ___eapi_has_usex && unset -f usex
80         ___eapi_has_master_repositories && unset -f master_repositories
81         ___eapi_has_repository_path && unset -f repository_path
82         ___eapi_has_available_eclasses && unset -f available_eclasses
83         ___eapi_has_eclass_path && unset -f eclass_path
84         ___eapi_has_license_path && unset -f license_path
85         ___eapi_has_package_manager_build_user && unset -f package_manager_build_user
86         ___eapi_has_package_manager_build_group && unset -f package_manager_build_group
87
88         unset -f $(compgen -A function ___eapi_)
89
90         # portage config variables and variables set directly by portage
91         unset ACCEPT_LICENSE BAD BRACKET BUILD_PREFIX COLS \
92                 DISTCC_DIR DISTDIR DOC_SYMLINKS_DIR \
93                 EBUILD_FORCE_TEST EBUILD_MASTER_PID \
94                 ECLASS_DEPTH ENDCOL FAKEROOTKEY \
95                 GOOD HILITE HOME \
96                 LAST_E_CMD LAST_E_LEN LD_PRELOAD MISC_FUNCTIONS_ARGS MOPREFIX \
97                 NOCOLOR NORMAL PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
98                 PORTAGE_BASHRCS_SOURCED PORTAGE_COMPRESS \
99                 PORTAGE_COMPRESS_EXCLUDE_SUFFIXES \
100                 PORTAGE_DOHTML_UNWARNED_SKIPPED_EXTENSIONS \
101                 PORTAGE_DOHTML_UNWARNED_SKIPPED_FILES \
102                 PORTAGE_DOHTML_WARN_ON_SKIPPED_FILES \
103                 PORTAGE_NONFATAL PORTAGE_QUIET \
104                 PORTAGE_SANDBOX_DENY PORTAGE_SANDBOX_PREDICT \
105                 PORTAGE_SANDBOX_READ PORTAGE_SANDBOX_WRITE PREROOTPATH \
106                 QA_INTERCEPTORS \
107                 RC_DEFAULT_INDENT RC_DOT_PATTERN RC_ENDCOL RC_INDENTATION  \
108                 ROOT ROOTPATH RPMDIR TEMP TMP TMPDIR USE_EXPAND \
109                 WARN XARGS _RC_GET_KV_CACHE
110
111         # user config variables
112         unset DOC_SYMLINKS_DIR INSTALL_MASK PKG_INSTALL_MASK
113
114         declare -p
115         declare -fp
116         if [[ ${BASH_VERSINFO[0]} == 3 ]]; then
117                 export
118         fi
119         )
120 }