From a88eeb4be49a008c03d54fbaeeac86e550b979df Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Tue, 27 Oct 2020 22:54:11 +0200 Subject: [PATCH] Add new Gradle build --- README.markdown | 2 +- build.gradle | 33 ---- build.gradle.kts | 131 +++++++++++++++ data/build.xml | 50 ------ extension.properties | 5 - gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew.bat | 203 ++++++++++++----------- settings.gradle.kts | 14 ++ 9 files changed, 252 insertions(+), 190 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 data/build.xml delete mode 100644 extension.properties create mode 100644 gradle.properties create mode 100644 settings.gradle.kts diff --git a/README.markdown b/README.markdown index 5015807..df42e1c 100644 --- a/README.markdown +++ b/README.markdown @@ -36,7 +36,7 @@ or ./gradlew -PGHIDRA_INSTALL_DIR=/path/to/ghidra ``` -You can then find a built extension .zip in the `dist` directory. +You can then find a built extension .zip in the `build/distributions` directory. ## How to install diff --git a/build.gradle b/build.gradle deleted file mode 100644 index d631d6c..0000000 --- a/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -// Builds a Ghidra Extension for a given Ghidra installation. -// -// An absolute path to the Ghidra installation directory must be supplied either by setting the -// GHIDRA_INSTALL_DIR environment variable or Gradle project property: -// -// > export GHIDRA_INSTALL_DIR= -// > gradle -// -// or -// -// > gradle -PGHIDRA_INSTALL_DIR= -// -// Gradle should be invoked from the directory of the project to build. Please see the -// application.gradle.version property in /Ghidra/application.properties -// for the correction version of Gradle to use for the Ghidra installation you specify. - -//----------------------START "DO NOT MODIFY" SECTION------------------------------ -def ghidraInstallDir - -if (System.env.GHIDRA_INSTALL_DIR) { - ghidraInstallDir = System.env.GHIDRA_INSTALL_DIR -} -else if (project.hasProperty("GHIDRA_INSTALL_DIR")) { - ghidraInstallDir = project.getProperty("GHIDRA_INSTALL_DIR") -} - -if (ghidraInstallDir) { - apply from: new File(ghidraInstallDir).getCanonicalPath() + "/support/buildExtension.gradle" -} -else { - throw new GradleException("GHIDRA_INSTALL_DIR is not defined!") -} -//----------------------END "DO NOT MODIFY" SECTION------------------------------- diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..32b3140 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,131 @@ +// Copyright 2019-2020 Joonas Javanainen +// +// 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. +import java.time.LocalDate +import java.time.format.DateTimeFormatter.BASIC_ISO_DATE +import java.util.Properties +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.4.10" + java +} + +repositories { + jcenter() +} + +val ghidraDir = System.getenv("GHIDRA_INSTALL_DIR") + ?: (project.findProperty("ghidra.dir") as? String) + ?: throw IllegalStateException("Can't find Ghidra installation") + +val ghidraProps = Properties().apply { file("$ghidraDir/Ghidra/application.properties").inputStream().use { load(it) } } +val ghidraVersion = ghidraProps.getProperty("application.version")!! +val ghidraRelease = ghidraProps.getProperty("application.release.name")!! + +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + withSourcesJar() +} + +tasks.withType { + kotlinOptions { + jvmTarget = "11" + } +} + +val ghidra: Configuration by configurations.creating + +dependencies { + ghidra(fileTree("$ghidraDir/Ghidra/Framework") { include("**/*.jar") }) + ghidra(fileTree("$ghidraDir/Ghidra/Features") { include("**/*.jar") }) + + compileOnly(ghidra) + + testImplementation(ghidra) + testImplementation(kotlin("stdlib-jdk8")) + testImplementation(platform("org.junit:junit-bom:5.7.0")) + testImplementation("org.junit.jupiter:junit-jupiter-api") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") +} + +val generateExtensionProps by tasks.registering() { + val output = file("$buildDir/generated/extension.properties") + outputs.file(output) + doLast { + output.outputStream().use { + val props = Properties() + props += mapOf( + ("name" to "GhidraBoy"), + ("description" to "Support for Sharp SM83 / Game Boy"), + ("author" to "Gekkio"), + ("createdOn" to LocalDate.now().toString()), + ("version" to ghidraVersion) + ) + props.store(it, null) + } + } +} + +val compileSleigh by tasks.registering(JavaExec::class) { + val slaspecFile = file("data/languages/sm83.slaspec") + val slaFile = file("data/languages/sm83.sla") + + inputs.files(fileTree("data/languages").include("*.slaspec", "*.sinc")) + .withPropertyName("sourceFiles") + .withPathSensitivity(PathSensitivity.RELATIVE) + outputs.files(slaFile) + .withPropertyName("outputFile") + + classpath = configurations["ghidra"] + main = "ghidra.pcodeCPort.slgh_compile.SleighCompile" + args = listOf("-u", "-l", "-n", "-t", "-e", "-c", "-f", slaspecFile.absolutePath) +} + +val zip by tasks.registering(Zip::class) { + archiveFileName.set("ghidra_${ghidraVersion}_${ghidraRelease}_${LocalDate.now().format(BASIC_ISO_DATE)}_${project.name}.zip") + + into("${project.name}/") + from(tasks.named("jar")) { + into("lib/") + } + from(tasks.named("sourcesJar")) { + into("lib/") + rename { "${project.name}-src.zip" } + } + from(configurations.runtimeClasspath.get()) { + into("lib/") + } + + from(generateExtensionProps) + from("data") { + into("data/") + include("**/*.cspec", "**/*.ldefs", "**/*.pspec", "**/*.sinc", "**/*.slaspec", "**/sleighArgs.txt") + } + from("README.markdown", "LICENSE", "Module.manifest") +} + +tasks.named("assemble") { + dependsOn("zip") +} + +tasks.named("test") { + dependsOn("compileSleigh") + useJUnitPlatform() + + systemProperty("ghidra.dir", ghidraDir) + systemProperty("SystemUtilities.isTesting", true) +} + +defaultTasks("clean", "assemble") diff --git a/data/build.xml b/data/build.xml deleted file mode 100644 index 74a29fa..0000000 --- a/data/build.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/extension.properties b/extension.properties deleted file mode 100644 index 2025ad6..0000000 --- a/extension.properties +++ /dev/null @@ -1,5 +0,0 @@ -name=@extname@ -description=Support for Sharp SM83 / Game Boy -author=Gekkio -createdOn= -version=@extversion@ diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..269e8fb --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +kotlin.stdlib.default.dependency=false +org.gradle.vfs.watch=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b7c8c5d..be52383 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew.bat b/gradlew.bat index 9618d8d..9109989 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,100 +1,103 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..9b3310a --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,14 @@ +// Copyright 2019-2020 Joonas Javanainen +// +// 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. +rootProject.name = "GhidraBoy"