455 lines
13 KiB
Groovy
455 lines
13 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.*
|
|
|
|
buildscript {
|
|
apply from: "gradle/kotlinGradlePlugin.gradle"
|
|
dependencies {
|
|
classpath "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
|
}
|
|
}
|
|
import org.jetbrains.kotlin.konan.*
|
|
|
|
// Allows generating wrappers for the root build and all the samples during execution of the default 'wrapper' task.
|
|
// Run './gradlew wrapper --gradle-version <version>' to update all the wrappers.
|
|
apply plugin: org.jetbrains.kotlin.GradleWrappers
|
|
|
|
wrappers.projects = ['samples', 'samples/calculator', 'samples/androidNativeActivity']
|
|
wrapper.distributionType = Wrapper.DistributionType.ALL
|
|
|
|
defaultTasks 'clean', 'dist'
|
|
|
|
convention.plugins.platformInfo = new PlatformInfo()
|
|
|
|
ext {
|
|
distDir = file('dist')
|
|
dependenciesDir = DependencyProcessor.defaultDependenciesRoot
|
|
platformManager = new PlatformManager(DistributionKt.buildDistribution(projectDir.absolutePath))
|
|
|
|
kotlinCommonStdlibModule="org.jetbrains.kotlin:kotlin-stdlib-common:${kotlinVersion}:sources"
|
|
kotlinCompilerModule="org.jetbrains.kotlin:kotlin-compiler:${kotlinVersion}"
|
|
kotlinStdLibModule="org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
|
|
kotlinReflectModule="org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
|
|
kotlinScriptRuntimeModule="org.jetbrains.kotlin:kotlin-script-runtime:${kotlinVersion}"
|
|
|
|
konanVersionFull = KonanVersion.Companion.CURRENT
|
|
gradlePluginVersion = konanVersionFull.toString()
|
|
}
|
|
|
|
allprojects {
|
|
if (path != ":dependencies") {
|
|
evaluationDependsOn(":dependencies")
|
|
}
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
maven {
|
|
url kotlinCompilerRepo
|
|
}
|
|
}
|
|
|
|
setupHostAndTarget()
|
|
loadCommandLineProperties()
|
|
loadLocalProperties()
|
|
setupClang(project)
|
|
}
|
|
|
|
void setupHostAndTarget() {
|
|
ext.hostName = platformManager.hostName
|
|
ext.targetList = platformManager.enabled.collect { it.visibleName } as List
|
|
ext.konanTargetList = platformManager.enabled as List
|
|
}
|
|
|
|
void setupClang(Project project) {
|
|
|
|
project.convention.plugins.platformManager = project.rootProject.ext.platformManager
|
|
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) {
|
|
hostPlatform.clang.clangPaths.each {
|
|
path it
|
|
}
|
|
|
|
eachPlatform { // TODO: will not work when cross-compiling
|
|
[cCompiler, cppCompiler, linker].each {
|
|
it.withArguments { it.addAll(project.hostPlatform.clang.clangArgs) }
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 HostManager.hostIsMac
|
|
}
|
|
|
|
boolean isWindows() {
|
|
return HostManager.hostIsMingw
|
|
}
|
|
|
|
boolean isLinux() {
|
|
return HostManager.hostIsLinux
|
|
}
|
|
|
|
Throwable unsupportedPlatformException() {
|
|
return new TargetSupportException()
|
|
}
|
|
}
|
|
|
|
task sharedJar {
|
|
dependsOn gradle.includedBuild('kotlin-native-shared').task(':jar')
|
|
}
|
|
|
|
task gradlePluginJar {
|
|
dependsOn gradle.includedBuild('kotlin-native-gradle-plugin').task(':shadowJar')
|
|
}
|
|
|
|
task gradlePluginCheck() {
|
|
dependsOn gradle.includedBuild('kotlin-native-gradle-plugin').task(':check')
|
|
}
|
|
|
|
task gradlePluginUpload {
|
|
dependsOn gradle.includedBuild('kotlin-native-gradle-plugin').task(':bintrayUpload')
|
|
}
|
|
|
|
task dist_compiler(dependsOn: "distCompiler")
|
|
task dist_runtime(dependsOn: "distRuntime")
|
|
task cross_dist(dependsOn: "crossDist")
|
|
task list_dist(dependsOn: "listDist")
|
|
task build {
|
|
dependsOn ':dist', ':distPlatformLibs'
|
|
}
|
|
|
|
task distCompiler(type: Copy) {
|
|
dependsOn ':backend.native:jar'
|
|
dependsOn ':utilities:jar'
|
|
dependsOn ':klib:jar'
|
|
dependsOn ':sharedJar'
|
|
|
|
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(file("${gradle.includedBuild('kotlin-native-shared').projectDir}/build/libs")) {
|
|
into('konan/lib')
|
|
}
|
|
|
|
from(file('cmd')) {
|
|
fileMode(0755)
|
|
into('bin')
|
|
if (!isWindows()) {
|
|
exclude('**/*.bat')
|
|
}
|
|
}
|
|
from(project.file('konan')) {
|
|
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') {
|
|
into("$stdlib/targets/wasm32/included") {
|
|
from(project(':runtime').file('src/main/js'))
|
|
from(project(':runtime').file('src/launcher/js'))
|
|
from(project(':Interop:JsRuntime').file('src/main/js'))
|
|
}
|
|
}
|
|
}
|
|
|
|
task("${target}PlatformLibs") {
|
|
dependsOn ":platformLibs:${target}Install"
|
|
}
|
|
|
|
task("${target}CrossDist") {
|
|
dependsOn "${target}CrossDistRuntime", 'distCompiler', 'commonDistRuntime'
|
|
}
|
|
}
|
|
|
|
task distPlatformLibs {
|
|
dependsOn ':platformLibs:hostInstall'
|
|
}
|
|
|
|
task dist {
|
|
dependsOn 'distCompiler', 'distRuntime'
|
|
}
|
|
|
|
task crossDist {
|
|
dependsOn 'crossDistRuntime', 'distCompiler'
|
|
}
|
|
|
|
configurations {
|
|
ftpAntTask
|
|
}
|
|
|
|
dependencies {
|
|
ftpAntTask 'org.apache.ant:ant-commons-net:1.9.9'
|
|
}
|
|
|
|
task bundle(type: (isWindows()) ? Zip : Tar) {
|
|
dependsOn('crossDistPlatformLibs')
|
|
dependsOn('crossDist')
|
|
def simpleOsName = HostManager.simpleOsName()
|
|
baseName = "kotlin-native-$simpleOsName-$konanVersionFull"
|
|
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 'INTEROP.md'
|
|
include 'RELEASE_NOTES.md'
|
|
include 'GRADLE_PLUGIN.md'
|
|
include 'PLATFORM_LIBS.md'
|
|
include 'samples/**'
|
|
exclude '**/gradle.properties'
|
|
exclude '**/settings.gradle'
|
|
exclude '**/build'
|
|
exclude '**/.gradle'
|
|
exclude 'samples/**/*.kt.bc-build'
|
|
into baseName
|
|
}
|
|
|
|
from(project.file("samples")) {
|
|
include '**/settings.gradle'
|
|
into "$baseName/samples"
|
|
filter { it.startsWith("includeBuild") ? null : it }
|
|
}
|
|
|
|
from(project.file("samples")) {
|
|
include '**/gradle.properties'
|
|
into "$baseName/samples"
|
|
filter {
|
|
if (it.startsWith("konan.home=")) {
|
|
return it.replace("/dist", "")
|
|
}
|
|
if (it.startsWith("konan.plugin.version=")) {
|
|
return "konan.plugin.version=$gradlePluginVersion"
|
|
}
|
|
return it
|
|
}
|
|
}
|
|
|
|
destinationDir = file('.')
|
|
if (!isWindows()) {
|
|
extension = 'tar.gz'
|
|
compression = Compression.GZIP
|
|
}
|
|
}
|
|
|
|
task uploadBundle {
|
|
dependsOn ':bundle'
|
|
doLast {
|
|
def kind = (konanVersionFull.meta == MetaVersion.DEV) ? "dev" : "releases"
|
|
def ftpSettings = [
|
|
server: project.findProperty("cdnUrl") ?: System.getenv("CDN_URL"),
|
|
userid: project.findProperty("cdnUser") ?: System.getenv("CDN_USER"),
|
|
password: project.findProperty("cdnPass") ?: System.getenv("CDN_PASS"),
|
|
remoteDir: "/builds/$kind/$konanVersion/${HostManager.simpleOsName()}"
|
|
]
|
|
ant {
|
|
taskdef(name: 'ftp',
|
|
classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
|
|
classpath: configurations.ftpAntTask.asPath)
|
|
ftp([action: "mkdir"] + ftpSettings)
|
|
ftp(ftpSettings) {
|
|
fileset(file: bundle.archivePath)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
task performance {
|
|
dependsOn 'dist'
|
|
dependsOn ':performance:bench'
|
|
}
|
|
|
|
task teamcityKonanVersion {
|
|
doLast {
|
|
println("##teamcity[setParameter name='kotlin.native.version.base' value='$konanVersion']")
|
|
println("##teamcity[setParameter name='kotlin.native.version.full' value='$konanVersionFull']")
|
|
println("##teamcity[setParameter name='kotlin.native.version.meta' value='${konanVersionFull.meta.toString().toLowerCase()}']")
|
|
println("##teamcity[buildNumber '${konanVersionFull.toString(true, true)}']")
|
|
}
|
|
}
|
|
|
|
task clean {
|
|
dependsOn subprojects.collect { it.tasks.matching { it.name == "clean" } }
|
|
doLast {
|
|
delete distDir
|
|
delete bundle.outputs.files
|
|
}
|
|
}
|