xpipe-mirror/dist/cli.gradle
2023-02-01 09:16:26 +00:00

84 lines
2.8 KiB
Groovy

import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
def distDir = "$buildDir/dist"
apply plugin: 'org.asciidoctor.jvm.convert'
asciidoctor {
dependsOn(project(':cli').runManPageGenerator)
sourceDir = file("${project(':cli').buildDir}/generated-picocli-docs")
outputDir = file("$distDir/docs")
logDocuments = false
outputOptions {
backends = ['manpage', 'html5']
}
inProcess = JAVA_EXEC
forkOptions {
jvmArgs("--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED", "--add-opens", "java.base/java.io=ALL-UNNAMED")
}
options header_footer: false
}
task copyCompletion(type: Copy) {
dependsOn(project(':cli').runAutocompleteGenerator)
from new File(project(':cli').buildDir, 'xpipe_completion')
into "$distDir/cli"
}
task setupMusl(type: Exec) {
commandLine "${project(':cli').projectDir.toString()}/musl-setup.sh", project(':cli').projectDir.toString()
}
task buildCli(type: DefaultTask) {
if (org.gradle.internal.os.OperatingSystem.current().isLinux()) {
dependsOn(setupMusl)
project(':cli').getTasksByName('nativeCompile', true).forEach(v->v.mustRunAfter(setupMusl))
}
if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
dependsOn(project(':cli').getTasksByName('nativeCompile', true))
}
doLast {
if (rootProject.os.isWindows()) {
exec {
executable project(':cli').projectDir.toString() + '/native-build.bat'
environment System.getenv()
}
}
if (rootProject.os.isLinux()) {
exec {
commandLine project(':cli').projectDir.toString() + '/native-build-musl.sh', project(':cli').projectDir.toString()
environment System.getenv()
}
}
Files.createDirectories(Paths.get(distDir, 'cli'))
def ending = rootProject.os.isWindows() ? ".exe" : ""
var outputFile = Paths.get(project(':cli').buildDir.toString() + "/native/nativeCompile/xpipe$ending")
if (!Files.exists(outputFile)) {
throw new IOException("Cli output file does not exist")
}
Files.copy(outputFile, Paths.get(distDir, 'cli', "xpipe$ending"), StandardCopyOption.REPLACE_EXISTING)
}
}
if (rootProject.os.isWindows() && rootProject.fullVersion) {
task signCliExecutable(type: Exec) {
commandLine "$projectDir\\tools\\sign_cli.bat"
}
buildCli.finalizedBy(signCliExecutable)
task iconCliExecutable(type: Exec) {
commandLine "$projectDir\\tools\\rcedit-x64.exe", "$distDir\\cli\\xpipe.exe", '--set-icon', "$projectDir\\logo\\logo.ico"
}
buildCli.finalizedBy(iconCliExecutable)
}
buildCli.dependsOn(copyCompletion)
buildCli.dependsOn(asciidoctor)