mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
GP-0: Python build improvements
This commit is contained in:
parent
4b14601927
commit
5f24502d0f
4 changed files with 35 additions and 31 deletions
|
@ -70,7 +70,7 @@ task installEditablePyGhidra(type: Exec) {
|
||||||
commandLine "$PYTHON3_VENV", "-m", "pip", "install", "-e", "src/main/py", "--no-index", "-f", "$dir"
|
commandLine "$PYTHON3_VENV", "-m", "pip", "install", "-e", "src/main/py", "--no-index", "-f", "$dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findPython3(false)) {
|
if (findPython3(false, false)) {
|
||||||
rootProject.prepDev.dependsOn installEditablePyGhidra
|
rootProject.prepDev.dependsOn installEditablePyGhidra
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
build.gradle
39
build.gradle
|
@ -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)
|
project.ext.PYTHON3 = findPython3(true, true)
|
||||||
project.ext.PYTHON_DEPS = new HashSet<String>()
|
project.ext.PYTHON_DEPS = new HashSet<String>()
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
|
@ -160,11 +160,12 @@ def checkGradleVersion() {
|
||||||
* Although warnings may be produced no exception is thrown since python only required
|
* Although warnings may be produced no exception is thrown since python only required
|
||||||
* for specific build tasks and is not required for prepdev
|
* for specific build tasks and is not required for prepdev
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
def checkPythonVersion(String pyCmd) {
|
def checkPythonVersion(List<String> pyCmd) {
|
||||||
try {
|
try {
|
||||||
def stdout = new ByteArrayOutputStream()
|
def stdout = new ByteArrayOutputStream()
|
||||||
exec {
|
exec {
|
||||||
commandLine pyCmd, "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))"
|
commandLine pyCmd
|
||||||
|
args "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))"
|
||||||
standardOutput = stdout
|
standardOutput = stdout
|
||||||
errorOutput = OutputStream.nullOutputStream()
|
errorOutput = OutputStream.nullOutputStream()
|
||||||
}
|
}
|
||||||
|
@ -176,49 +177,53 @@ def checkPythonVersion(String pyCmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def checkPip(String pyCmd) {
|
def checkPip(List<String> pyCmd, boolean shouldPrint) {
|
||||||
try {
|
try {
|
||||||
def stdout = new ByteArrayOutputStream()
|
def stdout = new ByteArrayOutputStream()
|
||||||
exec {
|
exec {
|
||||||
commandLine pyCmd, "-c", "import pip; print(pip.__version__)"
|
commandLine pyCmd
|
||||||
|
args "-c", "import pip; print(pip.__version__)"
|
||||||
standardOutput = stdout
|
standardOutput = stdout
|
||||||
errorOutput = OutputStream.nullOutputStream()
|
errorOutput = OutputStream.nullOutputStream()
|
||||||
}
|
}
|
||||||
def version = "$stdout".strip();
|
def version = "$stdout".strip();
|
||||||
|
if (shouldPrint) {
|
||||||
if (version.length() == 0) {
|
if (version.length() == 0) {
|
||||||
println("Warning: Python3 pip not installed (required for build)")
|
println("Warning: Python3 pip not installed (required for build)")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
println("Python3 pip version: ${version}")
|
println("Python3 pip version: ${version}")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
if (shouldPrint) {
|
||||||
println("Warning: Python3 pip not installed (required for build)")
|
println("Warning: Python3 pip not installed (required for build)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def findPython3(boolean useDefault) {
|
def findPython3(boolean useDefault, boolean shouldPrint) {
|
||||||
for (pyCmd in ['py', 'python3', 'python']) {
|
def pyCmds = [['py'], ['python3'], ['python']]
|
||||||
|
pyCmds += SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] }
|
||||||
|
for (pyCmd in pyCmds) {
|
||||||
def pyVer = checkPythonVersion(pyCmd)
|
def pyVer = checkPythonVersion(pyCmd)
|
||||||
if (pyVer in SUPPORTED_PY_VERSIONS) {
|
if (pyVer in SUPPORTED_PY_VERSIONS) {
|
||||||
|
if (shouldPrint) {
|
||||||
println("Python3 command: ${pyCmd} (version ${pyVer})")
|
println("Python3 command: ${pyCmd} (version ${pyVer})")
|
||||||
checkPip(pyCmd)
|
}
|
||||||
return pyCmd
|
checkPip(pyCmd, shouldPrint)
|
||||||
}
|
|
||||||
}
|
|
||||||
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
|
return pyCmd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't fail until task execution. Just let "python3" fail.
|
// Don't fail until task execution. Just let "python3" fail.
|
||||||
// Force use of non-existent python3.9 instead of unsupported python version
|
// Force use of non-existent python3.9 instead of unsupported python version
|
||||||
// which should fail if a python build is performed.
|
// which should fail if a python build is performed.
|
||||||
println("Warning: Python3 command not found (required for build)")
|
if (shouldPrint) {
|
||||||
|
println("Warning: Supported Python ${SUPPORTED_PY_VERSIONS} not found (required for build)")
|
||||||
|
}
|
||||||
|
|
||||||
return useDefault ? 'python3.9' : null
|
return useDefault ? 'python3.9' : null
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,10 +51,8 @@ task buildPyPackage {
|
||||||
File setuptools = project(":Debugger-rmi-trace").findPyDep(".")
|
File setuptools = project(":Debugger-rmi-trace").findPyDep(".")
|
||||||
exec {
|
exec {
|
||||||
workingDir { "build/pypkg" }
|
workingDir { "build/pypkg" }
|
||||||
commandLine rootProject.PYTHON3, "-m", "pip"
|
commandLine rootProject.PYTHON3
|
||||||
args "wheel", "-w", "dist/", "--no-index", "--no-deps"
|
args "-m", "pip", "wheel", "-w", "dist/", "--no-index", "--no-deps", "-f", setuptools, "."
|
||||||
args "-f", setuptools
|
|
||||||
args "."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,10 @@ task createPythonVirtualEnvironment(type: Exec) {
|
||||||
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, "-m", "venv", venvDir, "--copies"
|
commandLine rootProject.PYTHON3
|
||||||
|
args "-m", "venv", venvDir, "--copies"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findPython3(false)) {
|
if (findPython3(false, false)) {
|
||||||
rootProject.prepDev.dependsOn createPythonVirtualEnvironment
|
rootProject.prepDev.dependsOn createPythonVirtualEnvironment
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue