Guest User

Untitled

a guest
Feb 16th, 2013
41
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. declare -x ALSA_CARDS="hda-intel"
  2. declare -x ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol"
  3. declare -x ANT_HOME="/usr/share/ant"
  4. declare -x APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias"
  5. declare -x ARCH="x86"
  6. declare -x BOOTSTRAP_USE="cxx unicode"
  7. declare -x CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump"
  8. declare -x CAMERAS="ptp2"
  9. declare -x CBUILD="i686-pc-linux-gnu"
  10. declare -x CFLAGS="-O1 -march=i686 -pipe"
  11. declare -x CFLAGS_default
  12. declare -x CHOST="i686-pc-linux-gnu"
  13. declare -x CHOST_default="i686-pc-linux-gnu"
  14. declare -x COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog"
  15. declare -x CTARGET_default="i686-pc-linux-gnu"
  16. declare -x CUR_WIDTH="0"
  17. declare -x CXXFLAGS="-O2 -march=i686 -pipe"
  18. declare -x DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-YXt6TlsHZA,guid=7facacd418a6e08bb5f0c7f3511fc712"
  19. declare -x DEFAULT_ABI="default"
  20. declare -x DEFINED_PHASES=" compile configure install prepare setup test"
  21. declare DEPEND=">=dev-lang/v8-3.11.10:=
  22. dev-libs/openssl =dev-lang/python-2*"
  23. declare DESCRIPTION="Evented IO for V8 Javascript"
  24. declare -x DESKTOP_SESSION="default"
  25. declare -x DESTTREE="/usr"
  26. declare -x DIROPTIONS="-m0755"
  27. declare -x DM_CONTROL="/var/run/xdmctl"
  28. declare -x EAPI="5"
  29. declare -x ELIBC="glibc"
  30. declare -- EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
  31. declare -- EPATCH_EXCLUDE=""
  32. declare -- EPATCH_FORCE="no"
  33. declare -- EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
  34. declare -- EPATCH_OPTS=""
  35. declare -- EPATCH_SINGLE_MSG=""
  36. declare -- EPATCH_SOURCE="/var/tmp/portage/net-libs/nodejs-0.9.9/work/patch"
  37. declare -- EPATCH_SUFFIX="patch.bz2"
  38. declare -x EPYTHON="python2.7"
  39. declare -x EXEOPTIONS="-m0755"
  40. declare -x FCFLAGS="-O2 -march=i686 -pipe"
  41. declare -x FETCHCOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port=22 ; exec rsync --rsh=\\\"ssh -p\\\${port}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
  42. declare -x FFLAGS="-O2 -march=i686 -pipe"
  43. declare -x GCC_SPECS=""
  44. declare -x GDK_USE_XFT="1"
  45. declare -x GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx"
  46. declare -x GRUB_PLATFORMS=""
  47. declare -x GSETTINGS_BACKEND="dconf"
  48. declare -x GS_LIB="/home/summerwind/.fonts"
  49. declare -x GTK2_RC_FILES="/etc/gtk-2.0/gtkrc:/home/summerwind/.gtkrc-2.0:/home/summerwind/.kde4/share/config/gtkrc-2.0"
  50. declare -x GTK_RC_FILES="/etc/gtk/gtkrc:/home/summerwind/.gtkrc:/home/summerwind/.kde4/share/config/gtkrc"
  51. declare -x GUILE_LOAD_PATH="/usr/share/guile/1.8"
  52. declare HDEPEND=""
  53. declare -x HG="/usr/bin/hg"
  54. declare HOMEPAGE="http://nodejs.org/"
  55. declare -x INFINALITY_FT_AUTOHINT_HORIZONTAL_STEM_DARKEN_STRENGTH="10"
  56. declare -x INFINALITY_FT_AUTOHINT_INCREASE_GLYPH_HEIGHTS="true"
  57. declare -x INFINALITY_FT_AUTOHINT_SNAP_STEM_HEIGHT="100"
  58. declare -x INFINALITY_FT_AUTOHINT_VERTICAL_STEM_DARKEN_STRENGTH="25"
  59. declare -x INFINALITY_FT_BOLD_EMBOLDEN_X_VALUE="0"
  60. declare -x INFINALITY_FT_BOLD_EMBOLDEN_Y_VALUE="0"
  61. declare -x INFINALITY_FT_BRIGHTNESS="0"
  62. declare -x INFINALITY_FT_CHROMEOS_STYLE_SHARPENING_STRENGTH="0"
  63. declare -x INFINALITY_FT_CONTRAST="0"
  64. declare -x INFINALITY_FT_FILTER_PARAMS="11 22 38 22 11"
  65. declare -x INFINALITY_FT_FRINGE_FILTER_STRENGTH="0"
  66. declare -x INFINALITY_FT_GAMMA_CORRECTION="0 100"
  67. declare -x INFINALITY_FT_GLOBAL_EMBOLDEN_X_VALUE="0"
  68. declare -x INFINALITY_FT_GLOBAL_EMBOLDEN_Y_VALUE="0"
  69. declare -x INFINALITY_FT_GRAYSCALE_FILTER_STRENGTH="0"
  70. declare -x INFINALITY_FT_STEM_ALIGNMENT_STRENGTH="25"
  71. declare -x INFINALITY_FT_STEM_FITTING_STRENGTH="25"
  72. declare -x INFINALITY_FT_STEM_SNAPPING_SLIDING_SCALE="40"
  73. declare -x INFINALITY_FT_USE_KNOWN_SETTINGS_ON_SELECTED_FONTS="true"
  74. declare -x INFINALITY_FT_USE_VARIOUS_TWEAKS="true"
  75. declare -x INFINALITY_FT_WINDOWS_STYLE_SHARPENING_STRENGTH="10"
  76. declare -x INHERITED=" multilib toolchain-funcs python user eutils pax-utils"
  77. declare -x INPUT_DEVICES="keyboard mouse evdev"
  78. declare -x INSDESTTREE=""
  79. declare -x INSOPTIONS="-m0644"
  80. declare IUSE=""
  81. declare -x IUSE_EFFECTIVE="alpha amd64 amd64-fbsd amd64-linux arm arm-linux elibc_AIX elibc_Cygwin elibc_Darwin elibc_FreeBSD elibc_HPUX elibc_Interix elibc_NetBSD elibc_OpenBSD elibc_SunOS elibc_Winnt elibc_glibc elibc_mintlib elibc_uclibc hppa hppa-hpux ia64 ia64-hpux ia64-linux kernel_AIX kernel_Cygwin kernel_Darwin kernel_FreeBSD kernel_HPUX kernel_Interix kernel_NetBSD kernel_OpenBSD kernel_SunOS kernel_Winnt kernel_freemint kernel_linux m68k m68k-mint mips ppc ppc-aix ppc-macos ppc-openbsd ppc64 ppc64-linux prefix s390 sh sparc sparc-fbsd sparc-solaris sparc64-freebsd sparc64-solaris userland_BSD userland_GNU x64-freebsd x64-macos x64-openbsd x64-solaris x86 x86-cygwin x86-fbsd x86-freebsd x86-interix x86-linux x86-macos x86-netbsd x86-openbsd x86-solaris x86-winnt"
  82. declare -x IUSE_IMPLICIT="prefix"
  83. declare -x JAVAC="/etc/java-config-2/current-system-vm/bin/javac"
  84. declare -x JAVACC_HOME="/usr/share/javacc/"
  85. declare -x JAVA_HOME="/etc/java-config-2/current-system-vm"
  86. declare -x JDK_HOME="/etc/java-config-2/current-system-vm"
  87. declare -x JYTHON_SYSTEM_CACHEDIR="1"
  88. declare -x KDE_FULL_SESSION="true"
  89. declare -x KDE_MULTIHEAD="false"
  90. declare -x KDE_SESSION_UID="1000"
  91. declare -x KDE_SESSION_VERSION="4"
  92. declare -x KERNEL="linux"
  93. declare -x KERNEL_ABI="default"
  94. declare -x KEYWORDS="~amd64 ~arm ~x86 ~x64-macos"
  95. declare -x LANG="ru_RU.UTF-8"
  96. declare -x LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text"
  97. declare -x LC_ALL=""
  98. declare -x LDFLAGS="-Wl,-O1 -Wl,--as-needed"
  99. declare -x LDFLAGS_default
  100. declare -x LIBDIR_default="lib"
  101. declare -x LIBOPTIONS="-m0644"
  102. declare -x LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer"
  103. declare -x LICENSE="GPL-2"
  104. declare -x LINGUAS="en ru"
  105. declare -x MAKEOPTS="-j1"
  106. declare -x MULTILIB_ABIS="default"
  107. declare -x MULTIOSDIRS="../lib"
  108. declare -x NETBEANS="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml"
  109. declare -x OPENGL_PROFILE="xorg-x11"
  110. declare -x ORBIT_SOCKETDIR="/tmp/orbit-summerwind"
  111. declare -x PATH="/usr/lib/portage/bin/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.6.3"
  112. declare -- PAX_MARKINGS="PT"
  113. declare PDEPEND=""
  114. declare -x PHP_TARGETS="php5-3"
  115. declare -a PORTAGE_DOCOMPRESS='([0]="/usr/share/doc" [1]="/usr/share/info" [2]="/usr/share/man")'
  116. declare -a PORTAGE_DOCOMPRESS_SKIP='([0]="/usr/share/doc/nodejs-0.9.9/html")'
  117. declare -x PRELINK_PATH_MASK="/usr/lib/libfreebl3.so:/usr/lib/libnssdbm3.so:/usr/lib/libsoftokn3.so:/opt/bin/skype"
  118. declare -x PROFILE_ONLY_VARIABLES="ARCH ELIBC IUSE_IMPLICIT KERNEL USERLAND USE_EXPAND_IMPLICIT USE_EXPAND_UNPREFIXED USE_EXPAND_VALUES_ARCH USE_EXPAND_VALUES_ELIBC USE_EXPAND_VALUES_KERNEL USE_EXPAND_VALUES_USERLAND"
  119. declare -x PROPERTIES=""
  120. declare -x PROVIDE=""
  121. declare -x PYTHONDONTWRITEBYTECODE="1"
  122. declare -x PYTHONPATH="/usr/lib/portage/pym"
  123. declare -- PYTHON_ABI="2.7"
  124. declare -- PYTHON_COLORS="0"
  125. declare -- PYTHON_DEPEND="2"
  126. declare -- PYTHON_PKG_SETUP_EXECUTED="1"
  127. declare -- PYTHON_REQUESTED_ACTIVE_VERSION="2"
  128. declare -- PYTHON_SANITY_CHECKS_EXECUTED="1"
  129. declare -x PYTHON_SINGLE_TARGET="python2_7"
  130. declare -x PYTHON_TARGETS="python2_7"
  131. declare -- PYTHON_TEST_VERBOSITY="1"
  132. declare -x QT_GRAPHICSSYSTEM="raster"
  133. declare -x QT_PLUGIN_PATH="/usr/lib/kde4/plugins"
  134. declare RDEPEND=">=dev-lang/v8-3.11.10:=
  135. dev-libs/openssl =dev-lang/python-2*"
  136. declare REPOSITORY
  137. declare REQUIRED_USE=""
  138. declare -x RESTRICT="test"
  139. declare -x RESUMECOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port=22 ; exec rsync --rsh=\\\"ssh -p\\\${port}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
  140. declare -x RUBYOPT="-rauto_gem"
  141. declare -x RUBY_TARGETS="ruby19"
  142. declare -x S="/var/tmp/portage/net-libs/nodejs-0.9.9/work/node-v0.9.9"
  143. declare -x SANDBOX_DEBUG="0"
  144. declare -x SANDBOX_DENY=""
  145. declare -x SANDBOX_PID="15224"
  146. declare -x SANDBOX_PREDICT="/var/tmp/portage/net-libs/nodejs-0.9.9/homedir:/dev/crypto:/proc/self/coredump_filter:/dev/random:/var/cache/fontconfig"
  147. declare -x SANDBOX_READ="/:/var/tmp"
  148. declare -x SANDBOX_VERBOSE="1"
  149. declare -x SANDBOX_WRITE=":/dev/console:/dev/fd:/dev/full:/dev/null:/dev/pts/:/dev/pty:/dev/shm:/dev/tts:/dev/tty:/dev/vc/:/dev/zero:/proc/self/fd:/tmp/:/usr/lib32/cf:/usr/lib32/conftest:/usr/lib64/cf:/usr/lib64/conftest:/usr/lib/cf:/usr/lib/conftest:/usr/tmp/cf:/usr/tmp/conftest:/var/cache/jython:/var/tmp:/var/tmp/:/var/tmp/portage/net-libs/nodejs-0.9.9/homedir/.bash_history"
  150. declare -x SESSION_MANAGER="local/wps:@/tmp/.ICE-unix/13932,unix/wps:/tmp/.ICE-unix/13932"
  151. declare -x SLOT="0"
  152. declare SRC_URI="http://nodejs.org/dist/v0.9.9/node-v0.9.9.tar.gz"
  153. declare -x USE="elibc_glibc kernel_linux userland_GNU x86"
  154. declare -x USERLAND="GNU"
  155. declare -x USE_EXPAND_IMPLICIT="ARCH ELIBC KERNEL USERLAND"
  156. declare -x USE_EXPAND_UNPREFIXED="ARCH"
  157. declare -x USE_EXPAND_VALUES_ARCH="alpha amd64 amd64-fbsd amd64-linux arm arm-linux hppa hppa-hpux ia64 ia64-hpux ia64-linux m68k m68k-mint mips ppc ppc64 ppc64-linux ppc-aix ppc-macos ppc-openbsd s390 sh sparc sparc64-freebsd sparc64-solaris sparc-fbsd sparc-solaris x64-freebsd x64-macos x64-openbsd x64-solaris x86 x86-cygwin x86-fbsd x86-freebsd x86-interix x86-linux x86-macos x86-netbsd x86-openbsd x86-solaris x86-winnt"
  158. declare -x USE_EXPAND_VALUES_ELIBC="AIX Cygwin Darwin FreeBSD glibc HPUX Interix mintlib NetBSD OpenBSD SunOS uclibc Winnt"
  159. declare -x USE_EXPAND_VALUES_KERNEL="AIX Cygwin Darwin FreeBSD freemint HPUX Interix linux NetBSD OpenBSD SunOS Winnt"
  160. declare -x USE_EXPAND_VALUES_USERLAND="BSD GNU"
  161. declare -x USE_PYTHON="2.7"
  162. declare -x VBOX_APP_HOME="/usr/lib/virtualbox"
  163. declare -x VIDEO_CARDS="intel"
  164. declare -x WINDOWID="52428804"
  165. declare -x WINDOWPATH="7"
  166. declare -x XCURSOR_THEME="default"
  167. declare -x XDG_CONFIG_DIRS="/etc/xdg"
  168. declare -x XDG_DATA_DIRS="/usr/local/share:/usr/share:/usr/share/gdm"
  169. declare -x XDG_SESSION_COOKIE="c4da4fa0cc3ce07d9086e88b000001ee-1361037071.932860-978118995"
  170. declare -x XDM_MANAGED="method=classic"
  171. declare -x XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
  172. declare -a _CPYTHON2_GLOBALLY_SUPPORTED_ABIS='([0]="2.4" [1]="2.5" [2]="2.6" [3]="2.7")'
  173. declare -a _CPYTHON3_GLOBALLY_SUPPORTED_ABIS='([0]="3.1" [1]="3.2" [2]="3.3")'
  174. declare -x _E_DOCDESTTREE_=""
  175. declare -x _E_EXEDESTTREE_=""
  176. declare -a _JYTHON_GLOBALLY_SUPPORTED_ABIS='([0]="2.5-jython")'
  177. declare -a _PYPY_GLOBALLY_SUPPORTED_ABIS='([0]="2.7-pypy-1.7" [1]="2.7-pypy-1.8" [2]="2.7-pypy-1.9" [3]="2.7-pypy-2.0")'
  178. declare -- _PYTHON_ABI_EXTRACTION_COMMAND="import platform
  179. import sys
  180. sys.stdout.write(\".\".join(str(x) for x in sys.version_info[:2]))
  181. if platform.system()[:4] == \"Java\":
  182. sys.stdout.write(\"-jython\")
  183. elif hasattr(platform, \"python_implementation\") and platform.python_implementation() == \"PyPy\":
  184. sys.stdout.write(\"-pypy-\" + \".\".join(str(x) for x in sys.pypy_version_info[:2]))"
  185. declare -- _PYTHON_ABI_PATTERN_REGEX="([[:alnum:]]|\\.|-|\\*|\\[|\\])+"
  186. declare -- _PYTHON_ECLASS_INHERITED="1"
  187. declare -a _PYTHON_GLOBALLY_SUPPORTED_ABIS='([0]="2.4" [1]="2.5" [2]="2.6" [3]="2.7" [4]="3.1" [5]="3.2" [6]="3.3" [7]="2.5-jython" [8]="2.7-pypy-1.7" [9]="2.7-pypy-1.8" [10]="2.7-pypy-1.9" [11]="2.7-pypy-2.0")'
  188. declare -- _PYTHON_SHEBANG_BASE_PART_REGEX="^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)"
  189. declare -- ___ECLASS_ONCE_EUTILS="recur -_+^+_- spank"
  190. declare -- ___ECLASS_ONCE_MULTILIB="recur -_+^+_- spank"
  191. declare -- ___ECLASS_ONCE_PAX_UTILS="recur -_+^+_- spank"
  192. declare -- ___ECLASS_ONCE_TOOLCHAIN_FUNCS="recur -_+^+_- spank"
  193. declare -- ___ECLASS_ONCE_USER="recur -_+^+_- spank"
  194. declare -- phase_func
  195. PYTHON ()
  196. {
  197. _python_check_python_pkg_setup_execution;
  198. local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0";
  199. while (($#)); do
  200. case "$1" in
  201. -2)
  202. python2="1"
  203. ;;
  204. -3)
  205. python3="1"
  206. ;;
  207. --ABI)
  208. ABI_output="1"
  209. ;;
  210. -a | --absolute-path)
  211. absolute_path_output="1"
  212. ;;
  213. -f | --final-ABI)
  214. final_ABI="1"
  215. ;;
  216. --)
  217. shift;
  218. break
  219. ;;
  220. -*)
  221. die "${FUNCNAME}(): Unrecognized option '$1'"
  222. ;;
  223. *)
  224. break
  225. ;;
  226. esac;
  227. shift;
  228. done;
  229. if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
  230. die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously";
  231. fi;
  232. if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
  233. die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously";
  234. fi;
  235. if [[ "$#" -eq 0 ]]; then
  236. if [[ "${final_ABI}" == "1" ]]; then
  237. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  238. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  239. fi;
  240. _python_calculate_PYTHON_ABIS;
  241. PYTHON_ABI="${PYTHON_ABIS##* }";
  242. else
  243. if [[ "${python2}" == "1" ]]; then
  244. PYTHON_ABI="$(ROOT="/" eselect python show --python2 --ABI)";
  245. if [[ -z "${PYTHON_ABI}" ]]; then
  246. die "${FUNCNAME}(): Active version of CPython 2 not set";
  247. else
  248. if [[ "${PYTHON_ABI}" != "2."* ]]; then
  249. die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`";
  250. fi;
  251. fi;
  252. else
  253. if [[ "${python3}" == "1" ]]; then
  254. PYTHON_ABI="$(ROOT="/" eselect python show --python3 --ABI)";
  255. if [[ -z "${PYTHON_ABI}" ]]; then
  256. die "${FUNCNAME}(): Active version of CPython 3 not set";
  257. else
  258. if [[ "${PYTHON_ABI}" != "3."* ]]; then
  259. die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`";
  260. fi;
  261. fi;
  262. else
  263. if _python_package_supporting_installation_for_multiple_python_abis; then
  264. if ! _python_abi-specific_local_scope; then
  265. die "${FUNCNAME}() should be used in ABI-specific local scope";
  266. fi;
  267. else
  268. PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")";
  269. if [[ -z "${PYTHON_ABI}" ]]; then
  270. die "${FUNCNAME}(): Failure of extraction of locally active version of Python";
  271. fi;
  272. fi;
  273. fi;
  274. fi;
  275. fi;
  276. else
  277. if [[ "$#" -eq 1 ]]; then
  278. if [[ "${final_ABI}" == "1" ]]; then
  279. die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously";
  280. fi;
  281. if [[ "${python2}" == "1" ]]; then
  282. die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously";
  283. fi;
  284. if [[ "${python3}" == "1" ]]; then
  285. die "${FUNCNAME}(): '-3' option and Python ABI cannot be specified simultaneously";
  286. fi;
  287. PYTHON_ABI="$1";
  288. else
  289. die "${FUNCNAME}(): Invalid usage";
  290. fi;
  291. fi;
  292. if [[ "${ABI_output}" == "1" ]]; then
  293. echo -n "${PYTHON_ABI}";
  294. return;
  295. else
  296. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  297. python_interpreter="python${PYTHON_ABI}";
  298. else
  299. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  300. python_interpreter="jython${PYTHON_ABI%-jython}";
  301. else
  302. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  303. python_interpreter="pypy-c${PYTHON_ABI#*-pypy-}";
  304. fi;
  305. fi;
  306. fi;
  307. if [[ "${absolute_path_output}" == "1" ]]; then
  308. echo -n "${EPREFIX}/usr/bin/${python_interpreter}";
  309. else
  310. echo -n "${python_interpreter}";
  311. fi;
  312. fi;
  313. if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then
  314. echo -n "-${ABI}";
  315. fi
  316. }
  317. _assert_pkg_ebuild_phase ()
  318. {
  319. case ${EBUILD_PHASE} in
  320. setup | preinst | postinst)
  321.  
  322. ;;
  323. *)
  324. eerror "'$1()' called from '${EBUILD_PHASE}' phase which is not OK:";
  325. eerror "You may only call from pkg_{setup,preinst,postinst} functions.";
  326. eerror "Package fails at QA and at life. Please file a bug.";
  327. die "Bad package! $1 is only for use in some pkg_* functions!"
  328. ;;
  329. esac
  330. }
  331. _gcc-install-dir ()
  332. {
  333. echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null | awk '$1=="install:" {print $2}')"
  334. }
  335. _gcc-specs-directive_raw ()
  336. {
  337. local cc=$(tc-getCC);
  338. local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}');
  339. ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN { pspec=""; spec=""; outside=1 }
  340. $1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
  341. outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
  342. spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
  343. { spec=spec $0 }
  344. END { print spec }';
  345. return 0
  346. }
  347. _gcc-specs-exists ()
  348. {
  349. [[ -f $(_gcc-install-dir)/$1 ]]
  350. }
  351. _gcc_fullversion ()
  352. {
  353. local ver="$1";
  354. shift;
  355. set -- `$(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"`;
  356. eval echo "$ver"
  357. }
  358. _iconins ()
  359. {
  360. ( local funcname=$1;
  361. shift;
  362. local size dir;
  363. local context=apps;
  364. local theme=hicolor;
  365. while [[ $# -gt 0 ]]; do
  366. case $1 in
  367. -s | --size)
  368. if [[ ${2%%x*}x${2%%x*} == "$2" ]]; then
  369. size=${2%%x*};
  370. else
  371. size=${2};
  372. fi;
  373. case ${size} in
  374. 16 | 22 | 24 | 32 | 36 | 48 | 64 | 72 | 96 | 128 | 192 | 256)
  375. size=${size}x${size}
  376. ;;
  377. scalable)
  378.  
  379. ;;
  380. *)
  381. eerror "${size} is an unsupported icon size!";
  382. exit 1
  383. ;;
  384. esac;
  385. shift 2
  386. ;;
  387. -t | --theme)
  388. theme=${2};
  389. shift 2
  390. ;;
  391. -c | --context)
  392. context=${2};
  393. shift 2
  394. ;;
  395. *)
  396. if [[ -z ${size} ]]; then
  397. insinto /usr/share/pixmaps;
  398. else
  399. insinto /usr/share/icons/${theme}/${size}/${context};
  400. fi;
  401. if [[ ${funcname} == doicon ]]; then
  402. if [[ -f $1 ]]; then
  403. doins "${1}";
  404. else
  405. if [[ -d $1 ]]; then
  406. shopt -s nullglob;
  407. doins "${1}"/*.{png,svg};
  408. shopt -u nullglob;
  409. else
  410. eerror "${1} is not a valid file/directory!";
  411. exit 1;
  412. fi;
  413. fi;
  414. else
  415. break;
  416. fi;
  417. shift 1
  418. ;;
  419. esac;
  420. done;
  421. if [[ ${funcname} == newicon ]]; then
  422. newins "$@";
  423. fi ) || die
  424. }
  425. _pax_list_files ()
  426. {
  427. local f cmd;
  428. cmd=$1;
  429. shift;
  430. for f in "$@";
  431. do
  432. ${cmd} " ${f}";
  433. done
  434. }
  435. _python_abi-specific_local_scope ()
  436. {
  437. [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
  438. }
  439. _python_calculate_PYTHON_ABIS ()
  440. {
  441. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  442. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  443. fi;
  444. _python_initial_sanity_checks;
  445. if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]]; then
  446. local PYTHON_ABI;
  447. if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
  448. local cpython_enabled="0";
  449. if [[ -z "${USE_PYTHON}" ]]; then
  450. die "USE_PYTHON variable is empty";
  451. fi;
  452. for PYTHON_ABI in ${USE_PYTHON};
  453. do
  454. if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then
  455. die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'";
  456. fi;
  457. if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
  458. cpython_enabled="1";
  459. fi;
  460. if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  461. export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}";
  462. fi;
  463. done;
  464. if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
  465. die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}";
  466. fi;
  467. if [[ "${cpython_enabled}" == "0" ]]; then
  468. die "USE_PYTHON variable does not enable any CPython ABI";
  469. fi;
  470. else
  471. local python_version python2_version python3_version support_python_major_version;
  472. if ! has_version "dev-lang/python"; then
  473. die "${FUNCNAME}(): 'dev-lang/python' is not installed";
  474. fi;
  475. python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')";
  476. if has_version "=dev-lang/python-2*"; then
  477. if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
  478. die "'${EPREFIX}/usr/bin/python2' is not valid symlink";
  479. fi;
  480. python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')";
  481. support_python_major_version="0";
  482. for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}";
  483. do
  484. if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  485. support_python_major_version="1";
  486. break;
  487. fi;
  488. done;
  489. if [[ "${support_python_major_version}" == "1" ]]; then
  490. if _python_check_python_abi_matching --patterns-list "${python2_version}" "${RESTRICT_PYTHON_ABIS}"; then
  491. die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}";
  492. fi;
  493. else
  494. python2_version="";
  495. fi;
  496. fi;
  497. if has_version "=dev-lang/python-3*"; then
  498. if [[ "$(readlink "${EPREFIX}/usr/bin/python3")" != "python3."* ]]; then
  499. die "'${EPREFIX}/usr/bin/python3' is not valid symlink";
  500. fi;
  501. python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')";
  502. support_python_major_version="0";
  503. for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}";
  504. do
  505. if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  506. support_python_major_version="1";
  507. break;
  508. fi;
  509. done;
  510. if [[ "${support_python_major_version}" == "1" ]]; then
  511. if _python_check_python_abi_matching --patterns-list "${python3_version}" "${RESTRICT_PYTHON_ABIS}"; then
  512. die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}";
  513. fi;
  514. else
  515. python3_version="";
  516. fi;
  517. fi;
  518. if [[ -z "${python2_version}" && -z "${python3_version}" ]]; then
  519. eerror "${CATEGORY}/${PF} requires at least one of the following packages:";
  520. for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}";
  521. do
  522. if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  523. eerror " dev-lang/python:${PYTHON_ABI}";
  524. fi;
  525. done;
  526. die "No supported version of CPython installed";
  527. fi;
  528. if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then
  529. eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink";
  530. eerror "is set incorrectly. Use \`eselect python\` to fix configuration.";
  531. die "Incorrect configuration of Python";
  532. fi;
  533. if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then
  534. eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python3' symlink";
  535. eerror "is set incorrectly. Use \`eselect python\` to fix configuration.";
  536. die "Incorrect configuration of Python";
  537. fi;
  538. PYTHON_ABIS="${python2_version} ${python3_version}";
  539. PYTHON_ABIS="${PYTHON_ABIS# }";
  540. export PYTHON_ABIS="${PYTHON_ABIS% }";
  541. fi;
  542. fi;
  543. _python_final_sanity_checks
  544. }
  545. _python_check_python_abi_matching ()
  546. {
  547. local pattern patterns patterns_list="0" PYTHON_ABI;
  548. while (($#)); do
  549. case "$1" in
  550. --patterns-list)
  551. patterns_list="1"
  552. ;;
  553. --)
  554. shift;
  555. break
  556. ;;
  557. -*)
  558. die "${FUNCNAME}(): Unrecognized option '$1'"
  559. ;;
  560. *)
  561. break
  562. ;;
  563. esac;
  564. shift;
  565. done;
  566. if [[ "$#" -ne 2 ]]; then
  567. die "${FUNCNAME}() requires 2 arguments";
  568. fi;
  569. PYTHON_ABI="$1";
  570. if [[ "${patterns_list}" == "0" ]]; then
  571. pattern="$2";
  572. if [[ "${pattern}" == *"-cpython" ]]; then
  573. [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]];
  574. else
  575. if [[ "${pattern}" == *"-jython" ]]; then
  576. [[ "${PYTHON_ABI}" == ${pattern} ]];
  577. else
  578. if [[ "${pattern}" == *"-pypy-"* ]]; then
  579. [[ "${PYTHON_ABI}" == ${pattern} ]];
  580. else
  581. if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
  582. [[ "${PYTHON_ABI}" == ${pattern} ]];
  583. else
  584. if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
  585. [[ "${PYTHON_ABI%-jython}" == ${pattern} ]];
  586. else
  587. if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then
  588. [[ "${PYTHON_ABI%-pypy-*}" == ${pattern} ]];
  589. else
  590. die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'";
  591. fi;
  592. fi;
  593. fi;
  594. fi;
  595. fi;
  596. fi;
  597. else
  598. patterns="${2// /
  599. }";
  600. while read pattern; do
  601. if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
  602. return 0;
  603. fi;
  604. done <<< "${patterns}";
  605. return 1;
  606. fi
  607. }
  608. _python_check_python_pkg_setup_execution ()
  609. {
  610. [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return;
  611. if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
  612. die "python_pkg_setup() not called";
  613. fi
  614. }
  615. _python_clean_compiled_modules ()
  616. {
  617. _python_initialize_prefix_variables;
  618. _python_set_color_variables;
  619. [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage";
  620. local base_module_name compiled_file compiled_files=() dir path py_file root;
  621. root="${EROOT%/}";
  622. for path in "$@";
  623. do
  624. compiled_files=();
  625. if [[ -d "${path}" ]]; then
  626. while read -d '' -r compiled_file; do
  627. compiled_files+=("${compiled_file}");
  628. done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0);
  629. if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
  630. find "${path}" -type d | sort -r | while read -r dir; do
  631. if rmdir "${dir}" 2> /dev/null; then
  632. _python_vecho "<<< ${dir}";
  633. fi;
  634. done;
  635. fi;
  636. else
  637. if [[ "${path}" == *.py ]]; then
  638. base_module_name="${path##*/}";
  639. base_module_name="${base_module_name%.py}";
  640. if [[ -d "${path%/*}/__pycache__" ]]; then
  641. while read -d '' -r compiled_file; do
  642. compiled_files+=("${compiled_file}");
  643. done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0);
  644. fi;
  645. compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class");
  646. fi;
  647. fi;
  648. for compiled_file in "${compiled_files[@]}";
  649. do
  650. [[ ! -f "${compiled_file}" ]] && continue;
  651. dir="${compiled_file%/*}";
  652. dir="${dir##*/}";
  653. if [[ "${compiled_file}" == *.py[co] ]]; then
  654. if [[ "${dir}" == "__pycache__" ]]; then
  655. base_module_name="${compiled_file##*/}";
  656. base_module_name="${base_module_name%.*py[co]}";
  657. base_module_name="${base_module_name%.*}";
  658. py_file="${compiled_file%__pycache__/*}${base_module_name}.py";
  659. else
  660. py_file="${compiled_file%[co]}";
  661. fi;
  662. if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
  663. [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue;
  664. else
  665. [[ -f "${py_file}" ]] && continue;
  666. fi;
  667. _python_vecho "<<< ${compiled_file%[co]}[co]";
  668. rm -f "${compiled_file%[co]}"[co];
  669. else
  670. if [[ "${compiled_file}" == *\$py.class ]]; then
  671. if [[ "${dir}" == "__pycache__" ]]; then
  672. base_module_name="${compiled_file##*/}";
  673. base_module_name="${base_module_name%\$py.class}";
  674. py_file="${compiled_file%__pycache__/*}${base_module_name}.py";
  675. else
  676. py_file="${compiled_file%\$py.class}.py";
  677. fi;
  678. if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
  679. [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue;
  680. else
  681. [[ -f "${py_file}" ]] && continue;
  682. fi;
  683. _python_vecho "<<< ${compiled_file}";
  684. rm -f "${compiled_file}";
  685. else
  686. die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'";
  687. fi;
  688. fi;
  689. dir="${compiled_file%/*}";
  690. while [[ "${dir}" != "${root}" ]]; do
  691. if rmdir "${dir}" 2> /dev/null; then
  692. _python_vecho "<<< ${dir}";
  693. else
  694. break;
  695. fi;
  696. dir="${dir%/*}";
  697. done;
  698. done;
  699. done
  700. }
  701. _python_final_sanity_checks ()
  702. {
  703. if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
  704. local PYTHON_ABI="${PYTHON_ABI}";
  705. for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}};
  706. do
  707. if ! has_version "$(python_get_implementational_package)"; then
  708. die "$(python_get_implementational_package) is not installed";
  709. fi;
  710. if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
  711. eerror "Path to 'python': '$(type -p python)'";
  712. eerror "ABI: '${ABI}'";
  713. eerror "DEFAULT_ABI: '${DEFAULT_ABI}'";
  714. eerror "EPYTHON: '$(PYTHON)'";
  715. eerror "PYTHON_ABI: '${PYTHON_ABI}'";
  716. eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'";
  717. die "'python' does not respect EPYTHON variable";
  718. fi;
  719. done;
  720. fi;
  721. PYTHON_SANITY_CHECKS_EXECUTED="1"
  722. }
  723. _python_get_implementation ()
  724. {
  725. local ignore_invalid="0";
  726. while (($#)); do
  727. case "$1" in
  728. --ignore-invalid)
  729. ignore_invalid="1"
  730. ;;
  731. --)
  732. shift;
  733. break
  734. ;;
  735. -*)
  736. die "${FUNCNAME}(): Unrecognized option '$1'"
  737. ;;
  738. *)
  739. break
  740. ;;
  741. esac;
  742. shift;
  743. done;
  744. if [[ "$#" -ne 1 ]]; then
  745. die "${FUNCNAME}() requires 1 argument";
  746. fi;
  747. if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
  748. echo "CPython";
  749. else
  750. if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
  751. echo "Jython";
  752. else
  753. if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then
  754. echo "PyPy";
  755. else
  756. if [[ "${ignore_invalid}" == "0" ]]; then
  757. die "${FUNCNAME}(): Unrecognized Python ABI '$1'";
  758. fi;
  759. fi;
  760. fi;
  761. fi
  762. }
  763. _python_implementation ()
  764. {
  765. if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
  766. return 0;
  767. else
  768. if [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
  769. return 0;
  770. else
  771. if [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then
  772. return 0;
  773. else
  774. return 1;
  775. fi;
  776. fi;
  777. fi
  778. }
  779. _python_initial_sanity_checks ()
  780. {
  781. if [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
  782. if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
  783. eerror "'${EPREFIX}/usr/bin/python' is not valid symlink.";
  784. eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem.";
  785. die "'${EPREFIX}/usr/bin/python' is not valid symlink";
  786. fi;
  787. if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
  788. eerror "'${EPREFIX}/usr/bin/python-config' is not valid script";
  789. eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem.";
  790. die "'${EPREFIX}/usr/bin/python-config' is not valid script";
  791. fi;
  792. fi
  793. }
  794. _python_initialize_prefix_variables ()
  795. {
  796. if has "${EAPI:-0}" 0 1 2; then
  797. if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
  798. EROOT="${ROOT%/}${EPREFIX}/";
  799. fi;
  800. if [[ -n "${D}" && -z "${ED}" ]]; then
  801. ED="${D%/}${EPREFIX}/";
  802. fi;
  803. fi
  804. }
  805. _python_package_supporting_installation_for_multiple_python_abis ()
  806. {
  807. [[ -n "${SUPPORT_PYTHON_ABIS}" ]]
  808. }
  809. _python_prepare_flags ()
  810. {
  811. local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable;
  812. for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS;
  813. do
  814. eval "_PYTHON_SAVED_${variable}=\"\${!variable}\"";
  815. for prefix in PYTHON_USER_ PYTHON_;
  816. do
  817. if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
  818. eval "array=(\"\${${prefix}${variable}[@]}\")";
  819. for element in "${array[@]}";
  820. do
  821. if [[ "${element}" =~ ^${_PYTHON_ABI_PATTERN_REGEX}\ (\+|-)\ .+ ]]; then
  822. pattern="${element%% *}";
  823. element="${element#* }";
  824. operator="${element%% *}";
  825. flags="${element#* }";
  826. if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
  827. if [[ "${operator}" == "+" ]]; then
  828. eval "export ${variable}+=\"\${variable:+ }${flags}\"";
  829. else
  830. if [[ "${operator}" == "-" ]]; then
  831. flags="${flags// /
  832. }";
  833. old_value="${!variable// /
  834. }";
  835. new_value="";
  836. while read old_flag; do
  837. while read deleted_flag; do
  838. if [[ "${old_flag}" == ${deleted_flag} ]]; then
  839. continue 2;
  840. fi;
  841. done <<< "${flags}";
  842. new_value+="${new_value:+ }${old_flag}";
  843. done <<< "${old_value}";
  844. eval "export ${variable}=\"\${new_value}\"";
  845. fi;
  846. fi;
  847. fi;
  848. else
  849. die "Element '${element}' of ${prefix}${variable} array has invalid syntax";
  850. fi;
  851. done;
  852. else
  853. if [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
  854. die "${prefix}${variable} should be indexed array";
  855. fi;
  856. fi;
  857. done;
  858. done
  859. }
  860. _python_restore_flags ()
  861. {
  862. local variable;
  863. for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS;
  864. do
  865. eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\"";
  866. unset _PYTHON_SAVED_${variable};
  867. done
  868. }
  869. _python_set_color_variables ()
  870. {
  871. if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
  872. _BOLD='';
  873. _RED='';
  874. _GREEN='';
  875. _BLUE='';
  876. _CYAN='';
  877. _NORMAL='';
  878. else
  879. _BOLD=;
  880. _RED=;
  881. _GREEN=;
  882. _BLUE=;
  883. _CYAN=;
  884. _NORMAL=;
  885. fi
  886. }
  887. _python_test_hook ()
  888. {
  889. if [[ "$#" -ne 1 ]]; then
  890. die "${FUNCNAME}() requires 1 argument";
  891. fi;
  892. if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${_PYTHON_TEST_FUNCTION}_$1_hook")" == "function" ]]; then
  893. "${_PYTHON_TEST_FUNCTION}_$1_hook";
  894. fi
  895. }
  896. _python_vecho ()
  897. {
  898. [[ -z ${PORTAGE_VERBOSE} ]] || echo "$@"
  899. }
  900. _tc-getPROG ()
  901. {
  902. local tuple=$1;
  903. local v var vars=$2;
  904. local prog=$3;
  905. var=${vars%% *};
  906. for v in ${vars};
  907. do
  908. if [[ -n ${!v} ]]; then
  909. export ${var}="${!v}";
  910. echo "${!v}";
  911. return 0;
  912. fi;
  913. done;
  914. local search=;
  915. [[ -n $4 ]] && search=$(type -p "$4-${prog}");
  916. [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}");
  917. [[ -n ${search} ]] && prog=${search##*/};
  918. export ${var}=${prog};
  919. echo "${!var}"
  920. }
  921. built_with_use ()
  922. {
  923. local hidden="no";
  924. if [[ $1 == "--hidden" ]]; then
  925. hidden="yes";
  926. shift;
  927. fi;
  928. local missing_action="die";
  929. if [[ $1 == "--missing" ]]; then
  930. missing_action=$2;
  931. shift;
  932. shift;
  933. case ${missing_action} in
  934. true | false | die)
  935.  
  936. ;;
  937. *)
  938. die "unknown action '${missing_action}'"
  939. ;;
  940. esac;
  941. fi;
  942. local opt=$1;
  943. [[ ${opt:0:1} = "-" ]] && shift || opt="-a";
  944. local PKG=$(best_version $1);
  945. [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package";
  946. shift;
  947. local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE;
  948. local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE;
  949. if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]]; then
  950. case ${missing_action} in
  951. true)
  952. return 0
  953. ;;
  954. false)
  955. return 1
  956. ;;
  957. die)
  958. die "Unable to determine what USE flags $PKG was built with"
  959. ;;
  960. esac;
  961. fi;
  962. if [[ ${hidden} == "no" ]]; then
  963. local IUSE_BUILT=($(<"${IUSEFILE}"));
  964. local expand;
  965. for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]');
  966. do
  967. if [[ $1 == ${expand}_* ]]; then
  968. expand="";
  969. break;
  970. fi;
  971. done;
  972. if [[ -n ${expand} ]]; then
  973. if ! has $1 ${IUSE_BUILT[@]#[-+]}; then
  974. case ${missing_action} in
  975. true)
  976. return 0
  977. ;;
  978. false)
  979. return 1
  980. ;;
  981. die)
  982. die "$PKG does not actually support the $1 USE flag!"
  983. ;;
  984. esac;
  985. fi;
  986. fi;
  987. fi;
  988. local USE_BUILT=$(<${USEFILE});
  989. while [[ $# -gt 0 ]]; do
  990. if [[ ${opt} = "-o" ]]; then
  991. has $1 ${USE_BUILT} && return 0;
  992. else
  993. has $1 ${USE_BUILT} || return 1;
  994. fi;
  995. shift;
  996. done;
  997. [[ ${opt} = "-a" ]]
  998. }
  999. check_license ()
  1000. {
  1001. die "you no longer need this as portage supports ACCEPT_LICENSE itself"
  1002. }
  1003. doicon ()
  1004. {
  1005. _iconins ${FUNCNAME} "$@"
  1006. }
  1007. domenu ()
  1008. {
  1009. ( local i j ret=0;
  1010. insinto /usr/share/applications;
  1011. for i in "$@";
  1012. do
  1013. if [[ -f ${i} ]]; then
  1014. doins "${i}";
  1015. ((ret+=$?));
  1016. else
  1017. if [[ -d ${i} ]]; then
  1018. for j in "${i}"/*.desktop;
  1019. do
  1020. doins "${j}";
  1021. ((ret+=$?));
  1022. done;
  1023. else
  1024. ((++ret));
  1025. fi;
  1026. fi;
  1027. done;
  1028. exit ${ret} )
  1029. }
  1030. ebeep ()
  1031. {
  1032. ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at http://bugs.gentoo.org"
  1033. }
  1034. econf_build ()
  1035. {
  1036. tc-env_build econf --build=${CBUILD:-${CHOST}} "$@"
  1037. }
  1038. ecvs_clean ()
  1039. {
  1040. [[ -z $* ]] && set -- .;
  1041. find "$@" -type d -name 'CVS' -prune -print0 | xargs -0 rm -rf;
  1042. find "$@" -type f -name '.cvs*' -print0 | xargs -0 rm -rf
  1043. }
  1044. edos2unix ()
  1045. {
  1046. [[ $# -eq 0 ]] && return 0;
  1047. sed -i 's/\r$//' -- "$@" || die
  1048. }
  1049. egetent ()
  1050. {
  1051. local db=$1 key=$2;
  1052. [[ $# -ge 3 ]] && die "usage: egetent <database> <key>";
  1053. case ${db} in
  1054. passwd | group)
  1055.  
  1056. ;;
  1057. *)
  1058. die "sorry, database '${db}' not yet supported; file a bug"
  1059. ;;
  1060. esac;
  1061. case ${CHOST} in
  1062. *-darwin[678])
  1063. case ${key} in
  1064. *[!0-9]*)
  1065. nidump ${db} . | awk -F: "(\$1 ~ /^${key}\$/) {print;exit;}"
  1066. ;;
  1067. *)
  1068. nidump ${db} . | awk -F: "(\$3 == ${key}) {print;exit;}"
  1069. ;;
  1070. esac
  1071. ;;
  1072. *-darwin*)
  1073. local mykey;
  1074. case ${db} in
  1075. passwd)
  1076. db="Users" mykey="UniqueID"
  1077. ;;
  1078. group)
  1079. db="Groups" mykey="PrimaryGroupID"
  1080. ;;
  1081. esac;
  1082. case ${key} in
  1083. *[!0-9]*)
  1084. dscl . -read /${db}/${key} 2> /dev/null | grep RecordName
  1085. ;;
  1086. *)
  1087. dscl . -search /${db} ${mykey} ${key} 2> /dev/null
  1088. ;;
  1089. esac
  1090. ;;
  1091. *-freebsd* | *-dragonfly*)
  1092. case ${db} in
  1093. passwd)
  1094. db="user"
  1095. ;;
  1096. *)
  1097.  
  1098. ;;
  1099. esac;
  1100. local opts;
  1101. if [[ ${key} == [[:digit:]]* ]]; then
  1102. [[ ${db} == "user" ]] && opts="-u" || opts="-g";
  1103. fi;
  1104. pw show ${db} ${opts} "${key}" -q
  1105. ;;
  1106. *-netbsd* | *-openbsd*)
  1107. grep "${key}:\*:" /etc/${db}
  1108. ;;
  1109. *)
  1110. nscd -i "${db}" 2> /dev/null;
  1111. getent "${db}" "${key}"
  1112. ;;
  1113. esac
  1114. }
  1115. egethome ()
  1116. {
  1117. local pos;
  1118. [[ $# -eq 1 ]] || die "usage: egethome <user>";
  1119. case ${CHOST} in
  1120. *-darwin* | *-freebsd* | *-dragonfly*)
  1121. pos=9
  1122. ;;
  1123. *)
  1124. pos=6
  1125. ;;
  1126. esac;
  1127. egetent passwd "$1" | cut -d: -f${pos}
  1128. }
  1129. egetshell ()
  1130. {
  1131. local pos;
  1132. [[ $# -eq 1 ]] || die "usage: egetshell <user>";
  1133. case ${CHOST} in
  1134. *-darwin* | *-freebsd* | *-dragonfly*)
  1135. pos=10
  1136. ;;
  1137. *)
  1138. pos=7
  1139. ;;
  1140. esac;
  1141. egetent passwd "$1" | cut -d: -f${pos}
  1142. }
  1143. emktemp ()
  1144. {
  1145. local exe="touch";
  1146. [[ $1 == -d ]] && exe="mkdir" && shift;
  1147. local topdir=$1;
  1148. if [[ -z ${topdir} ]]; then
  1149. [[ -z ${T} ]] && topdir="/tmp" || topdir=${T};
  1150. fi;
  1151. if ! type -P mktemp > /dev/null; then
  1152. local tmp=/;
  1153. while [[ -e ${tmp} ]]; do
  1154. tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM};
  1155. done;
  1156. ${exe} "${tmp}" || ${exe} -p "${tmp}";
  1157. echo "${tmp}";
  1158. else
  1159. if [[ ${exe} == "touch" ]]; then
  1160. TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX;
  1161. else
  1162. TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX;
  1163. fi;
  1164. fi
  1165. }
  1166. enewgroup ()
  1167. {
  1168. _assert_pkg_ebuild_phase ${FUNCNAME};
  1169. local egroup=$1;
  1170. shift;
  1171. if [[ -z ${egroup} ]]; then
  1172. eerror "No group specified !";
  1173. die "Cannot call enewgroup without a group";
  1174. fi;
  1175. if [[ -n $(egetent group "${egroup}") ]]; then
  1176. return 0;
  1177. fi;
  1178. einfo "Adding group '${egroup}' to your system ...";
  1179. local egid=$1;
  1180. shift;
  1181. if [[ ! -z ${egid} ]]; then
  1182. if [[ ${egid} -gt 0 ]]; then
  1183. if [[ -n $(egetent group ${egid}) ]]; then
  1184. egid="next available; requested gid taken";
  1185. fi;
  1186. else
  1187. eerror "Groupid given but is not greater than 0 !";
  1188. die "${egid} is not a valid GID";
  1189. fi;
  1190. else
  1191. egid="next available";
  1192. fi;
  1193. einfo " - Groupid: ${egid}";
  1194. if [[ $# -gt 0 ]]; then
  1195. die "extra arguments no longer supported; please file a bug";
  1196. fi;
  1197. function _enewgroup_next_gid ()
  1198. {
  1199. if [[ ${egid} == *[!0-9]* ]]; then
  1200. for ((egid = 101; egid <= 999; egid++))
  1201. do
  1202. [[ -z $(egetent group ${egid}) ]] && break;
  1203. done;
  1204. fi
  1205. };
  1206. case ${CHOST} in
  1207. *-darwin*)
  1208. _enewgroup_next_gid;
  1209. dscl . create "/groups/${egroup}" gid ${egid};
  1210. dscl . create "/groups/${egroup}" passwd '*'
  1211. ;;
  1212. *-freebsd* | *-dragonfly*)
  1213. _enewgroup_next_gid;
  1214. pw groupadd "${egroup}" -g ${egid} || die
  1215. ;;
  1216. *-netbsd*)
  1217. _enewgroup_next_gid;
  1218. groupadd -g ${egid} "${egroup}" || die
  1219. ;;
  1220. *)
  1221. local opts;
  1222. if [[ ${egid} == *[!0-9]* ]]; then
  1223. opts="";
  1224. else
  1225. opts="-g ${egid}";
  1226. fi;
  1227. groupadd -r ${opts} "${egroup}" || die
  1228. ;;
  1229. esac
  1230. }
  1231. enewuser ()
  1232. {
  1233. _assert_pkg_ebuild_phase ${FUNCNAME};
  1234. local euser=$1;
  1235. shift;
  1236. if [[ -z ${euser} ]]; then
  1237. eerror "No username specified !";
  1238. die "Cannot call enewuser without a username";
  1239. fi;
  1240. if [[ -n $(egetent passwd "${euser}") ]]; then
  1241. return 0;
  1242. fi;
  1243. einfo "Adding user '${euser}' to your system ...";
  1244. local opts=();
  1245. local euid=$1;
  1246. shift;
  1247. if [[ -n ${euid} && ${euid} != -1 ]]; then
  1248. if [[ ${euid} -gt 0 ]]; then
  1249. if [[ -n $(egetent passwd ${euid}) ]]; then
  1250. euid="next";
  1251. fi;
  1252. else
  1253. eerror "Userid given but is not greater than 0 !";
  1254. die "${euid} is not a valid UID";
  1255. fi;
  1256. else
  1257. euid="next";
  1258. fi;
  1259. if [[ ${euid} == "next" ]]; then
  1260. for ((euid = 101; euid <= 999; euid++))
  1261. do
  1262. [[ -z $(egetent passwd ${euid}) ]] && break;
  1263. done;
  1264. fi;
  1265. opts+=(-u ${euid});
  1266. einfo " - Userid: ${euid}";
  1267. local eshell=$1;
  1268. shift;
  1269. if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]]; then
  1270. if [[ ! -e ${ROOT}${eshell} ]]; then
  1271. eerror "A shell was specified but it does not exist !";
  1272. die "${eshell} does not exist in ${ROOT}";
  1273. fi;
  1274. if [[ ${eshell} == */false || ${eshell} == */nologin ]]; then
  1275. eerror "Do not specify ${eshell} yourself, use -1";
  1276. die "Pass '-1' as the shell parameter";
  1277. fi;
  1278. else
  1279. for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null;
  1280. do
  1281. [[ -x ${ROOT}${eshell} ]] && break;
  1282. done;
  1283. if [[ ${eshell} == "/dev/null" ]]; then
  1284. eerror "Unable to identify the shell to use, proceeding with userland default.";
  1285. case ${USERLAND} in
  1286. GNU)
  1287. eshell="/bin/false"
  1288. ;;
  1289. BSD)
  1290. eshell="/sbin/nologin"
  1291. ;;
  1292. Darwin)
  1293. eshell="/usr/sbin/nologin"
  1294. ;;
  1295. *)
  1296. die "Unable to identify the default shell for userland ${USERLAND}"
  1297. ;;
  1298. esac;
  1299. fi;
  1300. fi;
  1301. einfo " - Shell: ${eshell}";
  1302. opts+=(-s "${eshell}");
  1303. local ehome=$1;
  1304. shift;
  1305. if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]]; then
  1306. ehome="/dev/null";
  1307. fi;
  1308. einfo " - Home: ${ehome}";
  1309. opts+=(-d "${ehome}");
  1310. local egroups=$1;
  1311. shift;
  1312. local g egroups_arr;
  1313. IFS="," read -r -a egroups_arr <<< "${egroups}";
  1314. shift;
  1315. if [[ ${#egroups_arr[@]} -gt 0 ]]; then
  1316. local defgroup exgroups;
  1317. for g in "${egroups_arr[@]}";
  1318. do
  1319. if [[ -z $(egetent group "${g}") ]]; then
  1320. eerror "You must add group ${g} to the system first";
  1321. die "${g} is not a valid GID";
  1322. fi;
  1323. if [[ -z ${defgroup} ]]; then
  1324. defgroup=${g};
  1325. else
  1326. exgroups+=",${g}";
  1327. fi;
  1328. done;
  1329. opts+=(-g "${defgroup}");
  1330. if [[ ! -z ${exgroups} ]]; then
  1331. opts+=(-G "${exgroups:1}");
  1332. fi;
  1333. fi;
  1334. einfo " - Groups: ${egroups:-(none)}";
  1335. if [[ $# -gt 0 ]]; then
  1336. die "extra arguments no longer supported; please file a bug";
  1337. else
  1338. local comment="added by portage for ${PN}";
  1339. opts+=(-c "${comment}");
  1340. einfo " - GECOS: ${comment}";
  1341. fi;
  1342. case ${CHOST} in
  1343. *-darwin*)
  1344. dscl . create "/users/${euser}" uid ${euid};
  1345. dscl . create "/users/${euser}" shell "${eshell}";
  1346. dscl . create "/users/${euser}" home "${ehome}";
  1347. dscl . create "/users/${euser}" realname "added by portage for ${PN}";
  1348. for g in "${egroups_arr[@]}";
  1349. do
  1350. dscl . merge "/groups/${g}" users "${euser}";
  1351. done
  1352. ;;
  1353. *-freebsd* | *-dragonfly*)
  1354. pw useradd "${euser}" "${opts[@]}" || die
  1355. ;;
  1356. *-netbsd*)
  1357. useradd "${opts[@]}" "${euser}" || die
  1358. ;;
  1359. *-openbsd*)
  1360. useradd -u ${euid} -s "${eshell}" -d "${ehome}" -g "${egroups}" "${euser}" || die
  1361. ;;
  1362. *)
  1363. useradd -r "${opts[@]}" "${euser}" || die
  1364. ;;
  1365. esac;
  1366. if [[ ! -e ${ROOT}/${ehome} ]]; then
  1367. einfo " - Creating ${ehome} in ${ROOT}";
  1368. mkdir -p "${ROOT}/${ehome}";
  1369. chown "${euser}" "${ROOT}/${ehome}";
  1370. chmod 755 "${ROOT}/${ehome}";
  1371. fi
  1372. }
  1373. epatch ()
  1374. {
  1375. function _epatch_draw_line ()
  1376. {
  1377. [[ -z $1 ]] && set "$(printf "%65s" '')";
  1378. echo "${1//?/=}"
  1379. };
  1380. unset P4CONFIG P4PORT P4USER;
  1381. local EPATCH_OPTS=(${EPATCH_OPTS[*]});
  1382. while [[ $# -gt 0 ]]; do
  1383. case $1 in
  1384. -*)
  1385. EPATCH_OPTS+=("$1")
  1386. ;;
  1387. *)
  1388. break
  1389. ;;
  1390. esac;
  1391. shift;
  1392. done;
  1393. if [[ $# -gt 1 ]]; then
  1394. local m;
  1395. for m in "$@";
  1396. do
  1397. epatch "${m}";
  1398. done;
  1399. return 0;
  1400. fi;
  1401. local SINGLE_PATCH="no";
  1402. [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}";
  1403. if [[ -f $1 ]]; then
  1404. SINGLE_PATCH="yes";
  1405. set -- "$1";
  1406. local EPATCH_SUFFIX=$1;
  1407. else
  1408. if [[ -d $1 ]]; then
  1409. set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"};
  1410. else
  1411. if [[ -f ${EPATCH_SOURCE}/$1 ]]; then
  1412. epatch "${EPATCH_SOURCE}/$1";
  1413. return $?;
  1414. else
  1415. [[ $# -ne 0 ]] && EPATCH_SOURCE=$1;
  1416. echo;
  1417. eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:";
  1418. eerror;
  1419. eerror " ${EPATCH_SOURCE}";
  1420. eerror " ( ${EPATCH_SOURCE##*/} )";
  1421. echo;
  1422. die "Cannot find \$EPATCH_SOURCE!";
  1423. fi;
  1424. fi;
  1425. fi;
  1426. EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}";
  1427. local PIPE_CMD;
  1428. case ${EPATCH_SUFFIX##*\.} in
  1429. xz)
  1430. PIPE_CMD="xz -dc"
  1431. ;;
  1432. lzma)
  1433. PIPE_CMD="lzma -dc"
  1434. ;;
  1435. bz2)
  1436. PIPE_CMD="bzip2 -dc"
  1437. ;;
  1438. gz | Z | z)
  1439. PIPE_CMD="gzip -dc"
  1440. ;;
  1441. ZIP | zip)
  1442. PIPE_CMD="unzip -p"
  1443. ;;
  1444. *)
  1445.  
  1446. ;;
  1447. esac;
  1448. [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}";
  1449. local x;
  1450. for x in "$@";
  1451. do
  1452. [[ ! -f ${x} ]] && continue;
  1453. local patchname=${x##*/};
  1454. local a=${patchname#*_};
  1455. a=${a%%_*};
  1456. if ! [[ ${SINGLE_PATCH} == "yes" || ${EPATCH_FORCE} == "yes" || ${a} == all || ${a} == ${ARCH} ]]; then
  1457. continue;
  1458. fi;
  1459. if [[ -n ${EPATCH_EXCLUDE} ]]; then
  1460. eshopts_push -o noglob;
  1461. local ex;
  1462. for ex in ${EPATCH_EXCLUDE};
  1463. do
  1464. if [[ ${patchname} == ${ex} ]]; then
  1465. eshopts_pop;
  1466. continue 2;
  1467. fi;
  1468. done;
  1469. eshopts_pop;
  1470. fi;
  1471. if [[ ${SINGLE_PATCH} == "yes" ]]; then
  1472. if [[ -n ${EPATCH_SINGLE_MSG} ]]; then
  1473. einfo "${EPATCH_SINGLE_MSG}";
  1474. else
  1475. einfo "Applying ${patchname} ...";
  1476. fi;
  1477. else
  1478. einfo " ${patchname} ...";
  1479. fi;
  1480. local STDERR_TARGET="${T}/${patchname}.out";
  1481. if [[ -e ${STDERR_TARGET} ]]; then
  1482. STDERR_TARGET="${T}/${patchname}-$$.out";
  1483. fi;
  1484. printf "***** %s *****\nPWD: %s\n\n" "${patchname}" "${PWD}" > "${STDERR_TARGET}";
  1485. local count=0;
  1486. local PATCH_TARGET;
  1487. if [[ -n ${PIPE_CMD} ]]; then
  1488. PATCH_TARGET="${T}/$$.patch";
  1489. echo "PIPE_COMMAND: ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}";
  1490. if ! ( ${PIPE_CMD} "${x}" > "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
  1491. echo;
  1492. eerror "Could not extract patch!";
  1493. count=5;
  1494. break;
  1495. fi;
  1496. else
  1497. PATCH_TARGET=${x};
  1498. fi;
  1499. local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }');
  1500. if [[ -n ${abs_paths} ]]; then
  1501. count=1;
  1502. printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}";
  1503. fi;
  1504. local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}");
  1505. if [[ -n ${rel_paths} ]]; then
  1506. eqawarn "QA Notice: Your patch uses relative paths '../'.";
  1507. eqawarn " In the future this will cause a failure.";
  1508. eqawarn "${rel_paths}";
  1509. fi;
  1510. local patch_cmd;
  1511. while [[ ${count} -lt 5 ]]; do
  1512. patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}";
  1513. ( _epatch_draw_line "***** ${patchname} *****";
  1514. echo;
  1515. echo "PATCH COMMAND: ${patch_cmd} < '${PATCH_TARGET}'";
  1516. echo;
  1517. _epatch_draw_line "***** ${patchname} *****";
  1518. ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1;
  1519. ret=$?;
  1520. echo;
  1521. echo "patch program exited with status ${ret}";
  1522. exit ${ret} ) >> "${STDERR_TARGET}";
  1523. if [ $? -eq 0 ]; then
  1524. ( _epatch_draw_line "***** ${patchname} *****";
  1525. echo;
  1526. echo "ACTUALLY APPLYING ${patchname} ...";
  1527. echo;
  1528. _epatch_draw_line "***** ${patchname} *****";
  1529. ${patch_cmd} < "${PATCH_TARGET}" 2>&1;
  1530. ret=$?;
  1531. echo;
  1532. echo "patch program exited with status ${ret}";
  1533. exit ${ret} ) >> "${STDERR_TARGET}";
  1534. if [ $? -ne 0 ]; then
  1535. echo;
  1536. eerror "A dry-run of patch command succeeded, but actually";
  1537. eerror "applying the patch failed!";
  1538. count=5;
  1539. fi;
  1540. break;
  1541. fi;
  1542. : $(( count++ ));
  1543. done;
  1544. if [[ -n ${PIPE_CMD} ]]; then
  1545. rm -f "${PATCH_TARGET}";
  1546. fi;
  1547. if [[ ${count} -ge 5 ]]; then
  1548. echo;
  1549. eerror "Failed Patch: ${patchname} !";
  1550. eerror " ( ${PATCH_TARGET} )";
  1551. eerror;
  1552. eerror "Include in your bugreport the contents of:";
  1553. eerror;
  1554. eerror " ${STDERR_TARGET}";
  1555. echo;
  1556. die "Failed Patch: ${patchname}!";
  1557. fi;
  1558. rm -f "${STDERR_TARGET}";
  1559. cat >> "${T}/epatch.log" <<-EOF
  1560. PATCH: ${x}
  1561. CMD: ${patch_cmd}
  1562. PWD: ${PWD}
  1563.  
  1564. EOF
  1565.  
  1566. eend 0;
  1567. done;
  1568. [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching";
  1569. :
  1570. }
  1571. epatch_user ()
  1572. {
  1573. [[ $# -ne 0 ]] && die "epatch_user takes no options";
  1574. local applied="${T}/epatch_user.log";
  1575. [[ -e ${applied} ]] && return 2;
  1576. local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches;
  1577. for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}};
  1578. do
  1579. EPATCH_SOURCE=${base}/${CTARGET}/${check};
  1580. [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check};
  1581. [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check};
  1582. if [[ -d ${EPATCH_SOURCE} ]]; then
  1583. EPATCH_SOURCE=${EPATCH_SOURCE} EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." epatch;
  1584. echo "${EPATCH_SOURCE}" > "${applied}";
  1585. return 0;
  1586. fi;
  1587. done;
  1588. echo "none" > "${applied}";
  1589. return 1
  1590. }
  1591. epause ()
  1592. {
  1593. ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at http://bugs.gentoo.org"
  1594. }
  1595. epunt_cxx ()
  1596. {
  1597. local dir=$1;
  1598. [[ -z ${dir} ]] && dir=${S};
  1599. ebegin "Removing useless C++ checks";
  1600. local f any_found;
  1601. find "${dir}" -name configure | while read f; do
  1602. patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null && any_found=1;
  1603. done;
  1604. if [[ -z ${any_found} ]]; then
  1605. eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt).";
  1606. fi;
  1607. eend 0
  1608. }
  1609. esethome ()
  1610. {
  1611. _assert_pkg_ebuild_phase ${FUNCNAME};
  1612. local euser=$1;
  1613. shift;
  1614. if [[ -z ${euser} ]]; then
  1615. eerror "No username specified !";
  1616. die "Cannot call esethome without a username";
  1617. fi;
  1618. if [[ -z $(egetent passwd "${euser}") ]]; then
  1619. ewarn "User does not exist, cannot set home dir -- skipping.";
  1620. return 1;
  1621. fi;
  1622. local ehome=$1;
  1623. shift;
  1624. if [[ -z ${ehome} ]]; then
  1625. eerror "No home directory specified !";
  1626. die "Cannot call esethome without a home directory or '-1'";
  1627. fi;
  1628. if [[ ${ehome} == "-1" ]]; then
  1629. ehome="/dev/null";
  1630. fi;
  1631. if [[ $(egethome "${euser}") == ${ehome} ]]; then
  1632. return 0;
  1633. fi;
  1634. einfo "Updating home for user '${euser}' ...";
  1635. einfo " - Home: ${ehome}";
  1636. if [[ ! -e ${ROOT}/${ehome} ]]; then
  1637. einfo " - Creating ${ehome} in ${ROOT}";
  1638. mkdir -p "${ROOT}/${ehome}";
  1639. chown "${euser}" "${ROOT}/${ehome}";
  1640. chmod 755 "${ROOT}/${ehome}";
  1641. fi;
  1642. case ${CHOST} in
  1643. *-darwin*)
  1644. dscl . change "/users/${euser}" home "${ehome}"
  1645. ;;
  1646. *-freebsd* | *-dragonfly*)
  1647. pw usermod "${euser}" -d "${ehome}" && return 0;
  1648. [[ $? == 8 ]] && eerror "${euser} is in use, cannot update home";
  1649. eerror "There was an error when attempting to update the home directory for ${euser}";
  1650. eerror "Please update it manually on your system:";
  1651. eerror "\t pw usermod \"${euser}\" -d \"${ehome}\""
  1652. ;;
  1653. *)
  1654. usermod -d "${ehome}" "${euser}" && return 0;
  1655. [[ $? == 8 ]] && eerror "${euser} is in use, cannot update home";
  1656. eerror "There was an error when attempting to update the home directory for ${euser}";
  1657. eerror "Please update it manually on your system (as root):";
  1658. eerror "\t usermod -d \"${ehome}\" \"${euser}\""
  1659. ;;
  1660. esac
  1661. }
  1662. eshopts_pop ()
  1663. {
  1664. local s;
  1665. estack_pop eshopts s || die "${FUNCNAME}: unbalanced push";
  1666. if [[ ${s} == "shopt -"* ]]; then
  1667. eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}";
  1668. else
  1669. set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-";
  1670. set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}";
  1671. fi
  1672. }
  1673. eshopts_push ()
  1674. {
  1675. if [[ $1 == -[su] ]]; then
  1676. estack_push eshopts "$(shopt -p)";
  1677. [[ $# -eq 0 ]] && return 0;
  1678. shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*";
  1679. else
  1680. estack_push eshopts $-;
  1681. [[ $# -eq 0 ]] && return 0;
  1682. set "$@" || die "${FUNCNAME}: bad options to set: $*";
  1683. fi
  1684. }
  1685. estack_pop ()
  1686. {
  1687. [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments";
  1688. local __estack_name="__ESTACK_$1__";
  1689. shift;
  1690. local __estack_retvar=$1;
  1691. shift;
  1692. eval local __estack_i=\${#${__estack_name}\[@\]};
  1693. [[ $(( --__estack_i )) -eq -1 ]] && return 1;
  1694. if [[ -n ${__estack_retvar} ]]; then
  1695. eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\";
  1696. fi;
  1697. eval unset ${__estack_name}\[${__estack_i}\]
  1698. }
  1699. estack_push ()
  1700. {
  1701. [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments";
  1702. local stack_name="__ESTACK_$1__";
  1703. shift;
  1704. eval ${stack_name}+=\( \"\$@\" \)
  1705. }
  1706. esvn_clean ()
  1707. {
  1708. [[ -z $* ]] && set -- .;
  1709. find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
  1710. }
  1711. eumask_pop ()
  1712. {
  1713. [[ $# -eq 0 ]] || die "${FUNCNAME}: we take no options";
  1714. local s;
  1715. estack_pop eumask s || die "${FUNCNAME}: unbalanced push";
  1716. umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
  1717. }
  1718. eumask_push ()
  1719. {
  1720. estack_push eumask "$(umask)";
  1721. umask "$@" || die "${FUNCNAME}: bad options to umask: $*"
  1722. }
  1723. gcc-fullversion ()
  1724. {
  1725. _gcc_fullversion '$1.$2.$3' "$@"
  1726. }
  1727. gcc-major-version ()
  1728. {
  1729. _gcc_fullversion '$1' "$@"
  1730. }
  1731. gcc-micro-version ()
  1732. {
  1733. _gcc_fullversion '$3' "$@"
  1734. }
  1735. gcc-minor-version ()
  1736. {
  1737. _gcc_fullversion '$2' "$@"
  1738. }
  1739. gcc-specs-directive ()
  1740. {
  1741. local directive subdname subdirective;
  1742. directive="$(_gcc-specs-directive_raw $1)";
  1743. while [[ ${directive} == *%\(*\)* ]]; do
  1744. subdname=${directive/*%\(};
  1745. subdname=${subdname/\)*};
  1746. subdirective="$(_gcc-specs-directive_raw ${subdname})";
  1747. directive="${directive//\%(${subdname})/${subdirective}}";
  1748. done;
  1749. echo "${directive}";
  1750. return 0
  1751. }
  1752. gcc-specs-nostrict ()
  1753. {
  1754. local directive;
  1755. directive=$(gcc-specs-directive cc1);
  1756. return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]])
  1757. }
  1758. gcc-specs-now ()
  1759. {
  1760. local directive;
  1761. directive=$(gcc-specs-directive link_command);
  1762. return $([[ "${directive/\{!nonow:}" != "${directive}" ]])
  1763. }
  1764. gcc-specs-pie ()
  1765. {
  1766. local directive;
  1767. directive=$(gcc-specs-directive cc1);
  1768. return $([[ "${directive/\{!nopie:}" != "${directive}" ]])
  1769. }
  1770. gcc-specs-relro ()
  1771. {
  1772. local directive;
  1773. directive=$(gcc-specs-directive link_command);
  1774. return $([[ "${directive/\{!norelro:}" != "${directive}" ]])
  1775. }
  1776. gcc-specs-ssp ()
  1777. {
  1778. local directive;
  1779. directive=$(gcc-specs-directive cc1);
  1780. return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]])
  1781. }
  1782. gcc-specs-ssp-to-all ()
  1783. {
  1784. local directive;
  1785. directive=$(gcc-specs-directive cc1);
  1786. return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]])
  1787. }
  1788. gcc-version ()
  1789. {
  1790. _gcc_fullversion '$1.$2' "$@"
  1791. }
  1792. gen_usr_ldscript ()
  1793. {
  1794. local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname);
  1795. [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/;
  1796. tc-is-static-only && return;
  1797. case ${CTARGET:-${CHOST}} in
  1798. *-darwin*)
  1799.  
  1800. ;;
  1801. *linux* | *-freebsd* | *-openbsd* | *-netbsd*)
  1802. use prefix && return 0
  1803. ;;
  1804. *)
  1805. return 0
  1806. ;;
  1807. esac;
  1808. dodir /usr/${libdir};
  1809. if [[ $1 == "-a" ]]; then
  1810. auto=true;
  1811. shift;
  1812. dodir /${libdir};
  1813. fi;
  1814. output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p');
  1815. [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )";
  1816. for lib in "$@";
  1817. do
  1818. local tlib;
  1819. if ${auto}; then
  1820. lib="lib${lib}${suffix}";
  1821. else
  1822. [[ -r ${ED}/${libdir}/${lib} ]] || continue;
  1823. fi;
  1824. case ${CTARGET:-${CHOST}} in
  1825. *-darwin*)
  1826. if ${auto}; then
  1827. tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1828. else
  1829. tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib});
  1830. fi;
  1831. [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}";
  1832. tlib=${tlib##*/};
  1833. if ${auto}; then
  1834. mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1835. if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then
  1836. mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1837. fi;
  1838. rm -f "${ED}"/${libdir}/${lib};
  1839. fi;
  1840. if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then
  1841. chmod u+w "${ED}${libdir}/${tlib}";
  1842. local nowrite=yes;
  1843. fi;
  1844. install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed";
  1845. [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}";
  1846. pushd "${ED}/usr/${libdir}" > /dev/null;
  1847. ln -snf "../../${libdir}/${tlib}" "${lib}";
  1848. popd > /dev/null
  1849. ;;
  1850. *)
  1851. if ${auto}; then
  1852. tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1853. [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}";
  1854. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  1855. if [[ ${tlib} != ${lib}* ]]; then
  1856. mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  1857. fi;
  1858. rm -f "${ED}"/${libdir}/${lib};
  1859. else
  1860. tlib=${lib};
  1861. fi;
  1862. cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
  1863. /* GNU ld script
  1864. Since Gentoo has critical dynamic libraries in /lib, and the static versions
  1865. in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
  1866. run into linking problems. This "fake" dynamic lib is a linker script that
  1867. redirects the linker to the real lib. And yes, this works in the cross-
  1868. compiling scenario as the sysroot-ed linker will prepend the real path.
  1869.  
  1870. See bug http://bugs.gentoo.org/4411 for more info.
  1871. */
  1872. ${output_format}
  1873. GROUP ( ${EPREFIX}/${libdir}/${tlib} )
  1874. END_LDSCRIPT
  1875.  
  1876. ;;
  1877. esac
  1878. fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}";
  1879. done
  1880. }
  1881. get_abi_CFLAGS ()
  1882. {
  1883. get_abi_var CFLAGS "$@"
  1884. }
  1885. get_abi_CHOST ()
  1886. {
  1887. get_abi_var CHOST "$@"
  1888. }
  1889. get_abi_CTARGET ()
  1890. {
  1891. get_abi_var CTARGET "$@"
  1892. }
  1893. get_abi_FAKE_TARGETS ()
  1894. {
  1895. get_abi_var FAKE_TARGETS "$@"
  1896. }
  1897. get_abi_LDFLAGS ()
  1898. {
  1899. get_abi_var LDFLAGS "$@"
  1900. }
  1901. get_abi_LIBDIR ()
  1902. {
  1903. get_abi_var LIBDIR "$@"
  1904. }
  1905. get_abi_var ()
  1906. {
  1907. local flag=$1;
  1908. local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}};
  1909. local var="${flag}_${abi}";
  1910. echo ${!var}
  1911. }
  1912. get_all_abis ()
  1913. {
  1914. local x order="" mvar dvar;
  1915. mvar="MULTILIB_ABIS";
  1916. dvar="DEFAULT_ABI";
  1917. if [[ -n $1 ]]; then
  1918. mvar="$1_${mvar}";
  1919. dvar="$1_${dvar}";
  1920. fi;
  1921. if [[ -z ${!mvar} ]]; then
  1922. echo "default";
  1923. return 0;
  1924. fi;
  1925. for x in ${!mvar};
  1926. do
  1927. if [[ ${x} != ${!dvar} ]]; then
  1928. order="${order:+${order} }${x}";
  1929. fi;
  1930. done;
  1931. order="${order:+${order} }${!dvar}";
  1932. echo ${order};
  1933. return 0
  1934. }
  1935. get_all_libdirs ()
  1936. {
  1937. local libdirs abi;
  1938. for abi in ${MULTILIB_ABIS};
  1939. do
  1940. libdirs+=" $(get_abi_LIBDIR ${abi})";
  1941. done;
  1942. [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib";
  1943. echo "${libdirs}"
  1944. }
  1945. get_install_abis ()
  1946. {
  1947. local x order="";
  1948. if [[ -z ${MULTILIB_ABIS} ]]; then
  1949. echo "default";
  1950. return 0;
  1951. fi;
  1952. if [[ ${EMULTILIB_PKG} == "true" ]]; then
  1953. for x in ${MULTILIB_ABIS};
  1954. do
  1955. if [[ ${x} != "${DEFAULT_ABI}" ]]; then
  1956. has ${x} ${ABI_DENY} || order="${order} ${x}";
  1957. fi;
  1958. done;
  1959. has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}";
  1960. if [[ -n ${ABI_ALLOW} ]]; then
  1961. local ordera="";
  1962. for x in ${order};
  1963. do
  1964. if has ${x} ${ABI_ALLOW}; then
  1965. ordera="${ordera} ${x}";
  1966. fi;
  1967. done;
  1968. order=${ordera};
  1969. fi;
  1970. else
  1971. order=${DEFAULT_ABI};
  1972. fi;
  1973. if [[ -z ${order} ]]; then
  1974. die "The ABI list is empty. Are you using a proper multilib profile? Perhaps your USE flags or MULTILIB_ABIS are too restrictive for this package.";
  1975. fi;
  1976. echo ${order};
  1977. return 0
  1978. }
  1979. get_libdir ()
  1980. {
  1981. local CONF_LIBDIR;
  1982. if [ -n "${CONF_LIBDIR_OVERRIDE}" ]; then
  1983. echo ${CONF_LIBDIR_OVERRIDE};
  1984. else
  1985. get_abi_LIBDIR;
  1986. fi
  1987. }
  1988. get_libname ()
  1989. {
  1990. local libname;
  1991. local ver=$1;
  1992. case ${CHOST} in
  1993. *-cygwin | mingw* | *-mingw*)
  1994. libname="dll"
  1995. ;;
  1996. *-darwin*)
  1997. libname="dylib"
  1998. ;;
  1999. *-mint*)
  2000. libname="irrelevant"
  2001. ;;
  2002. hppa*-hpux*)
  2003. libname="sl"
  2004. ;;
  2005. *)
  2006. libname="so"
  2007. ;;
  2008. esac;
  2009. if [[ -z $* ]]; then
  2010. echo ".${libname}";
  2011. else
  2012. for ver in "$@";
  2013. do
  2014. case ${CHOST} in
  2015. *-darwin*)
  2016. echo ".${ver}.${libname}"
  2017. ;;
  2018. *-mint*)
  2019. echo ".${libname}"
  2020. ;;
  2021. *)
  2022. echo ".${libname}.${ver}"
  2023. ;;
  2024. esac;
  2025. done;
  2026. fi
  2027. }
  2028. get_modname ()
  2029. {
  2030. local modname;
  2031. local ver=$1;
  2032. case ${CHOST} in
  2033. *-darwin*)
  2034. modname="bundle"
  2035. ;;
  2036. *)
  2037. modname="so"
  2038. ;;
  2039. esac;
  2040. echo ".${modname}"
  2041. }
  2042. has_multilib_profile ()
  2043. {
  2044. [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
  2045. }
  2046. host-is-pax ()
  2047. {
  2048. grep -qs ^PaX: /proc/self/status
  2049. }
  2050. in_iuse ()
  2051. {
  2052. debug-print-function ${FUNCNAME} "${@}";
  2053. [[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()";
  2054. local flag=${1};
  2055. local liuse=(${IUSE});
  2056. has "${flag}" "${liuse[@]#[+-]}"
  2057. }
  2058. is_final_abi ()
  2059. {
  2060. has_multilib_profile || return 0;
  2061. set -- $(get_install_abis);
  2062. local LAST_ABI=$#;
  2063. [[ ${!LAST_ABI} == ${ABI} ]]
  2064. }
  2065. list-paxables ()
  2066. {
  2067. file "$@" 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//'
  2068. }
  2069. make_desktop_entry ()
  2070. {
  2071. [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable";
  2072. local exec=${1};
  2073. local name=${2:-${PN}};
  2074. local icon=${3:-${PN}};
  2075. local type=${4};
  2076. local fields=${5};
  2077. if [[ -z ${type} ]]; then
  2078. local catmaj=${CATEGORY%%-*};
  2079. local catmin=${CATEGORY##*-};
  2080. case ${catmaj} in
  2081. app)
  2082. case ${catmin} in
  2083. accessibility)
  2084. type="Utility;Accessibility"
  2085. ;;
  2086. admin)
  2087. type=System
  2088. ;;
  2089. antivirus)
  2090. type=System
  2091. ;;
  2092. arch)
  2093. type="Utility;Archiving"
  2094. ;;
  2095. backup)
  2096. type="Utility;Archiving"
  2097. ;;
  2098. cdr)
  2099. type="AudioVideo;DiscBurning"
  2100. ;;
  2101. dicts)
  2102. type="Office;Dictionary"
  2103. ;;
  2104. doc)
  2105. type=Documentation
  2106. ;;
  2107. editors)
  2108. type="Utility;TextEditor"
  2109. ;;
  2110. emacs)
  2111. type="Development;TextEditor"
  2112. ;;
  2113. emulation)
  2114. type="System;Emulator"
  2115. ;;
  2116. laptop)
  2117. type="Settings;HardwareSettings"
  2118. ;;
  2119. office)
  2120. type=Office
  2121. ;;
  2122. pda)
  2123. type="Office;PDA"
  2124. ;;
  2125. vim)
  2126. type="Development;TextEditor"
  2127. ;;
  2128. xemacs)
  2129. type="Development;TextEditor"
  2130. ;;
  2131. esac
  2132. ;;
  2133. dev)
  2134. type="Development"
  2135. ;;
  2136. games)
  2137. case ${catmin} in
  2138. action | fps)
  2139. type=ActionGame
  2140. ;;
  2141. arcade)
  2142. type=ArcadeGame
  2143. ;;
  2144. board)
  2145. type=BoardGame
  2146. ;;
  2147. emulation)
  2148. type=Emulator
  2149. ;;
  2150. kids)
  2151. type=KidsGame
  2152. ;;
  2153. puzzle)
  2154. type=LogicGame
  2155. ;;
  2156. roguelike)
  2157. type=RolePlaying
  2158. ;;
  2159. rpg)
  2160. type=RolePlaying
  2161. ;;
  2162. simulation)
  2163. type=Simulation
  2164. ;;
  2165. sports)
  2166. type=SportsGame
  2167. ;;
  2168. strategy)
  2169. type=StrategyGame
  2170. ;;
  2171. esac;
  2172. type="Game;${type}"
  2173. ;;
  2174. gnome)
  2175. type="Gnome;GTK"
  2176. ;;
  2177. kde)
  2178. type="KDE;Qt"
  2179. ;;
  2180. mail)
  2181. type="Network;Email"
  2182. ;;
  2183. media)
  2184. case ${catmin} in
  2185. gfx)
  2186. type=Graphics
  2187. ;;
  2188. *)
  2189. case ${catmin} in
  2190. radio)
  2191. type=Tuner
  2192. ;;
  2193. sound)
  2194. type=Audio
  2195. ;;
  2196. tv)
  2197. type=TV
  2198. ;;
  2199. video)
  2200. type=Video
  2201. ;;
  2202. esac;
  2203. type="AudioVideo;${type}"
  2204. ;;
  2205. esac
  2206. ;;
  2207. net)
  2208. case ${catmin} in
  2209. dialup)
  2210. type=Dialup
  2211. ;;
  2212. ftp)
  2213. type=FileTransfer
  2214. ;;
  2215. im)
  2216. type=InstantMessaging
  2217. ;;
  2218. irc)
  2219. type=IRCClient
  2220. ;;
  2221. mail)
  2222. type=Email
  2223. ;;
  2224. news)
  2225. type=News
  2226. ;;
  2227. nntp)
  2228. type=News
  2229. ;;
  2230. p2p)
  2231. type=FileTransfer
  2232. ;;
  2233. voip)
  2234. type=Telephony
  2235. ;;
  2236. esac;
  2237. type="Network;${type}"
  2238. ;;
  2239. sci)
  2240. case ${catmin} in
  2241. astro*)
  2242. type=Astronomy
  2243. ;;
  2244. bio*)
  2245. type=Biology
  2246. ;;
  2247. calc*)
  2248. type=Calculator
  2249. ;;
  2250. chem*)
  2251. type=Chemistry
  2252. ;;
  2253. elec*)
  2254. type=Electronics
  2255. ;;
  2256. geo*)
  2257. type=Geology
  2258. ;;
  2259. math*)
  2260. type=Math
  2261. ;;
  2262. physics)
  2263. type=Physics
  2264. ;;
  2265. visual*)
  2266. type=DataVisualization
  2267. ;;
  2268. esac;
  2269. type="Education;Science;${type}"
  2270. ;;
  2271. sys)
  2272. type="System"
  2273. ;;
  2274. www)
  2275. case ${catmin} in
  2276. client)
  2277. type=WebBrowser
  2278. ;;
  2279. esac;
  2280. type="Network;${type}"
  2281. ;;
  2282. *)
  2283. type=
  2284. ;;
  2285. esac;
  2286. fi;
  2287. if [ "${SLOT}" == "0" ]; then
  2288. local desktop_name="${PN}";
  2289. else
  2290. local desktop_name="${PN}-${SLOT}";
  2291. fi;
  2292. local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop";
  2293. type=${type%;}${type:+;};
  2294. eshopts_push -s extglob;
  2295. if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
  2296. ewarn "As described in the Icon Theme Specification, icon file extensions are not";
  2297. ewarn "allowed in .desktop files if the value is not an absolute path.";
  2298. icon=${icon%.@(xpm|png|svg)};
  2299. fi;
  2300. eshopts_pop;
  2301. cat > "${desktop}" <<-EOF
  2302. [Desktop Entry]
  2303. Name=${name}
  2304. Type=Application
  2305. Comment=${DESCRIPTION}
  2306. Exec=${exec}
  2307. TryExec=${exec%% *}
  2308. Icon=${icon}
  2309. Categories=${type}
  2310. EOF
  2311.  
  2312. if [[ ${fields:-=} != *=* ]]; then
  2313. ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}";
  2314. fields="Path=${fields}";
  2315. fi;
  2316. [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}";
  2317. ( insinto /usr/share/applications;
  2318. doins "${desktop}" ) || die "installing desktop file failed"
  2319. }
  2320. make_session_desktop ()
  2321. {
  2322. [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1;
  2323. [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1;
  2324. local title=$1;
  2325. local command=$2;
  2326. local desktop=${T}/${wm:-${PN}}.desktop;
  2327. shift 2;
  2328. cat > "${desktop}" <<-EOF
  2329. [Desktop Entry]
  2330. Name=${title}
  2331. Comment=This session logs you into ${title}
  2332. Exec=${command} $*
  2333. TryExec=${command}
  2334. Type=XSession
  2335. EOF
  2336.  
  2337. ( insinto /usr/share/xsessions;
  2338. doins "${desktop}" )
  2339. }
  2340. make_wrapper ()
  2341. {
  2342. local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5;
  2343. local tmpwrapper=$(emktemp);
  2344. cat > "${tmpwrapper}" <<EOF
  2345. #!/bin/sh
  2346. cd "${chdir:-.}"
  2347. if [ -n "${libdir}" ] ; then
  2348. if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
  2349. export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
  2350. else
  2351. export LD_LIBRARY_PATH="${libdir}"
  2352. fi
  2353. fi
  2354. exec ${bin} "\$@"
  2355. EOF
  2356.  
  2357. chmod go+rx "${tmpwrapper}";
  2358. if [[ -n ${path} ]]; then
  2359. ( exeinto "${path}";
  2360. newexe "${tmpwrapper}" "${wrapper}" ) || die;
  2361. else
  2362. newbin "${tmpwrapper}" "${wrapper}" || die;
  2363. fi
  2364. }
  2365. multilib_env ()
  2366. {
  2367. local CTARGET=${1:-${CTARGET}};
  2368. case ${CTARGET} in
  2369. x86_64*)
  2370. export CFLAGS_x86=${CFLAGS_x86--m32};
  2371. export CHOST_x86=${CTARGET/x86_64/i686};
  2372. CHOST_x86=${CHOST_x86/%-gnux32/-gnu};
  2373. export CTARGET_x86=${CHOST_x86};
  2374. if [[ ${SYMLINK_LIB} == "yes" ]]; then
  2375. export LIBDIR_x86="lib32";
  2376. else
  2377. export LIBDIR_x86="lib";
  2378. fi;
  2379. export CFLAGS_amd64=${CFLAGS_amd64--m64};
  2380. export CHOST_amd64=${CTARGET/%-gnux32/-gnu};
  2381. export CTARGET_amd64=${CHOST_amd64};
  2382. export LIBDIR_amd64="lib64";
  2383. export CFLAGS_x32=${CFLAGS_x32--mx32};
  2384. export CHOST_x32=${CTARGET/%-gnu/-gnux32};
  2385. export CTARGET_x32=${CHOST_x32};
  2386. export LIBDIR_x32="libx32";
  2387. case ${CTARGET} in
  2388. *-gnux32)
  2389. : ${MULTILIB_ABIS=x32 amd64 x86};
  2390. : ${DEFAULT_ABI=x32}
  2391. ;;
  2392. *)
  2393. : ${MULTILIB_ABIS=amd64 x86};
  2394. : ${DEFAULT_ABI=amd64}
  2395. ;;
  2396. esac
  2397. ;;
  2398. mips64*)
  2399. export CFLAGS_o32=${CFLAGS_o32--mabi=32};
  2400. export CHOST_o32=${CTARGET/mips64/mips};
  2401. export CTARGET_o32=${CHOST_o32};
  2402. export LIBDIR_o32="lib";
  2403. export CFLAGS_n32=${CFLAGS_n32--mabi=n32};
  2404. export CHOST_n32=${CTARGET};
  2405. export CTARGET_n32=${CHOST_n32};
  2406. export LIBDIR_n32="lib32";
  2407. export CFLAGS_n64=${CFLAGS_n64--mabi=64};
  2408. export CHOST_n64=${CTARGET};
  2409. export CTARGET_n64=${CHOST_n64};
  2410. export LIBDIR_n64="lib64";
  2411. : ${MULTILIB_ABIS=n64 n32 o32};
  2412. : ${DEFAULT_ABI=n32}
  2413. ;;
  2414. powerpc64*)
  2415. export CFLAGS_ppc=${CFLAGS_ppc--m32};
  2416. export CHOST_ppc=${CTARGET/powerpc64/powerpc};
  2417. export CTARGET_ppc=${CHOST_ppc};
  2418. export LIBDIR_ppc="lib";
  2419. export CFLAGS_ppc64=${CFLAGS_ppc64--m64};
  2420. export CHOST_ppc64=${CTARGET};
  2421. export CTARGET_ppc64=${CHOST_ppc64};
  2422. export LIBDIR_ppc64="lib64";
  2423. : ${MULTILIB_ABIS=ppc64 ppc};
  2424. : ${DEFAULT_ABI=ppc64}
  2425. ;;
  2426. s390x*)
  2427. export CFLAGS_s390=${CFLAGS_s390--m31};
  2428. export CHOST_s390=${CTARGET/s390x/s390};
  2429. export CTARGET_s390=${CHOST_s390};
  2430. export LIBDIR_s390="lib";
  2431. export CFLAGS_s390x=${CFLAGS_s390x--m64};
  2432. export CHOST_s390x=${CTARGET};
  2433. export CTARGET_s390x=${CHOST_s390x};
  2434. export LIBDIR_s390x="lib64";
  2435. : ${MULTILIB_ABIS=s390x s390};
  2436. : ${DEFAULT_ABI=s390x}
  2437. ;;
  2438. sparc64*)
  2439. export CFLAGS_sparc32=${CFLAGS_sparc32--m32};
  2440. export CHOST_sparc32=${CTARGET/sparc64/sparc};
  2441. export CTARGET_sparc32=${CHOST_sparc32};
  2442. export LIBDIR_sparc32="lib";
  2443. export CFLAGS_sparc64=${CFLAGS_sparc64--m64};
  2444. export CHOST_sparc64=${CTARGET};
  2445. export CTARGET_sparc64=${CHOST_sparc64};
  2446. export LIBDIR_sparc64="lib64";
  2447. : ${MULTILIB_ABIS=sparc64 sparc32};
  2448. : ${DEFAULT_ABI=sparc64}
  2449. ;;
  2450. *)
  2451. : ${MULTILIB_ABIS=default};
  2452. : ${DEFAULT_ABI=default}
  2453. ;;
  2454. esac;
  2455. export MULTILIB_ABIS DEFAULT_ABI
  2456. }
  2457. multilib_toolchain_setup ()
  2458. {
  2459. local v vv;
  2460. export ABI=$1;
  2461. if [[ ${__DEFAULT_ABI_SAVED} == "true" ]]; then
  2462. for v in CHOST CBUILD AS CC CXX LD PKG_CONFIG_{LIBDIR,PATH};
  2463. do
  2464. vv="__abi_saved_${v}";
  2465. export ${v}="${!vv}";
  2466. unset ${vv};
  2467. done;
  2468. unset __DEFAULT_ABI_SAVED;
  2469. fi;
  2470. if [[ ${ABI} != ${DEFAULT_ABI} ]]; then
  2471. for v in CHOST CBUILD AS CC CXX LD PKG_CONFIG_{LIBDIR,PATH};
  2472. do
  2473. export __abi_saved_${v}="${!v}";
  2474. done;
  2475. export __DEFAULT_ABI_SAVED="true";
  2476. export CHOST=$(get_abi_CHOST ${DEFAULT_ABI});
  2477. export CC="$(tc-getCC) $(get_abi_CFLAGS)";
  2478. export CXX="$(tc-getCXX) $(get_abi_CFLAGS)";
  2479. export LD="$(tc-getLD) $(get_abi_LDFLAGS)";
  2480. export CHOST=$(get_abi_CHOST $1);
  2481. export CBUILD=$(get_abi_CHOST $1);
  2482. export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig;
  2483. export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig;
  2484. fi
  2485. }
  2486. newicon ()
  2487. {
  2488. _iconins ${FUNCNAME} "$@"
  2489. }
  2490. newmenu ()
  2491. {
  2492. ( insinto /usr/share/applications;
  2493. newins "$@" )
  2494. }
  2495. number_abis ()
  2496. {
  2497. set -- `get_install_abis`;
  2498. echo $#
  2499. }
  2500. path_exists ()
  2501. {
  2502. local opt=$1;
  2503. [[ ${opt} == -[ao] ]] && shift || opt="-a";
  2504. [[ $# -eq 0 ]] && return 1;
  2505. local p r=0;
  2506. for p in "$@";
  2507. do
  2508. [[ -e ${p} ]];
  2509. : $(( r += $? ));
  2510. done;
  2511. case ${opt} in
  2512. -a)
  2513. return $(( r != 0 ))
  2514. ;;
  2515. -o)
  2516. return $(( r == $# ))
  2517. ;;
  2518. esac
  2519. }
  2520. pax-mark ()
  2521. {
  2522. local f flags fail=0 failures="" zero_load_alignment;
  2523. flags=${1//-};
  2524. shift;
  2525. if type -p paxctl > /dev/null && has PT ${PAX_MARKINGS}; then
  2526. einfo "PT PaX marking -${flags}";
  2527. _pax_list_files einfo "$@";
  2528. for f in "$@";
  2529. do
  2530. paxctl -q${flags} "${f}" && continue;
  2531. paxctl -qc${flags} "${f}" && continue;
  2532. paxctl -qC${flags} "${f}" && continue;
  2533. fail=1;
  2534. failures="${failures} ${f}";
  2535. done;
  2536. else
  2537. if type -p scanelf > /dev/null && [[ ${PAX_MARKINGS} != "none" ]]; then
  2538. einfo "Fallback PaX marking -${flags}";
  2539. _pax_list_files einfo "$@";
  2540. scanelf -Xxz ${flags} "$@";
  2541. else
  2542. if [[ ${PAX_MARKINGS} != "none" ]]; then
  2543. failures="$*";
  2544. fail=1;
  2545. fi;
  2546. fi;
  2547. fi;
  2548. if [[ ${fail} == 1 ]]; then
  2549. ewarn "Failed to set PaX markings -${flags} for:";
  2550. _pax_list_files ewarn ${failures};
  2551. ewarn "Executables may be killed by PaX kernels.";
  2552. fi;
  2553. return ${fail}
  2554. }
  2555. pkg_nofetch ()
  2556. {
  2557. __eapi0_pkg_nofetch "$@"
  2558. }
  2559. pkg_setup ()
  2560. {
  2561. python_set_active_version 2;
  2562. python_pkg_setup
  2563. }
  2564. preserve_old_lib ()
  2565. {
  2566. if [[ ${EBUILD_PHASE} != "preinst" ]]; then
  2567. eerror "preserve_old_lib() must be called from pkg_preinst() only";
  2568. die "Invalid preserve_old_lib() usage";
  2569. fi;
  2570. [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]";
  2571. has preserve-libs ${FEATURES} && return 0;
  2572. local lib dir;
  2573. for lib in "$@";
  2574. do
  2575. [[ -e ${ROOT}/${lib} ]] || continue;
  2576. dir=${lib%/*};
  2577. dodir ${dir} || die "dodir ${dir} failed";
  2578. cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed";
  2579. touch "${D}"/${lib};
  2580. done
  2581. }
  2582. preserve_old_lib_notify ()
  2583. {
  2584. if [[ ${EBUILD_PHASE} != "postinst" ]]; then
  2585. eerror "preserve_old_lib_notify() must be called from pkg_postinst() only";
  2586. die "Invalid preserve_old_lib_notify() usage";
  2587. fi;
  2588. has preserve-libs ${FEATURES} && return 0;
  2589. local lib notice=0;
  2590. for lib in "$@";
  2591. do
  2592. [[ -e ${ROOT}/${lib} ]] || continue;
  2593. if [[ ${notice} -eq 0 ]]; then
  2594. notice=1;
  2595. ewarn "Old versions of installed libraries were detected on your system.";
  2596. ewarn "In order to avoid breaking packages that depend on these old libs,";
  2597. ewarn "the libraries are not being removed. You need to run revdep-rebuild";
  2598. ewarn "in order to remove these old dependencies. If you do not have this";
  2599. ewarn "helper program, simply emerge the 'gentoolkit' package.";
  2600. ewarn;
  2601. fi;
  2602. ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'";
  2603. done
  2604. }
  2605. prune_libtool_files ()
  2606. {
  2607. debug-print-function ${FUNCNAME} "$@";
  2608. local removing_all removing_modules opt;
  2609. for opt in "$@";
  2610. do
  2611. case "${opt}" in
  2612. --all)
  2613. removing_all=1;
  2614. removing_modules=1
  2615. ;;
  2616. --modules)
  2617. removing_modules=1
  2618. ;;
  2619. *)
  2620. die "Invalid argument to ${FUNCNAME}(): ${opt}"
  2621. ;;
  2622. esac;
  2623. done;
  2624. local f;
  2625. local queue=();
  2626. while IFS= read -r -d '' f; do
  2627. local archivefile=${f/%.la/.a};
  2628. [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed';
  2629. local reason pkgconfig_scanned;
  2630. if grep -q '^shouldnotlink=yes$' "${f}"; then
  2631. if [[ -f ${archivefile} ]]; then
  2632. einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)";
  2633. queue+=("${archivefile}");
  2634. fi;
  2635. if [[ -n ${removing_modules} ]]; then
  2636. reason='module';
  2637. fi;
  2638. else
  2639. if [[ -n ${removing_all} ]]; then
  2640. reason='requested';
  2641. else
  2642. if [[ ! -f ${archivefile} ]]; then
  2643. reason='no static archive';
  2644. else
  2645. if [[ ! -n $(sed -nre "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" "${f}") ]]; then
  2646. reason='no libs & flags';
  2647. else
  2648. if [[ ! -n ${pkgconfig_scanned} ]]; then
  2649. local pc_libs=();
  2650. if [[ ! -n ${removing_all} ]]; then
  2651. local pc;
  2652. local tf=${T}/prune-lt-files.pc;
  2653. local pkgconf=$(tc-getPKG_CONFIG);
  2654. while IFS= read -r -d '' pc; do
  2655. local arg;
  2656. sed -e '/^Requires:/d' "${pc}" > "${tf}";
  2657. for arg in $("${pkgconf}" --libs "${tf}");
  2658. do
  2659. [[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la);
  2660. done;
  2661. done < <(find "${D}" -type f -name '*.pc' -print0);
  2662. rm -f "${tf}";
  2663. fi;
  2664. pkgconfig_scanned=1;
  2665. fi;
  2666. has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc';
  2667. fi;
  2668. fi;
  2669. fi;
  2670. fi;
  2671. if [[ -n ${reason} ]]; then
  2672. einfo "Removing unnecessary ${f#${D%/}} (${reason})";
  2673. queue+=("${f}");
  2674. fi;
  2675. done < <(find "${D}" -xtype f -name '*.la' -print0);
  2676. if [[ -n ${queue[@]} ]]; then
  2677. rm -f "${queue[@]}";
  2678. fi
  2679. }
  2680. python_clean_installation_image ()
  2681. {
  2682. if [[ "${EBUILD_PHASE}" != "install" ]]; then
  2683. die "${FUNCNAME}() can be used only in src_install() phase";
  2684. fi;
  2685. _python_check_python_pkg_setup_execution;
  2686. _python_initialize_prefix_variables;
  2687. local file files=() quiet="0";
  2688. while (($#)); do
  2689. case "$1" in
  2690. -q | --quiet)
  2691. quiet="1"
  2692. ;;
  2693. -*)
  2694. die "${FUNCNAME}(): Unrecognized option '$1'"
  2695. ;;
  2696. *)
  2697. die "${FUNCNAME}(): Invalid usage"
  2698. ;;
  2699. esac;
  2700. shift;
  2701. done;
  2702. while read -d '' -r file; do
  2703. files+=("${file}");
  2704. done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0);
  2705. if [[ "${#files[@]}" -gt 0 ]]; then
  2706. if [[ "${quiet}" == "0" ]]; then
  2707. ewarn "Deleting byte-compiled Python modules needlessly generated by build system:";
  2708. fi;
  2709. for file in "${files[@]}";
  2710. do
  2711. if [[ "${quiet}" == "0" ]]; then
  2712. ewarn " ${file}";
  2713. fi;
  2714. rm -f "${file}";
  2715. if [[ "${file%/*}" == *"/__pycache__" ]]; then
  2716. rmdir "${file%/*}" 2> /dev/null;
  2717. fi;
  2718. done;
  2719. fi;
  2720. function python_clean_sitedirs ()
  2721. {
  2722. if [[ -d "${ED}$(python_get_sitedir)" ]]; then
  2723. find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f;
  2724. fi
  2725. };
  2726. if _python_package_supporting_installation_for_multiple_python_abis; then
  2727. python_execute_function -q python_clean_sitedirs;
  2728. else
  2729. python_clean_sitedirs;
  2730. fi;
  2731. unset -f python_clean_sitedirs
  2732. }
  2733. python_clean_py-compile_files ()
  2734. {
  2735. _python_check_python_pkg_setup_execution;
  2736. local file files=() quiet="0";
  2737. while (($#)); do
  2738. case "$1" in
  2739. -q | --quiet)
  2740. quiet="1"
  2741. ;;
  2742. -*)
  2743. die "${FUNCNAME}(): Unrecognized option '$1'"
  2744. ;;
  2745. *)
  2746. die "${FUNCNAME}(): Invalid usage"
  2747. ;;
  2748. esac;
  2749. shift;
  2750. done;
  2751. while read -d '' -r file; do
  2752. files+=("${file#./}");
  2753. done < <(find -name py-compile -type f -print0);
  2754. for file in "${files[@]}";
  2755. do
  2756. if [[ "${quiet}" == "0" ]]; then
  2757. einfo "Cleaning '${file}' file";
  2758. fi;
  2759. echo "#!/bin/sh" > "${file}";
  2760. done
  2761. }
  2762. python_convert_shebangs ()
  2763. {
  2764. _python_check_python_pkg_setup_execution;
  2765. local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" shebangs_converted="0";
  2766. while (($#)); do
  2767. case "$1" in
  2768. -r | --recursive)
  2769. recursive="1"
  2770. ;;
  2771. -q | --quiet)
  2772. quiet="1"
  2773. ;;
  2774. -x | --only-executables)
  2775. only_executables="1"
  2776. ;;
  2777. --)
  2778. shift;
  2779. break
  2780. ;;
  2781. -*)
  2782. die "${FUNCNAME}(): Unrecognized option '$1'"
  2783. ;;
  2784. *)
  2785. break
  2786. ;;
  2787. esac;
  2788. shift;
  2789. done;
  2790. if [[ "$#" -eq 0 ]]; then
  2791. die "${FUNCNAME}(): Missing Python version and files or directories";
  2792. else
  2793. if [[ "$#" -eq 1 ]]; then
  2794. die "${FUNCNAME}(): Missing files or directories";
  2795. fi;
  2796. fi;
  2797. if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
  2798. python_interpreter="$(PYTHON "$1")";
  2799. else
  2800. python_interpreter="python$1";
  2801. fi;
  2802. shift;
  2803. for argument in "$@";
  2804. do
  2805. if [[ ! -e "${argument}" ]]; then
  2806. die "${FUNCNAME}(): '${argument}' does not exist";
  2807. else
  2808. if [[ -f "${argument}" ]]; then
  2809. files+=("${argument}");
  2810. else
  2811. if [[ -d "${argument}" ]]; then
  2812. if [[ "${recursive}" == "1" ]]; then
  2813. while read -d '' -r file; do
  2814. files+=("${file}");
  2815. done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0);
  2816. else
  2817. die "${FUNCNAME}(): '${argument}' is not a regular file";
  2818. fi;
  2819. else
  2820. die "${FUNCNAME}(): '${argument}' is not a regular file or a directory";
  2821. fi;
  2822. fi;
  2823. fi;
  2824. done;
  2825. for file in "${files[@]}";
  2826. do
  2827. file="${file#./}";
  2828. [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue;
  2829. if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then
  2830. [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue;
  2831. shebangs_converted="1";
  2832. if [[ "${quiet}" == "0" ]]; then
  2833. einfo "Converting shebang in '${file}'";
  2834. fi;
  2835. sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed";
  2836. fi;
  2837. done;
  2838. if [[ "${shebangs_converted}" == "0" ]]; then
  2839. ewarn "${FUNCNAME}(): Python scripts not found";
  2840. fi
  2841. }
  2842. python_copy_sources ()
  2843. {
  2844. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  2845. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  2846. fi;
  2847. _python_check_python_pkg_setup_execution;
  2848. local dir dirs=() PYTHON_ABI;
  2849. if [[ "$#" -eq 0 ]]; then
  2850. if [[ "${WORKDIR}" == "${S}" ]]; then
  2851. die "${FUNCNAME}() cannot be used with current value of S variable";
  2852. fi;
  2853. dirs=("${S%/}");
  2854. else
  2855. dirs=("$@");
  2856. fi;
  2857. _python_calculate_PYTHON_ABIS;
  2858. for PYTHON_ABI in ${PYTHON_ABIS};
  2859. do
  2860. for dir in "${dirs[@]}";
  2861. do
  2862. cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed";
  2863. done;
  2864. done
  2865. }
  2866. python_disable_pyc ()
  2867. {
  2868. _python_check_python_pkg_setup_execution;
  2869. if [[ "$#" -ne 0 ]]; then
  2870. die "${FUNCNAME}() does not accept arguments";
  2871. fi;
  2872. export PYTHONDONTWRITEBYTECODE="1"
  2873. }
  2874. python_enable_pyc ()
  2875. {
  2876. _python_check_python_pkg_setup_execution;
  2877. if [[ "$#" -ne 0 ]]; then
  2878. die "${FUNCNAME}() does not accept arguments";
  2879. fi;
  2880. unset PYTHONDONTWRITEBYTECODE
  2881. }
  2882. python_execute_function ()
  2883. {
  2884. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  2885. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  2886. fi;
  2887. _python_check_python_pkg_setup_execution;
  2888. _python_set_color_variables;
  2889. local action action_message action_message_template default_function="0" failure_message failure_message_template final_ABI="0" function iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" return_code separate_build_dirs="0" source_dir;
  2890. while (($#)); do
  2891. case "$1" in
  2892. --action-message)
  2893. action_message_template="$2";
  2894. shift
  2895. ;;
  2896. -d | --default-function)
  2897. default_function="1"
  2898. ;;
  2899. --failure-message)
  2900. failure_message_template="$2";
  2901. shift
  2902. ;;
  2903. -f | --final-ABI)
  2904. final_ABI="1"
  2905. ;;
  2906. --nonfatal)
  2907. nonfatal="1"
  2908. ;;
  2909. -q | --quiet)
  2910. quiet="1"
  2911. ;;
  2912. -s | --separate-build-dirs)
  2913. separate_build_dirs="1"
  2914. ;;
  2915. --source-dir)
  2916. source_dir="$2";
  2917. shift
  2918. ;;
  2919. --)
  2920. shift;
  2921. break
  2922. ;;
  2923. -*)
  2924. die "${FUNCNAME}(): Unrecognized option '$1'"
  2925. ;;
  2926. *)
  2927. break
  2928. ;;
  2929. esac;
  2930. shift;
  2931. done;
  2932. if [[ -n "${source_dir}" && "${separate_build_dirs}" == 0 ]]; then
  2933. die "${FUNCNAME}(): '--source-dir' option can be specified only with '--separate-build-dirs' option";
  2934. fi;
  2935. if [[ "${default_function}" == "0" ]]; then
  2936. if [[ "$#" -eq 0 ]]; then
  2937. die "${FUNCNAME}(): Missing function name";
  2938. fi;
  2939. function="$1";
  2940. shift;
  2941. if [[ -z "$(type -t "${function}")" ]]; then
  2942. die "${FUNCNAME}(): '${function}' function is not defined";
  2943. fi;
  2944. else
  2945. if has "${EAPI:-0}" 0 1; then
  2946. die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI";
  2947. fi;
  2948. if [[ "${EBUILD_PHASE}" == "configure" ]]; then
  2949. if has "${EAPI}" 2 3; then
  2950. function python_default_function ()
  2951. {
  2952. econf "$@"
  2953. };
  2954. else
  2955. function python_default_function ()
  2956. {
  2957. nonfatal econf "$@"
  2958. };
  2959. fi;
  2960. else
  2961. if [[ "${EBUILD_PHASE}" == "compile" ]]; then
  2962. function python_default_function ()
  2963. {
  2964. emake "$@"
  2965. };
  2966. else
  2967. if [[ "${EBUILD_PHASE}" == "test" ]]; then
  2968. function python_default_function ()
  2969. {
  2970. local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}";
  2971. if ${emake_cmd} -j1 -n check &>/dev/null; then
  2972. ${emake_cmd} -j1 check "$@";
  2973. else
  2974. if ${emake_cmd} -j1 -n test &>/dev/null; then
  2975. ${emake_cmd} -j1 test "$@";
  2976. fi;
  2977. fi
  2978. };
  2979. else
  2980. if [[ "${EBUILD_PHASE}" == "install" ]]; then
  2981. function python_default_function ()
  2982. {
  2983. emake DESTDIR="${D}" install "$@"
  2984. };
  2985. else
  2986. die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase";
  2987. fi;
  2988. fi;
  2989. fi;
  2990. fi;
  2991. function="python_default_function";
  2992. fi;
  2993. if _python_abi-specific_local_scope; then
  2994. die "${FUNCNAME}(): Invalid call stack";
  2995. fi;
  2996. if [[ "${quiet}" == "0" ]]; then
  2997. [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up";
  2998. [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking";
  2999. [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation";
  3000. [[ "${EBUILD_PHASE}" == "configure" ]] && action="Configuration";
  3001. [[ "${EBUILD_PHASE}" == "compile" ]] && action="Building";
  3002. [[ "${EBUILD_PHASE}" == "test" ]] && action="Testing";
  3003. [[ "${EBUILD_PHASE}" == "install" ]] && action="Installation";
  3004. [[ "${EBUILD_PHASE}" == "preinst" ]] && action="Preinstallation";
  3005. [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation";
  3006. [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation";
  3007. [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation";
  3008. fi;
  3009. _python_calculate_PYTHON_ABIS;
  3010. if [[ "${final_ABI}" == "1" ]]; then
  3011. iterated_PYTHON_ABIS="$(PYTHON -f --ABI)";
  3012. else
  3013. iterated_PYTHON_ABIS="${PYTHON_ABIS}";
  3014. fi;
  3015. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  3016. do
  3017. if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then
  3018. if [[ "${quiet}" == "0" ]]; then
  3019. echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation_and_version) skipped${_NORMAL}";
  3020. fi;
  3021. continue;
  3022. fi;
  3023. _python_prepare_flags;
  3024. if [[ "${quiet}" == "0" ]]; then
  3025. if [[ -n "${action_message_template}" ]]; then
  3026. eval "action_message=\"${action_message_template}\"";
  3027. else
  3028. action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation_and_version)...";
  3029. fi;
  3030. echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}";
  3031. fi;
  3032. if [[ "${separate_build_dirs}" == "1" ]]; then
  3033. if [[ -n "${source_dir}" ]]; then
  3034. export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}";
  3035. else
  3036. export BUILDDIR="${S}-${PYTHON_ABI}";
  3037. fi;
  3038. pushd "${BUILDDIR}" > /dev/null || die "pushd failed";
  3039. else
  3040. export BUILDDIR="${S}";
  3041. fi;
  3042. previous_directory="$(pwd)";
  3043. previous_directory_stack="$(dirs -p)";
  3044. previous_directory_stack_length="$(dirs -p | wc -l)";
  3045. if ! has "${EAPI}" 0 1 2 3 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
  3046. EPYTHON="$(PYTHON)" nonfatal "${function}" "$@";
  3047. else
  3048. EPYTHON="$(PYTHON)" "${function}" "$@";
  3049. fi;
  3050. return_code="$?";
  3051. _python_restore_flags;
  3052. if [[ "${return_code}" -ne 0 ]]; then
  3053. if [[ -n "${failure_message_template}" ]]; then
  3054. eval "failure_message=\"${failure_message_template}\"";
  3055. else
  3056. failure_message="${action} failed with $(python_get_implementation_and_version) in ${function}() function";
  3057. fi;
  3058. if [[ "${nonfatal}" == "1" ]]; then
  3059. if [[ "${quiet}" == "0" ]]; then
  3060. ewarn "${failure_message}";
  3061. fi;
  3062. else
  3063. if [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
  3064. if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
  3065. local enabled_PYTHON_ABIS= other_PYTHON_ABI;
  3066. for other_PYTHON_ABI in ${PYTHON_ABIS};
  3067. do
  3068. [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}";
  3069. done;
  3070. export PYTHON_ABIS="${enabled_PYTHON_ABIS}";
  3071. fi;
  3072. if [[ "${quiet}" == "0" ]]; then
  3073. ewarn "${failure_message}";
  3074. fi;
  3075. if [[ -z "${PYTHON_ABIS}" ]]; then
  3076. die "${function}() function failed with all enabled Python ABIs";
  3077. fi;
  3078. else
  3079. die "${failure_message}";
  3080. fi;
  3081. fi;
  3082. fi;
  3083. if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then
  3084. die "Directory stack decreased illegally";
  3085. fi;
  3086. while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do
  3087. popd > /dev/null || die "popd failed";
  3088. done;
  3089. cd "${previous_directory}";
  3090. if [[ "$(dirs -p)" != "${previous_directory_stack}" ]]; then
  3091. die "Directory stack changed illegally";
  3092. fi;
  3093. if [[ "${separate_build_dirs}" == "1" ]]; then
  3094. popd > /dev/null || die "popd failed";
  3095. fi;
  3096. unset BUILDDIR;
  3097. done;
  3098. if [[ "${default_function}" == "1" ]]; then
  3099. unset -f python_default_function;
  3100. fi
  3101. }
  3102. python_execute_nosetests ()
  3103. {
  3104. _python_check_python_pkg_setup_execution;
  3105. _python_set_color_variables;
  3106. local PYTHONPATH_template separate_build_dirs;
  3107. while (($#)); do
  3108. case "$1" in
  3109. -P | --PYTHONPATH)
  3110. PYTHONPATH_template="$2";
  3111. shift
  3112. ;;
  3113. -s | --separate-build-dirs)
  3114. separate_build_dirs="1"
  3115. ;;
  3116. --)
  3117. shift;
  3118. break
  3119. ;;
  3120. -*)
  3121. die "${FUNCNAME}(): Unrecognized option '$1'"
  3122. ;;
  3123. *)
  3124. break
  3125. ;;
  3126. esac;
  3127. shift;
  3128. done;
  3129. function python_test_function ()
  3130. {
  3131. local evaluated_PYTHONPATH;
  3132. eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"";
  3133. _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook pre;
  3134. if [[ -n "${evaluated_PYTHONPATH}" ]]; then
  3135. echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL};
  3136. PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?";
  3137. else
  3138. echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL};
  3139. nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?";
  3140. fi;
  3141. _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook post
  3142. };
  3143. if _python_package_supporting_installation_for_multiple_python_abis; then
  3144. python_execute_function ${separate_build_dirs:+-s} python_test_function "$@";
  3145. else
  3146. if [[ -n "${separate_build_dirs}" ]]; then
  3147. die "${FUNCNAME}(): Invalid usage";
  3148. fi;
  3149. python_test_function "$@" || die "Testing failed";
  3150. fi;
  3151. unset -f python_test_function
  3152. }
  3153. python_execute_py.test ()
  3154. {
  3155. _python_check_python_pkg_setup_execution;
  3156. _python_set_color_variables;
  3157. local PYTHONPATH_template separate_build_dirs;
  3158. while (($#)); do
  3159. case "$1" in
  3160. -P | --PYTHONPATH)
  3161. PYTHONPATH_template="$2";
  3162. shift
  3163. ;;
  3164. -s | --separate-build-dirs)
  3165. separate_build_dirs="1"
  3166. ;;
  3167. --)
  3168. shift;
  3169. break
  3170. ;;
  3171. -*)
  3172. die "${FUNCNAME}(): Unrecognized option '$1'"
  3173. ;;
  3174. *)
  3175. break
  3176. ;;
  3177. esac;
  3178. shift;
  3179. done;
  3180. function python_test_function ()
  3181. {
  3182. local evaluated_PYTHONPATH;
  3183. eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"";
  3184. _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook pre;
  3185. if [[ -n "${evaluated_PYTHONPATH}" ]]; then
  3186. echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL};
  3187. PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?";
  3188. else
  3189. echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL};
  3190. py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?";
  3191. fi;
  3192. _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook post
  3193. };
  3194. if _python_package_supporting_installation_for_multiple_python_abis; then
  3195. python_execute_function ${separate_build_dirs:+-s} python_test_function "$@";
  3196. else
  3197. if [[ -n "${separate_build_dirs}" ]]; then
  3198. die "${FUNCNAME}(): Invalid usage";
  3199. fi;
  3200. python_test_function "$@" || die "Testing failed";
  3201. fi;
  3202. unset -f python_test_function
  3203. }
  3204. python_execute_trial ()
  3205. {
  3206. _python_check_python_pkg_setup_execution;
  3207. _python_set_color_variables;
  3208. local PYTHONPATH_template separate_build_dirs;
  3209. while (($#)); do
  3210. case "$1" in
  3211. -P | --PYTHONPATH)
  3212. PYTHONPATH_template="$2";
  3213. shift
  3214. ;;
  3215. -s | --separate-build-dirs)
  3216. separate_build_dirs="1"
  3217. ;;
  3218. --)
  3219. shift;
  3220. break
  3221. ;;
  3222. -*)
  3223. die "${FUNCNAME}(): Unrecognized option '$1'"
  3224. ;;
  3225. *)
  3226. break
  3227. ;;
  3228. esac;
  3229. shift;
  3230. done;
  3231. function python_test_function ()
  3232. {
  3233. local evaluated_PYTHONPATH;
  3234. eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"";
  3235. _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook pre;
  3236. if [[ -n "${evaluated_PYTHONPATH}" ]]; then
  3237. echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL};
  3238. PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?";
  3239. else
  3240. echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL};
  3241. trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?";
  3242. fi;
  3243. _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook post
  3244. };
  3245. if _python_package_supporting_installation_for_multiple_python_abis; then
  3246. python_execute_function ${separate_build_dirs:+-s} python_test_function "$@";
  3247. else
  3248. if [[ -n "${separate_build_dirs}" ]]; then
  3249. die "${FUNCNAME}(): Invalid usage";
  3250. fi;
  3251. python_test_function "$@" || die "Testing failed";
  3252. fi;
  3253. unset -f python_test_function
  3254. }
  3255. python_generate_wrapper_scripts ()
  3256. {
  3257. if [[ "${EBUILD_PHASE}" != "install" ]]; then
  3258. die "${FUNCNAME}() can be used only in src_install() phase";
  3259. fi;
  3260. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3261. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3262. fi;
  3263. _python_check_python_pkg_setup_execution;
  3264. _python_initialize_prefix_variables;
  3265. local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0";
  3266. while (($#)); do
  3267. case "$1" in
  3268. -E | --respect-EPYTHON)
  3269. respect_EPYTHON="1"
  3270. ;;
  3271. -f | --force)
  3272. force="1"
  3273. ;;
  3274. -q | --quiet)
  3275. quiet="1"
  3276. ;;
  3277. --)
  3278. shift;
  3279. break
  3280. ;;
  3281. -*)
  3282. die "${FUNCNAME}(): Unrecognized option '$1'"
  3283. ;;
  3284. *)
  3285. break
  3286. ;;
  3287. esac;
  3288. shift;
  3289. done;
  3290. if [[ "$#" -eq 0 ]]; then
  3291. die "${FUNCNAME}(): Missing arguments";
  3292. fi;
  3293. _python_calculate_PYTHON_ABIS;
  3294. for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}";
  3295. do
  3296. if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
  3297. python2_enabled="1";
  3298. fi;
  3299. done;
  3300. for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}";
  3301. do
  3302. if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
  3303. python3_enabled="1";
  3304. fi;
  3305. done;
  3306. if [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "1" ]]; then
  3307. eselect_python_option=;
  3308. else
  3309. if [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "0" ]]; then
  3310. eselect_python_option="--python2";
  3311. else
  3312. if [[ "${python2_enabled}" == "0" && "${python3_enabled}" == "1" ]]; then
  3313. eselect_python_option="--python3";
  3314. else
  3315. die "${FUNCNAME}(): Unsupported environment";
  3316. fi;
  3317. fi;
  3318. fi;
  3319. PYTHON_ABIS_list="$("$(PYTHON -f)" -c "print(', '.join('\"%s\"' % x for x in reversed('${PYTHON_ABIS}'.split())))")";
  3320. for file in "$@";
  3321. do
  3322. if [[ -f "${file}" && "${force}" == "0" ]]; then
  3323. die "${FUNCNAME}(): '${file}' already exists";
  3324. fi;
  3325. if [[ "${quiet}" == "0" ]]; then
  3326. einfo "Generating '${file#${ED%/}}' wrapper script";
  3327. fi;
  3328. cat > "${file}" <<EOF
  3329. #!/usr/bin/env python
  3330. # Gentoo '${file##*/}' wrapper script generated by python_generate_wrapper_scripts()
  3331.  
  3332. import os
  3333. import re
  3334. import subprocess
  3335. import sys
  3336.  
  3337. cpython_ABI_re = re.compile(r"^(\d+\.\d+)$")
  3338. jython_ABI_re = re.compile(r"^(\d+\.\d+)-jython$")
  3339. pypy_ABI_re = re.compile(r"^\d+\.\d+-pypy-(\d+\.\d+)$")
  3340. cpython_interpreter_re = re.compile(r"^python(\d+\.\d+)$")
  3341. jython_interpreter_re = re.compile(r"^jython(\d+\.\d+)$")
  3342. pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$")
  3343. cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)")
  3344. python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)")
  3345. python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
  3346.  
  3347. #pypy_versions_mapping = {
  3348. # "1.5": "2.7",
  3349. # "1.6": "2.7",
  3350. # "1.7": "2.7",
  3351. # "1.8": "2.7",
  3352. # "1.9": "2.7",
  3353. # "2.0": "2.7",
  3354. #}
  3355.  
  3356. def get_PYTHON_ABI(python_interpreter):
  3357. cpython_matched = cpython_interpreter_re.match(python_interpreter)
  3358. jython_matched = jython_interpreter_re.match(python_interpreter)
  3359. pypy_matched = pypy_interpreter_re.match(python_interpreter)
  3360. if cpython_matched is not None:
  3361. PYTHON_ABI = cpython_matched.group(1)
  3362. elif jython_matched is not None:
  3363. PYTHON_ABI = jython_matched.group(1) + "-jython"
  3364. elif pypy_matched is not None:
  3365. #PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1)
  3366. PYTHON_ABI = "2.7-pypy-" + pypy_matched.group(1)
  3367. else:
  3368. PYTHON_ABI = None
  3369. return PYTHON_ABI
  3370.  
  3371. def get_python_interpreter(PYTHON_ABI):
  3372. cpython_matched = cpython_ABI_re.match(PYTHON_ABI)
  3373. jython_matched = jython_ABI_re.match(PYTHON_ABI)
  3374. pypy_matched = pypy_ABI_re.match(PYTHON_ABI)
  3375. if cpython_matched is not None:
  3376. python_interpreter = "python" + cpython_matched.group(1)
  3377. elif jython_matched is not None:
  3378. python_interpreter = "jython" + jython_matched.group(1)
  3379. elif pypy_matched is not None:
  3380. python_interpreter = "pypy-c" + pypy_matched.group(1)
  3381. else:
  3382. python_interpreter = None
  3383. return python_interpreter
  3384.  
  3385. EOF
  3386.  
  3387. if [[ "$?" != "0" ]]; then
  3388. die "${FUNCNAME}(): Generation of '$1' failed";
  3389. fi;
  3390. if [[ "${respect_EPYTHON}" == "1" ]]; then
  3391. cat >> "${file}" <<EOF
  3392. python_interpreter = os.environ.get("EPYTHON")
  3393. if python_interpreter:
  3394. PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
  3395. if PYTHON_ABI is None:
  3396. sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
  3397. sys.exit(1)
  3398. else:
  3399. try:
  3400. environment = os.environ.copy()
  3401. environment["ROOT"] = "/"
  3402. eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE)
  3403. if eselect_process.wait() != 0:
  3404. raise ValueError
  3405. except (OSError, ValueError):
  3406. sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
  3407. sys.exit(1)
  3408.  
  3409. python_interpreter = eselect_process.stdout.read()
  3410. if not isinstance(python_interpreter, str):
  3411. # Python 3
  3412. python_interpreter = python_interpreter.decode()
  3413. python_interpreter = python_interpreter.rstrip("\n")
  3414.  
  3415. PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
  3416. if PYTHON_ABI is None:
  3417. sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
  3418. sys.exit(1)
  3419.  
  3420. wrapper_script_path = os.path.realpath(sys.argv[0])
  3421. target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
  3422. if not os.path.exists(target_executable_path):
  3423. sys.stderr.write("%s: '%s' does not exist\n" % (sys.argv[0], target_executable_path))
  3424. sys.exit(1)
  3425. EOF
  3426.  
  3427. if [[ "$?" != "0" ]]; then
  3428. die "${FUNCNAME}(): Generation of '$1' failed";
  3429. fi;
  3430. else
  3431. cat >> "${file}" <<EOF
  3432. try:
  3433. environment = os.environ.copy()
  3434. environment["ROOT"] = "/"
  3435. eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE)
  3436. if eselect_process.wait() != 0:
  3437. raise ValueError
  3438. except (OSError, ValueError):
  3439. sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
  3440. sys.exit(1)
  3441.  
  3442. python_interpreter = eselect_process.stdout.read()
  3443. if not isinstance(python_interpreter, str):
  3444. # Python 3
  3445. python_interpreter = python_interpreter.decode()
  3446. python_interpreter = python_interpreter.rstrip("\n")
  3447.  
  3448. PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
  3449. if PYTHON_ABI is None:
  3450. sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
  3451. sys.exit(1)
  3452.  
  3453. wrapper_script_path = os.path.realpath(sys.argv[0])
  3454. for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
  3455. target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
  3456. if os.path.exists(target_executable_path):
  3457. break
  3458. else:
  3459. sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path))
  3460. sys.exit(1)
  3461.  
  3462. python_interpreter = get_python_interpreter(PYTHON_ABI)
  3463. if python_interpreter is None:
  3464. sys.stderr.write("%s: Unrecognized Python ABI '%s'\n" % (sys.argv[0], PYTHON_ABI))
  3465. sys.exit(1)
  3466. EOF
  3467.  
  3468. if [[ "$?" != "0" ]]; then
  3469. die "${FUNCNAME}(): Generation of '$1' failed";
  3470. fi;
  3471. fi
  3472. cat >> "${file}" <<EOF
  3473.  
  3474. target_executable = open(target_executable_path, "rb")
  3475. target_executable_first_line = target_executable.readline()
  3476. target_executable.close()
  3477. if not isinstance(target_executable_first_line, str):
  3478. # Python 3
  3479. target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
  3480.  
  3481. options = []
  3482. python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line)
  3483. if python_shebang_options_matched is not None:
  3484. options = [python_shebang_options_matched.group(1)]
  3485.  
  3486. cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line)
  3487.  
  3488. if cpython_shebang_matched is not None:
  3489. try:
  3490. python_interpreter_path = "${EPREFIX}/usr/bin/%s" % python_interpreter
  3491. os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
  3492. python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
  3493. del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
  3494. if python_verification_process.wait() != 0:
  3495. raise ValueError
  3496.  
  3497. python_verification_output = python_verification_process.stdout.read()
  3498. if not isinstance(python_verification_output, str):
  3499. # Python 3
  3500. python_verification_output = python_verification_output.decode()
  3501.  
  3502. if not python_verification_output_re.match(python_verification_output):
  3503. raise ValueError
  3504.  
  3505. if cpython_interpreter_re.match(python_interpreter) is not None:
  3506. os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
  3507. os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
  3508. os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
  3509.  
  3510. if hasattr(os, "execv"):
  3511. os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv)
  3512. else:
  3513. sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait())
  3514. except (KeyboardInterrupt, SystemExit):
  3515. raise
  3516. except:
  3517. pass
  3518. for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"):
  3519. if variable in os.environ:
  3520. del os.environ[variable]
  3521.  
  3522. if hasattr(os, "execv"):
  3523. os.execv(target_executable_path, sys.argv)
  3524. else:
  3525. sys.exit(subprocess.Popen([target_executable_path] + sys.argv[1:]).wait())
  3526. EOF
  3527.  
  3528. if [[ "$?" != "0" ]]; then
  3529. die "${FUNCNAME}(): Generation of '$1' failed";
  3530. fi;
  3531. fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed";
  3532. done
  3533. }
  3534. python_get_implementation ()
  3535. {
  3536. _python_check_python_pkg_setup_execution;
  3537. local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}";
  3538. while (($#)); do
  3539. case "$1" in
  3540. -f | --final-ABI)
  3541. final_ABI="1"
  3542. ;;
  3543. -*)
  3544. die "${FUNCNAME}(): Unrecognized option '$1'"
  3545. ;;
  3546. *)
  3547. die "${FUNCNAME}(): Invalid usage"
  3548. ;;
  3549. esac;
  3550. shift;
  3551. done;
  3552. if [[ "${final_ABI}" == "1" ]]; then
  3553. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3554. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3555. fi;
  3556. PYTHON_ABI="$(PYTHON -f --ABI)";
  3557. else
  3558. if _python_package_supporting_installation_for_multiple_python_abis; then
  3559. if ! _python_abi-specific_local_scope; then
  3560. die "${FUNCNAME}() should be used in ABI-specific local scope";
  3561. fi;
  3562. else
  3563. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3564. fi;
  3565. fi;
  3566. echo "$(_python_get_implementation "${PYTHON_ABI}")"
  3567. }
  3568. python_get_implementation_and_version ()
  3569. {
  3570. _python_check_python_pkg_setup_execution;
  3571. local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}";
  3572. while (($#)); do
  3573. case "$1" in
  3574. -f | --final-ABI)
  3575. final_ABI="1"
  3576. ;;
  3577. -*)
  3578. die "${FUNCNAME}(): Unrecognized option '$1'"
  3579. ;;
  3580. *)
  3581. die "${FUNCNAME}(): Invalid usage"
  3582. ;;
  3583. esac;
  3584. shift;
  3585. done;
  3586. if [[ "${final_ABI}" == "1" ]]; then
  3587. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3588. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3589. fi;
  3590. PYTHON_ABI="$(PYTHON -f --ABI)";
  3591. else
  3592. if _python_package_supporting_installation_for_multiple_python_abis; then
  3593. if ! _python_abi-specific_local_scope; then
  3594. die "${FUNCNAME}() should be used in ABI-specific local scope";
  3595. fi;
  3596. else
  3597. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3598. fi;
  3599. fi;
  3600. if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-[[:alnum:]]+-[[:digit:]]+\.[[:digit:]]+$ ]]; then
  3601. echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI##*-} (Python ${PYTHON_ABI%%-*})";
  3602. else
  3603. echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI%%-*}";
  3604. fi
  3605. }
  3606. python_get_implementational_package ()
  3607. {
  3608. _python_check_python_pkg_setup_execution;
  3609. local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}";
  3610. while (($#)); do
  3611. case "$1" in
  3612. -f | --final-ABI)
  3613. final_ABI="1"
  3614. ;;
  3615. -*)
  3616. die "${FUNCNAME}(): Unrecognized option '$1'"
  3617. ;;
  3618. *)
  3619. die "${FUNCNAME}(): Invalid usage"
  3620. ;;
  3621. esac;
  3622. shift;
  3623. done;
  3624. if [[ "${final_ABI}" == "1" ]]; then
  3625. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3626. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3627. fi;
  3628. PYTHON_ABI="$(PYTHON -f --ABI)";
  3629. else
  3630. if _python_package_supporting_installation_for_multiple_python_abis; then
  3631. if ! _python_abi-specific_local_scope; then
  3632. die "${FUNCNAME}() should be used in ABI-specific local scope";
  3633. fi;
  3634. else
  3635. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3636. fi;
  3637. fi;
  3638. if [[ "${EAPI:-0}" == "0" ]]; then
  3639. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3640. echo "=dev-lang/python-${PYTHON_ABI}*";
  3641. else
  3642. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3643. echo "=dev-java/jython-${PYTHON_ABI%-jython}*";
  3644. else
  3645. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3646. echo "=dev-python/pypy-${PYTHON_ABI#*-pypy-}*";
  3647. fi;
  3648. fi;
  3649. fi;
  3650. else
  3651. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3652. echo "dev-lang/python:${PYTHON_ABI}";
  3653. else
  3654. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3655. echo "dev-java/jython:${PYTHON_ABI%-jython}";
  3656. else
  3657. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3658. echo "dev-python/pypy:${PYTHON_ABI#*-pypy-}";
  3659. fi;
  3660. fi;
  3661. fi;
  3662. fi
  3663. }
  3664. python_get_includedir ()
  3665. {
  3666. _python_check_python_pkg_setup_execution;
  3667. local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  3668. while (($#)); do
  3669. case "$1" in
  3670. -b | --base-path)
  3671. base_path="1"
  3672. ;;
  3673. -f | --final-ABI)
  3674. final_ABI="1"
  3675. ;;
  3676. -*)
  3677. die "${FUNCNAME}(): Unrecognized option '$1'"
  3678. ;;
  3679. *)
  3680. die "${FUNCNAME}(): Invalid usage"
  3681. ;;
  3682. esac;
  3683. shift;
  3684. done;
  3685. if [[ "${base_path}" == "0" ]]; then
  3686. prefix="/";
  3687. fi;
  3688. if [[ "${final_ABI}" == "1" ]]; then
  3689. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3690. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3691. fi;
  3692. PYTHON_ABI="$(PYTHON -f --ABI)";
  3693. else
  3694. if _python_package_supporting_installation_for_multiple_python_abis; then
  3695. if ! _python_abi-specific_local_scope; then
  3696. die "${FUNCNAME}() should be used in ABI-specific local scope";
  3697. fi;
  3698. else
  3699. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3700. fi;
  3701. fi;
  3702. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3703. echo "${prefix}usr/include/python${PYTHON_ABI}";
  3704. else
  3705. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3706. echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include";
  3707. else
  3708. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3709. echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/include";
  3710. fi;
  3711. fi;
  3712. fi
  3713. }
  3714. python_get_libdir ()
  3715. {
  3716. _python_check_python_pkg_setup_execution;
  3717. local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  3718. while (($#)); do
  3719. case "$1" in
  3720. -b | --base-path)
  3721. base_path="1"
  3722. ;;
  3723. -f | --final-ABI)
  3724. final_ABI="1"
  3725. ;;
  3726. -*)
  3727. die "${FUNCNAME}(): Unrecognized option '$1'"
  3728. ;;
  3729. *)
  3730. die "${FUNCNAME}(): Invalid usage"
  3731. ;;
  3732. esac;
  3733. shift;
  3734. done;
  3735. if [[ "${base_path}" == "0" ]]; then
  3736. prefix="/";
  3737. fi;
  3738. if [[ "${final_ABI}" == "1" ]]; then
  3739. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3740. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3741. fi;
  3742. PYTHON_ABI="$(PYTHON -f --ABI)";
  3743. else
  3744. if _python_package_supporting_installation_for_multiple_python_abis; then
  3745. if ! _python_abi-specific_local_scope; then
  3746. die "${FUNCNAME}() should be used in ABI-specific local scope";
  3747. fi;
  3748. else
  3749. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3750. fi;
  3751. fi;
  3752. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3753. echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}";
  3754. else
  3755. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3756. echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib";
  3757. else
  3758. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3759. die "${FUNCNAME}(): PyPy has multiple standard library directories";
  3760. fi;
  3761. fi;
  3762. fi
  3763. }
  3764. python_get_library ()
  3765. {
  3766. _python_check_python_pkg_setup_execution;
  3767. local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  3768. while (($#)); do
  3769. case "$1" in
  3770. -b | --base-path)
  3771. base_path="1"
  3772. ;;
  3773. -f | --final-ABI)
  3774. final_ABI="1"
  3775. ;;
  3776. -l | --linker-option)
  3777. linker_option="1"
  3778. ;;
  3779. -*)
  3780. die "${FUNCNAME}(): Unrecognized option '$1'"
  3781. ;;
  3782. *)
  3783. die "${FUNCNAME}(): Invalid usage"
  3784. ;;
  3785. esac;
  3786. shift;
  3787. done;
  3788. if [[ "${base_path}" == "0" ]]; then
  3789. prefix="/";
  3790. fi;
  3791. if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
  3792. die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously";
  3793. fi;
  3794. if [[ "${final_ABI}" == "1" ]]; then
  3795. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3796. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3797. fi;
  3798. PYTHON_ABI="$(PYTHON -f --ABI)";
  3799. else
  3800. if _python_package_supporting_installation_for_multiple_python_abis; then
  3801. if ! _python_abi-specific_local_scope; then
  3802. die "${FUNCNAME}() should be used in ABI-specific local scope";
  3803. fi;
  3804. else
  3805. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3806. fi;
  3807. fi;
  3808. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3809. if [[ "${linker_option}" == "1" ]]; then
  3810. echo "-lpython${PYTHON_ABI}";
  3811. else
  3812. echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)";
  3813. fi;
  3814. else
  3815. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3816. die "${FUNCNAME}(): Jython does not have shared library";
  3817. else
  3818. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3819. die "${FUNCNAME}(): PyPy does not have shared library";
  3820. fi;
  3821. fi;
  3822. fi
  3823. }
  3824. python_get_sitedir ()
  3825. {
  3826. _python_check_python_pkg_setup_execution;
  3827. local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  3828. while (($#)); do
  3829. case "$1" in
  3830. -b | --base-path)
  3831. base_path="1"
  3832. ;;
  3833. -f | --final-ABI)
  3834. final_ABI="1"
  3835. ;;
  3836. -*)
  3837. die "${FUNCNAME}(): Unrecognized option '$1'"
  3838. ;;
  3839. *)
  3840. die "${FUNCNAME}(): Invalid usage"
  3841. ;;
  3842. esac;
  3843. shift;
  3844. done;
  3845. if [[ "${base_path}" == "0" ]]; then
  3846. prefix="/";
  3847. fi;
  3848. if [[ "${final_ABI}" == "1" ]]; then
  3849. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3850. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3851. fi;
  3852. PYTHON_ABI="$(PYTHON -f --ABI)";
  3853. else
  3854. if _python_package_supporting_installation_for_multiple_python_abis; then
  3855. if ! _python_abi-specific_local_scope; then
  3856. die "${FUNCNAME}() should be used in ABI-specific local scope";
  3857. fi;
  3858. else
  3859. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3860. fi;
  3861. fi;
  3862. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3863. echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}/site-packages";
  3864. else
  3865. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3866. echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib/site-packages";
  3867. else
  3868. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3869. echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/site-packages";
  3870. fi;
  3871. fi;
  3872. fi
  3873. }
  3874. python_get_version ()
  3875. {
  3876. _python_check_python_pkg_setup_execution;
  3877. local final_ABI="0" language="0" language_version full="0" major="0" minor="0" micro="0" PYTHON_ABI="${PYTHON_ABI}" python_command;
  3878. while (($#)); do
  3879. case "$1" in
  3880. -f | --final-ABI)
  3881. final_ABI="1"
  3882. ;;
  3883. -l | --language)
  3884. language="1"
  3885. ;;
  3886. --full)
  3887. full="1"
  3888. ;;
  3889. --major)
  3890. major="1"
  3891. ;;
  3892. --minor)
  3893. minor="1"
  3894. ;;
  3895. --micro)
  3896. micro="1"
  3897. ;;
  3898. -*)
  3899. die "${FUNCNAME}(): Unrecognized option '$1'"
  3900. ;;
  3901. *)
  3902. die "${FUNCNAME}(): Invalid usage"
  3903. ;;
  3904. esac;
  3905. shift;
  3906. done;
  3907. if [[ "${final_ABI}" == "1" ]]; then
  3908. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3909. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3910. fi;
  3911. else
  3912. if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
  3913. die "${FUNCNAME}() should be used in ABI-specific local scope";
  3914. fi;
  3915. fi;
  3916. if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
  3917. die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously";
  3918. fi;
  3919. if [[ "${language}" == "1" ]]; then
  3920. if [[ "${final_ABI}" == "1" ]]; then
  3921. PYTHON_ABI="$(PYTHON -f --ABI)";
  3922. else
  3923. if [[ -z "${PYTHON_ABI}" ]]; then
  3924. PYTHON_ABI="$(PYTHON --ABI)";
  3925. fi;
  3926. fi;
  3927. language_version="${PYTHON_ABI%%-*}";
  3928. if [[ "${full}" == "1" ]]; then
  3929. die "${FUNCNAME}(): '--language' and '--full' options cannot be specified simultaneously";
  3930. else
  3931. if [[ "${major}" == "1" ]]; then
  3932. echo "${language_version%.*}";
  3933. else
  3934. if [[ "${minor}" == "1" ]]; then
  3935. echo "${language_version#*.}";
  3936. else
  3937. if [[ "${micro}" == "1" ]]; then
  3938. die "${FUNCNAME}(): '--language' and '--micro' options cannot be specified simultaneously";
  3939. else
  3940. echo "${language_version}";
  3941. fi;
  3942. fi;
  3943. fi;
  3944. fi;
  3945. else
  3946. if [[ "${full}" == "1" ]]; then
  3947. python_command="import sys; print('.'.join(str(x) for x in getattr(sys, 'pypy_version_info', sys.version_info)[:3]))";
  3948. else
  3949. if [[ "${major}" == "1" ]]; then
  3950. python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[0])";
  3951. else
  3952. if [[ "${minor}" == "1" ]]; then
  3953. python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[1])";
  3954. else
  3955. if [[ "${micro}" == "1" ]]; then
  3956. python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[2])";
  3957. else
  3958. if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
  3959. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3960. echo "${PYTHON_ABI}";
  3961. else
  3962. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3963. echo "${PYTHON_ABI%-jython}";
  3964. else
  3965. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3966. echo "${PYTHON_ABI#*-pypy-}";
  3967. fi;
  3968. fi;
  3969. fi;
  3970. return;
  3971. fi;
  3972. python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))";
  3973. fi;
  3974. fi;
  3975. fi;
  3976. fi;
  3977. if [[ "${final_ABI}" == "1" ]]; then
  3978. "$(PYTHON -f)" -c "${python_command}";
  3979. else
  3980. "$(PYTHON ${PYTHON_ABI})" -c "${python_command}";
  3981. fi;
  3982. fi
  3983. }
  3984. python_merge_intermediate_installation_images ()
  3985. {
  3986. if [[ "${EBUILD_PHASE}" != "install" ]]; then
  3987. die "${FUNCNAME}() can be used only in src_install() phase";
  3988. fi;
  3989. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3990. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3991. fi;
  3992. _python_check_python_pkg_setup_execution;
  3993. _python_initialize_prefix_variables;
  3994. local absolute_file b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=();
  3995. while (($#)); do
  3996. case "$1" in
  3997. -q | --quiet)
  3998. quiet="1"
  3999. ;;
  4000. --)
  4001. shift;
  4002. break
  4003. ;;
  4004. -*)
  4005. die "${FUNCNAME}(): Unrecognized option '$1'"
  4006. ;;
  4007. *)
  4008. break
  4009. ;;
  4010. esac;
  4011. shift;
  4012. done;
  4013. if [[ "$#" -ne 1 ]]; then
  4014. die "${FUNCNAME}() requires 1 argument";
  4015. fi;
  4016. intermediate_installation_images_directory="$1";
  4017. if [[ ! -d "${intermediate_installation_images_directory}" ]]; then
  4018. die "${FUNCNAME}(): Intermediate installation images directory '${intermediate_installation_images_directory}' does not exist";
  4019. fi;
  4020. _python_calculate_PYTHON_ABIS;
  4021. if [[ "$(PYTHON -f --ABI)" == 3.* ]]; then
  4022. b="b";
  4023. fi;
  4024. while read -d '' -r file; do
  4025. files+=("${file}");
  4026. done < <("$(PYTHON -f)" -c "import os
  4027. import sys
  4028.  
  4029. if hasattr(sys.stdout, 'buffer'):
  4030. # Python 3
  4031. stdout = sys.stdout.buffer
  4032. else:
  4033. # Python 2
  4034. stdout = sys.stdout
  4035.  
  4036. files_set = set()
  4037.  
  4038. os.chdir(${b}'${intermediate_installation_images_directory}')
  4039.  
  4040. for PYTHON_ABI in ${b}'${PYTHON_ABIS}'.split():
  4041. for root, dirs, files in os.walk(PYTHON_ABI + ${b}'${EPREFIX}'):
  4042. root = root[len(PYTHON_ABI + ${b}'${EPREFIX}')+1:]
  4043. files_set.update(root + ${b}'/' + file for file in files)
  4044.  
  4045. for file in sorted(files_set):
  4046. stdout.write(file)
  4047. stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of files in intermediate installation images");
  4048. for PYTHON_ABI in ${PYTHON_ABIS};
  4049. do
  4050. if [[ ! -d "${intermediate_installation_images_directory}/${PYTHON_ABI}" ]]; then
  4051. die "${FUNCNAME}(): Intermediate installation image for Python ABI '${PYTHON_ABI}' does not exist";
  4052. fi;
  4053. pushd "${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}" > /dev/null || die "pushd failed";
  4054. for file in "${files[@]}";
  4055. do
  4056. version_executable="0";
  4057. for regex in "/usr/bin/.*" "/usr/sbin/.*" "${PYTHON_VERSIONED_SCRIPTS[@]}";
  4058. do
  4059. if [[ "/${file}" =~ ^${regex}$ ]]; then
  4060. version_executable="1";
  4061. break;
  4062. fi;
  4063. done;
  4064. for regex in "${PYTHON_VERSIONED_EXECUTABLES[@]}";
  4065. do
  4066. if [[ "/${file}" =~ ^${regex}$ ]]; then
  4067. version_executable="2";
  4068. break;
  4069. fi;
  4070. done;
  4071. if [[ "${version_executable}" != "0" ]]; then
  4072. for regex in "${PYTHON_NONVERSIONED_EXECUTABLES[@]}";
  4073. do
  4074. if [[ "/${file}" =~ ^${regex}$ ]]; then
  4075. version_executable="0";
  4076. break;
  4077. fi;
  4078. done;
  4079. fi;
  4080. [[ "${version_executable}" == "0" ]] && continue;
  4081. if [[ -L "${file}" ]]; then
  4082. absolute_file="$(readlink "${file}")";
  4083. if [[ "${absolute_file}" == /* ]]; then
  4084. absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file##/}";
  4085. else
  4086. if [[ "${file}" == */* ]]; then
  4087. absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file%/*}/${absolute_file}";
  4088. else
  4089. absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file}";
  4090. fi;
  4091. fi;
  4092. else
  4093. absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file}";
  4094. fi;
  4095. [[ ! -x "${absolute_file}" ]] && continue;
  4096. shebang="$(head -n1 "${absolute_file}")" || die "Extraction of shebang from '${absolute_file}' failed";
  4097. if [[ "${version_executable}" == "2" ]]; then
  4098. wrapper_scripts+=("${ED}${file}");
  4099. else
  4100. if [[ "${version_executable}" == "1" ]]; then
  4101. if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then
  4102. wrapper_scripts+=("${ED}${file}");
  4103. else
  4104. version_executable="0";
  4105. fi;
  4106. fi;
  4107. fi;
  4108. [[ "${version_executable}" == "0" ]] && continue;
  4109. if [[ -e "${file}-${PYTHON_ABI}" ]]; then
  4110. die "${FUNCNAME}(): '${EPREFIX}/${file}-${PYTHON_ABI}' already exists";
  4111. fi;
  4112. mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed";
  4113. if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then
  4114. if [[ -L "${file}-${PYTHON_ABI}" ]]; then
  4115. python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${absolute_file}";
  4116. else
  4117. python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}";
  4118. fi;
  4119. fi;
  4120. done;
  4121. popd > /dev/null || die "popd failed";
  4122. if ROOT="/" has_version '>=sys-apps/coreutils-6.9.90'; then
  4123. cp -fr --preserve=all --no-preserve=context "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed";
  4124. else
  4125. if ROOT="/" has_version sys-apps/coreutils; then
  4126. cp -fr --preserve=all "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed";
  4127. else
  4128. cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed";
  4129. fi;
  4130. fi;
  4131. done;
  4132. rm -fr "${intermediate_installation_images_directory}";
  4133. if [[ "${#wrapper_scripts[@]}" -ge 1 ]]; then
  4134. rm -f "${T}/python_wrapper_scripts";
  4135. for file in "${wrapper_scripts[@]}";
  4136. do
  4137. echo -n "${file}" >> "${T}/python_wrapper_scripts";
  4138. echo -en "\x00" >> "${T}/python_wrapper_scripts";
  4139. done;
  4140. while read -d '' -r file; do
  4141. wrapper_scripts_set+=("${file}");
  4142. done < <("$(PYTHON -f)" -c "import sys
  4143.  
  4144. if hasattr(sys.stdout, 'buffer'):
  4145. # Python 3
  4146. stdout = sys.stdout.buffer
  4147. else:
  4148. # Python 2
  4149. stdout = sys.stdout
  4150.  
  4151. python_wrapper_scripts_file = open('${T}/python_wrapper_scripts', 'rb')
  4152. files = set(python_wrapper_scripts_file.read().rstrip(${b}'\x00').split(${b}'\x00'))
  4153. python_wrapper_scripts_file.close()
  4154.  
  4155. for file in sorted(files):
  4156. stdout.write(file)
  4157. stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts");
  4158. python_generate_wrapper_scripts $([[ "${quiet}" == "1" ]] && echo --quiet) "${wrapper_scripts_set[@]}";
  4159. fi
  4160. }
  4161. python_mod_cleanup ()
  4162. {
  4163. if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
  4164. die "${FUNCNAME}() can be used only in pkg_postrm() phase";
  4165. fi;
  4166. _python_check_python_pkg_setup_execution;
  4167. _python_initialize_prefix_variables;
  4168. local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir;
  4169. if _python_package_supporting_installation_for_multiple_python_abis; then
  4170. if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
  4171. die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called";
  4172. fi;
  4173. iterated_PYTHON_ABIS="${PYTHON_ABIS}";
  4174. else
  4175. if has "${EAPI:-0}" 0 1 2 3; then
  4176. iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4177. else
  4178. iterated_PYTHON_ABIS="${PYTHON_ABI}";
  4179. fi;
  4180. fi;
  4181. root="${EROOT%/}";
  4182. while (($#)); do
  4183. case "$1" in
  4184. --allow-evaluated-non-sitedir-paths)
  4185. allow_evaluated_non_sitedir_paths="1"
  4186. ;;
  4187. --)
  4188. shift;
  4189. break
  4190. ;;
  4191. -*)
  4192. die "${FUNCNAME}(): Unrecognized option '$1'"
  4193. ;;
  4194. *)
  4195. break
  4196. ;;
  4197. esac;
  4198. shift;
  4199. done;
  4200. if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
  4201. die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4202. fi;
  4203. if [[ "$#" -eq 0 ]]; then
  4204. die "${FUNCNAME}(): Missing files or directories";
  4205. fi;
  4206. if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
  4207. while (($#)); do
  4208. if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
  4209. die "${FUNCNAME}(): Invalid argument '$1'";
  4210. else
  4211. if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
  4212. die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories";
  4213. else
  4214. if [[ "$1" =~ ^/ ]]; then
  4215. if _python_package_supporting_installation_for_multiple_python_abis; then
  4216. if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
  4217. die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  4218. fi;
  4219. if [[ "$1" != *\$* ]]; then
  4220. die "${FUNCNAME}(): '$1' has invalid syntax";
  4221. fi;
  4222. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  4223. do
  4224. eval "search_paths+=(\"\${root}$1\")";
  4225. done;
  4226. else
  4227. search_paths+=("${root}$1");
  4228. fi;
  4229. else
  4230. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  4231. do
  4232. search_paths+=("${root}$(python_get_sitedir)/$1");
  4233. done;
  4234. fi;
  4235. fi;
  4236. fi;
  4237. shift;
  4238. done;
  4239. else
  4240. ewarn;
  4241. ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation";
  4242. ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01.";
  4243. ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax.";
  4244. ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported.";
  4245. ewarn;
  4246. search_paths=("${@#/}");
  4247. search_paths=("${search_paths[@]/#/${root}/}");
  4248. fi;
  4249. _python_clean_compiled_modules "${search_paths[@]}"
  4250. }
  4251. python_mod_optimize ()
  4252. {
  4253. if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
  4254. die "${FUNCNAME}() can be used only in pkg_postinst() phase";
  4255. fi;
  4256. _python_check_python_pkg_setup_execution;
  4257. _python_initialize_prefix_variables;
  4258. if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
  4259. local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=() stderr stderr_line;
  4260. if _python_package_supporting_installation_for_multiple_python_abis; then
  4261. if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
  4262. die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called";
  4263. fi;
  4264. iterated_PYTHON_ABIS="${PYTHON_ABIS}";
  4265. else
  4266. if has "${EAPI:-0}" 0 1 2 3; then
  4267. iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}";
  4268. else
  4269. iterated_PYTHON_ABIS="${PYTHON_ABI}";
  4270. fi;
  4271. fi;
  4272. root="${EROOT%/}";
  4273. while (($#)); do
  4274. case "$1" in
  4275. --allow-evaluated-non-sitedir-paths)
  4276. allow_evaluated_non_sitedir_paths="1"
  4277. ;;
  4278. -l | -f | -q)
  4279. options+=("$1")
  4280. ;;
  4281. -d | -x)
  4282. options+=("$1" "$2");
  4283. shift
  4284. ;;
  4285. --)
  4286. shift;
  4287. break
  4288. ;;
  4289. -*)
  4290. die "${FUNCNAME}(): Unrecognized option '$1'"
  4291. ;;
  4292. *)
  4293. break
  4294. ;;
  4295. esac;
  4296. shift;
  4297. done;
  4298. if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
  4299. die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4300. fi;
  4301. if [[ "$#" -eq 0 ]]; then
  4302. die "${FUNCNAME}(): Missing files or directories";
  4303. fi;
  4304. while (($#)); do
  4305. if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
  4306. die "${FUNCNAME}(): Invalid argument '$1'";
  4307. else
  4308. if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
  4309. die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories";
  4310. else
  4311. if [[ "$1" =~ ^/ ]]; then
  4312. if _python_package_supporting_installation_for_multiple_python_abis; then
  4313. if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
  4314. die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  4315. fi;
  4316. if [[ "$1" != *\$* ]]; then
  4317. die "${FUNCNAME}(): '$1' has invalid syntax";
  4318. fi;
  4319. if [[ "$1" == *.py ]]; then
  4320. evaluated_files+=("$1");
  4321. else
  4322. evaluated_dirs+=("$1");
  4323. fi;
  4324. else
  4325. if [[ -d "${root}$1" ]]; then
  4326. other_dirs+=("${root}$1");
  4327. else
  4328. if [[ -f "${root}$1" ]]; then
  4329. other_files+=("${root}$1");
  4330. else
  4331. if [[ -e "${root}$1" ]]; then
  4332. eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory";
  4333. else
  4334. eerror "${FUNCNAME}(): '${root}$1' does not exist";
  4335. fi;
  4336. fi;
  4337. fi;
  4338. fi;
  4339. else
  4340. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  4341. do
  4342. if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
  4343. site_packages_dirs+=("$1");
  4344. break;
  4345. else
  4346. if [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
  4347. site_packages_files+=("$1");
  4348. break;
  4349. else
  4350. if [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
  4351. eerror "${FUNCNAME}(): '$1' is not a regular file or a directory";
  4352. else
  4353. eerror "${FUNCNAME}(): '$1' does not exist";
  4354. fi;
  4355. fi;
  4356. fi;
  4357. done;
  4358. fi;
  4359. fi;
  4360. fi;
  4361. shift;
  4362. done;
  4363. options+=("-q");
  4364. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  4365. do
  4366. if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
  4367. return_code="0";
  4368. stderr="";
  4369. ebegin "Compilation and optimization of Python modules for $(python_get_implementation_and_version)";
  4370. if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
  4371. for dir in "${site_packages_dirs[@]}";
  4372. do
  4373. dirs+=("${root}$(python_get_sitedir)/${dir}");
  4374. done;
  4375. for dir in "${evaluated_dirs[@]}";
  4376. do
  4377. eval "dirs+=(\"\${root}${dir}\")";
  4378. done;
  4379. stderr+="${stderr:+
  4380. }$("$(PYTHON)" -m compileall "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1";
  4381. if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  4382. "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &>/dev/null || return_code="1";
  4383. fi;
  4384. _python_clean_compiled_modules "${dirs[@]}";
  4385. fi;
  4386. if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
  4387. for file in "${site_packages_files[@]}";
  4388. do
  4389. files+=("${root}$(python_get_sitedir)/${file}");
  4390. done;
  4391. for file in "${evaluated_files[@]}";
  4392. do
  4393. eval "files+=(\"\${root}${file}\")";
  4394. done;
  4395. stderr+="${stderr:+
  4396. }$("$(PYTHON)" -m py_compile "${files[@]}" 2>&1)" || return_code="1";
  4397. if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  4398. "$(PYTHON)" -O -m py_compile "${files[@]}" &>/dev/null || return_code="1";
  4399. fi;
  4400. _python_clean_compiled_modules "${files[@]}";
  4401. fi;
  4402. eend "${return_code}";
  4403. if [[ -n "${stderr}" ]]; then
  4404. eerror "Syntax errors / warnings in Python modules for $(python_get_implementation_and_version):" &>/dev/null;
  4405. while read stderr_line; do
  4406. eerror " ${stderr_line}";
  4407. done <<< "${stderr}";
  4408. fi;
  4409. fi;
  4410. unset dirs files;
  4411. done;
  4412. if _python_package_supporting_installation_for_multiple_python_abis; then
  4413. if [[ -n "${previous_PYTHON_ABI}" ]]; then
  4414. PYTHON_ABI="${previous_PYTHON_ABI}";
  4415. else
  4416. unset PYTHON_ABI;
  4417. fi;
  4418. fi;
  4419. if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
  4420. return_code="0";
  4421. stderr="";
  4422. ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)";
  4423. if ((${#other_dirs[@]})); then
  4424. stderr+="${stderr:+
  4425. }$("$(PYTHON ${PYTHON_ABI})" -m compileall "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1";
  4426. if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  4427. "$(PYTHON ${PYTHON_ABI})" -O -m compileall "${options[@]}" "${other_dirs[@]}" &>/dev/null || return_code="1";
  4428. fi;
  4429. _python_clean_compiled_modules "${other_dirs[@]}";
  4430. fi;
  4431. if ((${#other_files[@]})); then
  4432. stderr+="${stderr:+
  4433. }$("$(PYTHON ${PYTHON_ABI})" -m py_compile "${other_files[@]}" 2>&1)" || return_code="1";
  4434. if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  4435. "$(PYTHON ${PYTHON_ABI})" -O -m py_compile "${other_files[@]}" &>/dev/null || return_code="1";
  4436. fi;
  4437. _python_clean_compiled_modules "${other_files[@]}";
  4438. fi;
  4439. eend "${return_code}";
  4440. if [[ -n "${stderr}" ]]; then
  4441. eerror "Syntax errors / warnings in Python modules placed outside of site-packages directories for $(python_get_implementation_and_version):" &>/dev/null;
  4442. while read stderr_line; do
  4443. eerror " ${stderr_line}";
  4444. done <<< "${stderr}";
  4445. fi;
  4446. fi;
  4447. else
  4448. ewarn;
  4449. ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation";
  4450. ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01.";
  4451. ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax.";
  4452. ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported.";
  4453. ewarn;
  4454. local myroot mydirs=() myfiles=() myopts=() return_code="0";
  4455. myroot="${EROOT%/}";
  4456. while (($#)); do
  4457. case "$1" in
  4458. -l | -f | -q)
  4459. myopts+=("$1")
  4460. ;;
  4461. -d | -x)
  4462. myopts+=("$1" "$2");
  4463. shift
  4464. ;;
  4465. --)
  4466. shift;
  4467. break
  4468. ;;
  4469. -*)
  4470. die "${FUNCNAME}(): Unrecognized option '$1'"
  4471. ;;
  4472. *)
  4473. break
  4474. ;;
  4475. esac;
  4476. shift;
  4477. done;
  4478. if [[ "$#" -eq 0 ]]; then
  4479. die "${FUNCNAME}(): Missing files or directories";
  4480. fi;
  4481. while (($#)); do
  4482. if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
  4483. die "${FUNCNAME}(): Invalid argument '$1'";
  4484. else
  4485. if [[ -d "${myroot}/${1#/}" ]]; then
  4486. mydirs+=("${myroot}/${1#/}");
  4487. else
  4488. if [[ -f "${myroot}/${1#/}" ]]; then
  4489. myfiles+=("${myroot}/${1#/}");
  4490. else
  4491. if [[ -e "${myroot}/${1#/}" ]]; then
  4492. eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory";
  4493. else
  4494. eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist";
  4495. fi;
  4496. fi;
  4497. fi;
  4498. fi;
  4499. shift;
  4500. done;
  4501. myopts+=(-q);
  4502. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4503. ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)";
  4504. if ((${#mydirs[@]})); then
  4505. "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1";
  4506. "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &>/dev/null || return_code="1";
  4507. _python_clean_compiled_modules "${mydirs[@]}";
  4508. fi;
  4509. if ((${#myfiles[@]})); then
  4510. "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1";
  4511. "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &>/dev/null || return_code="1";
  4512. _python_clean_compiled_modules "${myfiles[@]}";
  4513. fi;
  4514. eend "${return_code}";
  4515. fi
  4516. }
  4517. python_need_rebuild ()
  4518. {
  4519. if _python_package_supporting_installation_for_multiple_python_abis; then
  4520. die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  4521. fi;
  4522. _python_check_python_pkg_setup_execution;
  4523. if [[ "$#" -ne 0 ]]; then
  4524. die "${FUNCNAME}() does not accept arguments";
  4525. fi;
  4526. export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
  4527. }
  4528. python_pkg_setup ()
  4529. {
  4530. if [[ "${EBUILD_PHASE}" != "setup" ]]; then
  4531. die "${FUNCNAME}() can be used only in pkg_setup() phase";
  4532. fi;
  4533. if [[ "$#" -ne 0 ]]; then
  4534. die "${FUNCNAME}() does not accept arguments";
  4535. fi;
  4536. export JYTHON_SYSTEM_CACHEDIR="1";
  4537. addwrite "${EPREFIX}/var/cache/jython";
  4538. if _python_package_supporting_installation_for_multiple_python_abis; then
  4539. _python_calculate_PYTHON_ABIS;
  4540. export EPYTHON="$(PYTHON -f)";
  4541. else
  4542. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4543. fi;
  4544. if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
  4545. if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
  4546. if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
  4547. use ${PYTHON_USE_WITH_OPT#!} && return;
  4548. else
  4549. use !${PYTHON_USE_WITH_OPT} && return;
  4550. fi;
  4551. fi;
  4552. function python_pkg_setup_check_USE_flags ()
  4553. {
  4554. local python_atom USE_flag;
  4555. python_atom="$(python_get_implementational_package)";
  4556. for USE_flag in ${PYTHON_USE_WITH};
  4557. do
  4558. if ! has_version "${python_atom}[${USE_flag}]"; then
  4559. eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}";
  4560. die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}";
  4561. fi;
  4562. done;
  4563. for USE_flag in ${PYTHON_USE_WITH_OR};
  4564. do
  4565. if has_version "${python_atom}[${USE_flag}]"; then
  4566. return;
  4567. fi;
  4568. done;
  4569. if [[ -n ${PYTHON_USE_WITH_OR} ]]; then
  4570. eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}";
  4571. die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}";
  4572. fi
  4573. };
  4574. if _python_package_supporting_installation_for_multiple_python_abis; then
  4575. PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags;
  4576. else
  4577. python_pkg_setup_check_USE_flags;
  4578. fi;
  4579. unset -f python_pkg_setup_check_USE_flags;
  4580. fi;
  4581. PYTHON_PKG_SETUP_EXECUTED="1"
  4582. }
  4583. python_set_active_version ()
  4584. {
  4585. if [[ "${EBUILD_PHASE}" != "setup" ]]; then
  4586. die "${FUNCNAME}() can be used only in pkg_setup() phase";
  4587. fi;
  4588. if _python_package_supporting_installation_for_multiple_python_abis; then
  4589. die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  4590. fi;
  4591. if [[ "$#" -ne 1 ]]; then
  4592. die "${FUNCNAME}() requires 1 argument";
  4593. fi;
  4594. _python_initial_sanity_checks;
  4595. if [[ -z "${PYTHON_ABI}" ]]; then
  4596. if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
  4597. PYTHON_ABI="$1";
  4598. if ! _python_implementation && ! has_version "$(python_get_implementational_package)"; then
  4599. die "${FUNCNAME}(): '$(python_get_implementational_package)' is not installed";
  4600. fi;
  4601. export EPYTHON="$(PYTHON "$1")";
  4602. else
  4603. if [[ "$1" == "2" ]]; then
  4604. if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
  4605. die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed";
  4606. fi;
  4607. export EPYTHON="$(PYTHON -2)";
  4608. PYTHON_ABI="${EPYTHON#python}";
  4609. PYTHON_ABI="${PYTHON_ABI%%-*}";
  4610. else
  4611. if [[ "$1" == "3" ]]; then
  4612. if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
  4613. die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed";
  4614. fi;
  4615. export EPYTHON="$(PYTHON -3)";
  4616. PYTHON_ABI="${EPYTHON#python}";
  4617. PYTHON_ABI="${PYTHON_ABI%%-*}";
  4618. else
  4619. die "${FUNCNAME}(): Unrecognized argument '$1'";
  4620. fi;
  4621. fi;
  4622. fi;
  4623. fi;
  4624. _python_final_sanity_checks;
  4625. PYTHON_REQUESTED_ACTIVE_VERSION="$1"
  4626. }
  4627. python_src_compile ()
  4628. {
  4629. if [[ "${EBUILD_PHASE}" != "compile" ]]; then
  4630. die "${FUNCNAME}() can be used only in src_compile() phase";
  4631. fi;
  4632. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4633. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4634. fi;
  4635. _python_check_python_pkg_setup_execution;
  4636. python_execute_function -d -s -- "$@"
  4637. }
  4638. python_src_configure ()
  4639. {
  4640. if [[ "${EBUILD_PHASE}" != "configure" ]]; then
  4641. die "${FUNCNAME}() can be used only in src_configure() phase";
  4642. fi;
  4643. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4644. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4645. fi;
  4646. _python_check_python_pkg_setup_execution;
  4647. python_execute_function -d -s -- "$@"
  4648. }
  4649. python_src_install ()
  4650. {
  4651. if [[ "${EBUILD_PHASE}" != "install" ]]; then
  4652. die "${FUNCNAME}() can be used only in src_install() phase";
  4653. fi;
  4654. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4655. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4656. fi;
  4657. _python_check_python_pkg_setup_execution;
  4658. if has "${EAPI:-0}" 0 1 2 3; then
  4659. python_execute_function -d -s -- "$@";
  4660. else
  4661. function python_installation ()
  4662. {
  4663. emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@"
  4664. };
  4665. python_execute_function -s python_installation "$@";
  4666. unset python_installation;
  4667. python_merge_intermediate_installation_images "${T}/images";
  4668. fi
  4669. }
  4670. python_src_prepare ()
  4671. {
  4672. if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
  4673. die "${FUNCNAME}() can be used only in src_prepare() phase";
  4674. fi;
  4675. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4676. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4677. fi;
  4678. _python_check_python_pkg_setup_execution;
  4679. if [[ "$#" -ne 0 ]]; then
  4680. die "${FUNCNAME}() does not accept arguments";
  4681. fi;
  4682. python_copy_sources
  4683. }
  4684. python_src_test ()
  4685. {
  4686. if [[ "${EBUILD_PHASE}" != "test" ]]; then
  4687. die "${FUNCNAME}() can be used only in src_test() phase";
  4688. fi;
  4689. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4690. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4691. fi;
  4692. _python_check_python_pkg_setup_execution;
  4693. python_execute_function -d -s -- "$@"
  4694. }
  4695. src_compile ()
  4696. {
  4697. emake || die
  4698. }
  4699. src_configure ()
  4700. {
  4701. ./configure --shared-v8 --prefix="${EPREFIX}"/usr --shared-v8-includes="${EPREFIX}"/usr/include --openssl-use-sys --shared-zlib || die
  4702. }
  4703. src_install ()
  4704. {
  4705. docompress -x /usr/$(get_libdir)/node_modules/npm/man;
  4706. local MYLIB=$(get_libdir);
  4707. mkdir -p "${ED}"/usr/include/node;
  4708. mkdir -p "${ED}"/usr/bin;
  4709. mkdir -p "${ED}"/usr/"${MYLIB}"/node_modules/npm;
  4710. mkdir -p "${ED}"/usr/"${MYLIB}"/node;
  4711. cp src/*.h "${ED}"/usr/include/node || die "Failed to copy stuff";
  4712. cp -R deps/uv/include/* "${ED}"/usr/include/node || die "Failed to copy stuff";
  4713. cp 'out/Release/node' "${ED}"/usr/bin/node || die "Failed to copy stuff";
  4714. cp -R deps/npm/* "${ED}"/usr/"${MYLIB}"/node_modules/npm || die "Failed to copy stuff";
  4715. dosym /usr/"${MYLIB}"/node_modules/npm/bin/npm-cli.js /usr/bin/npm;
  4716. pax-mark -m "${ED}"/usr/bin/node
  4717. }
  4718. src_prepare ()
  4719. {
  4720. sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die
  4721. }
  4722. src_test ()
  4723. {
  4724. emake test || die
  4725. }
  4726. src_unpack ()
  4727. {
  4728. __eapi0_src_unpack "$@"
  4729. }
  4730. strip-linguas ()
  4731. {
  4732. local ls newls nols;
  4733. if [[ $1 == "-i" ]] || [[ $1 == "-u" ]]; then
  4734. local op=$1;
  4735. shift;
  4736. ls=$(find "$1" -name '*.po' -exec basename {} .po ';');
  4737. shift;
  4738. local d f;
  4739. for d in "$@";
  4740. do
  4741. if [[ ${op} == "-u" ]]; then
  4742. newls=${ls};
  4743. else
  4744. newls="";
  4745. fi;
  4746. for f in $(find "$d" -name '*.po' -exec basename {} .po ';');
  4747. do
  4748. if [[ ${op} == "-i" ]]; then
  4749. has ${f} ${ls} && newls="${newls} ${f}";
  4750. else
  4751. has ${f} ${ls} || newls="${newls} ${f}";
  4752. fi;
  4753. done;
  4754. ls=${newls};
  4755. done;
  4756. else
  4757. ls="$@";
  4758. fi;
  4759. nols="";
  4760. newls="";
  4761. for f in ${LINGUAS};
  4762. do
  4763. if has ${f} ${ls}; then
  4764. newls="${newls} ${f}";
  4765. else
  4766. nols="${nols} ${f}";
  4767. fi;
  4768. done;
  4769. [[ -n ${nols} ]] && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols};
  4770. export LINGUAS=${newls:1}
  4771. }
  4772. tc-arch ()
  4773. {
  4774. tc-ninja_magic_to_arch portage "$@"
  4775. }
  4776. tc-arch-kernel ()
  4777. {
  4778. tc-ninja_magic_to_arch kern "$@"
  4779. }
  4780. tc-endian ()
  4781. {
  4782. local host=$1;
  4783. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  4784. host=${host%%-*};
  4785. case ${host} in
  4786. aarch64*be)
  4787. echo big
  4788. ;;
  4789. aarch64)
  4790. echo little
  4791. ;;
  4792. alpha*)
  4793. echo big
  4794. ;;
  4795. arm*b*)
  4796. echo big
  4797. ;;
  4798. arm*)
  4799. echo little
  4800. ;;
  4801. cris*)
  4802. echo little
  4803. ;;
  4804. hppa*)
  4805. echo big
  4806. ;;
  4807. i?86*)
  4808. echo little
  4809. ;;
  4810. ia64*)
  4811. echo little
  4812. ;;
  4813. m68*)
  4814. echo big
  4815. ;;
  4816. mips*l*)
  4817. echo little
  4818. ;;
  4819. mips*)
  4820. echo big
  4821. ;;
  4822. powerpc*)
  4823. echo big
  4824. ;;
  4825. s390*)
  4826. echo big
  4827. ;;
  4828. sh*b*)
  4829. echo big
  4830. ;;
  4831. sh*)
  4832. echo little
  4833. ;;
  4834. sparc*)
  4835. echo big
  4836. ;;
  4837. x86_64*)
  4838. echo little
  4839. ;;
  4840. *)
  4841. echo wtf
  4842. ;;
  4843. esac
  4844. }
  4845. tc-env_build ()
  4846. {
  4847. tc-export_build_env;
  4848. CFLAGS=${BUILD_CFLAGS} CXXFLAGS=${BUILD_CXXFLAGS} CPPFLAGS=${BUILD_CPPFLAGS} LDFLAGS=${BUILD_LDFLAGS} AR=$(tc-getBUILD_AR) AS=$(tc-getBUILD_AS) CC=$(tc-getBUILD_CC) CPP=$(tc-getBUILD_CPP) CXX=$(tc-getBUILD_CXX) LD=$(tc-getBUILD_LD) NM=$(tc-getBUILD_NM) PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) RANLIB=$(tc-getBUILD_RANLIB) "$@"
  4849. }
  4850. tc-export ()
  4851. {
  4852. local var;
  4853. for var in "$@";
  4854. do
  4855. [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'";
  4856. eval tc-get${var} > /dev/null;
  4857. done
  4858. }
  4859. tc-export_build_env ()
  4860. {
  4861. tc-export "$@";
  4862. : ${BUILD_CFLAGS:=-O1 -pipe};
  4863. : ${BUILD_CXXFLAGS:=-O1 -pipe};
  4864. : ${BUILD_CPPFLAGS:=};
  4865. : ${BUILD_LDFLAGS:=};
  4866. export BUILD_{C,CXX,CPP,LD}FLAGS
  4867. }
  4868. tc-getAR ()
  4869. {
  4870. tc-getPROG AR ar "$@"
  4871. }
  4872. tc-getAS ()
  4873. {
  4874. tc-getPROG AS as "$@"
  4875. }
  4876. tc-getBUILD_AR ()
  4877. {
  4878. tc-getBUILD_PROG AR ar "$@"
  4879. }
  4880. tc-getBUILD_AS ()
  4881. {
  4882. tc-getBUILD_PROG AS as "$@"
  4883. }
  4884. tc-getBUILD_CC ()
  4885. {
  4886. tc-getBUILD_PROG CC gcc "$@"
  4887. }
  4888. tc-getBUILD_CPP ()
  4889. {
  4890. tc-getBUILD_PROG CPP cpp "$@"
  4891. }
  4892. tc-getBUILD_CXX ()
  4893. {
  4894. tc-getBUILD_PROG CXX g++ "$@"
  4895. }
  4896. tc-getBUILD_LD ()
  4897. {
  4898. tc-getBUILD_PROG LD ld "$@"
  4899. }
  4900. tc-getBUILD_NM ()
  4901. {
  4902. tc-getBUILD_PROG NM nm "$@"
  4903. }
  4904. tc-getBUILD_OBJCOPY ()
  4905. {
  4906. tc-getBUILD_PROG OBJCOPY objcopy "$@"
  4907. }
  4908. tc-getBUILD_PKG_CONFIG ()
  4909. {
  4910. tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"
  4911. }
  4912. tc-getBUILD_PROG ()
  4913. {
  4914. _tc-getPROG CBUILD "BUILD_$1 $1_FOR_BUILD HOST$1" "${@:2}"
  4915. }
  4916. tc-getBUILD_RANLIB ()
  4917. {
  4918. tc-getBUILD_PROG RANLIB ranlib "$@"
  4919. }
  4920. tc-getBUILD_STRIP ()
  4921. {
  4922. tc-getBUILD_PROG STRIP strip "$@"
  4923. }
  4924. tc-getCC ()
  4925. {
  4926. tc-getPROG CC gcc "$@"
  4927. }
  4928. tc-getCPP ()
  4929. {
  4930. tc-getPROG CPP cpp "$@"
  4931. }
  4932. tc-getCXX ()
  4933. {
  4934. tc-getPROG CXX g++ "$@"
  4935. }
  4936. tc-getDLLWRAP ()
  4937. {
  4938. tc-getPROG DLLWRAP dllwrap "$@"
  4939. }
  4940. tc-getF77 ()
  4941. {
  4942. tc-getPROG F77 gfortran "$@"
  4943. }
  4944. tc-getFC ()
  4945. {
  4946. tc-getPROG FC gfortran "$@"
  4947. }
  4948. tc-getGCJ ()
  4949. {
  4950. tc-getPROG GCJ gcj "$@"
  4951. }
  4952. tc-getLD ()
  4953. {
  4954. tc-getPROG LD ld "$@"
  4955. }
  4956. tc-getNM ()
  4957. {
  4958. tc-getPROG NM nm "$@"
  4959. }
  4960. tc-getOBJCOPY ()
  4961. {
  4962. tc-getPROG OBJCOPY objcopy "$@"
  4963. }
  4964. tc-getPKG_CONFIG ()
  4965. {
  4966. tc-getPROG PKG_CONFIG pkg-config "$@"
  4967. }
  4968. tc-getPROG ()
  4969. {
  4970. _tc-getPROG CHOST "$@"
  4971. }
  4972. tc-getRANLIB ()
  4973. {
  4974. tc-getPROG RANLIB ranlib "$@"
  4975. }
  4976. tc-getRC ()
  4977. {
  4978. tc-getPROG RC windres "$@"
  4979. }
  4980. tc-getSTRIP ()
  4981. {
  4982. tc-getPROG STRIP strip "$@"
  4983. }
  4984. tc-has-openmp ()
  4985. {
  4986. local base="${T}/test-tc-openmp";
  4987. cat > "${base}.c" <<-EOF
  4988. #include <omp.h>
  4989. int main() {
  4990. int nthreads, tid, ret = 0;
  4991. #pragma omp parallel private(nthreads, tid)
  4992. {
  4993. tid = omp_get_thread_num();
  4994. nthreads = omp_get_num_threads(); ret += tid + nthreads;
  4995. }
  4996. return ret;
  4997. }
  4998. EOF
  4999.  
  5000. $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" &>/dev/null;
  5001. local ret=$?;
  5002. rm -f "${base}"*;
  5003. return ${ret}
  5004. }
  5005. tc-has-tls ()
  5006. {
  5007. local base="${T}/test-tc-tls";
  5008. cat > "${base}.c" <<-EOF
  5009. int foo(int *i) {
  5010. static __thread int j = 0;
  5011. return *i ? j : *i;
  5012. }
  5013. EOF
  5014.  
  5015. local flags;
  5016. case $1 in
  5017. -s)
  5018. flags="-S"
  5019. ;;
  5020. -c)
  5021. flags="-c"
  5022. ;;
  5023. -l)
  5024.  
  5025. ;;
  5026. -*)
  5027. die "Usage: tc-has-tls [-c|-l] [toolchain prefix]"
  5028. ;;
  5029. esac;
  5030. : ${flags:=-fPIC -shared -Wl,-z,defs};
  5031. [[ $1 == -* ]] && shift;
  5032. $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" &>/dev/null;
  5033. local ret=$?;
  5034. rm -f "${base}"*;
  5035. return ${ret}
  5036. }
  5037. tc-is-cross-compiler ()
  5038. {
  5039. return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]])
  5040. }
  5041. tc-is-softfloat ()
  5042. {
  5043. local CTARGET=${CTARGET:-${CHOST}};
  5044. case ${CTARGET} in
  5045. bfin* | h8300*)
  5046. echo "only"
  5047. ;;
  5048. *)
  5049. if [[ ${CTARGET//_/-} == *-softfloat-* ]]; then
  5050. echo "yes";
  5051. else
  5052. if [[ ${CTARGET//_/-} == *-softfp-* ]]; then
  5053. echo "softfp";
  5054. else
  5055. echo "no";
  5056. fi;
  5057. fi
  5058. ;;
  5059. esac
  5060. }
  5061. tc-is-static-only ()
  5062. {
  5063. local host=${CTARGET:-${CHOST}};
  5064. return $([[ ${host} == *-mint* ]])
  5065. }
  5066. tc-ninja_magic_to_arch ()
  5067. {
  5068. function ninj ()
  5069. {
  5070. [[ ${type} == "kern" ]] && echo $1 || echo $2
  5071. };
  5072. local type=$1;
  5073. local host=$2;
  5074. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  5075. local KV=${KV:-${KV_FULL}};
  5076. [[ ${type} == "kern" ]] && [[ -z ${KV} ]] && ewarn "QA: Kernel version could not be determined, please inherit kernel-2 or linux-info";
  5077. case ${host} in
  5078. aarch64*)
  5079. ninj arm64 arm
  5080. ;;
  5081. alpha*)
  5082. echo alpha
  5083. ;;
  5084. arm*)
  5085. echo arm
  5086. ;;
  5087. avr*)
  5088. ninj avr32 avr
  5089. ;;
  5090. bfin*)
  5091. ninj blackfin bfin
  5092. ;;
  5093. cris*)
  5094. echo cris
  5095. ;;
  5096. hppa*)
  5097. ninj parisc hppa
  5098. ;;
  5099. i?86*)
  5100. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]]; then
  5101. echo i386;
  5102. else
  5103. echo x86;
  5104. fi
  5105. ;;
  5106. ia64*)
  5107. echo ia64
  5108. ;;
  5109. m68*)
  5110. echo m68k
  5111. ;;
  5112. mips*)
  5113. echo mips
  5114. ;;
  5115. nios2*)
  5116. echo nios2
  5117. ;;
  5118. nios*)
  5119. echo nios
  5120. ;;
  5121. powerpc*)
  5122. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]]; then
  5123. echo powerpc;
  5124. else
  5125. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]]; then
  5126. if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  5127. echo powerpc;
  5128. else
  5129. echo ppc;
  5130. fi;
  5131. else
  5132. if [[ ${host} == powerpc64* ]]; then
  5133. echo ppc64;
  5134. else
  5135. if [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  5136. ninj ppc64 ppc;
  5137. else
  5138. echo ppc;
  5139. fi;
  5140. fi;
  5141. fi;
  5142. fi
  5143. ;;
  5144. s390*)
  5145. echo s390
  5146. ;;
  5147. sh64*)
  5148. ninj sh64 sh
  5149. ;;
  5150. sh*)
  5151. echo sh
  5152. ;;
  5153. sparc64*)
  5154. ninj sparc64 sparc
  5155. ;;
  5156. sparc*)
  5157. [[ ${PROFILE_ARCH} == "sparc64" ]] && ninj sparc64 sparc || echo sparc
  5158. ;;
  5159. vax*)
  5160. echo vax
  5161. ;;
  5162. x86_64*freebsd*)
  5163. echo amd64
  5164. ;;
  5165. x86_64*)
  5166. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]]; then
  5167. echo x86;
  5168. else
  5169. ninj x86_64 amd64;
  5170. fi
  5171. ;;
  5172. *)
  5173. echo unknown
  5174. ;;
  5175. esac
  5176. }
  5177. use_if_iuse ()
  5178. {
  5179. in_iuse $1 || return 1;
  5180. use $1
  5181. }
  5182. validate_desktop_entries ()
  5183. {
  5184. if [[ -x /usr/bin/desktop-file-validate ]]; then
  5185. einfo "Checking desktop entry validity";
  5186. local directories="";
  5187. for d in /usr/share/applications $@;
  5188. do
  5189. [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}";
  5190. done;
  5191. if [[ -n ${directories} ]]; then
  5192. for FILE in $(find ${directories} -name "*\.desktop" -not -path '*.hidden*' | sort -u 2>/dev/null);
  5193. do
  5194. local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | sed -e "s|error: ||" -e "s|${FILE}:|--|g" );
  5195. [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:};
  5196. done;
  5197. fi;
  5198. echo "";
  5199. else
  5200. einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo.";
  5201. fi
  5202. }
RAW Paste Data