Skip to content

Ghidra is a software reverse engineering (SRE) framework

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

Ryan Kurtz3558fe59a41f
diff --git a/Ghidra/Features/PyGhidra/build.gradle b/Ghidra/Features/PyGhidra/build.gradle
index d2647bbc16..1860361ea3 100644
--- a/Ghidra/Features/PyGhidra/build.gradle
+++ b/Ghidra/Features/PyGhidra/build.gradle
@@ -56,7 +56,9 @@ task installJPype(type: Exec) {
File binRepoDir = file("${BIN_REPO}/ExternalPyWheels")
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
@@ -67,10 +69,12 @@ task installEditablePyGhidra(type: Exec) {
File binRepoDir = file("${BIN_REPO}/ExternalPyWheels")
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
}
diff --git a/build.gradle b/build.gradle
index 818ea8fecb..98ceaf52b9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -50,7 +50,7 @@ if ("32".equals(System.getProperty("sun.arch.data.model"))) {
* Identify supported Python command
***************************************************************************************/
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>()
/*********************************************************************************
@@ -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']]
pyCmds += SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] }
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) {
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
}
/******************************************************************************************
diff --git a/gradle/hasPythonPackage.gradle b/gradle/hasPythonPackage.gradle
index 3755575dd8..bb260eef05 100644
--- a/gradle/hasPythonPackage.gradle
+++ b/gradle/hasPythonPackage.gradle
@@ -48,6 +48,10 @@ task buildPyPackage {
outputs.dir(dist)
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(".")
exec {
workingDir { "build/pypkg" }
diff --git a/gradle/root/distribution.gradle b/gradle/root/distribution.gradle
index 4f5af41f3d..0826f9088e 100644
--- a/gradle/root/distribution.gradle
+++ b/gradle/root/distribution.gradle
@@ -271,6 +271,11 @@ task createGhidraStubsWheel {
doLast {
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 {
workingDir { cwd.toString() }
commandLine rootProject.PYTHON3
diff --git a/gradle/root/venv.gradle b/gradle/root/venv.gradle
index c20bdd54a8..aa4cefad47 100644
--- a/gradle/root/venv.gradle
+++ b/gradle/root/venv.gradle
@@ -24,11 +24,17 @@ task createPythonVirtualEnvironment(type: Exec) {
def suffix = isCurrentWindows() ? ".exe" : "3"
project.ext.PYTHON3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/python${suffix}"
project.ext.PIP3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/pip${suffix}"
-
- commandLine rootProject.PYTHON3
- args "-m", "venv", venvDir, "--copies"
+
+ doFirst {
+ 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
}