mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-24 13:11:47 +00:00
GP-4570 Moved python3 search to root project
This commit is contained in:
parent
8163d9f912
commit
26fe4d63a7
74
build.gradle
74
build.gradle
@ -45,6 +45,12 @@ if ("32".equals(System.getProperty("sun.arch.data.model"))) {
|
|||||||
throw new GradleException("\n\n\t32-bit Java detected! Please use 64-bit Java.\n\n");
|
throw new GradleException("\n\n\t32-bit Java detected! Please use 64-bit Java.\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************************************
|
||||||
|
* Identify supported Python command
|
||||||
|
***************************************************************************************/
|
||||||
|
project.ext.SUPPORTED_PY_VERSIONS = ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
|
||||||
|
project.ext.PYTHON3 = findPython3()
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* Define the location of bin repo
|
* Define the location of bin repo
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
@ -145,6 +151,74 @@ def checkGradleVersion() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* Identifies supported python3 command to be used when building and checks for pip install.
|
||||||
|
* 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) {
|
||||||
|
try {
|
||||||
|
def stdout = new ByteArrayOutputStream()
|
||||||
|
exec {
|
||||||
|
commandLine pyCmd, "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))"
|
||||||
|
standardOutput = stdout
|
||||||
|
errorOutput = OutputStream.nullOutputStream()
|
||||||
|
}
|
||||||
|
def version = "$stdout".strip()
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return "ABSENT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def checkPip(String pyCmd) {
|
||||||
|
try {
|
||||||
|
def stdout = new ByteArrayOutputStream()
|
||||||
|
exec {
|
||||||
|
commandLine pyCmd, "-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}")
|
||||||
|
}
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
println("Warning: Python3 pip not installed (required for build)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def findPython3() {
|
||||||
|
for (pyCmd in ['py', 'python3', 'python']) {
|
||||||
|
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)
|
||||||
|
return pyCmd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Don't fail until task execution. Just let "python3" fail.
|
||||||
|
// Force use of non-existent python3.7 instead of unsupported python version
|
||||||
|
// which should fail if a python build is performed.
|
||||||
|
println("Warning: Python3 command not found (required for build)")
|
||||||
|
return 'python3.7'
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************************
|
/******************************************************************************************
|
||||||
*
|
*
|
||||||
* Utility methods used by multiple build.gradle files
|
* Utility methods used by multiple build.gradle files
|
||||||
|
@ -13,79 +13,10 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
def checkPythonVersion(String pyCmd) {
|
/**
|
||||||
try {
|
* NOTE: Supported Python3 command is established by root project build.gradle
|
||||||
def stdout = new ByteArrayOutputStream()
|
*/
|
||||||
exec {
|
|
||||||
commandLine pyCmd, "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))"
|
|
||||||
standardOutput = stdout
|
|
||||||
errorOutput = OutputStream.nullOutputStream()
|
|
||||||
}
|
|
||||||
def version = "$stdout".strip()
|
|
||||||
return version
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
return "ABSENT"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ext.MIN_PIP_VERSION = [20, 2] // 20.2+
|
|
||||||
|
|
||||||
def checkPipVersion(String pyCmd) {
|
|
||||||
try {
|
|
||||||
def stdout = new ByteArrayOutputStream()
|
|
||||||
exec {
|
|
||||||
commandLine pyCmd, "-c", "import pip; print(pip.__version__)"
|
|
||||||
standardOutput = stdout
|
|
||||||
errorOutput = OutputStream.nullOutputStream()
|
|
||||||
}
|
|
||||||
def version = "$stdout".strip();
|
|
||||||
if (version.length() == 0) {
|
|
||||||
println("Warning: python pip not installed (required for build)")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
println("Found python pip version ${version}")
|
|
||||||
def (majorVer, minorVer) = version.tokenize('.')
|
|
||||||
def major = majorVer.toInteger()
|
|
||||||
def minor = minorVer.toInteger()
|
|
||||||
if (major < MIN_PIP_VERSION[0] || (major == MIN_PIP_VERSION[0] && minor < MIN_PIP_VERSION[1])) {
|
|
||||||
println("Warning: python pip may require upgrade")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return version
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
println("Warning: python pip not installed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ext.SUPPORTED_PY_VERSIONS = ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
|
|
||||||
|
|
||||||
def findPython3() {
|
|
||||||
for (pyCmd in ['py', 'python3', 'python']) {
|
|
||||||
def pyVer = checkPythonVersion(pyCmd)
|
|
||||||
if (pyVer in SUPPORTED_PY_VERSIONS) {
|
|
||||||
println("Using python command: ${pyCmd} (version ${pyVer})")
|
|
||||||
checkPipVersion(pyCmd)
|
|
||||||
return pyCmd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (pyVer in SUPPORTED_PY_VERSIONS) {
|
|
||||||
def pyCmd = "python${pyVer}"
|
|
||||||
if (checkPythonVersion(pyCmd) in SUPPORTED_PY_VERSIONS) {
|
|
||||||
println("Using python command: ${pyCmd}")
|
|
||||||
checkPipVersion(pyCmd)
|
|
||||||
return pyCmd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Don't fail until task execution. Just let "python3" fail.
|
|
||||||
// Force use of non-existent python3.7 instead of unsupported python version
|
|
||||||
// which should fail if a python build is performed.
|
|
||||||
return 'python3.7'
|
|
||||||
}
|
|
||||||
|
|
||||||
ext.PYTHON3 = findPython3()
|
|
||||||
|
|
||||||
ext.findPyDep = { name ->
|
ext.findPyDep = { name ->
|
||||||
File inDeps = file("${DEPS_DIR}/${project.name}/${name}")
|
File inDeps = file("${DEPS_DIR}/${project.name}/${name}")
|
||||||
@ -114,7 +45,7 @@ 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 PYTHON3, "-m", "pip"
|
commandLine rootProject.PYTHON3, "-m", "pip"
|
||||||
args "wheel", "-w", "dist/", "--no-index", "--no-deps"
|
args "wheel", "-w", "dist/", "--no-index", "--no-deps"
|
||||||
args "-f", setuptools
|
args "-f", setuptools
|
||||||
args "."
|
args "."
|
||||||
|
Loading…
Reference in New Issue
Block a user