Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 286191 | Differences between
and this patch

Collapse All | Expand All

(-)file_not_specified_in_diff (-16 / +52 lines)
Line  Link Here
0
-- python.eclass
0
++ python.eclass
Lines 774-779 Link Here
774
import sys
774
import sys
775
775
776
EPYTHON_re = re.compile(r"^python(\d+\.\d+)$")
776
EPYTHON_re = re.compile(r"^python(\d+\.\d+)$")
777
python_shebang_re = re.compile(r"^#!.*python")
778
python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
777
779
778
EOF
780
EOF
779
		if [[ "$?" != "0" ]]; then
781
		if [[ "$?" != "0" ]]; then
Lines 798-813 Link Here
798
		sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
800
		sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
799
		sys.exit(1)
801
		sys.exit(1)
800
802
801
	eselect_output = eselect_process.stdout.read()
803
	EPYTHON = eselect_process.stdout.read().rstrip("\n")
802
	if not isinstance(eselect_output, str):
804
	if not isinstance(EPYTHON, str):
803
		# Python 3
805
		# Python 3
804
		eselect_output = eselect_output.decode()
806
		EPYTHON = EPYTHON.decode()
805
807
806
	EPYTHON_matched = EPYTHON_re.match(eselect_output)
808
	EPYTHON_matched = EPYTHON_re.match(EPYTHON)
807
	if EPYTHON_matched:
809
	if EPYTHON_matched:
808
		PYTHON_ABI = EPYTHON_matched.group(1)
810
		PYTHON_ABI = EPYTHON_matched.group(1)
809
	else:
811
	else:
810
		sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output)
812
		sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % EPYTHON)
811
		sys.exit(1)
813
		sys.exit(1)
812
EOF
814
EOF
813
			if [[ "$?" != "0" ]]; then
815
			if [[ "$?" != "0" ]]; then
Lines 823-838 Link Here
823
	sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
825
	sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n")
824
	sys.exit(1)
826
	sys.exit(1)
825
827
826
eselect_output = eselect_process.stdout.read()
828
EPYTHON = eselect_process.stdout.read().rstrip("\n")
827
if not isinstance(eselect_output, str):
829
if not isinstance(EPYTHON, str):
828
	# Python 3
830
	# Python 3
829
	eselect_output = eselect_output.decode()
831
	EPYTHON = EPYTHON.decode()
830
832
831
EPYTHON_matched = EPYTHON_re.match(eselect_output)
833
EPYTHON_matched = EPYTHON_re.match(EPYTHON)
832
if EPYTHON_matched:
834
if EPYTHON_matched:
833
	PYTHON_ABI = EPYTHON_matched.group(1)
835
	PYTHON_ABI = EPYTHON_matched.group(1)
834
else:
836
else:
835
	sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output)
837
	sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % EPYTHON)
836
	sys.exit(1)
838
	sys.exit(1)
837
EOF
839
EOF
838
			if [[ "$?" != "0" ]]; then
840
			if [[ "$?" != "0" ]]; then
Lines 841-853 Link Here
841
		fi
843
		fi
842
		cat << EOF >> "${file}"
844
		cat << EOF >> "${file}"
843
845
844
os.environ["PYTHON_SCRIPT_NAME"] = sys.argv[0]
846
wrapper_script_path = os.path.realpath(sys.argv[0])
845
target_executable = "%s-%s" % (os.path.realpath(sys.argv[0]), PYTHON_ABI)
847
target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
846
if not os.path.exists(target_executable):
848
os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
847
	sys.stderr.write("'%s' does not exist\n" % target_executable)
849
os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
850
if not os.path.exists(target_executable_path):
851
	sys.stderr.write("'%s' does not exist\n" % target_executable_path)
848
	sys.exit(1)
852
	sys.exit(1)
849
853
850
os.execv(target_executable, sys.argv)
854
target_executable = open(target_executable_path, "rb")
855
target_executable_first_line = target_executable.readline()
856
if not isinstance(target_executable_first_line, str):
857
	# Python 3
858
	target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
859
860
python_shebang_matched = python_shebang_re.match(target_executable_first_line)
861
target_executable.close()
862
863
if python_shebang_matched:
864
	try:
865
		python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON
866
		os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
867
		python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
868
		del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
869
		if python_verification_process.wait() != 0:
870
			raise ValueError
871
872
		python_verification_output = python_verification_process.stdout.read()
873
		if not isinstance(python_verification_output, str):
874
			# Python 3
875
			python_verification_output = python_verification_output.decode()
876
877
		if not python_verification_output_re.match(python_verification_output):
878
			raise ValueError
879
880
		os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv)
881
	except:
882
		pass
883
	if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ:
884
		del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
885
886
os.execv(target_executable_path, sys.argv)
851
EOF
887
EOF
852
		if [[ "$?" != "0" ]]; then
888
		if [[ "$?" != "0" ]]; then
853
			die "${FUNCNAME}(): Generation of '$1' failed"
889
			die "${FUNCNAME}(): Generation of '$1' failed"

Return to bug 286191