Files
kotlin-fork/dependencies/build.gradle
T
Alexander Gorshenev afaa50ce34 Introduced -target and -list_targets flags.
Use it like

    $ konanc hello.kt -target iphone
2017-01-23 00:17:39 +04:00

102 lines
2.4 KiB
Groovy

abstract class NativeDep extends DefaultTask {
private String getCurrentHostTarget() {
if (project.isMac() && project.isAmd64()) {
return 'darwin-macos'
} else if (project.isLinux() && project.isAmd64()) {
return 'linux-x86-64'
} else {
throw project.unsupportedPlatformException()
}
}
protected final String host = getCurrentHostTarget();
@Input
abstract String getFileName()
protected String getUrl() {
return "https://jetbrains.bintray.com/kotlin-native-dependencies/$fileName"
}
protected File getBaseOutDir() {
final File res = project.file("all")
res.mkdirs()
return res
}
protected File download() {
File result = new File(baseOutDir, fileName)
if (!result.exists())
ant.get(src: url, dest: result, usetimestamp: true)
return result
}
}
class TgzNativeDep extends NativeDep {
String baseName
@Override
String getFileName() {
return "${baseName}.tar.gz"
}
@OutputDirectory
File getOutputDir() {
return new File(baseOutDir, baseName)
}
@TaskAction
public void downloadAndExtract() {
File archived = this.download()
try {
// Builtin Gradle unpacking tools seem to unable to handle symlinks;
// Use external "tar" executable as workaround:
project.exec {
executable "tar"
workingDir baseOutDir
args "xf", archived
}
} catch (Throwable e) {
e.printStackTrace()
project.delete(outputDir)
throw e
}
// TODO: improve downloaded files caching
// TODO: do not extract if already extracted
}
}
task libffi(type: TgzNativeDep) {
baseName = "libffi-3.2.1-2-$host"
}
task llvm(type: TgzNativeDep) {
baseName = "clang+llvm-3.8.0-$host"
}
if (isLinux()) {
task gccToolchain(type: TgzNativeDep) {
baseName = "target-gcc-toolchain-3-$host"
}
} else {
task hostSysroot(type: TgzNativeDep) {
baseName = "target-sysroot-1-$host"
}
task iphoneSysroot(type: TgzNativeDep) {
baseName = "target-sysroot-1-darwin-ios"
}
}
task update {
dependsOn tasks.withType(NativeDep)
}
tasks.withType(TgzNativeDep) {
rootProject.ext.set("${name}Dir", outputDir.path)
}