mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 01:39:21 +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
53
build.gradle
53
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)
|
||||
project.ext.PYTHON3 = findPython3(true, true)
|
||||
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
|
||||
* for specific build tasks and is not required for prepdev
|
||||
*********************************************************************************/
|
||||
def checkPythonVersion(String pyCmd) {
|
||||
def checkPythonVersion(List<String> pyCmd) {
|
||||
try {
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
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
|
||||
errorOutput = OutputStream.nullOutputStream()
|
||||
}
|
||||
|
@ -176,49 +177,53 @@ def checkPythonVersion(String pyCmd) {
|
|||
}
|
||||
}
|
||||
|
||||
def checkPip(String pyCmd) {
|
||||
def checkPip(List<String> pyCmd, boolean shouldPrint) {
|
||||
try {
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine pyCmd, "-c", "import pip; print(pip.__version__)"
|
||||
commandLine pyCmd
|
||||
args "-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}")
|
||||
if (shouldPrint) {
|
||||
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)")
|
||||
if (shouldPrint) {
|
||||
println("Warning: Python3 pip not installed (required for build)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def findPython3(boolean useDefault) {
|
||||
for (pyCmd in ['py', 'python3', 'python']) {
|
||||
def findPython3(boolean useDefault, boolean shouldPrint) {
|
||||
def pyCmds = [['py'], ['python3'], ['python']]
|
||||
pyCmds += SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] }
|
||||
for (pyCmd in pyCmds) {
|
||||
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)
|
||||
if (shouldPrint) {
|
||||
println("Python3 command: ${pyCmd} (version ${pyVer})")
|
||||
}
|
||||
checkPip(pyCmd, shouldPrint)
|
||||
return pyCmd
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue