Files
kotlin-fork/dependencies/build.gradle
T
Svyatoslav Scherbina bee2a76008 build: refactor platform checks
also improve verbosity when downloading dependencies fails
2016-11-11 19:22:34 +07:00

93 lines
2.2 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 target = 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-$target"
}
task llvm(type: TgzNativeDep) {
baseName = "clang+llvm-3.8.0-$target"
}
task sysroot(type: TgzNativeDep) {
String version = (target == 'linux-x86-64') ? '2' : '1'
baseName = "target-sysroot-$version-$target"
}
task update {
dependsOn tasks.withType(NativeDep)
}
tasks.withType(TgzNativeDep) {
rootProject.ext.set("${name}Dir", outputDir.path)
}