Skip to content

Commit

Permalink
[ci] Upgrade gradle to 8.12 (#3573)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyang16 authored Jan 23, 2025
1 parent 3db96cb commit 0935af3
Show file tree
Hide file tree
Showing 20 changed files with 174 additions and 107 deletions.
1 change: 1 addition & 0 deletions basicdataset/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
}

tasks.register<Exec>("syncS3") {
workingDir = project.projectDir
commandLine(
"sh",
"-c",
Expand Down
24 changes: 14 additions & 10 deletions buildSrc/src/main/kotlin/ai/djl/cppFormatter.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,48 @@ project.extensions.create<FormatterConfig>("formatCpp")

project.tasks {
register("formatCpp") {
val rootProject = project.rootProject
val clang = rootProject.projectDir / ".clang/clang-format"
val formatCpp = project.extensions.getByName<FormatterConfig>("formatCpp")
val files = project.fileTree("src")
val logger = project.logger

doLast {
if ("mac" !in os)
return@doLast
val rootProject = project.rootProject
val clang = rootProject.projectDir / ".clang/clang-format"
checkClang(clang)
val files = project.fileTree("src")
files.include("**/*.cc", "**/*.cpp", "**/*.h")
val formatCpp = project.extensions.getByName<FormatterConfig>("formatCpp")
if (formatCpp.exclusions.isPresent)
for (exclusion in formatCpp.exclusions.get())
files.exclude(exclusion)

for (f in files) {
if (!f.isFile())
continue
project.logger.info("formatting cpp file: $f")
logger.info("formatting cpp file: $f")
f.text = formatCpp(f, clang)
}
}
}

register("verifyCpp") {
val rootProject = project.rootProject
val clang = rootProject.projectDir / ".clang/clang-format"
val files = project.fileTree("src")
val logger = project.logger

doLast {
if ("mac" !in os)
return@doLast
val rootProject = project.rootProject
val clang = rootProject.projectDir / ".clang/clang-format"
checkClang(clang)
val files = project.fileTree("src")
files.include("**/*.cc", "**/*.cpp", "**/*.h")
for (f in files) {
if (!f.isFile())
continue
project.logger.info("checking cpp file: $f")
logger.info("checking cpp file: $f")
if (f.text != formatCpp(f, clang))
throw GradleException("File not formatted: " + f.absolutePath)
}
}
}
}
}
11 changes: 7 additions & 4 deletions buildSrc/src/main/kotlin/ai/djl/javaFormatter.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import java.io.PrintWriter

tasks {
register("formatJava") {
val sourceSets = project.sourceSets
doLast {
val formatter = Main(PrintWriter(System.out, true), PrintWriter(System.err, true), System.`in`)
for (item in project.sourceSets)
for (item in sourceSets)
for (file in item.allSource) {
if (!file.name.endsWith(".java") || "generated-src" in file.absolutePath)
continue
Expand All @@ -24,9 +25,11 @@ tasks {
inputs.files(project.sourceSets.flatMap { it.allSource })
inputs.files(project.fileTree("generated-src"))
outputs.file(project.file(resultFilePath))

val proj = project
doLast {
val formatter = Main(PrintWriter(System.out, true), PrintWriter(System.err, true), System.`in`)
for (item in project.sourceSets)
for (item in proj.sourceSets)
for (file in item.allSource) {
if (!file.name.endsWith(".java") || "generated-src" in file.absolutePath)
continue
Expand All @@ -39,12 +42,12 @@ tasks {
+ "See https://github.com/deepjavalibrary/djl/blob/master/docs/development/development_guideline.md#coding-conventions for more details"
)
}
project.file(resultFilePath).writeText("Success")
proj.file(resultFilePath).writeText("Success")
}
}

named("check") { dependsOn(verifyJava) }
}

val Project.sourceSets: SourceSetContainer
get() = extensions.getByName<SourceSetContainer>("sourceSets")
get() = extensions.getByName<SourceSetContainer>("sourceSets")
6 changes: 4 additions & 2 deletions engines/ml/xgboost/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ tasks {
val jnilibDir = buildDirectory / "resources/main/lib/linux/aarch64/"
inputs.properties(mapOf("xgboostVersion" to libs.versions.xgboost.get()))
outputs.dir(jnilibDir)

val logger = project.logger
doLast {
val url =
"https://publish.djl.ai/xgboost/${libs.versions.xgboost.get()}/jnilib/linux/aarch64/libxgboost4j.so"
val file = jnilibDir / "libxgboost4j.so"
if (!file.exists()) {
project.logger.lifecycle("Downloading $url")
logger.lifecycle("Downloading $url")
url.url into file
}
}
Expand Down Expand Up @@ -116,4 +118,4 @@ tasks {
}
}
}
}
}
11 changes: 7 additions & 4 deletions engines/mxnet/mxnet-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ tasks {
.withPropertyName("jna/mapping.properties file")
outputs.dir(buildDirectory / "generated-src")
outputs.cacheIf { true }

val dir = project.projectDir
doLast {
val jnaGenerator = jnaratorJar.get().outputs.files.singleFile
javaexec {
providers.javaexec {
workingDir = dir
mainClass = "-jar"
args(
jnaGenerator.absolutePath,
Expand All @@ -55,12 +58,12 @@ tasks {
"-o",
"$buildDirectory/generated-src",
"-m",
"${project.projectDir}/src/main/jna/mapping.properties",
"${dir}/src/main/jna/mapping.properties",
"-f",
"src/main/include/mxnet/c_api.h",
"src/main/include/nnvm/c_api.h"
)
}
}.result.get()
}
}

Expand Down Expand Up @@ -121,4 +124,4 @@ tasks {
}
}
}
}
}
1 change: 1 addition & 0 deletions engines/mxnet/mxnet-model-zoo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
}

tasks.register<Exec>("syncS3") {
workingDir = project.projectDir
commandLine(
"sh",
"-c",
Expand Down
3 changes: 2 additions & 1 deletion engines/mxnet/native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ tasks {
// this line is to enforce gradle to build the jar otherwise it doesn't generate the placeholder jar at times
// when there is no java code inside src/main
outputs.dir("build/libs")

var versionName = project.version.toString()
doFirst {
var versionName = project.version.toString()
if (!isRelease)
versionName += "-$nowFormatted"
val dir = placeholder / "native/lib"
Expand Down
9 changes: 5 additions & 4 deletions engines/onnxruntime/onnxruntime-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ dependencies {
}

tasks {
val basePath = "${project.projectDir}/build/resources/main/nlp"
val logger = project.logger
processResources {
val basePath = "${project.projectDir}/build/resources/main/nlp"
outputs.dir(basePath)
doLast {
val url = "https://mlrepo.djl.ai/model/nlp"
Expand All @@ -33,9 +34,9 @@ tasks {
for (task in tasks) {
val file = File("$basePath/$task/ai.djl.huggingface.onnxruntime.json")
if (file.exists())
project.logger.lifecycle("model zoo metadata already exists: $task")
logger.lifecycle("model zoo metadata already exists: $task")
else {
project.logger.lifecycle("Downloading model zoo metadata: $task")
logger.lifecycle("Downloading model zoo metadata: $task")
file.parentFile.mkdirs()
"$url/$task/ai/djl/huggingface/onnxruntime/models.json.gz".url gzipInto file
}
Expand All @@ -55,4 +56,4 @@ publishing {
}
}
}
}
}
20 changes: 13 additions & 7 deletions engines/pytorch/pytorch-jni/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ tasks {

processResources {
outputs.dir(buildDirectory / "classes/java/main/jnilib")

val logger = project.logger
val dir = project.projectDir
val nativeDir = project.parent!!.projectDir / "pytorch-native/jnilib/${libs.versions.djl.get()}/"
val version = project.version
val hasJni = project.hasProperty("jni")

doFirst {
val url = "https://publish.djl.ai/pytorch/$ptVersion/jnilib/${libs.versions.djl.get()}"
val files = listOf(
Expand Down Expand Up @@ -49,22 +56,21 @@ tasks {

else -> throw GradleException("Unsupported version: $ptVersion.")
}
val jnilibDir = project.projectDir / "jnilib" / libs.versions.djl.get()
val jnilibDir = dir / "jnilib" / libs.versions.djl.get()
for (entry in files) {
val file = jnilibDir / entry
if (file.exists())
project.logger.lifecycle("prebuilt or cached file found for $entry")
logger.lifecycle("prebuilt or cached file found for $entry")
else {
val nativeDir = project.parent!!.projectDir / "pytorch-native/jnilib/${libs.versions.djl.get()}/"
val jnilibFile = nativeDir / entry
if (jnilibFile.exists()) {
project.logger.lifecycle("Copying $jnilibFile")
logger.lifecycle("Copying $jnilibFile")
copy {
from(jnilibFile)
into(file.parent)
}
} else if (!project.hasProperty("jni")) {
project.logger.lifecycle("Downloading $url/$entry")
} else if (!hasJni) {
logger.lifecycle("Downloading $url/$entry")
file.parentFile.mkdirs()
"$url/$entry".url into file
}
Expand All @@ -77,7 +83,7 @@ tasks {

// write properties
val propFile = buildDirectory / "classes/java/main/jnilib/pytorch.properties"
propFile.text = "jni_version=" + project.version
propFile.text = "jni_version=$version"
}
}

Expand Down
1 change: 1 addition & 0 deletions engines/pytorch/pytorch-model-zoo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
}

tasks.register<Exec>("syncS3") {
workingDir = project.projectDir
commandLine(
"sh",
"-c",
Expand Down
32 changes: 22 additions & 10 deletions engines/pytorch/pytorch-native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ val isAarch64 = project.hasProperty("aarch64") || arch == "aarch64"

version = ptVersion + if (isRelease) "" else "-SNAPSHOT"


fun downloadBuild(ver: String, os: String, flavor: String, isPrecxx11: Boolean = false, isAarch64: Boolean = false) {
val arch = if (isAarch64) "aarch64" else "x86_64"
exec {
providers.exec {
workingDir = project.projectDir
if (os == "win")
commandLine(project.projectDir / "build.cmd", ver, flavor)
else
Expand All @@ -50,7 +52,8 @@ fun downloadBuild(ver: String, os: String, flavor: String, isPrecxx11: Boolean =

fun downloadBuildAndroid(ver: String) {
for (abi in listOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64")) {
exec {
providers.exec {
workingDir = project.projectDir
commandLine("bash", "build_android.sh", ver, abi)
}
val ciDir = project.projectDir / "jnilib/${libs.versions.djl.get()}/android/$abi"
Expand Down Expand Up @@ -93,15 +96,17 @@ fun prepareNativeLib(binaryRoot: String, ver: String, packageType: String?) {
copyNativeLibToOutputDir(files, binaryRoot, officialPytorchUrl)
copyNativeLibToOutputDir(aarch64Files, binaryRoot, aarch64PytorchUrl)

exec {
providers.exec {
workingDir = project.projectDir
commandLine(
"install_name_tool",
"-add_rpath",
"@loader_path",
"$binaryRoot/cpu/osx-aarch64/native/lib/libtorch_cpu.dylib"
)
}
exec {
providers.exec {
workingDir = project.projectDir
commandLine(
"install_name_tool",
"-add_rpath",
Expand Down Expand Up @@ -188,6 +193,8 @@ fun copyNativeLibToOutputDir(fileStoreMap: Map<String, String>, binaryRoot: Stri
}
}

open class Cmd @Inject constructor(@Internal val execOperations: ExecOperations) : DefaultTask()

tasks {
register("compileAndroidJNI") {
doFirst {
Expand Down Expand Up @@ -228,13 +235,15 @@ tasks {
}
}

register("uploadS3") {
register<Cmd>("uploadS3") {
val dir = project.projectDir
doLast {
delete("$binaryRoot")
prepareNativeLib("$binaryRoot", ptVersion, "cpu")
prepareNativeLib("$binaryRoot", ptVersion, "gpu")

exec {
execOperations.exec {
workingDir = dir
commandLine("sh", "-c", "find $binaryRoot -type f | xargs gzip")
}

Expand All @@ -255,13 +264,15 @@ tasks {
appendLine(out + "/" + URLEncoder.encode(it, "UTF-8"))
}
}
exec {
execOperations.exec {
workingDir = dir
commandLine("aws", "s3", "sync", "$binaryRoot", "s3://djl-ai/publish/pytorch/$ptVersion/")
}
}
}

// Create a placeholder jar without classifier to pass sonatype tests but throws an Exception if loaded
val version = project.version
jar {
val placeholder = buildDirectory / "placeholder"
// this line is to enforce gradle to build the jar
Expand All @@ -272,7 +283,7 @@ tasks {
val dir = placeholder / "native/lib"
dir.mkdirs()
val propFile = placeholder / "native/lib/pytorch.properties"
propFile.text = "placeholder=true\nversion=${project.version}\n"
propFile.text = "placeholder=true\nversion=${version}\n"
}

from(placeholder)
Expand Down Expand Up @@ -442,9 +453,10 @@ tasks {
}

clean {
val dir = project.projectDir
doFirst {
delete(project.projectDir / "jnilib")
delete(project.projectDir.parentFile / "pytorch-jni/jnilib")
delete(dir / "jnilib")
delete(dir.parentFile / "pytorch-jni/jnilib")
}
}
}
Expand Down
1 change: 1 addition & 0 deletions engines/tensorflow/tensorflow-model-zoo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
}

tasks.register<Exec>("syncS3") {
workingDir = project.projectDir
commandLine("sh", "-c", "find . -name .DS_Store | xargs rm && aws s3 sync src/test/resources/mlrepo s3://djl-ai/mlrepo --acl public-read")

standardOutput = ByteArrayOutputStream()
Expand Down
Loading

0 comments on commit 0935af3

Please sign in to comment.