mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-24 05:02:41 +00:00
GP-0: Python build improvements
This commit is contained in:
parent
4b14601927
commit
5f24502d0f
@ -70,7 +70,7 @@ task installEditablePyGhidra(type: Exec) {
|
||||
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
|
||||
}
|
||||
|
||||
|
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
|
||||
}
|
||||
|
@ -51,10 +51,8 @@ task buildPyPackage {
|
||||
File setuptools = project(":Debugger-rmi-trace").findPyDep(".")
|
||||
exec {
|
||||
workingDir { "build/pypkg" }
|
||||
commandLine rootProject.PYTHON3, "-m", "pip"
|
||||
args "wheel", "-w", "dist/", "--no-index", "--no-deps"
|
||||
args "-f", setuptools
|
||||
args "."
|
||||
commandLine rootProject.PYTHON3
|
||||
args "-m", "pip", "wheel", "-w", "dist/", "--no-index", "--no-deps", "-f", setuptools, "."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,10 @@ task createPythonVirtualEnvironment(type: Exec) {
|
||||
project.ext.PYTHON3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/python${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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user