diff --git a/Ghidra/Features/Base/ghidra_scripts/VSCodeProjectScript.java b/Ghidra/Features/Base/ghidra_scripts/VSCodeProjectScript.java index 135bb060d2..6572858e5f 100644 --- a/Ghidra/Features/Base/ghidra_scripts/VSCodeProjectScript.java +++ b/Ghidra/Features/Base/ghidra_scripts/VSCodeProjectScript.java @@ -136,6 +136,9 @@ public class VSCodeProjectScript extends GhidraScript { .filter(e -> e.getValue() != null) .forEach(e -> sourcesObject.addProperty(e.getKey(), e.getValue())); + json.addProperty("python.analysis.stubPath", + new File(installDir, "docs/ghidra_stubs/typestubs").getAbsolutePath()); + // Write settings json object if (!FileUtilities.mkdirs(settingsFile.getParentFile())) { throw new IOException("Failed to create: " + settingsFile.getParentFile()); diff --git a/Ghidra/Features/PyGhidra/build.gradle b/Ghidra/Features/PyGhidra/build.gradle index 655bbeb147..ab7992e4a7 100644 --- a/Ghidra/Features/PyGhidra/build.gradle +++ b/Ghidra/Features/PyGhidra/build.gradle @@ -62,9 +62,23 @@ task installJPype(type: Exec) { } } +// Install ghidra-stubs into the development virtual environment +task installGhidraStubs(type: Exec) { + dependsOn(":createGhidraStubsWheel") + + File depsDir = file("${DEPS_DIR}/PyGhidra") + File binRepoDir = file("${BIN_REPO}/ExternalPyWheels") + def dir = depsDir.exists() ? depsDir : binRepoDir + + doFirst { + commandLine "$PYTHON3_VENV", "-m", "pip", "install", "--no-index", "-f", "${ROOT_PROJECT_DIR}/build/typestubs/dist", "ghidra-stubs" + } +} + // Install PyGhidra in editable mode to the development virtual environment task installEditablePyGhidra(type: Exec) { dependsOn("installJPype") + dependsOn("installGhidraStubs") File depsDir = file("${DEPS_DIR}/PyGhidra") File binRepoDir = file("${BIN_REPO}/ExternalPyWheels") diff --git a/gradle/root/distribution.gradle b/gradle/root/distribution.gradle index 298fffaf2f..44da14c4b7 100644 --- a/gradle/root/distribution.gradle +++ b/gradle/root/distribution.gradle @@ -236,23 +236,21 @@ task createGhidraStubsWheel { dependsOn("createPythonTypeStubs") - String ROOT_PROJECT_DIR = rootProject.projectDir.toString() + def typestubsDir = file("${ROOT_PROJECT_DIR}/build/typestubs").getAbsolutePath() + def distDir = file("${typestubsDir}/dist").getAbsolutePath() - def cwd = file(ROOT_PROJECT_DIR + "/build/typestubs") - def destinationDir = file(cwd.toString() + "/dist") - - it.outputs.file(destinationDir.toString() + "/ghidra_stubs-${project.version}-py3-none-any.whl") + it.outputs.file("${distDir}/ghidra_stubs-${project.version}-py3-none-any.whl") doFirst { copy { - from(file(ROOT_PROJECT_DIR + "/LICENSE")) - into cwd + from(file("${ROOT_PROJECT_DIR}/LICENSE")) + into typestubsDir } - def manifest = file(cwd.toString() + "/MANIFEST.in" ) + def manifest = file("${typestubsDir}/MANIFEST.in") manifest.write("graft src\n") - def pyproject = file(cwd.toString() + "/pyproject.toml" ) + def pyproject = file("${typestubsDir}/pyproject.toml" ) pyproject.write("""\ [build-system] requires = ["setuptools", "wheel"] @@ -272,14 +270,14 @@ task createGhidraStubsWheel { doLast { File setuptools = project(":Debugger-rmi-trace").findPyDep(".") - if (rootProject.PYTHON3 == null) { + if (PYTHON3 == null) { throw new GradleException("A supported version of Python ${SUPPORTED_PY_VERSIONS} was not found!") } exec { - workingDir { cwd.toString() } - commandLine rootProject.PYTHON3 - args "-m", "pip", "wheel", "-w", destinationDir.toString(), "--no-index", "-f", setuptools, "." + workingDir { typestubsDir } + commandLine PYTHON3 + args "-m", "pip", "wheel", "-w", distDir, "--no-index", "-f", setuptools, "." } } } @@ -431,8 +429,11 @@ task assembleDistribution (type: Copy) { //////////////////////////// // Ghidra Python type stubs //////////////////////////// + from ("${ROOT_PROJECT_DIR}/build/typestubs/src") { + into 'docs/ghidra_stubs/typestubs' + } from (createGhidraStubsWheel) { - into 'docs' + into 'docs/ghidra_stubs' } ////////////////