GP-4570 Moved python3 search to root project

This commit is contained in:
ghidra1 2024-05-01 09:56:08 -04:00
parent 8163d9f912
commit 26fe4d63a7
2 changed files with 79 additions and 74 deletions

View File

@ -45,6 +45,12 @@ if ("32".equals(System.getProperty("sun.arch.data.model"))) {
throw new GradleException("\n\n\t32-bit Java detected! Please use 64-bit Java.\n\n");
}
/***************************************************************************************
* Identify supported Python command
***************************************************************************************/
project.ext.SUPPORTED_PY_VERSIONS = ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
project.ext.PYTHON3 = findPython3()
/*********************************************************************************
* Define the location of bin repo
*********************************************************************************/
@ -145,6 +151,74 @@ def checkGradleVersion() {
}
}
/*********************************************************************************
* Identifies supported python3 command to be used when building and checks for pip install.
* Although warnings may be produced no exception is thrown since python only required
* for specific build tasks and is not required for prepdev
*********************************************************************************/
def checkPythonVersion(String pyCmd) {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine pyCmd, "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))"
standardOutput = stdout
errorOutput = OutputStream.nullOutputStream()
}
def version = "$stdout".strip()
return version
}
catch (Exception e) {
return "ABSENT"
}
}
def checkPip(String pyCmd) {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine pyCmd, "-c", "import pip; print(pip.__version__)"
standardOutput = stdout
errorOutput = OutputStream.nullOutputStream()
}
def version = "$stdout".strip();
if (version.length() == 0) {
println("Warning: Python3 pip not installed (required for build)")
}
else {
println("Python3 pip version: ${version}")
}
return version
}
catch (Exception e) {
println("Warning: Python3 pip not installed (required for build)")
}
}
def findPython3() {
for (pyCmd in ['py', 'python3', 'python']) {
def pyVer = checkPythonVersion(pyCmd)
if (pyVer in SUPPORTED_PY_VERSIONS) {
println("Python3 command: ${pyCmd} (version ${pyVer})")
checkPip(pyCmd)
return pyCmd
}
}
for (pyVer in SUPPORTED_PY_VERSIONS) {
def pyCmd = "python${pyVer}"
if (checkPythonVersion(pyCmd) in SUPPORTED_PY_VERSIONS) {
println("Python3 command: ${pyCmd}")
checkPip(pyCmd)
return pyCmd
}
}
// Don't fail until task execution. Just let "python3" fail.
// Force use of non-existent python3.7 instead of unsupported python version
// which should fail if a python build is performed.
println("Warning: Python3 command not found (required for build)")
return 'python3.7'
}
/******************************************************************************************
*
* Utility methods used by multiple build.gradle files

View File

@ -13,79 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
def checkPythonVersion(String pyCmd) {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine pyCmd, "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))"
standardOutput = stdout
errorOutput = OutputStream.nullOutputStream()
}
def version = "$stdout".strip()
return version
}
catch (Exception e) {
return "ABSENT"
}
}
ext.MIN_PIP_VERSION = [20, 2] // 20.2+
def checkPipVersion(String pyCmd) {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine pyCmd, "-c", "import pip; print(pip.__version__)"
standardOutput = stdout
errorOutput = OutputStream.nullOutputStream()
}
def version = "$stdout".strip();
if (version.length() == 0) {
println("Warning: python pip not installed (required for build)")
}
else {
println("Found python pip version ${version}")
def (majorVer, minorVer) = version.tokenize('.')
def major = majorVer.toInteger()
def minor = minorVer.toInteger()
if (major < MIN_PIP_VERSION[0] || (major == MIN_PIP_VERSION[0] && minor < MIN_PIP_VERSION[1])) {
println("Warning: python pip may require upgrade")
}
}
return version
}
catch (Exception e) {
println("Warning: python pip not installed")
}
}
ext.SUPPORTED_PY_VERSIONS = ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
def findPython3() {
for (pyCmd in ['py', 'python3', 'python']) {
def pyVer = checkPythonVersion(pyCmd)
if (pyVer in SUPPORTED_PY_VERSIONS) {
println("Using python command: ${pyCmd} (version ${pyVer})")
checkPipVersion(pyCmd)
return pyCmd
}
}
for (pyVer in SUPPORTED_PY_VERSIONS) {
def pyCmd = "python${pyVer}"
if (checkPythonVersion(pyCmd) in SUPPORTED_PY_VERSIONS) {
println("Using python command: ${pyCmd}")
checkPipVersion(pyCmd)
return pyCmd
}
}
// Don't fail until task execution. Just let "python3" fail.
// Force use of non-existent python3.7 instead of unsupported python version
// which should fail if a python build is performed.
return 'python3.7'
}
ext.PYTHON3 = findPython3()
/**
* NOTE: Supported Python3 command is established by root project build.gradle
*/
ext.findPyDep = { name ->
File inDeps = file("${DEPS_DIR}/${project.name}/${name}")
@ -114,7 +45,7 @@ task buildPyPackage {
File setuptools = project(":Debugger-rmi-trace").findPyDep(".")
exec {
workingDir { "build/pypkg" }
commandLine PYTHON3, "-m", "pip"
commandLine rootProject.PYTHON3, "-m", "pip"
args "wheel", "-w", "dist/", "--no-index", "--no-deps"
args "-f", setuptools
args "."