Files
kotlin-fork/build.gradle
T
Ilya Matveev 1c16fc1166 build: Rename kotlin version properties
kotlin_version -> buildKotlinVersion
kotlinVersion -> kotlinCompilerVersion
2017-12-01 13:01:08 +07:00

412 lines
12 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 groovy.io.FileType
import org.jetbrains.kotlin.konan.target.*
import org.jetbrains.kotlin.konan.properties.*
import org.jetbrains.kotlin.konan.util.*
defaultTasks 'clean', 'dist'
convention.plugins.platformInfo = new PlatformInfo()
ext {
konanPropertiesFile = project(':backend.native').file('konan.properties')
konanProperties = PropertiesKt.loadProperties(konanPropertiesFile.absolutePath)
distDir = file('dist')
dependenciesDir = DependencyProcessor.defaultDependenciesRoot
clangManager = new ClangManager(konanProperties, dependenciesDir.absolutePath)
kotlinCompilerModule="org.jetbrains.kotlin:kotlin-compiler:${kotlinCompilerVersion}"
kotlinStdLibModule="org.jetbrains.kotlin:kotlin-stdlib:${kotlinStdLibVersion}"
kotlinReflectModule="org.jetbrains.kotlin:kotlin-reflect:${kotlinReflectVersion}"
kotlinScriptRuntimeModule="org.jetbrains.kotlin:kotlin-script-runtime:${kotlinScriptRuntimeVersion}"
}
allprojects {
if (path != ":dependencies") {
evaluationDependsOn(":dependencies")
}
repositories {
mavenCentral()
maven {
url kotlinCompilerRepo
}
}
setupHostAndTarget()
loadCommandLineProperties()
loadLocalProperties()
setupClang(project)
}
void setupHostAndTarget() {
ext.hostName = TargetManager.hostName
ext.targetList = TargetManager.enabled*.userName as List
}
void setupClang(Project project) {
project.convention.plugins.clangManager = project.rootProject.ext.clangManager
project.convention.plugins.execClang = new org.jetbrains.kotlin.ExecClang(project)
project.plugins.withType(NativeComponentPlugin) {
project.model {
if (isWindows()) {
platforms {
host {
architecture 'x86_64'
}
}
components {
withType(NativeComponentSpec) {
targetPlatform 'host'
}
}
toolChains {
gcc(Gcc) {
path "$llvmDir/bin"
}
}
} else {
toolChains {
clang(Clang) {
hostClang.hostClangPath.each {
path it
}
eachPlatform { // TODO: will not work when cross-compiling
[cCompiler, cppCompiler, linker].each {
it.withArguments { it.addAll(project.hostClangArgs) }
}
}
}
}
}
}
}
}
void loadLocalProperties() {
if (new File("$project.rootDir/local.properties").exists()) {
Properties props = new Properties()
props.load(new FileInputStream("$project.rootDir/local.properties"))
props.each { prop -> project.ext.set(prop.key, prop.value) }
}
}
void loadCommandLineProperties() {
if (project.hasProperty("konanc_flags")) {
throw new Error("Specify either -Ptest_flags or -Pbuild_flags.")
}
ext.globalBuildArgs = project.hasProperty("build_flags") ? ext.build_flags.split() : []
ext.globalTestArgs = project.hasProperty("test_flags") ? ext.test_flags.split() : []
ext.testTarget = project.hasProperty("test_target") ? ext.test_target : null
}
class PlatformInfo {
boolean isMac() {
return TargetManager.host == KonanTarget.MACBOOK
}
boolean isWindows() {
return TargetManager.host == KonanTarget.MINGW
}
boolean isLinux() {
return TargetManager.host == KonanTarget.LINUX
}
Throwable unsupportedPlatformException() {
return new TargetSupportException()
}
}
task dist_compiler(dependsOn: "distCompiler")
task dist_runtime(dependsOn: "distRuntime")
task cross_dist(dependsOn: "crossDist")
task list_dist(dependsOn: "listDist")
task distCompiler(type: Copy) {
dependsOn ':backend.native:jar'
dependsOn ':utilities:jar'
dependsOn ':klib:jar'
dependsOn ':shared:jar'
destinationDir distDir
from(project(':backend.native').file('build/libs')) {
into('konan/lib')
}
from(project('Interop').file('Runtime/build/libs')) {
into('konan/lib')
}
from(project('Interop').file('Indexer/build/libs')) {
into('konan/lib')
}
from(project('Interop').file('StubGenerator/build/libs')) {
into('konan/lib')
}
from(project(':backend.native').file('build/external_jars')) {
into('konan/lib')
}
from(project(':backend.native').file("build/nativelibs/$hostName")) {
into('konan/nativelib')
}
from(project(':Interop').file('Indexer/build/nativelibs')) {
into('konan/nativelib')
}
from(project(':Interop').file('Runtime/build/nativelibs')) {
into('konan/nativelib')
}
from(project(':llvmDebugInfoC').file('build/libs/debugInfo/shared')) {
into('konan/nativelib')
}
from(project(':llvmDebugInfoC').file('src/scripts/konan_lldb.py')) {
into('tools')
}
from(project(':utilities').file('env_blacklist')) {
into('tools')
}
from(project(':utilities').file('build/libs')) {
into('konan/lib')
}
from(project(':klib').file('build/libs')) {
into('konan/lib')
}
from(project(':shared').file('build/libs')) {
into('konan/lib')
}
from(file('cmd')) {
fileMode(0755)
into('bin')
if (!isWindows()) {
exclude('**/*.bat')
}
}
from(konanPropertiesFile) {
into('konan')
}
}
task listDist(type: Exec) {
commandLine 'find', distDir
}
task distRuntime(type: Copy) {
dependsOn "${hostName}CrossDistRuntime"
dependsOn('commonDistRuntime')
}
def stdlib = 'klib/common/stdlib'
task commonDistRuntime(type: Copy) {
destinationDir distDir
// Target independant common part.
from(project(':runtime').file("build/${hostName}Stdlib")) {
include('**')
into(stdlib)
}
}
task crossDistRuntime(type: Copy) {
dependsOn.addAll(targetList.collect { "${it}CrossDistRuntime" })
dependsOn('commonDistRuntime')
}
task crossDistPlatformLibs {
dependsOn.addAll(targetList.collect { "${it}PlatformLibs" })
}
targetList.each { target ->
task("${target}CrossDistRuntime", type: Copy) {
dependsOn ":runtime:${target}Runtime"
dependsOn ":backend.native:${target}Stdlib"
dependsOn ":backend.native:${target}Start"
destinationDir distDir
from(project(':runtime').file("build/$target")) {
include("runtime.bc")
into("$stdlib/targets/$target/native")
}
from(project(':runtime').file("build/$target")) {
include("*.bc")
exclude("runtime.bc")
into("konan/targets/$target/native")
}
from(project(':runtime').file("build/${target}Stdlib")) {
include('**')
into(stdlib)
}
from(project(':runtime').file("build/${target}Start.bc")) {
rename("${target}Start.bc", 'start.bc')
into("konan/targets/$target/native")
}
if (target == 'wasm32') {
from(project(':runtime').file('src/launcher/js')) {
into("$stdlib/targets/wasm32/included")
}
}
}
Task platformLibs = task("${target}PlatformLibs") {}
targetDefFiles(target).forEach{
defFile ->
def taskName = defFileToTaskName(target, defFile.name)
def jvmArgs = project.findProperty("platfromLibsJvmArgs") ?: "-Xmx3G"
def suffix = null
if (new PlatformInfo().isWindows())
suffix = 'bat'
Task libTask = task(taskName, type:GradleBuild) {
dependsOn ':dist'
dependsOn ':tools:kotlin-native-gradle-plugin:jar'
dependsOn defFile.config.depends.collect{defFileToTaskName(target, it)}
tasks = ['clean', 'klibInstall']
buildFile project('klib').file('platform.gradle')
dir project(':klib').projectDir
startParameter.projectProperties = [
'konan.jvmArgs' : jvmArgs,
'konanVersion' : konanVersion,
'name' : defFile.name,
'defFile' : defFile.file.absolutePath,
'konan.home' : distDir,
'target' : target,
'suffix' : suffix,
'libraries' : defFile.config.depends.join(" ")
]
}
platformLibs.dependsOn(libTask)
}
}
private ArrayList<DefFile> targetDefFiles(String target) {
def platform = targetToPlatform(target)
def substitution = ['arch': target,
'os' : targetToOs(target)]
project(':klib').file("src/platform/$platform")
.listFiles()
.findAll { it.name.endsWith(".def") }
// The libz.a/libz.so and zlib.h are missing in raspberrypi and mips sysroots.
// Just workaround it until we have sysroots corrected.
.findAll { ! ((target == 'raspberrypi' || target == 'linux_mips32' || target == 'linux_mipsel32') && it.name == 'zlib.def') }
.collect { new DefFile(it, substitution) }
}
private String targetToPlatform(String target) {
new TargetManager(target).target.family.name().toLowerCase()
}
private String targetToOs(String target) {
new TargetManager(target).target.detailedName.toLowerCase()
}
private String defFileToTaskName(String target, String name) {
return "$target-$name".toString()
}
task distPlatformLibs {
dependsOn targetDefFiles(hostName).collect {defFileToTaskName(hostName, it.name)}
}
task dist {
dependsOn 'distCompiler', 'distRuntime'
}
task crossDist {
dependsOn 'crossDistRuntime', 'distCompiler'
}
task bundle(type: (isWindows()) ? Zip : Tar) {
dependsOn('crossDistPlatformLibs')
dependsOn('crossDist')
def simpleOsName = TargetManager.simpleOsName()
baseName = "kotlin-native-$simpleOsName-${project.konanVersion}"
from("$project.rootDir/dist") {
include '**'
exclude 'dependencies'
exclude 'klib/testLibrary'
into baseName
}
from(project.rootDir) {
include 'DISTRO_README.md'
rename {
return "README.md"
}
into baseName
}
from(project.rootDir) {
include 'samples/**'
include 'INTEROP.md'
include 'RELEASE_NOTES.md'
include 'GRADLE_PLUGIN.md'
include 'PLATFORM_LIBS.md'
exclude '**/gradle.properties'
exclude '**/settings.gradle'
exclude '**/build'
exclude '**/.gradle'
exclude 'samples/**/*.kt.bc-build'
rename('(.*)\\.for_bundle', '$1')
into baseName
}
destinationDir = file('.')
if (!isWindows()) {
extension = 'tar.gz'
compression = Compression.GZIP
}
}
task performance(type: GradleBuild) {
dependsOn 'dist'
dependsOn ':tools:kotlin-native-gradle-plugin:jar'
dir = 'performance'
tasks = ['build', 'bench']
doFirst {
startParameter.projectProperties = [
'konanPluginClasspath' : project(':tools:kotlin-native-gradle-plugin').tasks.getByName('jar').archivePath.canonicalPath,
'exe_suffix': TargetManager.host.family.exeSuffix]
}
}
task clean {
doLast {
delete distDir
delete bundle.outputs.files
}
}