GP-0: Improving python build error reporting (Closes #7036)

This commit is contained in:
Ryan Kurtz 2024-10-11 14:13:24 -04:00
parent ddf1efd486
commit 3558fe59a4
5 changed files with 30 additions and 13 deletions

View File

@ -56,7 +56,9 @@ task installJPype(type: Exec) {
File binRepoDir = file("${BIN_REPO}/ExternalPyWheels") File binRepoDir = file("${BIN_REPO}/ExternalPyWheels")
def dir = depsDir.exists() ? depsDir : binRepoDir def dir = depsDir.exists() ? depsDir : binRepoDir
commandLine "$PYTHON3_VENV", "-m", "pip", "install", "--no-index", "-f", "$dir", "JPype1" doFirst {
commandLine "$PYTHON3_VENV", "-m", "pip", "install", "--no-index", "-f", "$dir", "JPype1"
}
} }
// Install PyGhidra in editable mode to the development virtual environment // Install PyGhidra in editable mode to the development virtual environment
@ -67,10 +69,12 @@ task installEditablePyGhidra(type: Exec) {
File binRepoDir = file("${BIN_REPO}/ExternalPyWheels") File binRepoDir = file("${BIN_REPO}/ExternalPyWheels")
def dir = depsDir.exists() ? depsDir : binRepoDir def dir = depsDir.exists() ? depsDir : binRepoDir
commandLine "$PYTHON3_VENV", "-m", "pip", "install", "-e", "src/main/py", "--no-index", "-f", "$dir" doFirst {
commandLine "$PYTHON3_VENV", "-m", "pip", "install", "-e", "src/main/py", "--no-index", "-f", "$dir"
}
} }
if (findPython3(false, false)) { if (findPython3(false)) {
rootProject.prepDev.dependsOn installEditablePyGhidra rootProject.prepDev.dependsOn installEditablePyGhidra
} }

View File

@ -50,7 +50,7 @@ if ("32".equals(System.getProperty("sun.arch.data.model"))) {
* Identify supported Python command * Identify supported Python command
***************************************************************************************/ ***************************************************************************************/
project.ext.SUPPORTED_PY_VERSIONS = ['3.12', '3.11', '3.10', '3.9'] project.ext.SUPPORTED_PY_VERSIONS = ['3.12', '3.11', '3.10', '3.9']
project.ext.PYTHON3 = findPython3(true, true) project.ext.PYTHON3 = findPython3(true)
project.ext.PYTHON_DEPS = new HashSet<String>() project.ext.PYTHON_DEPS = new HashSet<String>()
/********************************************************************************* /*********************************************************************************
@ -204,7 +204,7 @@ def checkPip(List<String> pyCmd, boolean shouldPrint) {
} }
} }
def findPython3(boolean useDefault, boolean shouldPrint) { def findPython3(boolean shouldPrint) {
def pyCmds = [['py'], ['python3'], ['python']] def pyCmds = [['py'], ['python3'], ['python']]
pyCmds += SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] } pyCmds += SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] }
for (pyCmd in pyCmds) { for (pyCmd in pyCmds) {
@ -218,14 +218,12 @@ def findPython3(boolean useDefault, boolean shouldPrint) {
} }
} }
// Don't fail until task execution. Just let "python3" fail.
// Force use of non-existent python3.9 instead of unsupported python version
// which should fail if a python build is performed.
if (shouldPrint) { if (shouldPrint) {
println("Warning: Supported Python ${SUPPORTED_PY_VERSIONS} not found (required for build)") println("Warning: Supported Python ${SUPPORTED_PY_VERSIONS} not found (required for build)")
} }
return useDefault ? 'python3.9' : null // Don't fail until task execution. Just retun null, which can be gracefully handled later.
return null
} }
/****************************************************************************************** /******************************************************************************************

View File

@ -48,6 +48,10 @@ task buildPyPackage {
outputs.dir(dist) outputs.dir(dist)
doLast { doLast {
if (rootProject.PYTHON3 == null) {
throw new GradleException("A supported version of Python ${SUPPORTED_PY_VERSIONS} was not found!")
}
File setuptools = project(":Debugger-rmi-trace").findPyDep(".") File setuptools = project(":Debugger-rmi-trace").findPyDep(".")
exec { exec {
workingDir { "build/pypkg" } workingDir { "build/pypkg" }

View File

@ -271,6 +271,11 @@ task createGhidraStubsWheel {
doLast { doLast {
File setuptools = project(":Debugger-rmi-trace").findPyDep(".") File setuptools = project(":Debugger-rmi-trace").findPyDep(".")
if (rootProject.PYTHON3 == null) {
throw new GradleException("A supported version of Python ${SUPPORTED_PY_VERSIONS} was not found!")
}
exec { exec {
workingDir { cwd.toString() } workingDir { cwd.toString() }
commandLine rootProject.PYTHON3 commandLine rootProject.PYTHON3

View File

@ -24,11 +24,17 @@ task createPythonVirtualEnvironment(type: Exec) {
def suffix = isCurrentWindows() ? ".exe" : "3" def suffix = isCurrentWindows() ? ".exe" : "3"
project.ext.PYTHON3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/python${suffix}" project.ext.PYTHON3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/python${suffix}"
project.ext.PIP3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/pip${suffix}" project.ext.PIP3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/pip${suffix}"
commandLine rootProject.PYTHON3 doFirst {
args "-m", "venv", venvDir, "--copies" if (rootProject.PYTHON3 == null) {
throw new GradleException("A supported version of Python ${SUPPORTED_PY_VERSIONS} was not found!")
}
commandLine rootProject.PYTHON3
args "-m", "venv", venvDir, "--copies"
}
} }
if (findPython3(false, false)) { if (findPython3(false)) {
rootProject.prepDev.dependsOn createPythonVirtualEnvironment rootProject.prepDev.dependsOn createPythonVirtualEnvironment
} }