ghidra/gradle/debugger/hasPythonPackage.gradle

76 lines
1.9 KiB
Groovy

/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
def checkPythonVersion(String pyCmd) {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine pyCmd, "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))"
standardOutput = stdout
standardError = null
}
def version = "$stdout".strip()
return version
}
catch (Exception e) {
return "ABSENT"
}
}
ext.SUPPORTED_PY_VERSIONS = ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
def findPython3() {
for (pyCmd in ['python3', 'python']) {
if (checkPythonVersion(pyCmd) in SUPPORTED_PY_VERSIONS) {
return pyCmd
}
}
// Don't fail until task execution. Just let "python3" fail.
return 'python3'
}
ext.PYTHON3 = findPython3()
task assemblePyPackage(type: Copy) {
from "src/main/py"
into "build/pypkg/"
}
rootProject.tasks.prepDev.dependsOn(assemblePyPackage)
task buildPyPackage(type: Exec) {
ext.dist = { file("build/pypkg/dist") }
inputs.files(assemblePyPackage)
outputs.dir(dist)
workingDir { "build/pypkg" }
commandLine PYTHON3, "-m", "build"
}
// At the moment, any module with a python package also distributes it.
// We can separate this into `distributePythonPackage` later, if necessary.
rootProject.assembleDistribution {
def p = this.project
def zipPath = getZipPath(p)
from (p.assemblePyPackage) {
exclude '**/*.pyc'
exclude '**/*.pyo'
exclude '**/__pycache__/**'
into { zipPath + "/pypkg" }
}
}