Skip to content

Commit

Permalink
Simplify build process.
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al committed Jul 27, 2024
1 parent ee066d3 commit 4870923
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 69 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ tasks.named<ShadowJar>("shadowJar") {
attributes(mapOf("Main-Class" to "cmu.pasta.fray.core.MainKt"))
}
}

tasks.named("build") {
dependsOn("shadowJar")
}
9 changes: 5 additions & 4 deletions instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ tasks.withType<JavaExec> {
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}")
Expand All @@ -42,8 +40,6 @@ tasks.jar {
}

tasks.named<ShadowJar>("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"))
Expand All @@ -53,3 +49,8 @@ tasks.named<ShadowJar>("shadowJar") {
tasks.test {
useJUnitPlatform()
}

tasks.named("build") {
dependsOn("shadowJar")
}

2 changes: 2 additions & 0 deletions integration-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Copy>("copyDependencies") {
Expand Down
51 changes: 27 additions & 24 deletions jdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Copy>("copyDependencies") {
from(configurations.runtimeClasspath)
into("${layout.buildDirectory.get().asFile}/libs")
}


tasks.register<Exec>("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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
30 changes: 0 additions & 30 deletions examples/build.gradle.kts → junit-runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,8 @@ tasks.compileJava {
options.compilerArgs.addAll(listOf("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED"))
}

tasks.register<JavaExec>("runExample") {
args = listOf("example.Main", "-o", "${layout.buildDirectory.get().asFile}/report", "--scheduler", "fifo")
}

tasks.register<JavaExec>("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<Copy>("copyDependencies") {
from(configurations.runtimeClasspath)
into("${layout.buildDirectory.get().asFile}/dependency")
}


fun resolveClasspath(classpath: String): List<String> {
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)
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmu.pasta.fray.examples;
package cmu.pasta.fray.runner;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
rootProject.name = "fray"
include("jdk")
include("runtime")
include("examples")
include("junit-runner")
include("jvmti")
include("core")
include("instrumentation")
Expand Down

0 comments on commit 4870923

Please sign in to comment.