From 4870923676f87b2fc95a89bff7ae8bc21b122b1f Mon Sep 17 00:00:00 2001 From: Ao Li Date: Sat, 27 Jul 2024 09:55:35 -0400 Subject: [PATCH] Simplify build process. --- .github/workflows/main.yml | 11 +--- core/build.gradle.kts | 4 ++ instrumentation/build.gradle.kts | 9 ++-- integration-tests/build.gradle.kts | 2 + jdk/build.gradle.kts | 51 ++++++++++--------- .../cmu/pasta/fray/jdk/jlink/JlinkPlugin.kt | 1 + {examples => junit-runner}/build.gradle.kts | 30 ----------- .../cmu/pasta/fray/runner}/JUnitRunner.java | 2 +- settings.gradle.kts | 2 +- 9 files changed, 43 insertions(+), 69 deletions(-) rename {examples => junit-runner}/build.gradle.kts (69%) rename {examples/src/main/java/cmu/pasta/fray/examples => junit-runner/src/main/java/cmu/pasta/fray/runner}/JUnitRunner.java (99%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4361775c..4de4f86a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,12 +18,5 @@ jobs: distribution: 'temurin' java-version: '21' cache: 'gradle' - - name: Build fray (no tests) - run: ./gradlew build -x test - - name: Instrument JDK - run: ./gradlew jlink - - name: Build shadow JAR - run: ./gradlew shadowJar - - name: Test fray - run: ./gradlew test - + - name: Build fray and run tests + run: ./gradlew build \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 09e7a4b5..a9eee524 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -28,3 +28,7 @@ tasks.named("shadowJar") { attributes(mapOf("Main-Class" to "cmu.pasta.fray.core.MainKt")) } } + +tasks.named("build") { + dependsOn("shadowJar") +} diff --git a/instrumentation/build.gradle.kts b/instrumentation/build.gradle.kts index 71f6ed86..03121de5 100644 --- a/instrumentation/build.gradle.kts +++ b/instrumentation/build.gradle.kts @@ -26,9 +26,7 @@ tasks.withType { jvmArgs("--patch-module", "cmu.pasta.fray.instrumentation=${sourceSets["main"].output.asPath}") } - tasks.compileJava { - println(sourceSets["main"].output.asPath) options.compilerArgumentProviders.add(CommandLineArgumentProvider { // Provide compiled Kotlin classes to javac – needed for Java/Kotlin mixed sources to work listOf("--patch-module", "cmu.pasta.fray.instrumentation=${sourceSets["main"].output.asPath}") @@ -42,8 +40,6 @@ tasks.jar { } tasks.named("shadowJar") { - // In Kotlin DSL, setting properties is done through Kotlin property syntax. -// isEnableRelocation = true relocate("org.objectweb.asm", "cmu.pasta.fray.instrumentation.asm") manifest { attributes(mapOf("Premain-Class" to "cmu.pasta.fray.instrumentation.PreMainKt")) @@ -53,3 +49,8 @@ tasks.named("shadowJar") { tasks.test { useJUnitPlatform() } + +tasks.named("build") { + dependsOn("shadowJar") +} + diff --git a/integration-tests/build.gradle.kts b/integration-tests/build.gradle.kts index 56a54947..eaebaaa7 100644 --- a/integration-tests/build.gradle.kts +++ b/integration-tests/build.gradle.kts @@ -25,6 +25,8 @@ tasks.test { executable("${jdk.layout.buildDirectory.get().asFile}/java-inst/bin/java") jvmArgs("-agentpath:$agentPath") jvmArgs("-javaagent:${instrumentation.layout.buildDirectory.get().asFile}/libs/${instrumentation.name}-${instrumentation.version}-all.jar") + dependsOn(":jdk:build") + dependsOn(":jvmti:build") } tasks.register("copyDependencies") { diff --git a/jdk/build.gradle.kts b/jdk/build.gradle.kts index fd6bfce0..3ac18151 100644 --- a/jdk/build.gradle.kts +++ b/jdk/build.gradle.kts @@ -30,34 +30,37 @@ tasks.jar { manifest { attributes(mapOf("Premain-Class" to "cmu.pasta.fray.jdk.agent.AgentKt")) } - dependsOn("copyDependencies") } +tasks.build { + dependsOn("jar") + val path = "${layout.buildDirectory.get().asFile}/libs" + val jdkPath = "${layout.buildDirectory.get().asFile}/java-inst" + outputs.dirs(jdkPath) + doLast { + println(state) + if (!state.upToDate) { + exec { + if (File(jdkPath).exists()) { + delete(file(jdkPath)) + } + var runtimeJar = "$path/${project.name}-$version.jar" + val jarDir = file(path) + + val jars = jarDir.listFiles { file -> file.extension == "jar" } + ?.joinToString(separator = ":") { it.absolutePath } + ?: "No JAR files found." + val command = listOf("jlink", "-J-javaagent:$runtimeJar", "-J--module-path=$jars", + "-J--add-modules=cmu.pasta.fray.jdk", "-J--class-path=$jars", + "--output=$jdkPath", "--add-modules=ALL-MODULE-PATH", "--fray-instrumentation") + commandLine(command) + } + } + } +} + tasks.register("copyDependencies") { from(configurations.runtimeClasspath) into("${layout.buildDirectory.get().asFile}/libs") } - - -tasks.register("jlink") { - var path = "${layout.buildDirectory.get().asFile}/libs" - var jdkPath = "${layout.buildDirectory.get().asFile}/java-inst" - /* delete(file(jdkPath)) */ - - if (!File(jdkPath).exists()) { - var runtimeJar = "$path/${project.name}-$version.jar" - val jarDir = file(path) - - val jars = jarDir.listFiles { file -> file.extension == "jar" } - ?.joinToString(separator = ":") { it.absolutePath } - ?: "No JAR files found." - val command = listOf("jlink", "-J-javaagent:$runtimeJar", "-J--module-path=$jars", - "-J--add-modules=cmu.pasta.fray.jdk", "-J--class-path=$jars", - "--output=$jdkPath", "--add-modules=ALL-MODULE-PATH", "--fray-instrumentation") - println(command.joinToString(" ")) - commandLine(command) - /* commandLine(listOf("java", "--version")) */ - dependsOn(tasks.jar) - } -} diff --git a/jdk/src/main/kotlin/cmu/pasta/fray/jdk/jlink/JlinkPlugin.kt b/jdk/src/main/kotlin/cmu/pasta/fray/jdk/jlink/JlinkPlugin.kt index ebbf35aa..947c0d68 100644 --- a/jdk/src/main/kotlin/cmu/pasta/fray/jdk/jlink/JlinkPlugin.kt +++ b/jdk/src/main/kotlin/cmu/pasta/fray/jdk/jlink/JlinkPlugin.kt @@ -28,6 +28,7 @@ class JlinkPlugin : Plugin { override fun transform(input: ResourcePool, output: ResourcePoolBuilder): ResourcePool { println("Start fray plugin!") + Utils.prepareDebugFolder("jdk") Utils.prepareDebugFolder("origin") input.transformAndCopy( diff --git a/examples/build.gradle.kts b/junit-runner/build.gradle.kts similarity index 69% rename from examples/build.gradle.kts rename to junit-runner/build.gradle.kts index 6883868b..d84b3939 100644 --- a/examples/build.gradle.kts +++ b/junit-runner/build.gradle.kts @@ -64,38 +64,8 @@ tasks.compileJava { options.compilerArgs.addAll(listOf("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED")) } -tasks.register("runExample") { - args = listOf("example.Main", "-o", "${layout.buildDirectory.get().asFile}/report", "--scheduler", "fifo") -} - -tasks.register("runJC") { - val cp = properties["classpath"] as String? ?: "" - val main = properties["mainClass"] as String? ?: "" - val extraArgs = when (val extraArgs = properties["extraArgs"]) { - is String -> extraArgs.split(" ") - else -> emptyList() - } - classpath += files(cp.split(":")) - args = listOf(main, "main", "-o", "${layout.buildDirectory.get().asFile}/report", "--logger", "csv", "--iter", "10000", "-s", "10000000") + extraArgs -} - tasks.register("copyDependencies") { from(configurations.runtimeClasspath) into("${layout.buildDirectory.get().asFile}/dependency") } - -fun resolveClasspath(classpath: String): List { - return classpath.split(":").flatMap { path -> - if (path.contains("*")) { - val dir = File(path.substringBeforeLast("/")) - val pattern = path.substringAfterLast("/") - dir.listFiles { _, name -> name.matches(Regex(pattern.replace("*", ".*"))) } - ?.map { it.absolutePath } - ?: emptyList() - } else { - listOf(File(path).absolutePath) - } - } -} - diff --git a/examples/src/main/java/cmu/pasta/fray/examples/JUnitRunner.java b/junit-runner/src/main/java/cmu/pasta/fray/runner/JUnitRunner.java similarity index 99% rename from examples/src/main/java/cmu/pasta/fray/examples/JUnitRunner.java rename to junit-runner/src/main/java/cmu/pasta/fray/runner/JUnitRunner.java index 30d3cc95..f6e3baa7 100644 --- a/examples/src/main/java/cmu/pasta/fray/examples/JUnitRunner.java +++ b/junit-runner/src/main/java/cmu/pasta/fray/runner/JUnitRunner.java @@ -1,4 +1,4 @@ -package cmu.pasta.fray.examples; +package cmu.pasta.fray.runner; import java.io.PrintWriter; import java.io.StringWriter; diff --git a/settings.gradle.kts b/settings.gradle.kts index adb67a97..2432431e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,7 +4,7 @@ plugins { rootProject.name = "fray" include("jdk") include("runtime") -include("examples") +include("junit-runner") include("jvmti") include("core") include("instrumentation")