mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
Build: support local.properties for JPS build. Apply JPS related tweaks only inside IDEA import.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -39,4 +39,5 @@ build/
|
||||
kotlin-ultimate/
|
||||
node_modules/
|
||||
.rpt2_cache/
|
||||
libraries/tools/kotlin-test-nodejs-runner/lib/
|
||||
libraries/tools/kotlin-test-nodejs-runner/lib/
|
||||
local.properties
|
||||
|
||||
88
buildSrc/src/main/kotlin/buildProperties.kt
Normal file
88
buildSrc/src/main/kotlin/buildProperties.kt
Normal file
@@ -0,0 +1,88 @@
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.initialization.Settings
|
||||
import org.gradle.api.internal.DynamicObjectAware
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
interface PropertiesProvider {
|
||||
val rootProjectDir: File
|
||||
fun getProperty(key: String): Any?
|
||||
}
|
||||
|
||||
class KotlinBuildProperties(
|
||||
private val propertiesProvider: PropertiesProvider
|
||||
) {
|
||||
private val localProperties: Properties = Properties()
|
||||
|
||||
init {
|
||||
val localPropertiesFile = propertiesProvider.rootProjectDir.resolve("local.properties")
|
||||
if (localPropertiesFile.isFile) {
|
||||
localPropertiesFile.reader().use(localProperties::load)
|
||||
}
|
||||
}
|
||||
|
||||
private operator fun get(key: String): Any? = localProperties.getProperty(key) ?: propertiesProvider.getProperty(key)
|
||||
|
||||
private fun getBoolean(key: String): Boolean = this[key]?.toString() == "true"
|
||||
|
||||
val isJpsBuildEnabled: Boolean = getBoolean("jpsBuild")
|
||||
|
||||
val isInIdeaSync: Boolean = run {
|
||||
// "idea.sync.active" was introduced in 2019.1
|
||||
System.getProperty("idea.sync.active")?.toBoolean() == true || let {
|
||||
// before 2019.1 there is "idea.active" that was true only on sync,
|
||||
// but since 2019.1 "idea.active" present in task execution too.
|
||||
// So let's check Idea version
|
||||
val majorIdeaVersion = System.getProperty("idea.version")
|
||||
?.split(".")
|
||||
?.getOrNull(0)
|
||||
val isBeforeIdea2019 = majorIdeaVersion == null || majorIdeaVersion.toInt() < 2019
|
||||
|
||||
isBeforeIdea2019 && System.getProperty("idea.active")?.toBoolean() == true
|
||||
}
|
||||
}
|
||||
|
||||
val isInJpsBuildIdeaSync: Boolean
|
||||
get() = isJpsBuildEnabled && isInIdeaSync
|
||||
|
||||
val includeJava9: Boolean
|
||||
get() = !isInJpsBuildIdeaSync
|
||||
}
|
||||
|
||||
private const val extensionName = "kotlinBuildFlags"
|
||||
|
||||
class ProjectProperties(val project: Project): PropertiesProvider {
|
||||
override val rootProjectDir: File
|
||||
get() = project.projectDir
|
||||
|
||||
override fun getProperty(key: String): Any? = project.findProperty(key)
|
||||
}
|
||||
|
||||
val Project.kotlinBuildProperties: KotlinBuildProperties
|
||||
get() = rootProject.extensions.findByName(extensionName) as KotlinBuildProperties?
|
||||
?: KotlinBuildProperties(ProjectProperties(rootProject)).also {
|
||||
rootProject.extensions.add(extensionName, it)
|
||||
}
|
||||
|
||||
class SettingsProperties(val settings: Settings): PropertiesProvider {
|
||||
override val rootProjectDir: File
|
||||
get() = settings.rootDir
|
||||
|
||||
override fun getProperty(key: String): Any? {
|
||||
val obj = (settings as DynamicObjectAware).asDynamicObject
|
||||
return if (obj.hasProperty(key)) obj.getProperty(key) else null
|
||||
}
|
||||
}
|
||||
|
||||
fun getKotlinBuildPropertiesForSettings(settings: Any) = (settings as Settings).kotlinBuildProperties
|
||||
|
||||
val Settings.kotlinBuildProperties: KotlinBuildProperties
|
||||
get() = extensions.findByName(extensionName) as KotlinBuildProperties?
|
||||
?: KotlinBuildProperties(SettingsProperties(this)).also {
|
||||
extensions.add(extensionName, it)
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
@file:Suppress("unused") // usages in build scripts are not tracked properly
|
||||
@file:Suppress("unused")
|
||||
|
||||
// usages in build scripts are not tracked properly
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.ProjectDependency
|
||||
import org.gradle.api.artifacts.dsl.DependencyHandler
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.gradle.api.tasks.AbstractCopyTask
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.gradle.kotlin.dsl.extra
|
||||
import org.gradle.kotlin.dsl.project
|
||||
import java.io.File
|
||||
@@ -73,8 +75,8 @@ fun Project.ideaUltimatePreloadedDeps(vararg artifactBaseNames: String, subdir:
|
||||
|
||||
fun Project.kotlinDep(artifactBaseName: String, version: String): String = "org.jetbrains.kotlin:kotlin-$artifactBaseName:$version"
|
||||
|
||||
val Project.useBootstrapStdlib: Boolean get() =
|
||||
findProperty("jpsBuild")?.toString() == "true"
|
||||
val Project.useBootstrapStdlib: Boolean
|
||||
get() = kotlinBuildProperties.isInJpsBuildIdeaSync
|
||||
|
||||
fun Project.kotlinStdlib(suffix: String? = null): Any {
|
||||
return if (useBootstrapStdlib)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import java.io.File
|
||||
import org.gradle.api.tasks.bundling.Jar
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
@@ -67,7 +66,7 @@ dependencies {
|
||||
antLauncherJar(files(toolsJar()))
|
||||
|
||||
// For JPS build
|
||||
if (System.getProperty("idea.active") != null) {
|
||||
if (project.kotlinBuildProperties.isInJpsBuildIdeaSync) {
|
||||
testRuntimeOnly(files("${rootProject.projectDir}/dist/kotlinc/lib/kotlin-reflect.jar"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import org.jetbrains.gradle.ext.*
|
||||
import org.jetbrains.kotlin.ideaExt.*
|
||||
import org.jetbrains.kotlin.buildUtils.idea.*
|
||||
|
||||
val isJpsBuildEnabled = findProperty("jpsBuild")?.toString() == "true"
|
||||
val ideaPluginDir: File by extra
|
||||
val ideaSandboxDir: File by extra
|
||||
val ideaSdkPath: String
|
||||
@@ -29,7 +28,7 @@ fun org.jetbrains.gradle.ext.JUnit.configureForKotlin() {
|
||||
workingDirectory = rootDir.toString()
|
||||
}
|
||||
|
||||
if (isJpsBuildEnabled && System.getProperty("idea.active") != null) {
|
||||
if (kotlinBuildProperties.isInJpsBuildIdeaSync) {
|
||||
allprojects {
|
||||
apply(mapOf("plugin" to "idea"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
@@ -126,7 +124,9 @@ dependencies {
|
||||
testRuntime(intellijPluginDep("smali"))
|
||||
testRuntime(intellijPluginDep("testng"))
|
||||
|
||||
if (System.getProperty("idea.active") != null) testRuntimeOnly(files("${rootProject.projectDir}/dist/kotlinc/lib/kotlin-reflect.jar"))
|
||||
if (project.kotlinBuildProperties.isInJpsBuildIdeaSync) {
|
||||
testRuntimeOnly(files("${rootProject.projectDir}/dist/kotlinc/lib/kotlin-reflect.jar"))
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
"main" {
|
||||
|
||||
@@ -11,10 +11,10 @@ pill {
|
||||
importAsLibrary = true
|
||||
}
|
||||
|
||||
def jpsBuild = findProperty("jpsBuild")?.toString() == "true"
|
||||
def includeJava9 = BuildPropertiesKt.getKotlinBuildProperties(project).includeJava9
|
||||
|
||||
sourceSets {
|
||||
if (!jpsBuild) {
|
||||
if (includeJava9) {
|
||||
java9
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ task modularJar(type: Jar) {
|
||||
classifier = 'modular'
|
||||
|
||||
from zipTree(jar.outputs.files.singleFile)
|
||||
if (!jpsBuild) {
|
||||
if (includeJava9) {
|
||||
from sourceSets.java9.output
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,6 @@ compileTestKotlin {
|
||||
kotlinOptions.freeCompilerArgs = ["-Xallow-kotlin-package"]
|
||||
}
|
||||
|
||||
if (!jpsBuild) {
|
||||
if (includeJava9) {
|
||||
compileJava9Sources(project, 'kotlin.test')
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ apply plugin: 'kotlin'
|
||||
|
||||
configureJvm6Project(project)
|
||||
|
||||
def jpsBuild = findProperty("jpsBuild")?.toString() == "true"
|
||||
def includeJava9 = BuildPropertiesKt.getKotlinBuildProperties(project).includeJava9
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
@@ -13,7 +13,7 @@ sourceSets {
|
||||
}
|
||||
}
|
||||
|
||||
if (!jpsBuild) {
|
||||
if (includeJava9) {
|
||||
java9
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ dependencies {
|
||||
compileOnly "org.jetbrains:annotations:13.0"
|
||||
}
|
||||
|
||||
if (!jpsBuild) {
|
||||
if (includeJava9) {
|
||||
compileJava9Sources(
|
||||
project, 'kotlin.reflect',
|
||||
[sourceSets.main.output, configurations.compileOnly.filter {
|
||||
@@ -52,7 +52,7 @@ jar {
|
||||
|
||||
task java9Jar(type: Jar) {
|
||||
classifier = "java9"
|
||||
if (!jpsBuild) {
|
||||
if (includeJava9) {
|
||||
from sourceSets.java9.output
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ sourceSets {
|
||||
test {
|
||||
kotlin {
|
||||
srcDir 'test'
|
||||
if(!System.properties.'idea.active') {
|
||||
if(!BuildPropertiesKt.getKotlinBuildProperties(project).inIdeaSync) {
|
||||
srcDir '../jvm/test'
|
||||
srcDir '../common/test'
|
||||
srcDir '../test'
|
||||
|
||||
@@ -28,7 +28,7 @@ sourceSets {
|
||||
test {
|
||||
kotlin {
|
||||
srcDir 'test'
|
||||
if(!System.properties.'idea.active') {
|
||||
if(!BuildPropertiesKt.getKotlinBuildProperties(project).inIdeaSync) {
|
||||
srcDir '../jvm/test'
|
||||
srcDir '../common/test'
|
||||
srcDir '../test'
|
||||
|
||||
@@ -51,7 +51,7 @@ sourceSets {
|
||||
}
|
||||
|
||||
experimental {
|
||||
if(!System.properties.'idea.active')
|
||||
if(!BuildPropertiesKt.getKotlinBuildProperties(project).inIdeaSync)
|
||||
kotlin {
|
||||
srcDir experimentalSrcDir
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ sourceSets {
|
||||
}
|
||||
coroutinesExperimentalMigrationTest {
|
||||
kotlin {
|
||||
if(!System.properties.'idea.active') {
|
||||
if(!BuildPropertiesKt.getKotlinBuildProperties(project).inIdeaSync) {
|
||||
srcDir '../coroutines-experimental/jvm/test'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,8 +219,9 @@ if (isTeamcityBuild || includeUltimate) {
|
||||
)
|
||||
}
|
||||
|
||||
def isJpsBuild = hasProperty("jpsBuild") && jpsBuild == 'true'
|
||||
if (isJpsBuild) {
|
||||
def flags = BuildPropertiesKt.getKotlinBuildPropertiesForSettings(settings)
|
||||
|
||||
if (flags.inJpsBuildIdeaSync) {
|
||||
include ":kotlin-stdlib:jps-build"
|
||||
project(":kotlin-stdlib:jps-build").projectDir = "$rootDir/libraries/stdlib/jps-build" as File
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user