dev-lang/python-2.7: Install symlinks for python-exec

Install the following symlinks:

    ${libdir}/python-exec/python-2.7/
    |-- python
    |-- python2
    |-- python-config
    |-- python2-config
    |-- pydoc
    |-- pydoc2
    |-- 2to3

In particular, the 'python' and 'python2' symlinks are needed to safely
uprev app-eselect/eselect-python. If the symlinks are missing, newer
eselect refuses to select python2.7 as the system's default python, and
instead falls back to whatever Python version has the required symlinks
installed to ${libdir}/python-exec. Currently in the Chrome OS SDK,
eselect would fallback to python3.4 as the default, which breaks the
world.

BUG=chromium:884766
TEST=sudo emerge dev-lang/python:2.7;
     # confirm python versions remain unchanged
     python --version # expect 2.7
     python2 --version # expect 2.7

Change-Id: I596c9eef5e234b107d514b7a2882af17675125a9
Reviewed-on: https://chromium-review.googlesource.com/1315770
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Chad Versace <chadversary@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/dev-lang/python/python-2.7.10-r6.ebuild b/dev-lang/python/python-2.7.10-r7.ebuild
similarity index 100%
rename from dev-lang/python/python-2.7.10-r6.ebuild
rename to dev-lang/python/python-2.7.10-r7.ebuild
diff --git a/dev-lang/python/python-2.7.10.ebuild b/dev-lang/python/python-2.7.10.ebuild
index 01afd12..922537a 100644
--- a/dev-lang/python/python-2.7.10.ebuild
+++ b/dev-lang/python/python-2.7.10.ebuild
@@ -322,6 +322,8 @@
 	mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
 	rm -f "${ED}usr/bin/smtpd.py"
 
+	local abiver="python2.7"
+
 	if use build; then
 		rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test}
 	else
@@ -353,7 +355,7 @@
 		-i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
 
 	# for python-exec
-	python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
+	python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR
 
 	# if not using a cross-compiler, use the fresh binary
 	if ! tc-is-cross-compiler; then
@@ -364,6 +366,37 @@
 	echo "EPYTHON='${EPYTHON}'" > epython.py
 	python_domodule epython.py
 
+	# python-exec wrapping support
+	local pymajor=${SLOT%.*}
+	mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
+
+	# python-exec: python, pythonX
+	dosym "../../../bin/${abiver}" \
+		"${PYTHON_SCRIPTDIR}/python${pymajor}"
+	dosym "python${pymajor}" "${PYTHON_SCRIPTDIR}/python"
+
+	# python-exec: python-config, python-configX
+	#
+	# Note: we need to create a wrapper rather than symlinking it due
+	# to some random dirname(argv[0]) magic performed by python-config.
+	cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
+		#!/bin/sh
+		exec "${abiver}-config" "\${@}"
+	EOF
+	# Must strip EPREFIX because fperms prepends ED.
+	fperms 755 "${PYTHON_SCRIPTDIR#$EPREFIX}/python${pymajor}-config"
+	dosym "python${pymajor}-config" \
+		"${PYTHON_SCRIPTDIR}/python-config"
+
+	# python-exec: pydoc, pydocX
+	dosym "../../../bin/pydoc${SLOT}" \
+		"${PYTHON_SCRIPTDIR}/pydoc${pymajor}"
+	dosym "pydoc${pymajor}" "${PYTHON_SCRIPTDIR}/pydoc"
+
+	# python-exec: 2to3
+	dosym "../../../bin/2to3-${SLOT}" \
+		"${PYTHON_SCRIPTDIR}/2to3"
+
 	# The sysconfig module will actually read the pyconfig.h at runtime to see what kind
 	# of functionality is enabled in the build.  Deploy it behind the back of portage as
 	# need be.