Files
ghidra/gradle/hasPythonPackage.gradle
d-millar fc988976bf GP-4562: once more more...
GP-4562: once more...
GP-4562: once more...
GP-4562: test error
GP-4562: post-review pt4
GP-4562: post-review pt3
GP-4562: post-review pt2
GP-4562: post-review pt1
GP-4562: warnings (Win)
GP-4562: warnings
GP-4562: windows warning
GP-4562: notes
GP-4562: notes
GP-4562: rearranged slightly
GP-4562: clean-up
GP-4562: powershell adds
GP-4562: powershell adds
GP-4562: added task
GP-4562: oops
GP-4562: buildXml
GP-4562: moving stuff
GP-4562: re-generating
GP-4562: gdb (passes tests)
GP-4562: first pass
GP4562: xsltGP-4562: rearrangeGP-4562:  breaking things downGP-4562: basics in placeGP-4562: oops
2026-05-08 14:46:06 -04:00

158 lines
4.2 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.
*/
/**
* NOTE: Supported Python3 command is established by root project build.gradle
*/
// Enable the Python Nature in the Eclipse project
eclipse.project {
natures 'org.python.pydev.pythonNature'
}
ext.findPyDep = { name ->
File inDeps = file("${DEPS_DIR}/${project.name}/${name}")
File inRepo = file("${BIN_REPO}/ExternalPyWheels/${name}")
if (inDeps.exists()) {
return inDeps
}
if (inRepo.exists()) {
return inRepo
}
println("Warning: Could not find '${name}' for ${project.name}")
return inDeps
}
task assemblePyPackage(type: Copy) {
from "src/main/py"
into "build/pypkg/"
}
task typeCheckPyPackage(type: Exec) {
dependsOn assemblePyPackage
inputs.files(assemblePyPackage)
doFirst {
if (rootProject.PYTHON3 == null) {
throw new GradleException("A supported version of Python [${PYTHON_SUPPORTED}] was not found!")
}
file("build/pypkg/src").listFiles().each { pkg ->
if (pkg.isDirectory() && new File(pkg, "__init__.py").isFile()) {
args "-p", pkg.name
}
}
}
workingDir { file("build/pypkg/src") }
commandLine rootProject.PYTHON3
args "-m", "mypy"
}
task buildPyPackage {
dependsOn assemblePyPackage
ext.dist = { file("build/pypkg/dist") }
inputs.files(assemblePyPackage)
outputs.dir(dist)
def debuggerRmiTraceProject = project(":Debugger-rmi-trace")
doLast {
if (rootProject.PYTHON3 == null) {
throw new GradleException("A supported version of Python [${PYTHON_SUPPORTED}] was not found!")
}
File setuptools = debuggerRmiTraceProject.findPyDep(".")
def exec = providers.exec {
workingDir { file("build/pypkg") }
ignoreExitValue = true
commandLine rootProject.PYTHON3
args "-m", "pip", "wheel", "-w", "dist/", "--no-index", "--no-deps", "-f", setuptools, "."
}
if (exec.result.get().exitValue != 0) {
throw new GradleException(exec.standardError.asText.get().strip())
}
if (exec.standardOutput.asText.get().contains("Successfully built UNKNOWN")) {
throw new GradleException("UNKNOWN wheel built...upgrade pip")
}
}
}
// At the moment, any module with a python package also distributes it.
// We can separate this into `distributePythonPackage` later, if necessary.
rootProject.assembleDistribution {
dependsOn(buildPyPackage)
def p = this.project
def zipPath = getZipPath(p)
from (p.assemblePyPackage) {
exclude '**/*.pyc'
exclude '**/*.pyo'
exclude '**/__pycache__/**'
exclude '**/.pytest_cache'
exclude '**/*.egg-info'
exclude 'build'
into { zipPath + "/pypkg" }
}
}
ext.distributePyDep = { name ->
Set<File> wheelFiles = PYTHON_DEPS.get(project)
if (wheelFiles == null) {
wheelFiles = new HashSet<>()
PYTHON_DEPS.put(project, wheelFiles)
}
File dep = findPyDep(name)
wheelFiles.add(dep)
def zipPath = getZipPath(project)
rootProject.assembleDistribution {
into ("${zipPath}/pypkg/dist") {
from dep
}
}
}
// This task composes debugger schema files from their subpieces
def foundFiles = fileTree("src/main/py/src").matching {
include "**/build_xml.py"
}
task buildXmlSchema {
doLast {
if (rootProject.PYTHON3 == null) {
throw new GradleException("A supported version of Python [${PYTHON_SUPPORTED}] was not found!")
}
File buildScript = foundFiles.isEmpty() ? null : foundFiles.singleFile
if (buildScript == null || !buildScript.exists()) {
println "Warning: Could not find build_xml.py for ${project.name}"
return
}
def exec = providers.exec {
workingDir { buildScript.parentFile }
ignoreExitValue = true
commandLine rootProject.PYTHON3
args "build_xml.py"
}
if (exec.result.get().exitValue != 0) {
throw new GradleException(exec.standardError.asText.get().strip())
}
}
}