Skip to content

Commit

Permalink
build: fix symlink due to Gradle bug
Browse files Browse the repository at this point in the history
  • Loading branch information
iseki0 committed Mar 27, 2024
1 parent ca36fab commit 133fb68
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import org.graalvm.buildtools.gradle.dsl.GraalVMExtension
import java.nio.file.LinkOption
import java.nio.file.Path
import kotlin.io.path.createLinkPointingTo
import kotlin.io.path.deleteExisting
import kotlin.io.path.fileSize
import kotlin.io.path.isRegularFile

plugins {
`java-library`
Expand Down Expand Up @@ -136,14 +142,26 @@ graalvmNative {
}
}

fun fixSymlink(target: Path, expectedSrc: Path) {
if (!expectedSrc.isRegularFile(LinkOption.NOFOLLOW_LINKS)) {
logger.info("fixSymlink: expected is not regular, skip (expected: {})", expectedSrc)
return
}
if (!target.isRegularFile(LinkOption.NOFOLLOW_LINKS) || target.fileSize() > 0) {
logger.info("fixSymlink: target is not regular or the file size > 0, skip (target: {})", target)
return
}
logger.warn("fixSymlink: {} -> {}", target, expectedSrc)
target.deleteExisting()
target.createLinkPointingTo(expectedSrc)
}

tasks.nativeTestCompile {
doFirst {
val d =
project.extensions.getByType(GraalVMExtension::class).binaries["test"].asCompileOptions().javaLauncher.get().executablePath.asFile.parentFile
val ni = File(d, "native-image")
if (ni.exists()) {
ni.setExecutable(true)
}
val testCompileOpt = project.extensions.getByType(GraalVMExtension::class).binaries["test"].asCompileOptions()
val binPath = testCompileOpt.javaLauncher.get().executablePath.asFile.toPath().parent
val svmBinPath = binPath.resolve("../lib/svm/bin")
fixSymlink(binPath.resolve("native-image"), svmBinPath.resolve("native-image"))
}
}

Expand Down

0 comments on commit 133fb68

Please sign in to comment.