LAKITU: add functionality required for PEP517 code in distutils eclass

- allow pythonN.M format in the impl compat lines
- Allow python_domodule run in phases other than install if
    BUILD_DIR is set

BUG=b/257113269
TEST=presubmit
RELEASE_NOTE=None

Change-Id: I360fe7de88cf6c8888de5ae385a9b4ff110169cd
Reviewed-on: https://cos-review.googlesource.com/c/third_party/overlays/eclass-overlay/+/42429
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
Reviewed-by: Vaibhav Rustagi <vaibhavrustagi@google.com>
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 8dc6d85..c494e49 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -182,7 +182,7 @@
 			python_is_python3 "${impl}" && return 0
 			return
 		# unify value style to allow lax matching
-		elif [[ ${impl/./_} == ${pattern/./_} ]]; then
+		elif [[ ${impl/./_} == ${pattern/./_} || ${impl} == python${pattern/./_} ]]; then
 			return 0
 		fi
 	done
@@ -807,13 +807,24 @@
 		d=${sitedir#${SYSROOT}}/${python_moduleroot//.//}
 	fi
 
-	(
-		insopts -m 0644
-		insinto "${d}"
-		doins -r "${@}" || return ${?}
-	)
-
-	python_optimize "${ED%/}/${d}"
+	if [[ ${EBUILD_PHASE} == install ]]; then
+		(
+			insopts -m 0644
+			insinto "${d}"
+			doins -r "${@}" || return ${?}
+		)
+		python_optimize "${ED%/}/${d}"
+	elif [[ -n ${BUILD_DIR} ]]; then
+		local dest=${BUILD_DIR}/install${EPREFIX}/${d}
+		mkdir -p "${dest}" || die
+		cp -pR "${@}" "${dest}/" || die
+		(
+			cd "${dest}" &&
+			chmod -R a+rX "${@##*/}"
+		) || die
+	else
+		die "${FUNCNAME} can only be used in src_install or with BUILD_DIR set"
+	fi
 }
 
 # @FUNCTION: python_doheader