55c4966203
Collected clang args in ClangArgs.kt Switched dependencies/build.gradle to KonanTarget. Introduced KonanProperties to take care of target specific properties.
261 lines
7.9 KiB
Groovy
261 lines
7.9 KiB
Groovy
/*
|
|
* Copyright 2010-2017 JetBrains s.r.o.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import static DependencyTaskKind.*
|
|
import org.jetbrains.kotlin.konan.target.*
|
|
import static org.jetbrains.kotlin.konan.target.KonanTarget.*
|
|
import org.jetbrains.kotlin.konan.properties.KonanProperties
|
|
import org.jetbrains.kotlin.konan.properties.*
|
|
|
|
buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
jcenter()
|
|
}
|
|
|
|
dependencies {
|
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
|
|
}
|
|
}
|
|
|
|
apply plugin: 'com.jfrog.bintray'
|
|
|
|
configurations {
|
|
kotlin_compiler_jar
|
|
kotlin_compiler_pom
|
|
kotlin_compiler_src
|
|
kotlin_compiler_doc
|
|
}
|
|
|
|
// TODO: Check if we really need the our bintray mirror and delete the uploading code below if we don't.
|
|
repositories {
|
|
maven { url kotlinCompilerRepo }
|
|
}
|
|
|
|
dependencies {
|
|
kotlin_compiler_jar "$kotlinCompilerModule@jar"
|
|
kotlin_compiler_pom "$kotlinCompilerModule@pom"
|
|
kotlin_compiler_src "$kotlinCompilerModule:sources@jar"
|
|
kotlin_compiler_doc "$kotlinCompilerModule:javadoc@jar"
|
|
}
|
|
|
|
// Hack kotlin-compiler pom-file to resolve the dependency correctly.
|
|
task generatePom(type: DefaultTask) {
|
|
def originalPom = configurations.kotlin_compiler_pom.singleFile
|
|
inputs.file(originalPom)
|
|
|
|
def (_, artifactIdString, versionString) = kotlinCompilerModule.tokenize(':')
|
|
def newPom = file("${temporaryDir.canonicalPath}/$artifactIdString-${versionString}.pom")
|
|
outputs.file(newPom)
|
|
|
|
doLast {
|
|
def xml = new XmlParser().parse(originalPom)
|
|
def parent = xml.children().find() { it.name().localPart == 'parent' } // <parent> </parent> section, not the parent node.
|
|
if (parent != null) {
|
|
def groupId = parent.groupId
|
|
def version = parent.version
|
|
xml.append(groupId)
|
|
xml.append(version)
|
|
xml.remove(parent)
|
|
}
|
|
new XmlNodePrinter(new PrintWriter(new FileWriter(newPom))).print(xml)
|
|
}
|
|
}
|
|
|
|
bintray {
|
|
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
|
|
key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : System.getenv('BINTRAY_KEY')
|
|
pkg {
|
|
repo = 'kotlin-native-dependencies'
|
|
name = 'kotlin-compiler-builds'
|
|
userOrg = 'jetbrains'
|
|
publish = true
|
|
override = project.hasProperty("override")
|
|
}
|
|
filesSpec {
|
|
// kotlinCompilerModule@jar and @pom -> groupId/with/dots/replaced/by/slashes/artifactId/<major-version>-SNAPSHOT
|
|
// e.g. org.jetbrains.kotlin:kotlin-compiler:1.1-20170426.212805-507 -> org/jetbrains/kotlin/kotlin-compiler/1.1-SNAPSHOT
|
|
def (groupId, artifactId, version) = kotlinCompilerModule.tokenize(':')
|
|
def groupPath = groupId.replace('.', '/')
|
|
def artifactPath = artifactId
|
|
def versionPath = "${version.tokenize('-')[0]}-SNAPSHOT"
|
|
from project.configurations.kotlin_compiler_jar.files
|
|
from project.configurations.kotlin_compiler_src.files
|
|
from project.configurations.kotlin_compiler_doc.files
|
|
from generatePom.outputs.files
|
|
into "$groupPath/$artifactPath/$versionPath"
|
|
}
|
|
}
|
|
|
|
task update_kotlin_compiler(type: DefaultTask) {
|
|
dependsOn(bintrayUpload)
|
|
}
|
|
|
|
abstract class NativeDep extends DefaultTask {
|
|
protected final String hostSystem = TargetManager.longerSystemName();
|
|
String baseUrl = "https://jetbrains.bintray.com/kotlin-native-dependencies"
|
|
|
|
@Input
|
|
abstract String getFileName()
|
|
|
|
protected String getUrl() {
|
|
return "$baseUrl/$fileName"
|
|
}
|
|
|
|
protected File getBaseOutDir() {
|
|
final File res = project.rootProject.ext.dependenciesDir
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
class HelperNativeDep extends TgzNativeDep {
|
|
|
|
public HelperNativeDep() {
|
|
dependsOn(':tools:helpers:jar')
|
|
}
|
|
|
|
@TaskAction
|
|
public void downloadAndExtract() {
|
|
project.javaexec {
|
|
main = "org.jetbrains.kotlin.konan.MainKt"
|
|
classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime")
|
|
classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime").artifacts.files
|
|
args baseOutDir.canonicalPath, baseUrl, baseName
|
|
}
|
|
}
|
|
}
|
|
|
|
enum DependencyTaskKind {
|
|
LIBFFI("Libffi"), SYSROOT("Sysroot")
|
|
|
|
DependencyTaskKind(String name) {
|
|
this.name = name
|
|
}
|
|
|
|
String name = ""
|
|
String toString() { return name }
|
|
}
|
|
|
|
void dependencyTask(KonanTarget target, DependencyTaskKind kind) {
|
|
String dependencyBaseName
|
|
def properties = rootProject.ext.konanProperties
|
|
def dirs = new KonanProperties(target, properties, null)
|
|
switch (kind) {
|
|
case LIBFFI:
|
|
dependencyBaseName = dirs.libffiDir
|
|
break
|
|
case SYSROOT:
|
|
dependencyBaseName = dirs.targetSysRoot
|
|
break
|
|
}
|
|
if (dependencyBaseName == null) {
|
|
throw project.unsupportedPlatformException()
|
|
}
|
|
|
|
task "${target.userName}${kind}"(type: HelperNativeDep) {
|
|
baseName = dependencyBaseName
|
|
}
|
|
}
|
|
|
|
if (isLinux()) {
|
|
// The gcc toolchain contains the sysroot for linux platform.
|
|
task gccToolchain(type: HelperNativeDep) {
|
|
baseName = "target-gcc-toolchain-3-$hostSystem"
|
|
}
|
|
|
|
dependencyTask(LINUX, LIBFFI)
|
|
dependencyTask(RASPBERRYPI, SYSROOT)
|
|
dependencyTask(RASPBERRYPI, LIBFFI)
|
|
} else if (isWindows()) {
|
|
task mingwWithLlvm(type: HelperNativeDep) {
|
|
baseName = "msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-$hostSystem"
|
|
}
|
|
|
|
dependencyTask(MINGW, LIBFFI)
|
|
} else {
|
|
dependencyTask(MACBOOK, SYSROOT)
|
|
dependencyTask(MACBOOK, LIBFFI)
|
|
dependencyTask(IPHONE, SYSROOT)
|
|
dependencyTask(IPHONE, LIBFFI)
|
|
// TODO: re-enable when we known how to bring the simulator sysroot to dependencies.
|
|
// dependencyTask(IPHONE_SIM, SYSROOT)
|
|
}
|
|
|
|
if (isLinux() || isMac()) {
|
|
task llvm(type: HelperNativeDep) {
|
|
baseName = "clang-llvm-$llvmVersion-$hostSystem"
|
|
}
|
|
|
|
dependencyTask(ANDROID_ARM32, SYSROOT)
|
|
dependencyTask(ANDROID_ARM32, LIBFFI)
|
|
dependencyTask(ANDROID_ARM64, SYSROOT)
|
|
dependencyTask(ANDROID_ARM64, LIBFFI)
|
|
}
|
|
|
|
task update(type: Copy) {
|
|
dependsOn tasks.withType(NativeDep)
|
|
}
|
|
|
|
tasks.withType(TgzNativeDep) {
|
|
rootProject.ext.set("${name}Dir", outputDir.path)
|
|
}
|
|
|
|
if (isWindows()) {
|
|
rootProject.ext.set("llvmDir", mingwWithLlvmDir)
|
|
}
|