From 61dfb75e0e1e8df53980754c8675184f686ea093 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 2 Aug 2017 12:26:50 +0200 Subject: [PATCH] Implement Gradle Kotlin DSL build --- ant/build.gradle.kts | 29 +++ build-common/build.gradle.kts | 40 +++ build.gradle.kts | 207 ++++++++++++++++ buildSrc/build.gradle.kts | 48 ++++ buildSrc/settings.gradle | 1 + buildSrc/src/main/kotlin/CommonUtil.kt | 71 ++++++ buildSrc/src/main/kotlin/artifacts.kt | 135 +++++++++++ buildSrc/src/main/kotlin/dependencies.kt | 93 +++++++ buildSrc/src/main/kotlin/sourceSets.kt | 125 ++++++++++ compiler.tests-common/build.gradle.kts | 35 +++ compiler/android-tests/build.gradle.kts | 40 +++ compiler/backend-common/build.gradle.kts | 14 ++ compiler/backend/build.gradle.kts | 18 ++ compiler/build.gradle.kts | 227 ++++++++++++++++++ compiler/cli/build.gradle.kts | 32 +++ compiler/cli/cli-common/build.gradle.kts | 15 ++ compiler/cli/cli-runner/build.gradle.kts | 26 ++ compiler/compiler-runner/build.gradle.kts | 17 ++ compiler/container/build.gradle.kts | 31 +++ .../daemon/daemon-client/build.gradle.kts | 35 +++ .../daemon/daemon-common/build.gradle.kts | 14 ++ compiler/frontend.java/build.gradle.kts | 14 ++ compiler/frontend.script/build.gradle.kts | 14 ++ compiler/frontend/build.gradle.kts | 16 ++ .../build.gradle.kts | 16 ++ compiler/ir/ir.ir2cfg/build.gradle.kts | 13 + compiler/ir/ir.psi2ir/build.gradle.kts | 14 ++ compiler/ir/ir.tree/build.gradle.kts | 12 + compiler/light-classes/build.gradle.kts | 14 ++ compiler/plugin-api/build.gradle.kts | 13 + compiler/preloader/build.gradle.kts | 25 ++ compiler/resolution/build.gradle.kts | 12 + compiler/serialization/build.gradle.kts | 12 + compiler/tests-java8/build.gradle.kts | 56 +++++ compiler/util/build.gradle.kts | 14 ++ core/build.gradle.kts | 32 +++ core/builtins/build.gradle.kts | 64 +++++ core/reflection.jvm/build.gradle.kts | 48 ++++ core/script.runtime/build.gradle.kts | 20 ++ core/util.runtime/build.gradle.kts | 15 ++ .../protobuf-lite/build.gradle.kts | 121 ++++++++++ eval4j/build.gradle.kts | 16 ++ generators/build.gradle.kts | 69 ++++++ gradle.properties | 4 + idea/build.gradle.kts | 142 +++++++++++ idea/formatter/build.gradle.kts | 13 + idea/ide-common/build.gradle.kts | 16 ++ idea/idea-android/build.gradle.kts | 64 +++++ .../build.gradle.kts | 14 ++ idea/idea-core/build.gradle.kts | 27 +++ idea/idea-jps-common/build.gradle.kts | 16 ++ idea/idea-test-framework/build.gradle.kts | 18 ++ idea/kotlin-gradle-tooling/build.gradle.kts | 27 +++ j2k/build.gradle.kts | 17 ++ jps-plugin/build.gradle.kts | 51 ++++ js/js.ast/build.gradle.kts | 13 + js/js.dce/build.gradle.kts | 14 ++ js/js.frontend/build.gradle.kts | 16 ++ js/js.parser/build.gradle.kts | 14 ++ js/js.serializer/build.gradle.kts | 15 ++ js/js.tests/build.gradle.kts | 36 +++ js/js.translator/build.gradle.kts | 18 ++ kotlin-bootstrap-version.txt | 1 + kotlin-version-for-gradle.txt | 1 + .../build.gradle.kts | 12 + plugins/allopen/allopen-cli/build.gradle.kts | 30 +++ plugins/allopen/allopen-ide/build.gradle.kts | 29 +++ .../build.gradle.kts | 32 +++ .../android-extensions-idea/build.gradle.kts | 63 +++++ .../android-extensions-jps/build.gradle.kts | 14 ++ .../build.gradle.kts | 22 ++ plugins/kapt3/build.gradle.kts | 31 +++ plugins/lint/build.gradle.kts | 25 ++ plugins/noarg/noarg-cli/build.gradle.kts | 32 +++ plugins/noarg/noarg-ide/build.gradle.kts | 32 +++ plugins/plugins-tests/build.gradle.kts | 51 ++++ .../sam-with-receiver-cli/build.gradle.kts | 30 +++ .../sam-with-receiver-ide/build.gradle.kts | 26 ++ .../source-sections-compiler/build.gradle.kts | 48 ++++ plugins/uast-kotlin-idea/build.gradle.kts | 18 ++ plugins/uast-kotlin/build.gradle.kts | 39 +++ prepare/android-lint/build.gradle.kts | 31 +++ prepare/build.version/build.gradle.kts | 28 +++ prepare/compiler-embeddable/build.gradle.kts | 59 +++++ prepare/compiler/build.gradle.kts | 118 +++++++++ prepare/formatter/build.gradle.kts | 20 ++ prepare/ide-lazy-resolver/build.gradle.kts | 20 ++ prepare/jps-plugin/build.gradle.kts | 47 ++++ prepare/kotlin-plugin/build.gradle.kts | 86 +++++++ .../mock-runtime-for-test/build.gradle.kts | 42 ++++ prepare/reflect/build.gradle.kts | 131 ++++++++++ prepare/runtime/build.gradle.kts | 39 +++ settings.gradle | 162 +++++++++++++ 93 files changed, 3737 insertions(+) create mode 100644 ant/build.gradle.kts create mode 100644 build-common/build.gradle.kts create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/settings.gradle create mode 100644 buildSrc/src/main/kotlin/CommonUtil.kt create mode 100644 buildSrc/src/main/kotlin/artifacts.kt create mode 100644 buildSrc/src/main/kotlin/dependencies.kt create mode 100644 buildSrc/src/main/kotlin/sourceSets.kt create mode 100644 compiler.tests-common/build.gradle.kts create mode 100644 compiler/android-tests/build.gradle.kts create mode 100644 compiler/backend-common/build.gradle.kts create mode 100644 compiler/backend/build.gradle.kts create mode 100644 compiler/build.gradle.kts create mode 100644 compiler/cli/build.gradle.kts create mode 100644 compiler/cli/cli-common/build.gradle.kts create mode 100644 compiler/cli/cli-runner/build.gradle.kts create mode 100644 compiler/compiler-runner/build.gradle.kts create mode 100644 compiler/container/build.gradle.kts create mode 100644 compiler/daemon/daemon-client/build.gradle.kts create mode 100644 compiler/daemon/daemon-common/build.gradle.kts create mode 100644 compiler/frontend.java/build.gradle.kts create mode 100644 compiler/frontend.script/build.gradle.kts create mode 100644 compiler/frontend/build.gradle.kts create mode 100644 compiler/incremental-compilation-impl/build.gradle.kts create mode 100644 compiler/ir/ir.ir2cfg/build.gradle.kts create mode 100644 compiler/ir/ir.psi2ir/build.gradle.kts create mode 100644 compiler/ir/ir.tree/build.gradle.kts create mode 100644 compiler/light-classes/build.gradle.kts create mode 100644 compiler/plugin-api/build.gradle.kts create mode 100644 compiler/preloader/build.gradle.kts create mode 100644 compiler/resolution/build.gradle.kts create mode 100644 compiler/serialization/build.gradle.kts create mode 100644 compiler/tests-java8/build.gradle.kts create mode 100644 compiler/util/build.gradle.kts create mode 100644 core/build.gradle.kts create mode 100644 core/builtins/build.gradle.kts create mode 100644 core/reflection.jvm/build.gradle.kts create mode 100644 core/script.runtime/build.gradle.kts create mode 100644 core/util.runtime/build.gradle.kts create mode 100644 custom-dependencies/protobuf-lite/build.gradle.kts create mode 100644 eval4j/build.gradle.kts create mode 100644 generators/build.gradle.kts create mode 100644 gradle.properties create mode 100644 idea/build.gradle.kts create mode 100644 idea/formatter/build.gradle.kts create mode 100644 idea/ide-common/build.gradle.kts create mode 100644 idea/idea-android/build.gradle.kts create mode 100644 idea/idea-android/idea-android-output-parser/build.gradle.kts create mode 100644 idea/idea-core/build.gradle.kts create mode 100644 idea/idea-jps-common/build.gradle.kts create mode 100644 idea/idea-test-framework/build.gradle.kts create mode 100644 idea/kotlin-gradle-tooling/build.gradle.kts create mode 100644 j2k/build.gradle.kts create mode 100644 jps-plugin/build.gradle.kts create mode 100644 js/js.ast/build.gradle.kts create mode 100644 js/js.dce/build.gradle.kts create mode 100644 js/js.frontend/build.gradle.kts create mode 100644 js/js.parser/build.gradle.kts create mode 100644 js/js.serializer/build.gradle.kts create mode 100644 js/js.tests/build.gradle.kts create mode 100644 js/js.translator/build.gradle.kts create mode 100644 kotlin-bootstrap-version.txt create mode 100644 kotlin-version-for-gradle.txt create mode 100644 libraries/examples/annotation-processor-example/build.gradle.kts create mode 100644 plugins/allopen/allopen-cli/build.gradle.kts create mode 100644 plugins/allopen/allopen-ide/build.gradle.kts create mode 100644 plugins/android-extensions/android-extensions-compiler/build.gradle.kts create mode 100644 plugins/android-extensions/android-extensions-idea/build.gradle.kts create mode 100644 plugins/android-extensions/android-extensions-jps/build.gradle.kts create mode 100644 plugins/annotation-based-compiler-plugins-ide-support/build.gradle.kts create mode 100644 plugins/kapt3/build.gradle.kts create mode 100644 plugins/lint/build.gradle.kts create mode 100644 plugins/noarg/noarg-cli/build.gradle.kts create mode 100644 plugins/noarg/noarg-ide/build.gradle.kts create mode 100644 plugins/plugins-tests/build.gradle.kts create mode 100644 plugins/sam-with-receiver/sam-with-receiver-cli/build.gradle.kts create mode 100644 plugins/sam-with-receiver/sam-with-receiver-ide/build.gradle.kts create mode 100644 plugins/source-sections/source-sections-compiler/build.gradle.kts create mode 100644 plugins/uast-kotlin-idea/build.gradle.kts create mode 100644 plugins/uast-kotlin/build.gradle.kts create mode 100644 prepare/android-lint/build.gradle.kts create mode 100644 prepare/build.version/build.gradle.kts create mode 100644 prepare/compiler-embeddable/build.gradle.kts create mode 100644 prepare/compiler/build.gradle.kts create mode 100644 prepare/formatter/build.gradle.kts create mode 100644 prepare/ide-lazy-resolver/build.gradle.kts create mode 100644 prepare/jps-plugin/build.gradle.kts create mode 100644 prepare/kotlin-plugin/build.gradle.kts create mode 100644 prepare/mock-runtime-for-test/build.gradle.kts create mode 100644 prepare/reflect/build.gradle.kts create mode 100644 prepare/runtime/build.gradle.kts create mode 100644 settings.gradle diff --git a/ant/build.gradle.kts b/ant/build.gradle.kts new file mode 100644 index 00000000000..f3c25c46707 --- /dev/null +++ b/ant/build.gradle.kts @@ -0,0 +1,29 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(commonDep("org.apache.ant", "ant")) + compile(project(":compiler:preloader")) + compile(kotlinDep("stdlib")) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin Ant Tools") + archiveName = "kotlin-ant.jar" + from("$projectDir/src") { include("**/*.xml") } + + manifest.attributes.put("Class-Path", "kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar kotlin-preloader.jar") +} + +dist { + from(jar) +} + diff --git a/build-common/build.gradle.kts b/build-common/build.gradle.kts new file mode 100644 index 00000000000..69f2e647d01 --- /dev/null +++ b/build-common/build.gradle.kts @@ -0,0 +1,40 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + compile(project(":core:util.runtime")) + compile(project(":compiler:util")) + compile(project(":compiler:cli-common")) + compile(project(":compiler:frontend.java")) + compile(ideaSdkDeps("util")) + buildVersion() + testCompile(commonDep("junit:junit")) + testCompile(project(":compiler.tests-common")) + testCompile(protobufFull()) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectTestsDefault() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin Build Common") + baseName = "kotlin-build-common" +} + +testsJar {} + +tasks.withType { + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + systemProperty("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} + diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000000..ec1377ed0e4 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,207 @@ +import java.util.* +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.java +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile + +buildscript { + extra["kotlin_version"] = file("kotlin-bootstrap-version.txt").readText().trim() + extra["kotlinVersion"] = extra["kotlin_version"] + extra["kotlin_language_version"] = "1.1" + extra["kotlin_gradle_plugin_version"] = extra["kotlin_version"] + extra["repos"] = listOf("https://dl.bintray.com/kotlin/kotlin-dev", + "https://repo.gradle.org/gradle/repo", + "https://plugins.gradle.org/m2") + + repositories { + for (repo in (rootProject.extra["repos"] as List)) { + maven { setUrl(repo) } + } + } + + dependencies { + classpath(kotlinDep("gradle-plugin")) + classpath("com.gradle.publish:plugin-publish-plugin:0.9.7") + } +} + +plugins { + java // so we can benefit from the `java()` accessor below +} + +val buildNumber = "1.1-SNAPSHOT" +extra["build.number"] = buildNumber + +extra["kotlin_root"] = rootDir + +val bootstrapCompileCfg = configurations.create("bootstrapCompile") +val scriptCompileCfg = configurations.create("scriptCompile").extendsFrom(bootstrapCompileCfg) +val scriptRuntimeCfg = configurations.create("scriptRuntime").extendsFrom(scriptCompileCfg) + +repositories { + for (repo in (rootProject.extra["repos"] as List)) { + maven { setUrl(repo) } + } +} + +dependencies { + bootstrapCompileCfg(kotlinDep("compiler-embeddable")) +} + +val commonBuildDir = File(rootDir, "build") +val distDir = "$rootDir/dist" +val distLibDir = "$distDir/kotlinc/lib" +val ideaPluginDir = "$distDir/artifacts/Kotlin" + +extra["distDir"] = distDir +extra["distLibDir"] = project.file(distLibDir) +extra["libsDir"] = project.file(distLibDir) +extra["ideaPluginDir"] = project.file(ideaPluginDir) + +Properties().apply { + load(File(rootDir, "resources", "kotlinManifest.properties").reader()) + forEach { + val key = it.key + if (key != null && key is String) + extra[key] = it.value + } +} + +extra["JDK_16"] = jdkPath("1.6") +extra["JDK_17"] = jdkPath("1.7") +extra["JDK_18"] = jdkPath("1.8") + +extra["compilerBaseName"] = "kotlin-compiler" +extra["embeddableCompilerBaseName"] = "kotlin-compiler-embeddable" +//extra["compilerJarWithBootstrapRuntime"] = project.file("$distDir/kotlin-compiler-with-bootstrap-runtime.jar") +//extra["bootstrapCompilerFile"] = bootstrapCfg.files.first().canonicalPath + +extra["buildLocalRepoPath"] = File(commonBuildDir, "repo") + +extra["versions.protobuf-java"] = "2.6.1" +extra["versions.javax.inject"] = "1" +extra["versions.jsr305"] = "1.3.9" +extra["versions.cli-parser"] = "1.1.2" +extra["versions.jansi"] = "1.11" +extra["versions.jline"] = "2.12.1" +extra["versions.junit"] = "4.12" +extra["versions.javaslang"] = "2.0.6" +extra["versions.ant"] = "1.8.2" + +extra["ideaCoreSdkJars"] = arrayOf("annotations", "asm-all", "guava", "intellij-core", "jdom", "jna", "log4j", "picocontainer", + "snappy-in-java", "trove4j", "xpp3-1.1.4-min", "xstream") + +extra["compilerModules"] = arrayOf(":compiler:util", + ":compiler:container", + ":compiler:resolution", + ":compiler:serialization", + ":compiler:frontend", + ":compiler:frontend.java", + ":compiler:frontend.script", + ":compiler:cli-common", + ":compiler:daemon-common", + ":compiler:ir.tree", + ":compiler:ir.psi2ir", + ":compiler:backend-common", + ":compiler:backend", + ":compiler:plugin-api", + ":compiler:light-classes", + ":compiler:cli", + ":compiler:incremental-compilation-impl", + ":js:js.ast", + ":js:js.serializer", + ":js:js.parser", + ":js:js.frontend", + ":js:js.translator", + ":js:js.dce", + ":compiler", + ":build-common", + ":core:util.runtime", + ":core") + +allprojects { + group = "org.jetbrains.kotlin" + version = buildNumber +} + +applyFrom("libraries/commonConfiguration.gradle") +applyFrom("libraries/gradlePluginsConfiguration.gradle") +applyFrom("libraries/configureGradleTools.gradle") + +val importedAntTasksPrefix = "imported-ant-update-" + +// TODO: check the reasons of import conflict with xerces +//ant.importBuild("$rootDir/update_dependencies.xml") { antTaskName -> importedAntTasksPrefix + antTaskName } + +tasks.matching { task -> + task.name.startsWith(importedAntTasksPrefix) +}.forEach { + it.group = "Imported ant" +} + +//task("update-dependencies") { +// dependsOn(tasks.getByName(importedAntTasksPrefix + "update")) +//} + +//val prepareBootstrapTask = task("prepareBootstrap") { +// dependsOn(bootstrapCfg, scriptCompileCfg, scriptRuntimeCfg) +//} + +fun Project.allprojectsRecursive(body: Project.() -> Unit) { + this.body() + this.subprojects { allprojectsRecursive(body) } +} + +allprojects { + + setBuildDir(File(commonBuildDir, project.name)) + + repositories { + for (repo in (rootProject.extra["repos"] as List)) { + maven { setUrl(repo) } + } + mavenCentral() + jcenter() + } + + tasks.withType { + kotlinOptions.freeCompilerArgs = listOf("-Xallow-kotlin-package", "-module-name", project.name) + } + + tasks.withType { + kotlinOptions.freeCompilerArgs = listOf("-Xallow-kotlin-package", "-module-name", project.name) + } + + task("javadocJar") { + classifier = "javadoc" + } +} + +task("dist") { + into(distDir) + from(files("compiler/cli/bin")) { into("kotlinc/bin") } +} + +val compilerCopyTask = task("idea-plugin-copy-compiler") { + dependsOnTaskIfExistsRec("dist") + into(ideaPluginDir) + from(distDir) { include("kotlinc/**") } +} + +task("dist-plugin") { + dependsOn(compilerCopyTask) + dependsOnTaskIfExistsRec("idea-plugin") + into("$ideaPluginDir/lib") +} + +val clean by tasks +clean.apply { + doLast { + delete("${buildDir}/repo") + } +} + +fun jdkPath(version: String): String { + val varName = "JDK_${version.replace(".", "")}" + return System.getenv(varName) ?: throw GradleException ("Please set environment variable $varName to point to JDK $version installation") +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 00000000000..82420e4e9de --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,48 @@ + +buildscript { + extra["kotlin_version"] = file("../kotlin-version-for-gradle.txt").readText().trim() + extra["kotlin_gradle_plugin_version"] = extra["kotlin_version"] + extra["repos"] = listOf( + "https://dl.bintray.com/kotlin/kotlin-dev", + "https://repo.gradle.org/gradle/repo", + "https://plugins.gradle.org/m2", + "http://repository.jetbrains.com/utils/") + + repositories { + for (repo in (rootProject.extra["repos"] as List)) { + maven { setUrl(repo) } + } + } + + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlin_version"]}") + classpath("org.jetbrains.kotlin:kotlin-sam-with-receiver:${rootProject.extra["kotlin_version"]}") + } +} + +apply { + plugin("kotlin") + plugin("kotlin-sam-with-receiver") +} + +plugins { + `kotlin-dsl` +} + +repositories { + for (repo in (rootProject.extra["repos"] as List)) { + maven { setUrl(repo) } + } +} + +dependencies { + // TODO: adding the dep to the plugin breaks the build unexpectedly, resolve and uncomment +// compile("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlin_version"]}") +} + +samWithReceiver { + annotation("org.gradle.api.HasImplicitReceiver") +} + +fun Project.`samWithReceiver`(configure: org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverExtension.() -> Unit): Unit = + extensions.configure("samWithReceiver", configure) diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle new file mode 100644 index 00000000000..2df1179cacb --- /dev/null +++ b/buildSrc/settings.gradle @@ -0,0 +1 @@ +rootProject.buildFileName = 'build.gradle.kts' diff --git a/buildSrc/src/main/kotlin/CommonUtil.kt b/buildSrc/src/main/kotlin/CommonUtil.kt new file mode 100644 index 00000000000..925a21a9ed1 --- /dev/null +++ b/buildSrc/src/main/kotlin/CommonUtil.kt @@ -0,0 +1,71 @@ +@file:Suppress("unused") // usages in build scripts are not tracked properly + +import org.gradle.api.* +import org.gradle.api.tasks.* +import org.gradle.kotlin.dsl.* +import org.gradle.api.plugins.JavaPluginConvention +import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.internal.AbstractTask +import org.gradle.jvm.tasks.Jar +import java.io.File + +inline fun Project.task(noinline configuration: T.() -> Unit) = tasks.creating(T::class, configuration) + + +fun AbstractTask.dependsOnTaskIfExists(task: String) { + project.tasks.firstOrNull { it.name == task }?.let { dependsOn(it) } +} + +fun AbstractTask.dependsOnTaskIfExistsRec(task: String, project: Project? = null) { + dependsOnTaskIfExists(task) + (project ?: this.project).subprojects.forEach { + dependsOnTaskIfExistsRec(task, it) + } +} + +fun Jar.setupRuntimeJar(implementationTitle: String): Unit { + dependsOn(":prepare:build.version:prepare") + manifest.attributes.apply { + put("Built-By", project.rootProject.extra["manifest.impl.vendor"]) + put("Implementation-Vendor", project.rootProject.extra["manifest.impl.vendor"]) + put("Implementation-Title", implementationTitle) + put("Implementation-Version", project.rootProject.extra["build.number"]) + } +// from(project.configurations.getByName("build-version").files, action = { into("META-INF/") }) +} + +fun Jar.setupSourceJar(implementationTitle: String): Unit { + dependsOn("classes") + setupRuntimeJar(implementationTitle + " Sources") + project.pluginManager.withPlugin("java-base") { + from(project.the().sourceSets["main"].allSource) + } + classifier = "sources" + project.artifacts.add("archives", this) +} + + +inline fun Project.withJavaPlugin(crossinline body: () -> T?): T? { + var res: T? = null + pluginManager.withPlugin("java") { + res = body() + } + return res +} + +fun Project.getCompiledClasses(): SourceSetOutput? = withJavaPlugin { + the().sourceSets.getByName("main").output +} + +fun Project.getSources(): SourceDirectorySet? = withJavaPlugin { + the().sourceSets.getByName("main").allSource +} + +fun Project.getResourceFiles(): SourceDirectorySet? = withJavaPlugin { + the().sourceSets.getByName("main").resources +} + + + +fun File(root: File, vararg children: String): File = children.fold(root, { f, c -> File(f, c) }) +fun File(root: String, vararg children: String): File = children.fold(File(root), { f, c -> File(f, c) }) diff --git a/buildSrc/src/main/kotlin/artifacts.kt b/buildSrc/src/main/kotlin/artifacts.kt new file mode 100644 index 00000000000..0950002503d --- /dev/null +++ b/buildSrc/src/main/kotlin/artifacts.kt @@ -0,0 +1,135 @@ +@file:Suppress("unused") // usages in build scripts are not tracked properly + +import org.gradle.api.* +import org.gradle.api.artifacts.ConfigurablePublishArtifact +import org.gradle.api.tasks.* +import org.gradle.kotlin.dsl.* +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ConfigurationContainer +import org.gradle.api.plugins.JavaPluginConvention +import org.gradle.api.tasks.javadoc.Javadoc +import org.gradle.jvm.tasks.Jar + + +fun Project.testsJar(body: Jar.() -> Unit): Jar { + val testsJarCfg = configurations.getOrCreate("tests-jar").extendsFrom(configurations["testCompile"]) + + return task("testJar") { + dependsOn("testClasses") + pluginManager.withPlugin("java") { + from(project.the().sourceSets.getByName("test").output) + } + classifier = "tests" + body() + project.addArtifact(testsJarCfg, this, this) + } +} + +fun Project.runtimeJarArtifactBy(task: Task, artifactRef: T, body: ConfigurablePublishArtifact.() -> Unit = {}) { + addArtifact("archives", task, artifactRef, body) + addArtifact("runtimeJar", task, artifactRef, body) +} + +fun Project.runtimeJar(task: T, body: T.() -> Unit = {}): T = + task.apply { + setupPublicJar() + body() + project.runtimeJarArtifactBy(this, this) + } + +fun Project.runtimeJar(taskName: String = "jar", body: Jar.() -> Unit = {}): Jar = runtimeJar(getOrCreateTask(taskName, body)) + +fun Project.sourcesJar(body: Jar.() -> Unit = {}): Jar = + getOrCreateTask("sourcesJar") { + setupPublicJar("Sources") + try { + project.pluginManager.withPlugin("java-base") { + from(project.the().sourceSets["main"].allSource) + } + } catch (e: UnknownDomainObjectException) { + // skip default sources location + } + tasks.findByName("classes")?.let { dependsOn(it) } + body() + project.addArtifact("archives", this, this) + } + +fun Project.javadocJar(body: Jar.() -> Unit = {}): Jar = + getOrCreateTask("javadocJar") { + setupPublicJar("JavaDoc") + tasks.findByName("javadoc")?.let{ it as Javadoc }?.takeIf { it.enabled }?.let { + dependsOn(it) + from(it.destinationDir) + } + body() + project.addArtifact("archives", this, this) + } + + +fun Project.standardPublicJars(): Unit { + runtimeJar() + sourcesJar() + javadocJar() +} + +fun Project.publish(body: Upload.() -> Unit = {}): Upload { + apply() + + return (tasks.getByName("uploadArchives") as Upload).apply { + body() + } +} + +fun Project.ideaPlugin(subdir: String = "lib", body: Copy.() -> Unit) { + task("idea-plugin") { + body() + into(File(rootProject.extra["ideaPluginDir"].toString(), subdir).path) + rename("-${java.util.regex.Pattern.quote(rootProject.extra["build.number"].toString())}", "") + } +} + +fun Project.ideaPlugin() = ideaPlugin { + tasks.findByName("jar")?.let { + from(it) + } +} + + +fun Project.dist(body: Copy.() -> Unit = {}) { + task("dist") { + tasks.findByName("assemble")?.let { + dependsOn(it) + } + body() + rename("-${java.util.regex.Pattern.quote(rootProject.extra["build.number"].toString())}", "") + into(rootProject.extra["distLibDir"].toString()) + } +} + +fun ConfigurationContainer.getOrCreate(name: String): Configuration = findByName(name) ?: create(name) + +fun Jar.setupPublicJar(classifier: String = "", classifierDescr: String? = null) { + this.classifier = classifier.toLowerCase() + dependsOn(":prepare:build.version:prepare") + manifest.attributes.apply { + put("Built-By", project.rootProject.extra["manifest.impl.vendor"]) + put("Implementation-Vendor", project.rootProject.extra["manifest.impl.vendor"]) + put("Implementation-Title", "${project.description} ${classifierDescr ?: classifier}".trim()) + put("Implementation-Version", project.rootProject.extra["build.number"]) + } +// from(project.configurations.getByName("build-version").files, action = { into("META-INF/") }) +} + + +fun Project.addArtifact(configuration: Configuration, task: Task, artifactRef: T, body: ConfigurablePublishArtifact.() -> Unit = {}) { + artifacts.add(configuration.name, artifactRef) { + builtBy(task) + body() + } +} + +fun Project.addArtifact(configurationName: String, task: Task, artifactRef: T, body: ConfigurablePublishArtifact.() -> Unit = {}) = + addArtifact(configurations.getOrCreate(configurationName), task, artifactRef, body) + +inline fun Project.getOrCreateTask(taskName: String, body: T.() -> Unit): T = + (tasks.findByName(taskName)?.let { it as T } ?: task(taskName)).apply{ body() } diff --git a/buildSrc/src/main/kotlin/dependencies.kt b/buildSrc/src/main/kotlin/dependencies.kt new file mode 100644 index 00000000000..e329459902a --- /dev/null +++ b/buildSrc/src/main/kotlin/dependencies.kt @@ -0,0 +1,93 @@ + +@file:Suppress("unused") // usages in build scripts are not tracked properly + +import org.gradle.api.* +import org.gradle.api.artifacts.Dependency +import org.gradle.api.artifacts.ProjectDependency +import org.gradle.api.artifacts.dsl.DependencyHandler +import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.kotlin.dsl.* +import org.gradle.plugin.use.PluginDependenciesSpec +import org.gradle.plugin.use.PluginDependencySpec +import java.io.File +import java.util.* + +val bootstrapKotlinVersion: String = System.getProperty("bootstrap.kotlin.version") ?: embeddedKotlinVersion + +fun PluginDependenciesSpec.kotlin(module: String, version: String? = null): PluginDependencySpec = + id("org.jetbrains.kotlin.$module") version (version ?: bootstrapKotlinVersion) + +fun Project.buildVersion(): Dependency { + val cfg = configurations.create("build-version") + return dependencies.add(cfg.name, dependencies.project(":prepare:build.version", configuration = "default")) +} + +fun Project.commonDep(coord: String): String { + val parts = coord.split(':') + return when (parts.size) { + 1 -> "$coord:$coord:${rootProject.extra["versions.$coord"]}" + 2 -> "${parts[0]}:${parts[1]}:${rootProject.extra["versions.${parts[1]}"]}" + 3 -> coord + else -> throw IllegalArgumentException("Illegal maven coordinates: $coord") + } +} + +fun Project.commonDep(group: String, artifact: String): String = "$group:$artifact:${rootProject.extra["versions.$artifact"]}" + +fun Project.preloadedDeps(vararg artifactBaseNames: String, baseDir: File = File(rootDir, "dependencies"), subdir: String? = null): ConfigurableFileCollection { + val dir = if (subdir != null) File(baseDir, subdir) else baseDir + if (!dir.exists() || !dir.isDirectory) throw GradleException("Invalid base directory $dir") + val matchingFiles = dir.listFiles { file -> artifactBaseNames.any { file.matchMaybeVersionedArtifact(it) } } + if (matchingFiles == null || matchingFiles.size < artifactBaseNames.size) + throw GradleException("Not all matching artifacts '${artifactBaseNames.joinToString()}' found in the '$dir' (found: ${matchingFiles?.joinToString { it.name }})") + return files(*matchingFiles.map { it.canonicalPath }.toTypedArray()) +} + +fun Project.ideaSdkDeps(vararg artifactBaseNames: String, subdir: String = "lib"): ConfigurableFileCollection = + preloadedDeps(*artifactBaseNames, baseDir = File(rootDir, "ideaSDK"), subdir = subdir) + +fun Project.ideaSdkCoreDeps(vararg artifactBaseNames: String): ConfigurableFileCollection = ideaSdkDeps(*artifactBaseNames, subdir = "core") + +fun Project.ideaPluginDeps(vararg artifactBaseNames: String, plugin: String, subdir: String = "lib"): ConfigurableFileCollection = + preloadedDeps(*artifactBaseNames, baseDir = File(rootDir, "ideaSDK"), subdir = "plugins/$plugin/$subdir") + +fun Project.kotlinDep(artifactBaseName: String, version: String? = null): String = "org.jetbrains.kotlin:kotlin-$artifactBaseName:${version ?: bootstrapKotlinVersion}" + +fun DependencyHandler.projectDep(name: String): Dependency = project(name, configuration = "default") +fun DependencyHandler.projectDepIntransitive(name: String): Dependency = + project(name, configuration = "default").apply { isTransitive = false } + +fun DependencyHandler.projectTests(name: String): Dependency = project(name, configuration = "tests-jar").apply { isTransitive = false } + +val protobufLiteProject = ":custom-dependencies:protobuf-lite" +fun DependencyHandler.protobufLite(): ProjectDependency = + project(protobufLiteProject, configuration = "default").apply { isTransitive = false } +val protobufLiteTask = "$protobufLiteProject:prepare" + +fun DependencyHandler.protobufFull(): ProjectDependency = + project(protobufLiteProject, configuration = "relocated").apply { isTransitive = false } +val protobufFullTask = "$protobufLiteProject:prepare-relocated-protobuf" + + +private fun File.matchMaybeVersionedArtifact(baseName: String) = name.matches(baseName.toMaybeVersionedJarRegex()) + +private val wildcardsRe = """[^*?]+|(\*)|(\?)""".toRegex() + +private fun String.wildcardsToEscapedRegexString(): String = buildString { + wildcardsRe.findAll(this@wildcardsToEscapedRegexString).forEach { + when { + it.groups[1] != null -> append(".*") + it.groups[2] != null -> append(".") + else -> append("\\Q${it.groups[0]!!.value}\\E") + } + } +} + +private fun String.toMaybeVersionedJarRegex(): Regex { + val hasJarExtension = endsWith(".jar") + val escaped = this.wildcardsToEscapedRegexString() + return Regex(if (hasJarExtension) escaped else "$escaped(-\\d.*)?\\.jar") // TODO: consider more precise version part of the regex +} + +val propertiesX = + java.util.Properties().apply { load(java.io.FileInputStream("gradle.properties")) } diff --git a/buildSrc/src/main/kotlin/sourceSets.kt b/buildSrc/src/main/kotlin/sourceSets.kt new file mode 100644 index 00000000000..a4e02eb98f6 --- /dev/null +++ b/buildSrc/src/main/kotlin/sourceSets.kt @@ -0,0 +1,125 @@ +@file:Suppress("unused") // usages in build scripts are not tracked properly + +import org.gradle.api.* +import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.internal.HasConvention +import org.gradle.api.plugins.JavaPluginConvention +import org.gradle.api.tasks.* +import org.gradle.kotlin.dsl.* +import java.io.File +//import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet + +private fun Project.configureKotlinProjectSourceSet(srcs: Iterable, + sourceSetName: String, + getSources: SourceSet.() -> SourceDirectorySet, + configureSourceDirs: SourceDirectorySet.() -> Unit) = + configure { + // if (srcs.none()) { +// sourceSets.removeIf { it.name == sourceSetName } +// } +// else { + sourceSets.matching { it.name == sourceSetName }.forEach { it.getSources().setSrcDirs(srcs).configureSourceDirs() } +// } + } + +private fun Project.configureKotlinProjectSourceSet(vararg srcs: String, sourceSetName: String, + getSources: SourceSet.() -> SourceDirectorySet, + sourcesBaseDir: File? = null, + configureSourceDirs: SourceDirectorySet.() -> Unit = {}) = + configureKotlinProjectSourceSet(srcs.map { File(sourcesBaseDir ?: projectDir, it) }, sourceSetName, getSources, configureSourceDirs) + +fun Project.configureKotlinProjectSources(vararg srcs: String, + sourcesBaseDir: File? = null, + configureSourceDirs: SourceDirectorySet.() -> Unit = {}) = + configureKotlinProjectSourceSet(*srcs, sourceSetName = "main", getSources = { this.java }, + sourcesBaseDir = sourcesBaseDir, configureSourceDirs = configureSourceDirs) + +fun Project.configureKotlinProjectSources(srcs: Iterable, + configureSourceDirs: SourceDirectorySet.() -> Unit = {}) = + configureKotlinProjectSourceSet(srcs, sourceSetName = "main", getSources = { this.java }, configureSourceDirs = configureSourceDirs) + +fun Project.configureKotlinProjectSourcesDefault(sourcesBaseDir: File? = null, + configureSourceDirs: SourceDirectorySet.() -> Unit = {}) = + configureKotlinProjectSources("src", sourcesBaseDir = sourcesBaseDir, configureSourceDirs = configureSourceDirs) + +fun Project.configureKotlinProjectResources(vararg srcs: String, + sourcesBaseDir: File? = null, + configureSourceDirs: SourceDirectorySet.() -> Unit = {}) = + configureKotlinProjectSourceSet(*srcs, sourceSetName = "main", getSources = { this.resources }, + sourcesBaseDir = sourcesBaseDir, configureSourceDirs = configureSourceDirs) + +fun Project.configureKotlinProjectResources(srcs: Iterable, + configureSourceDirs: SourceDirectorySet.() -> Unit = {}) = + configureKotlinProjectSourceSet(srcs, sourceSetName = "main", getSources = { this.resources }, configureSourceDirs = configureSourceDirs) + +fun Project.configureKotlinProjectResourcesDefault(sourcesBaseDir: File? = null) { + configureKotlinProjectResources("resources", sourcesBaseDir = sourcesBaseDir) + configureKotlinProjectResources("src", sourcesBaseDir = sourcesBaseDir) { include("META-INF/**", "**/*.properties") } +} + +fun Project.configureKotlinProjectNoTests() { + configureKotlinProjectSourceSet(sourceSetName = "test", getSources = { this.java }) + configureKotlinProjectSourceSet(sourceSetName = "test", getSources = { this.resources }) +} + +fun Project.configureKotlinProjectTests(vararg srcs: String, sourcesBaseDir: File? = null, + configureSourceDirs: SourceDirectorySet.() -> Unit = {}) = + configureKotlinProjectSourceSet(*srcs, sourceSetName = "test", getSources = { this.java }, + sourcesBaseDir = sourcesBaseDir, configureSourceDirs = configureSourceDirs) + +fun Project.configureKotlinProjectTestsDefault(sourcesBaseDir: File? = null, + configureSourceDirs: SourceDirectorySet.() -> Unit = {}) = + configureKotlinProjectTests("test", "tests", sourcesBaseDir = sourcesBaseDir, configureSourceDirs = configureSourceDirs) + +fun Project.configureKotlinProjectTestResources(vararg srcs: String, + sourcesBaseDir: File? = null, + configureSourceDirs: SourceDirectorySet.() -> Unit = {}) = + configureKotlinProjectSourceSet(*srcs, sourceSetName = "test", getSources = { this.resources }, + sourcesBaseDir = sourcesBaseDir, configureSourceDirs = configureSourceDirs) + + +inline fun Project.sourceSets(crossinline body: SourceSetsBuilder.() -> Unit) = + SourceSetsBuilder(this).body() + +class SourceSetsBuilder(val project: Project) { + + inline operator fun String.invoke(crossinline body: SourceSet.() -> Unit) { + val sourceSetName = this + project.configure + { + sourceSets.matching { it.name == sourceSetName }.forEach { + it.body() + } + } + } +} + +fun SourceSet.none() { + java.srcDirs() + resources.srcDirs() +} + +fun SourceSet.default() { + when (name) { + "main" -> { + java.srcDirs("src") + resources.srcDir("resources") + resources.srcDir("src").apply { include("META-INF/**", "**/*.properties") } + } + "test" -> { + java.srcDirs("test", "tests") + } + } +} + +// TODO: adding dep to the plugin breaks the build unexpectedly, resolve and uncomment +//val SourceSet.kotlin: SourceDirectorySet +// get() = +// (this as HasConvention) +// .convention +// .getPlugin(KotlinSourceSet::class.java) +// .kotlin +// +// +//fun SourceSet.kotlin(action: SourceDirectorySet.() -> Unit) = +// kotlin.action() diff --git a/compiler.tests-common/build.gradle.kts b/compiler.tests-common/build.gradle.kts new file mode 100644 index 00000000000..45362fd15c1 --- /dev/null +++ b/compiler.tests-common/build.gradle.kts @@ -0,0 +1,35 @@ + +// Have to stay in the separate dir: attempt to move it to the source root dir lead to invalid import into IDEA + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core")) + compile(project(":core::util.runtime")) + compile(project(":compiler:util")) + compile(project(":compiler:backend")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:util")) + compile(project(":compiler:cli-common")) + compile(project(":compiler:cli")) + compile(project(":compiler:light-classes")) + compile(project(":compiler:serialization")) + compile(project(":compiler:preloader")) + compile(project(":compiler:daemon-common")) + compile(project(":compiler:daemon-client")) + compile(project(":js:js.serializer")) + compile(project(":js:js.frontend")) + compile(project(":js:js.translator")) + compile(project(":plugins:android-extensions-compiler")) + compile(kotlinDep("test")) + compile(commonDep("junit")) + compile(ideaSdkCoreDeps("intellij-core")) + compile(ideaSdkDeps("openapi", "idea", "idea_rt")) + compile(preloadedDeps("dx", subdir = "android-5.0/lib")) +} + +configureKotlinProjectSources("tests-common", sourcesBaseDir = File(rootDir, "compiler")) +configureKotlinProjectNoTests() + diff --git a/compiler/android-tests/build.gradle.kts b/compiler/android-tests/build.gradle.kts new file mode 100644 index 00000000000..20aed613fcc --- /dev/null +++ b/compiler/android-tests/build.gradle.kts @@ -0,0 +1,40 @@ + +apply { + plugin("kotlin") +} + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + + compile(project(":compiler:util")) + compile(project(":compiler:cli")) + compile(project(":compiler.tests-common")) + compile(project(":compiler:frontend")) + compile(project(":compiler:backend")) + + testCompile(project(":compiler:incremental-compilation-impl")) + testCompile(project(":core")) + testCompile(project(":compiler:frontend.java")) + testCompile(projectTests(":jps-plugin")) + testCompile(commonDep("junit:junit")) + testCompile(ideaSdkDeps("jps-model.jar", subdir = "jps")) + testCompile(ideaSdkDeps("groovy-all")) + testCompile(ideaSdkDeps("openapi", "idea")) + testCompile(ideaSdkDeps("jps-build-test", subdir = "jps/test")) + testCompile(ideaSdkDeps("jps-builders")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectTestsDefault() + + +tasks.withType { + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + systemProperty("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} diff --git a/compiler/backend-common/build.gradle.kts b/compiler/backend-common/build.gradle.kts new file mode 100644 index 00000000000..65b9e057606 --- /dev/null +++ b/compiler/backend-common/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core")) + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:ir.tree")) +} + +configureKotlinProjectSources("backend-common/src", "ir/backend.common/src", sourcesBaseDir = File(rootDir, "compiler")) +configureKotlinProjectNoTests() + diff --git a/compiler/backend/build.gradle.kts b/compiler/backend/build.gradle.kts new file mode 100644 index 00000000000..a70f01f307b --- /dev/null +++ b/compiler/backend/build.gradle.kts @@ -0,0 +1,18 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:backend-common")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:ir.tree")) + compile(project(":compiler:ir.psi2ir")) + compile(project(":compiler:serialization")) +} + +configureKotlinProjectSources("backend/src", "ir/backend.jvm/src", sourcesBaseDir = File(rootDir, "compiler")) +configureKotlinProjectResourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts new file mode 100644 index 00000000000..91868bf64ca --- /dev/null +++ b/compiler/build.gradle.kts @@ -0,0 +1,227 @@ + +import java.io.File +import proguard.gradle.ProGuardTask +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.file.DuplicatesStrategy +import org.gradle.api.internal.plugins.DslObject +import org.gradle.api.publication.maven.internal.deployer.MavenRemoteRepository + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3") + classpath("net.sf.proguard:proguard-gradle:5.3.1") + } +} + +apply { plugin("kotlin") } + +plugins { + maven +} +//apply { plugin("maven") } + + +// Set to false to disable proguard run on kotlin-compiler.jar. Speeds up the build +val shrink = true + +val compilerManifestClassPath = + "kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar" + +val fatJarContents by configurations.creating +val proguardLibraryJars by configurations.creating +val fatJar by configurations.creating +val compilerJar by configurations.creating +val embeddableCompilerJar by configurations.creating + +val compilerBaseName: String by rootProject.extra +val embeddableCompilerBaseName: String by rootProject.extra + +val javaHome = File(System.getProperty("java.home")) + +val buildLocalRepoPath: File by rootProject.extra + +val compilerModules: Array by rootProject.extra +val otherCompilerModules = compilerModules.filter { it != path } + +val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin" + +val packagesToRelocate = + listOf("com.intellij", + "com.google", + "com.sampullara", + "org.apache", + "org.jdom", + "org.picocontainer", + "jline", + "gnu", + "javax.inject", + "org.fusesource") + +fun firstFromJavaHomeThatExists(vararg paths: String): File = + paths.mapNotNull { File(javaHome, it).takeIf { it.exists() } }.firstOrNull() + ?: throw GradleException("Cannot find under '$javaHome' neither of: ${paths.joinToString()}") + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + compileOnly(project(":compiler:cli")) + compileOnly(project(":compiler:daemon-common")) + compileOnly(project(":compiler:incremental-compilation-impl")) + compileOnly(project(":build-common")) + compileOnly(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) + compileOnly(commonDep("org.fusesource.jansi", "jansi")) + compileOnly(commonDep("jline")) + + testCompile(commonDep("junit:junit")) + testCompile(project(":kotlin-test:kotlin-test-jvm")) + testCompile(project(":kotlin-test:kotlin-test-junit")) + testCompile(project(":compiler.tests-common")) + testCompileOnly(project(":compiler:ir.ir2cfg")) + testCompileOnly(project(":compiler:ir.tree")) // used for deepCopyWithSymbols call that is removed by proguard from the compiler TODO: make it more straightforward + testCompile(ideaSdkDeps("openapi", "idea", "util", "asm-all", "commons-httpclient-3.1-patched")) + // deps below are test runtime deps, but made test compile to split compilation and running to reduce mem req + testCompile(project(":kotlin-stdlib")) + testCompile(project(":kotlin-script-runtime")) + testCompile(project(":kotlin-runtime")) + testCompile(project(":kotlin-reflect")) + testCompile(project(":plugins:android-extensions-compiler")) + testCompile(project(":ant")) + otherCompilerModules.forEach { + testCompile(project(it)) + fatJarContents(project(it)) { isTransitive = false } + } + testRuntime(ideaSdkCoreDeps("*.jar")) + testRuntime(ideaSdkDeps("*.jar")) +// testRuntime(project(":prepare:compiler", configuration = "default")) + + buildVersion() + + fatJarContents(project(":core:builtins", configuration = "builtins")) + fatJarContents(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) + fatJarContents(ideaSdkDeps("jna-platform", "oromatcher")) + fatJarContents(ideaSdkDeps("jps-model.jar", subdir = "jps")) + fatJarContents(commonDep("javax.inject")) + fatJarContents(commonDep("jline")) + fatJarContents(protobufFull()) + fatJarContents(commonDep("com.github.spullara.cli-parser", "cli-parser")) + fatJarContents(commonDep("com.google.code.findbugs", "jsr305")) + fatJarContents(commonDep("io.javaslang", "javaslang")) + fatJarContents(preloadedDeps("json-org")) + + proguardLibraryJars(files(firstFromJavaHomeThatExists("lib/rt.jar", "../Classes/classes.jar"), + firstFromJavaHomeThatExists("lib/jsse.jar", "../Classes/jsse.jar"), + firstFromJavaHomeThatExists("../lib/tools.jar", "../Classes/tools.jar"))) + proguardLibraryJars(kotlinDep("stdlib")) + proguardLibraryJars(kotlinDep("script-runtime")) + proguardLibraryJars(kotlinDep("reflect")) + proguardLibraryJars(preloadedDeps("kotlinx-coroutines-core")) + +// proguardLibraryJars(project(":prepare:runtime", configuration = "default").apply { isTransitive = false }) +// proguardLibraryJars(project(":prepare:reflect", configuration = "default").apply { isTransitive = false }) +// proguardLibraryJars(project(":core:script.runtime").apply { isTransitive = false }) +} + +configureKotlinProjectSources( + "compiler/daemon/src", + "compiler/conditional-preprocessor/src", + sourcesBaseDir = rootDir) +configureKotlinProjectResources("idea/src", sourcesBaseDir = rootDir) { + include("META-INF/extensions/common.xml", + "META-INF/extensions/kotlin2jvm.xml", + "META-INF/extensions/kotlin2js.xml") +} +configureKotlinProjectTests("tests") + +testsJar {} + +tasks.withType { + dependsOnTaskIfExistsRec("dist", project = rootProject) + dependsOn(":prepare:mock-runtime-for-test:dist") + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + systemProperty("kotlin.test.script.classpath", the().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator)) + jvmArgs("-ea", "-XX:+HeapDumpOnOutOfMemoryError", "-Xmx1200m", "-XX:+UseCodeCacheFlushing", "-XX:ReservedCodeCacheSize=128m", "-Djna.nosys=true") + maxHeapSize = "1200m" + ignoreFailures = true +} + +val packCompiler by task { + configurations = listOf(fatJar) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + destinationDir = File(buildDir, "libs") + baseName = compilerBaseName + classifier = "before-proguard" + dependsOn(protobufFullTask) + + setupRuntimeJar("Kotlin Compiler") + from(getCompiledClasses()) + from(fatJarContents) + + manifest.attributes.put("Class-Path", compilerManifestClassPath) + manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") +} + +val proguard by task { + dependsOn(packCompiler) + configuration("$rootDir/compiler/compiler.pro") + + val outputJar = File(buildDir, "libs", "$compilerBaseName-after-proguard.jar") + + inputs.files(packCompiler.outputs.files.singleFile) + outputs.file(outputJar) + + // TODO: remove after dropping compatibility with ant build + doFirst { + System.setProperty("kotlin-compiler-jar-before-shrink", packCompiler.outputs.files.singleFile.canonicalPath) + System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath) + } + + libraryjars(proguardLibraryJars) + printconfiguration("$buildDir/compiler.pro.dump") +} + +val embeddable by task { + destinationDir = File(buildDir, "libs") + baseName = embeddableCompilerBaseName + configurations = listOf(embeddableCompilerJar) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + dependsOn(proguard) + from(proguard) + relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf") + packagesToRelocate.forEach { + relocate(it, "$kotlinEmbeddableRootPackage.$it") + } + relocate("org.fusesource", "$kotlinEmbeddableRootPackage.org.fusesource") { + // TODO: remove "it." after #KT-12848 get addressed + exclude("org.fusesource.jansi.internal.CLibrary") + } +} + +dist { + if (shrink) { + from(proguard) + } else { + from(packCompiler) + } + rename(".*", compilerBaseName + ".jar") +} + +artifacts.add(compilerJar.name, proguard.outputs.files.singleFile) { + builtBy(proguard) + classifier = "" + name = compilerBaseName +} +artifacts.add(embeddableCompilerJar.name, embeddable.outputs.files.singleFile) { + builtBy(embeddable) + classifier = "" + name = embeddableCompilerBaseName +} + diff --git a/compiler/cli/build.gradle.kts b/compiler/cli/build.gradle.kts new file mode 100644 index 00000000000..25ef63ba093 --- /dev/null +++ b/compiler/cli/build.gradle.kts @@ -0,0 +1,32 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:cli-common")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:frontend.script")) + compile(project(":compiler:backend-common")) + compile(project(":compiler:backend")) + compile(project(":compiler:light-classes")) + compile(project(":compiler:serialization")) + compile(project(":compiler:plugin-api")) + compile(project(":js:js.translator")) + compile(project(":js:js.serializer")) + compile(project(":js:js.dce")) + compile(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) + compile(commonDep("org.fusesource.jansi", "jansi")) + compile(commonDep("jline")) + compile(files("${System.getProperty("java.home")}/../lib/tools.jar")) +} + +configureKotlinProjectSources("compiler/cli/src", + "plugins/annotation-collector/src", + "compiler/builtins-serializer/src", + "compiler/javac-wrapper/src", + sourcesBaseDir = rootDir) +configureKotlinProjectResourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/cli/cli-common/build.gradle.kts b/compiler/cli/cli-common/build.gradle.kts new file mode 100644 index 00000000000..93aea51b28b --- /dev/null +++ b/compiler/cli/cli-common/build.gradle.kts @@ -0,0 +1,15 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core:util.runtime")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:frontend.script")) + compile(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/cli/cli-runner/build.gradle.kts b/compiler/cli/cli-runner/build.gradle.kts new file mode 100644 index 00000000000..efcba6bfdbb --- /dev/null +++ b/compiler/cli/cli-runner/build.gradle.kts @@ -0,0 +1,26 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(kotlinDep("stdlib")) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin Runner") + manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.runner.Main") + manifest.attributes.put("Class-Path", "kotlin-runtime.jar") + archiveName = "kotlin-runner.jar" +} + +dist { + from(jar) +} + diff --git a/compiler/compiler-runner/build.gradle.kts b/compiler/compiler-runner/build.gradle.kts new file mode 100644 index 00000000000..9f0cba17cd7 --- /dev/null +++ b/compiler/compiler-runner/build.gradle.kts @@ -0,0 +1,17 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":build-common")) + compile(project(":compiler:cli-common")) + compile(project(":compiler:preloader")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:daemon-common")) + compile(project(":compiler:daemon-client")) + compile(project(":compiler:util")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/container/build.gradle.kts b/compiler/container/build.gradle.kts new file mode 100644 index 00000000000..d51cb79e6e2 --- /dev/null +++ b/compiler/container/build.gradle.kts @@ -0,0 +1,31 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + compile(project(":core:util.runtime")) + compile(commonDep("javax.inject")) + compile(ideaSdkCoreDeps("intellij-core")) + testCompile(commonDep("junit:junit")) + testCompile(project(":kotlin-test:kotlin-test-jvm")) + testRuntime(ideaSdkCoreDeps("trove4j", "intellij-core")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectTestsDefault() + +testsJar {} + + +tasks.withType { + dependsOnTaskIfExistsRec("dist", project = rootProject) + dependsOn(":prepare:mock-runtime-for-test:dist") + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} diff --git a/compiler/daemon/daemon-client/build.gradle.kts b/compiler/daemon/daemon-client/build.gradle.kts new file mode 100644 index 00000000000..1b9eb5e1d25 --- /dev/null +++ b/compiler/daemon/daemon-client/build.gradle.kts @@ -0,0 +1,35 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +val nativePlatformUberjar = "$rootDir/dependencies/native-platform-uberjar.jar" + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:cli-common")) + compile(project(":compiler:daemon-common")) + compile(files(nativePlatformUberjar)) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin Daemon Client") + from(zipTree(nativePlatformUberjar)) + archiveName = "kotlin-daemon-client.jar" +} + +val sourcesJar by task { + setupSourceJar("Kotlin Daemon Client") + archiveName = "kotlin-daemon-client-sources.jar" +} + +dist { + from(jar) +} + diff --git a/compiler/daemon/daemon-common/build.gradle.kts b/compiler/daemon/daemon-common/build.gradle.kts new file mode 100644 index 00000000000..9caba671fa5 --- /dev/null +++ b/compiler/daemon/daemon-common/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core")) + compile(project(":compiler:util")) + compile(project(":compiler:cli-common")) + compile(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/frontend.java/build.gradle.kts b/compiler/frontend.java/build.gradle.kts new file mode 100644 index 00000000000..5d67f217602 --- /dev/null +++ b/compiler/frontend.java/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core")) + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectResourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/frontend.script/build.gradle.kts b/compiler/frontend.script/build.gradle.kts new file mode 100644 index 00000000000..ba21c3c29a7 --- /dev/null +++ b/compiler/frontend.script/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(kotlinDep("reflect")) + compile(preloadedDeps("kotlinx-coroutines-core")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/frontend/build.gradle.kts b/compiler/frontend/build.gradle.kts new file mode 100644 index 00000000000..61f0aa5683a --- /dev/null +++ b/compiler/frontend/build.gradle.kts @@ -0,0 +1,16 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core")) + compile(project(":compiler:util")) + compile(project(":compiler:container")) + compile(project(":compiler:resolution")) + compile(kotlinDep("script-runtime")) + compile(commonDep("io.javaslang","javaslang")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/incremental-compilation-impl/build.gradle.kts b/compiler/incremental-compilation-impl/build.gradle.kts new file mode 100644 index 00000000000..962c47f7f82 --- /dev/null +++ b/compiler/incremental-compilation-impl/build.gradle.kts @@ -0,0 +1,16 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core")) + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:cli")) + compile(project(":build-common")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectTestsDefault() + diff --git a/compiler/ir/ir.ir2cfg/build.gradle.kts b/compiler/ir/ir.ir2cfg/build.gradle.kts new file mode 100644 index 00000000000..887febe6941 --- /dev/null +++ b/compiler/ir/ir.ir2cfg/build.gradle.kts @@ -0,0 +1,13 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:ir.tree")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/ir/ir.psi2ir/build.gradle.kts b/compiler/ir/ir.psi2ir/build.gradle.kts new file mode 100644 index 00000000000..d5c58caf700 --- /dev/null +++ b/compiler/ir/ir.psi2ir/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:backend-common")) + compile(project(":compiler:ir.tree")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/ir/ir.tree/build.gradle.kts b/compiler/ir/ir.tree/build.gradle.kts new file mode 100644 index 00000000000..4666fa98542 --- /dev/null +++ b/compiler/ir/ir.tree/build.gradle.kts @@ -0,0 +1,12 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/light-classes/build.gradle.kts b/compiler/light-classes/build.gradle.kts new file mode 100644 index 00000000000..471f583b48b --- /dev/null +++ b/compiler/light-classes/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:backend")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/plugin-api/build.gradle.kts b/compiler/plugin-api/build.gradle.kts new file mode 100644 index 00000000000..32c07abdc4e --- /dev/null +++ b/compiler/plugin-api/build.gradle.kts @@ -0,0 +1,13 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(ideaSdkCoreDeps("intellij-core")) + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/preloader/build.gradle.kts b/compiler/preloader/build.gradle.kts new file mode 100644 index 00000000000..172f90818a6 --- /dev/null +++ b/compiler/preloader/build.gradle.kts @@ -0,0 +1,25 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(ideaSdkDeps("asm-all")) + buildVersion() +} + +configureKotlinProjectSources("src", "instrumentation/src") +configureKotlinProjectNoTests() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin Preloader") + manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.preloading.Preloader") + archiveName = "kotlin-preloader.jar" +} + +dist { + from(jar) +} + diff --git a/compiler/resolution/build.gradle.kts b/compiler/resolution/build.gradle.kts new file mode 100644 index 00000000000..571b3ba4008 --- /dev/null +++ b/compiler/resolution/build.gradle.kts @@ -0,0 +1,12 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":core")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/serialization/build.gradle.kts b/compiler/serialization/build.gradle.kts new file mode 100644 index 00000000000..571b3ba4008 --- /dev/null +++ b/compiler/serialization/build.gradle.kts @@ -0,0 +1,12 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":core")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/compiler/tests-java8/build.gradle.kts b/compiler/tests-java8/build.gradle.kts new file mode 100644 index 00000000000..5fad18b7396 --- /dev/null +++ b/compiler/tests-java8/build.gradle.kts @@ -0,0 +1,56 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + testCompile(commonDep("junit:junit")) + testCompile(project(":kotlin-test:kotlin-test-jvm")) + testCompile(project(":kotlin-test:kotlin-test-junit")) + testCompile(project(":compiler.tests-common")) + testCompile(project(":core")) + testCompile(project(":compiler:util")) + testCompile(project(":compiler:backend")) + testCompile(project(":compiler:frontend")) + testCompile(project(":compiler:frontend.java")) + testCompile(project(":compiler:cli")) + testCompile(project(":compiler:serialization")) + testCompile(ideaSdkDeps("openapi", "idea", "util", "asm-all")) + // deps below are test runtime deps, but made test compile to split compilation and running to reduce mem req + testCompile(project(":kotlin-stdlib")) + testCompile(project(":kotlin-script-runtime")) + testCompile(project(":kotlin-runtime")) + testCompile(project(":kotlin-reflect")) + testCompile(projectTests(":compiler")) + testRuntime(project(":compiler:preloader")) + testRuntime(ideaSdkCoreDeps("*.jar")) + testRuntime(ideaSdkDeps("*.jar")) +} + +configureKotlinProjectSources() +configureKotlinProjectTestsDefault() + +tasks.withType { + kotlinOptions.jdkHome = rootProject.extra["JDK_18"]!!.toString() + kotlinOptions.jvmTarget = "1.8" +} + +testsJar {} + +tasks.withType { + executable = "${rootProject.extra["JDK_18"]!!}/bin/java" + dependsOnTaskIfExistsRec("dist", project = rootProject) + dependsOn(":prepare:mock-runtime-for-test:dist") + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + systemProperty("kotlin.test.script.classpath", the().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator)) + jvmArgs("-ea", "-XX:+HeapDumpOnOutOfMemoryError", "-Xmx1200m", "-XX:+UseCodeCacheFlushing", "-XX:ReservedCodeCacheSize=128m", "-Djna.nosys=true") + maxHeapSize = "1200m" + ignoreFailures = true +} + diff --git a/compiler/util/build.gradle.kts b/compiler/util/build.gradle.kts new file mode 100644 index 00000000000..6e7593e0e8d --- /dev/null +++ b/compiler/util/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core")) + compile(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) + compile(ideaSdkDeps("jps-model.jar", subdir = "jps")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectResources("resources", sourcesBaseDir = rootDir) +configureKotlinProjectNoTests() + diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 00000000000..b5987215094 --- /dev/null +++ b/core/build.gradle.kts @@ -0,0 +1,32 @@ + +import org.gradle.api.tasks.compile.JavaCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core:builtins")) + compile(project("util.runtime")) + compile(protobufLite()) + compile(commonDep("javax.inject")) +} + +configureKotlinProjectSources( + "descriptor.loader.java/src", + "descriptors/src", + "descriptors.runtime/src", + "deserialization/src") +configureKotlinProjectResources( + "descriptor.loader.java/src", "deserialization/src") { include("META-INF/**") } +configureKotlinProjectNoTests() + +tasks.withType { + dependsOn(protobufLiteTask) +} + +tasks.withType { + dependsOn(protobufLiteTask) +} + + diff --git a/core/builtins/build.gradle.kts b/core/builtins/build.gradle.kts new file mode 100644 index 00000000000..a671b631a3d --- /dev/null +++ b/core/builtins/build.gradle.kts @@ -0,0 +1,64 @@ + +import org.gradle.api.tasks.compile.JavaCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.serialization.builtins.BuiltInsSerializer +import org.gradle.jvm.tasks.Jar +import java.io.File + +apply { plugin("kotlin") } + +val builtinsSrc = File(rootDir, "core", "builtins", "src") +val builtinsNative = File(rootDir, "core", "builtins", "native") +// TODO: rewrite dependent projects on using build results instead of the fixed location +val builtinsSerialized = File(rootProject.extra["distDir"].toString(), "builtins") + +val builtins by configurations.creating + +dependencies { + val compile by configurations + compile(protobufLite()) + compile(files(builtinsSerialized)) +} + +configureKotlinProjectSources("core/builtins/src", "core/runtime.jvm/src", sourcesBaseDir = rootDir) +configureKotlinProjectResources(listOf(builtinsSerialized)) +configureKotlinProjectNoTests() + +val serialize = task("serialize") { + val outDir = builtinsSerialized + val inDirs = arrayOf(builtinsSrc, builtinsNative) + outputs.file(outDir) + inputs.files(*inDirs) + doLast { + System.setProperty("kotlin.colors.enabled", "false") + BuiltInsSerializer(dependOnOldBuiltIns = false) + .serialize(outDir, inDirs.asList(), listOf()) { totalSize, totalFiles -> + println("Total bytes written: $totalSize to $totalFiles files") + } + } +} + +tasks.withType { + dependsOn(protobufLiteTask) + dependsOn(serialize) +} + +tasks.withType { + dependsOn(protobufLiteTask) + dependsOn(serialize) +} + +val jar: Jar by tasks +jar.apply { + dependsOn(serialize) + from(builtinsSerialized) { include("kotlin/**") } +} + +val builtinsJar by task { + dependsOn(serialize) + from(builtinsSerialized) { include("kotlin/**") } + baseName = "platform-builtins" + destinationDir = File(buildDir, "libs") +} + +artifacts.add(builtins.name, builtinsJar) diff --git a/core/reflection.jvm/build.gradle.kts b/core/reflection.jvm/build.gradle.kts new file mode 100644 index 00000000000..2af9d7a3d1c --- /dev/null +++ b/core/reflection.jvm/build.gradle.kts @@ -0,0 +1,48 @@ + +import org.gradle.api.tasks.compile.JavaCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import java.io.File + +buildscript { + repositories { + mavenLocal() + jcenter() + } + + dependencies { + classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3") + classpath(ideaSdkDeps("asm-all")) + } +} + +apply { + plugin("kotlin") + plugin("com.github.johnrengelman.shadow") +} + +configure { + sourceSets.getByName("main")?.apply { + val srcs = listOf(File(rootDir, "core/reflection.jvm/src")) + java.setSrcDirs(srcs) + } + sourceSets.getByName("test").apply { + java.setSrcDirs(emptyList()) + } +} + +dependencies { + val compile by configurations + compile(project(":core:builtins")) + compile(project(":core")) + compile(protobufLite()) +} + +tasks.withType { + dependsOn(protobufLiteTask) +} + +tasks.withType { + dependsOn(protobufLiteTask) +} + + diff --git a/core/script.runtime/build.gradle.kts b/core/script.runtime/build.gradle.kts new file mode 100644 index 00000000000..7344c80b58e --- /dev/null +++ b/core/script.runtime/build.gradle.kts @@ -0,0 +1,20 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core:builtins")) + compile(kotlinDep("stdlib")) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + +tasks.withType { + setupRuntimeJar("Kotlin Script Runtime") + archiveName = "kotlin-script-runtime.jar" +} + diff --git a/core/util.runtime/build.gradle.kts b/core/util.runtime/build.gradle.kts new file mode 100644 index 00000000000..bdd4793e6cd --- /dev/null +++ b/core/util.runtime/build.gradle.kts @@ -0,0 +1,15 @@ + +apply { + plugin("java") + plugin("kotlin") +} + +dependencies { + val compile by configurations + compile(project(":core:builtins")) + compile(kotlinDep("stdlib")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/custom-dependencies/protobuf-lite/build.gradle.kts b/custom-dependencies/protobuf-lite/build.gradle.kts new file mode 100644 index 00000000000..a43591549e3 --- /dev/null +++ b/custom-dependencies/protobuf-lite/build.gradle.kts @@ -0,0 +1,121 @@ + +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import java.io.BufferedOutputStream +import java.io.File +import java.io.FileOutputStream +import java.util.jar.JarEntry +import java.util.jar.JarFile +import java.util.zip.ZipOutputStream +import org.gradle.language.assembler.tasks.Assemble + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3") + } +} + +apply { plugin("com.github.johnrengelman.shadow") } + +val mainCfg = configurations.create("default") +val relocatedCfg = configurations.create("relocated") + +val protobufVersion = rootProject.extra["versions.protobuf-java"] +val protobufJarPrefix = "protobuf-$protobufVersion" +val renamedOutputJarPath = "$buildDir/jars/$protobufJarPrefix-relocated.jar" +val outputJarPath = "$buildDir/libs/$protobufJarPrefix-lite.jar" + +artifacts.add(mainCfg.name, File(outputJarPath)) +artifacts.add(relocatedCfg.name, File(renamedOutputJarPath)) + +dependencies { + mainCfg("com.google.protobuf:protobuf-java:$protobufVersion") +} + +val relocateTask = task("prepare-relocated-protobuf") { + archiveName = renamedOutputJarPath + this.configurations = listOf(relocatedCfg) + from(mainCfg.files.find { it.name.startsWith("protobuf-java") }?.canonicalPath) + relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf" ) { + // TODO: remove "it." after #KT-12848 get addressed + exclude("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties") + } +} + +val mainTask = task("prepare") { + dependsOn(relocateTask) + val inputJar = renamedOutputJarPath + inputs.files(inputJar) + outputs.file(outputJarPath) + doFirst { + File(outputJarPath).parentFile.mkdirs() + } + doLast { + val INCLUDE_START = "**/" + val INCLUDE_END = ".java" + val POM_PATH = "META-INF/maven/com.google.protobuf/protobuf-java/pom.xml" + + fun loadAllFromJar(file: File): Map> { + val result = hashMapOf>() + val jar = JarFile(file) + try { + for (jarEntry in jar.entries()) { + result[jarEntry.name] = Pair(jarEntry, jar.getInputStream(jarEntry).readBytes()) + } + } + finally { + // Yes, JarFile does not extend Closeable on JDK 6 so we can't use "use" here + jar.close() + } + return result + } + + val allFiles = loadAllFromJar(File(inputJar)) + + val keepClasses = arrayListOf() + + val pomBytes = allFiles[POM_PATH]?.second ?: error("pom.xml is not found in protobuf jar at $POM_PATH") + val lines = String(pomBytes).lines() + + var liteProfileReached = false + for (lineUntrimmed in lines) { + val line = lineUntrimmed.trim() + + if (liteProfileReached && line == "") { + break + } + else if (line == "lite") { + liteProfileReached = true + continue + } + + if (liteProfileReached && line.startsWith(INCLUDE_START) && line.endsWith(INCLUDE_END)) { + keepClasses.add(line.removeSurrounding(INCLUDE_START, INCLUDE_END)) + } + } + + assert(liteProfileReached && keepClasses.isNotEmpty()) { "Wrong pom.xml or the format has changed, check its contents at $POM_PATH" } + + val outputFile = File(outputJarPath).apply { delete() } + ZipOutputStream(BufferedOutputStream(FileOutputStream(outputFile))).use { output -> + for ((name, value) in allFiles) { + val className = name.substringAfter("org/jetbrains/kotlin/protobuf/").substringBeforeLast(".class") + if (keepClasses.any { className == it || className.startsWith(it + "$") }) { + val (entry, bytes) = value + output.putNextEntry(entry) + output.write(bytes) + output.closeEntry() + } + } + } + } +} + +defaultTasks(mainTask.name) + +tasks.withType() { + dependsOn(mainCfg) +} diff --git a/eval4j/build.gradle.kts b/eval4j/build.gradle.kts new file mode 100644 index 00000000000..996a129bdc5 --- /dev/null +++ b/eval4j/build.gradle.kts @@ -0,0 +1,16 @@ +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":kotlin-stdlib")) + compile(project(":kotlin-reflect")) + compile(project(":compiler:backend")) + compile(ideaSdkDeps("asm-all")) +// compile(files(PathUtil.getJdkClassesRootsFromCurrentJre())) // TODO: make this one work instead of the nex one, since it contains more universal logic + compile(files("${System.getProperty("java.home")}/../lib/tools.jar")) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/generators/build.gradle.kts b/generators/build.gradle.kts new file mode 100644 index 00000000000..f02f79f5e2b --- /dev/null +++ b/generators/build.gradle.kts @@ -0,0 +1,69 @@ + +apply { + plugin("kotlin") +} + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + compile(project(":core")) + compile(project(":idea")) + compile(project(":compiler:util")) + compile(project(":compiler:cli")) + compile(project(":compiler:backend")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:backend")) + compile(project(":js:js.ast")) + compile(project(":js:js.frontend")) + compile(project(":idea:idea-test-framework")) + compile(project(":kotlin-test:kotlin-test-jvm")) + compile(projectTests(":build-common")) + compile(projectTests(":compiler")) + compile(projectTests(":compiler:tests-java8")) + compile(projectTests(":compiler:container")) + compile(projectTests(":idea")) + compile(projectTests(":idea:idea-android")) + compile(projectTests(":jps-plugin")) + compile(projectTests(":plugins:plugins-tests")) + compile(projectTests(":plugins:android-extensions-idea")) + compile(projectTests(":plugins:kapt3")) + compile(projectTests(":plugins:uast-kotlin")) + compile(projectTests(":js:js.tests")) + compile(protobufFull()) + compileOnly(ideaSdkDeps("jps-build-test", subdir = "jps/test")) + testCompile(project(":compiler.tests-common")) + testCompile(project(":idea:idea-test-framework")) { isTransitive = false } + testCompile(project(":compiler:incremental-compilation-impl")) + testCompile(project(":plugins:kapt3")) + testCompile(commonDep("junit:junit")) + testCompile(ideaSdkDeps("openapi", "idea")) + testCompile(preloadedDeps("uast-tests")) + testRuntime(ideaSdkDeps("*.jar")) + testRuntime(ideaPluginDeps("idea-junit", "resources_en", plugin = "junit")) + testRuntime(ideaPluginDeps("IntelliLang", plugin = "IntelliLang")) + testRuntime(ideaPluginDeps("jcommander", "testng", "testng-plugin", "resources_en", plugin = "testng")) + testRuntime(ideaPluginDeps("copyright", plugin = "copyright")) + testRuntime(ideaPluginDeps("properties", "resources_en", plugin = "properties")) + testRuntime(ideaPluginDeps("java-i18n", plugin = "java-i18n")) + testRuntime(ideaPluginDeps("*.jar", plugin = "gradle")) + testRuntime(ideaPluginDeps("*.jar", plugin = "Groovy")) + testRuntime(ideaPluginDeps("coverage", "jacocoant", plugin = "coverage")) + testRuntime(ideaPluginDeps("java-decompiler", plugin = "java-decompiler")) + testRuntime(ideaPluginDeps("*.jar", plugin = "maven")) + testRuntime(ideaPluginDeps("*.jar", plugin = "android")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectTestsDefault() + + +tasks.withType { + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + systemProperty("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000000..9a85b0e3212 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,4 @@ +org.gradle.daemon=true +org.gradle.parallel=false +org.gradle.configureondemand=false +org.gradle.jvmargs=-Xmx1200m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled diff --git a/idea/build.gradle.kts b/idea/build.gradle.kts new file mode 100644 index 00000000000..4d59944bdc1 --- /dev/null +++ b/idea/build.gradle.kts @@ -0,0 +1,142 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + + testRuntime(ideaSdkDeps("*.jar")) + + compile(project(":kotlin-stdlib")) + compile(project(":core")) + compile(project(":compiler:backend")) + compile(project(":compiler:cli-common")) + compile(project(":compiler:daemon-client")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:frontend.script")) + compile(project(":js:js.frontend")) + compile(project(":js:js.serializer")) + compile(project(":compiler:light-classes")) + compile(project(":compiler:util")) + compile(project(":compiler:compiler-runner")) + compile(project(":compiler:plugin-api")) + compile(project(":eval4j")) + compile(project(":j2k")) + compile(project(":idea:formatter")) + compile(project(":idea:idea-core")) + compile(project(":idea:ide-common")) + compile(project(":idea:idea-jps-common")) + compile(project(":idea:kotlin-gradle-tooling")) + compile(project(":plugins:uast-kotlin")) + compile(project(":plugins:uast-kotlin-idea")) + + compile(ideaSdkCoreDeps("intellij-core", "util")) + + compileOnly(ideaSdkDeps("openapi", "idea", "velocity", "boot", "gson", "swingx-core", "jsr305", "forms_rt")) + + compile(ideaPluginDeps("idea-junit", plugin = "junit")) + compile(ideaPluginDeps("IntelliLang", plugin = "IntelliLang")) + compile(ideaPluginDeps("testng", "testng-plugin", plugin = "testng")) + compile(ideaPluginDeps("copyright", plugin = "copyright")) + compile(ideaPluginDeps("properties", plugin = "properties")) + compile(ideaPluginDeps("java-i18n", plugin = "java-i18n")) + compile(ideaPluginDeps("coverage", plugin = "coverage")) + compile(ideaPluginDeps("java-decompiler", plugin = "java-decompiler")) + + compileOnly(ideaPluginDeps("gradle-tooling-api", "gradle", plugin = "gradle")) + compileOnly(ideaPluginDeps("Groovy", plugin = "Groovy")) + compileOnly(ideaPluginDeps("maven", "maven-server-api", plugin = "maven")) + + compile(preloadedDeps("markdown", "kotlinx-coroutines-core")) + + testCompile(project(":kotlin-test:kotlin-test-junit")) + testCompile(project(":compiler:cli")) + testCompile(project(":compiler.tests-common")) + testCompile(project(":idea:idea-test-framework")) { isTransitive = false } + + testCompileOnly(ideaPluginDeps("gradle-base-services", "gradle-tooling-extension-impl", "gradle-wrapper", plugin = "gradle")) + testCompileOnly(ideaPluginDeps("Groovy", plugin = "Groovy")) + testCompileOnly(ideaPluginDeps("maven", "maven-server-api", plugin = "maven")) + + testCompileOnly(ideaSdkDeps("groovy-all", "velocity", "gson", "jsr305")) + + testRuntime(ideaPluginDeps("resources_en", plugin = "junit")) + testRuntime(ideaPluginDeps("jcommander", "resources_en", plugin = "testng")) + testRuntime(ideaPluginDeps("resources_en", plugin = "properties")) + testRuntime(ideaPluginDeps("*.jar", plugin = "gradle")) + testRuntime(ideaPluginDeps("*.jar", plugin = "Groovy")) + testRuntime(ideaPluginDeps("jacocoant", plugin = "coverage")) + testRuntime(ideaPluginDeps("*.jar", plugin = "maven")) + testRuntime(ideaPluginDeps("*.jar", plugin = "android")) + + testRuntime(preloadedDeps("uast-common", "uast-java")) + + // deps below are test runtime deps, but made test compile to split compilation and running to reduce mem req + testCompile(project(":plugins:android-extensions-compiler")) + testCompile(project(":plugins:android-extensions-idea")) { isTransitive = false } + testCompile(project(":plugins:allopen-ide")) { isTransitive = false } + testCompile(project(":plugins:allopen-cli")) + testCompile(project(":plugins:noarg-ide")) { isTransitive = false } + testCompile(project(":plugins:noarg-cli")) + testCompile(project(":plugins:annotation-based-compiler-plugins-ide-support")) { isTransitive = false } + testCompile(project(":plugins:sam-with-receiver-ide")) { isTransitive = false } + testCompile(project(":plugins:sam-with-receiver-cli")) + testCompile(project(":idea:idea-android")) { isTransitive = false } + testCompile(project(":plugins:lint")) { isTransitive = false } + testCompile(project(":plugins:uast-kotlin")) + + (rootProject.extra["compilerModules"] as Array).forEach { + testCompile(project(it)) + } + + buildVersion() +} + +configureKotlinProjectSources("src", + "idea-maven/src", + "idea-completion/src", + "idea-live-templates/src", + "idea-repl/src") +configure { + sourceSets["main"].apply { + resources { + srcDir(File(projectDir, "resources")) + .include("**") + srcDir(File(projectDir, "src")) + .include("META-INF/**", + "**/*.properties") + } + } +} +configureKotlinProjectTests("idea/tests", + "idea/idea-maven/test", + "idea/idea-completion/tests", + "j2k/tests", + "eval4j/test", + sourcesBaseDir = rootDir) + +tasks.withType { + dependsOnTaskIfExistsRec("dist", project = rootProject) + jvmArgs("-ea", "-XX:+HeapDumpOnOutOfMemoryError", "-Xmx1200m", "-XX:+UseCodeCacheFlushing", "-XX:ReservedCodeCacheSize=128m", "-Djna.nosys=true") + maxHeapSize = "1200m" + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") +// forkEvery = 100 + testLogging { +// events = setOf(TestLogEvent.FAILED) +// showStackTraces = true +// showCauses = true +// exceptionFormat = TestExceptionFormat.FULL +// showStandardStreams = false + } + ignoreFailures = true +} + +testsJar {} + + diff --git a/idea/formatter/build.gradle.kts b/idea/formatter/build.gradle.kts new file mode 100644 index 00000000000..5f2e976dfda --- /dev/null +++ b/idea/formatter/build.gradle.kts @@ -0,0 +1,13 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(ideaSdkDeps("openapi")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/idea/ide-common/build.gradle.kts b/idea/ide-common/build.gradle.kts new file mode 100644 index 00000000000..016fb56eb2f --- /dev/null +++ b/idea/ide-common/build.gradle.kts @@ -0,0 +1,16 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":js:js.frontend")) + compile(project(":js:js.serializer")) + compile(ideaSdkCoreDeps("annotations", "guava", "intellij-core")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/idea/idea-android/build.gradle.kts b/idea/idea-android/build.gradle.kts new file mode 100644 index 00000000000..13498c9ffd9 --- /dev/null +++ b/idea/idea-android/build.gradle.kts @@ -0,0 +1,64 @@ +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + + compile(kotlinDep("reflect")) + compile(project(":compiler:util")) + compile(project(":compiler:light-classes")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":idea")) + compile(project(":idea:idea-core")) + compile(project(":idea:ide-common")) + compile(ideaSdkDeps("openapi", "idea")) + compile(ideaPluginDeps("gradle-tooling-api", plugin = "gradle")) + compile(ideaPluginDeps("android", "common", "sdklib", "sdk-common", "layoutlib-api", plugin = "android")) + compile(preloadedDeps("uast-common", "uast-java")) + compile(preloadedDeps("dx", subdir = "android-5.0/lib")) + + testCompile(project(":kotlin-test:kotlin-test-jvm")) + testCompile(project(":compiler.tests-common")) + testCompile(project(":idea:idea-test-framework")) { isTransitive = false } + testCompile(project(":plugins:lint")) { isTransitive = false } + testCompile(projectTests(":idea")) + testCompile(ideaPluginDeps("android-common", "sdklib", plugin = "android")) + testCompile(ideaPluginDeps("properties", plugin = "properties")) + testCompile(ideaSdkDeps("gson")) + + testRuntime(preloadedDeps("uast-common", "uast-java")) + testRuntime(project(":plugins:android-extensions-idea")) + testRuntime(project(":plugins:sam-with-receiver-ide")) + testRuntime(project(":plugins:noarg-ide")) + testRuntime(project(":plugins:allopen-ide")) + testRuntime(ideaSdkDeps("*.jar")) + testRuntime(ideaPluginDeps("idea-junit", "resources_en", plugin = "junit")) + testRuntime(ideaPluginDeps("IntelliLang", plugin = "IntelliLang")) + testRuntime(ideaPluginDeps("jcommander", "testng", "testng-plugin", "resources_en", plugin = "testng")) + testRuntime(ideaPluginDeps("copyright", plugin = "copyright")) + testRuntime(ideaPluginDeps("properties", "resources_en", plugin = "properties")) + testRuntime(ideaPluginDeps("java-i18n", plugin = "java-i18n")) + testRuntime(ideaPluginDeps("*.jar", plugin = "gradle")) + testRuntime(ideaPluginDeps("*.jar", plugin = "Groovy")) + testRuntime(ideaPluginDeps("coverage", "jacocoant", plugin = "coverage")) + testRuntime(ideaPluginDeps("java-decompiler", plugin = "java-decompiler")) + testRuntime(ideaPluginDeps("*.jar", plugin = "maven")) + testRuntime(ideaPluginDeps("*.jar", plugin = "android")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectTestsDefault() + +tasks.withType { + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} + +testsJar {} + diff --git a/idea/idea-android/idea-android-output-parser/build.gradle.kts b/idea/idea-android/idea-android-output-parser/build.gradle.kts new file mode 100644 index 00000000000..794d58e3d03 --- /dev/null +++ b/idea/idea-android/idea-android-output-parser/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(ideaSdkCoreDeps("intellij-core")) + compile(ideaPluginDeps("gradle-tooling-api", plugin = "gradle")) + compile(ideaPluginDeps("android", "common", "sdk-common", plugin = "android")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/idea/idea-core/build.gradle.kts b/idea/idea-core/build.gradle.kts new file mode 100644 index 00000000000..e618e2c212b --- /dev/null +++ b/idea/idea-core/build.gradle.kts @@ -0,0 +1,27 @@ +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":kotlin-stdlib")) + compile(project(":core")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:frontend.script")) + compile(project(":compiler:light-classes")) + compile(project(":compiler:util")) + compile(project(":j2k")) + compile(project(":idea:ide-common")) + compile(project(":idea:idea-jps-common")) + compile(project(":plugins:android-extensions-compiler")) + compile(ideaSdkCoreDeps("intellij-core", "util")) + compile(ideaSdkDeps("openapi", "idea")) + compile(ideaPluginDeps("gradle-tooling-api", "gradle", plugin = "gradle")) + compile(preloadedDeps("uast-common", "kotlinx-coroutines-core", "kotlinx-coroutines-jdk8")) + buildVersion() +} + +configureKotlinProjectSources("idea-core/src", "idea-analysis/src", sourcesBaseDir = File(rootDir, "idea")) +configureKotlinProjectResources("idea-analysis/src", sourcesBaseDir = File(rootDir, "idea")) { + include("**/*.properties") +} +configureKotlinProjectNoTests() diff --git a/idea/idea-jps-common/build.gradle.kts b/idea/idea-jps-common/build.gradle.kts new file mode 100644 index 00000000000..49962609981 --- /dev/null +++ b/idea/idea-jps-common/build.gradle.kts @@ -0,0 +1,16 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":kotlin-stdlib")) + compile(project(":compiler:util")) + compile(project(":compiler:cli-common")) + compile(project(":compiler:frontend.java")) + compile(ideaSdkCoreDeps("intellij-core", "util")) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/idea/idea-test-framework/build.gradle.kts b/idea/idea-test-framework/build.gradle.kts new file mode 100644 index 00000000000..59b702542e7 --- /dev/null +++ b/idea/idea-test-framework/build.gradle.kts @@ -0,0 +1,18 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.script")) + compile(project(":compiler.tests-common")) + compile(project(":idea")) + compile(project(":idea:idea-core")) + compile(project(":idea:idea-jps-common")) + compile(ideaSdkDeps("openapi", "idea")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + + diff --git a/idea/kotlin-gradle-tooling/build.gradle.kts b/idea/kotlin-gradle-tooling/build.gradle.kts new file mode 100644 index 00000000000..c3e4cb5b374 --- /dev/null +++ b/idea/kotlin-gradle-tooling/build.gradle.kts @@ -0,0 +1,27 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":kotlin-stdlib")) + compile(project(":compiler:cli-common")) + compile(ideaSdkDeps("gradle-tooling-api", + "gradle-tooling-extension-api", + "gradle", + "gradle-core", + "gradle-base-services-groovy", + subdir = "plugins/gradle/lib")) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + + +val jar: Jar by tasks + +ideaPlugin { + from(jar) +} diff --git a/j2k/build.gradle.kts b/j2k/build.gradle.kts new file mode 100644 index 00000000000..3010fca4889 --- /dev/null +++ b/j2k/build.gradle.kts @@ -0,0 +1,17 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":kotlin-stdlib")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:light-classes")) + compile(project(":compiler:util")) + compile(ideaSdkCoreDeps("intellij-core", "util")) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/jps-plugin/build.gradle.kts b/jps-plugin/build.gradle.kts new file mode 100644 index 00000000000..1576eaf54a2 --- /dev/null +++ b/jps-plugin/build.gradle.kts @@ -0,0 +1,51 @@ +apply { + plugin("kotlin") +} + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + testRuntime(ideaSdkCoreDeps("*.jar")) + testRuntime(ideaSdkDeps("*.jar")) + testRuntime(ideaSdkDeps("*.jar", subdir = "jps/test")) + testRuntime(ideaSdkDeps("*.jar", subdir = "jps")) + compile(project(":build-common")) + compile(project(":core")) + compile(project(":compiler:compiler-runner")) + compile(project(":compiler:daemon-common")) + compile(project(":compiler:daemon-client")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:preloader")) + compile(project(":idea:idea-jps-common")) + compile(ideaSdkDeps("jps-builders", "jps-builders-6", subdir = "jps")) + buildVersion() + testCompile(project(":compiler.tests-common")) + testCompile(project(":compiler:incremental-compilation-impl")) + testCompileOnly(ideaSdkDeps("jps-build-test", subdir = "jps/test")) + testCompile(commonDep("junit:junit")) + testCompile(project(":kotlin-test:kotlin-test-jvm")) + testCompile(projectTests(":build-common")) + (rootProject.extra["compilerModules"] as Array).forEach { + testRuntime(project(it)) + } +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectResourcesDefault() +configureKotlinProjectTests("test", sourcesBaseDir = File(projectDir, "jps-tests")) +configureKotlinProjectTestResources("testData") + + +tasks.withType { + jvmArgs("-ea", "-XX:+HeapDumpOnOutOfMemoryError", "-Xmx1200m", "-XX:+UseCodeCacheFlushing", "-XX:ReservedCodeCacheSize=128m", "-Djna.nosys=true") + maxHeapSize = "1200m" + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + forkEvery = 100 + ignoreFailures = true +} + +testsJar {} diff --git a/js/js.ast/build.gradle.kts b/js/js.ast/build.gradle.kts new file mode 100644 index 00000000000..a3522d73f87 --- /dev/null +++ b/js/js.ast/build.gradle.kts @@ -0,0 +1,13 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(ideaSdkCoreDeps("trove4j", "intellij-core")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/js/js.dce/build.gradle.kts b/js/js.dce/build.gradle.kts new file mode 100644 index 00000000000..93685ead052 --- /dev/null +++ b/js/js.dce/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":js:js.ast")) + compile(project(":js:js.translator")) + compile(ideaSdkCoreDeps("intellij-core")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/js/js.frontend/build.gradle.kts b/js/js.frontend/build.gradle.kts new file mode 100644 index 00000000000..82aa0639612 --- /dev/null +++ b/js/js.frontend/build.gradle.kts @@ -0,0 +1,16 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":js:js.ast")) + compile(project(":js:js.parser")) + compile(project(":js:js.serializer")) + compile(ideaSdkCoreDeps("intellij-core")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/js/js.parser/build.gradle.kts b/js/js.parser/build.gradle.kts new file mode 100644 index 00000000000..ae05bf64513 --- /dev/null +++ b/js/js.parser/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":js:js.ast")) + compile(ideaSdkCoreDeps("intellij-core")) + compile(preloadedDeps("json-org")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/js/js.serializer/build.gradle.kts b/js/js.serializer/build.gradle.kts new file mode 100644 index 00000000000..638065acd2f --- /dev/null +++ b/js/js.serializer/build.gradle.kts @@ -0,0 +1,15 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:serialization")) + compile(project(":js:js.ast")) + compile(ideaSdkCoreDeps("intellij-core")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/js/js.tests/build.gradle.kts b/js/js.tests/build.gradle.kts new file mode 100644 index 00000000000..6c72320a49d --- /dev/null +++ b/js/js.tests/build.gradle.kts @@ -0,0 +1,36 @@ + +apply { plugin("kotlin") } + +dependencies { + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + + testCompile(project(":compiler.tests-common")) + testCompile(project(":compiler:frontend")) + testCompile(project(":compiler:cli")) + testCompileOnly(project(":compiler:util")) + testCompile(project(":js:js.translator")) + testCompile(project(":js:js.serializer")) + testCompile(project(":js:js.dce")) + testCompile(ideaSdkDeps("openapi", "idea")) + testRuntime(project(":kotlin-stdlib")) + testRuntime(project(":compiler:backend-common")) + testRuntime(ideaSdkDeps("*.jar")) +} + +configureKotlinProjectSources() +configureKotlinProjectTestsDefault() + +val test: Test by tasks +test.apply { + dependsOnTaskIfExistsRec("dist", project = rootProject) + dependsOn(":prepare:mock-runtime-for-test:dist") + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} + +testsJar {} + diff --git a/js/js.translator/build.gradle.kts b/js/js.translator/build.gradle.kts new file mode 100644 index 00000000000..52adfe122e7 --- /dev/null +++ b/js/js.translator/build.gradle.kts @@ -0,0 +1,18 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":core")) + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:backend-common")) + compile(project(":js:js.ast")) + compile(project(":js:js.frontend")) + compile(project(":js:js.parser")) + compile(ideaSdkCoreDeps("intellij-core")) +} + +configureKotlinProjectSources("js.translator/src", "js.inliner/src", sourcesBaseDir = File(rootDir, "js")) +configureKotlinProjectNoTests() + diff --git a/kotlin-bootstrap-version.txt b/kotlin-bootstrap-version.txt new file mode 100644 index 00000000000..814c8e60951 --- /dev/null +++ b/kotlin-bootstrap-version.txt @@ -0,0 +1 @@ +1.1.4-eap-33 diff --git a/kotlin-version-for-gradle.txt b/kotlin-version-for-gradle.txt new file mode 100644 index 00000000000..814c8e60951 --- /dev/null +++ b/kotlin-version-for-gradle.txt @@ -0,0 +1 @@ +1.1.4-eap-33 diff --git a/libraries/examples/annotation-processor-example/build.gradle.kts b/libraries/examples/annotation-processor-example/build.gradle.kts new file mode 100644 index 00000000000..09b0334d26b --- /dev/null +++ b/libraries/examples/annotation-processor-example/build.gradle.kts @@ -0,0 +1,12 @@ +description = "Simple Annotation Processor for testing kapt" + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(kotlinDep("stdlib")) +} + +configureKotlinProjectSources("src/kotlin") +configureKotlinProjectResources("src/resources") +configureKotlinProjectNoTests() diff --git a/plugins/allopen/allopen-cli/build.gradle.kts b/plugins/allopen/allopen-cli/build.gradle.kts new file mode 100644 index 00000000000..ac38a05786c --- /dev/null +++ b/plugins/allopen/allopen-cli/build.gradle.kts @@ -0,0 +1,30 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(ideaSdkCoreDeps("intellij-core")) + compile(project(":compiler:plugin-api")) + compile(project(":compiler:frontend")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin AllOpen Compiler Plugin") + from(fileTree("$projectDir/src")) { include("META-INF/**") } + archiveName = "allopen-compiler-plugin.jar" +} + +dist { + from(jar) +} + +ideaPlugin { + from(jar) +} + diff --git a/plugins/allopen/allopen-ide/build.gradle.kts b/plugins/allopen/allopen-ide/build.gradle.kts new file mode 100644 index 00000000000..4507e21a635 --- /dev/null +++ b/plugins/allopen/allopen-ide/build.gradle.kts @@ -0,0 +1,29 @@ +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":plugins:allopen-cli")) + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:cli-common")) + compile(project(":idea")) + compile(project(":idea:idea-jps-common")) + compile(project(":plugins:annotation-based-compiler-plugins-ide-support")) + compile(ideaSdkDeps("openapi", "idea")) + compile(ideaPluginDeps("maven", plugin = "maven")) + compile(ideaPluginDeps("gradle-tooling-api", "gradle", plugin = "gradle")) +} + + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + + +val jar: Jar by tasks + +ideaPlugin { + from(jar) +} + diff --git a/plugins/android-extensions/android-extensions-compiler/build.gradle.kts b/plugins/android-extensions/android-extensions-compiler/build.gradle.kts new file mode 100644 index 00000000000..cec502b8909 --- /dev/null +++ b/plugins/android-extensions/android-extensions-compiler/build.gradle.kts @@ -0,0 +1,32 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(ideaSdkCoreDeps("intellij-core")) + compile(project(":compiler:util")) + compile(project(":compiler:plugin-api")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:backend")) + compile(ideaPluginDeps("layoutlib", plugin = "android")) +} + +configureKotlinProjectSources("android-extensions-compiler/src", "android-extensions-runtime/src", sourcesBaseDir = File(rootDir, "plugins", "android-extensions")) +configureKotlinProjectNoTests() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin Android Extensions Compiler") +} + +dist { + from(jar) +} + +ideaPlugin { + from(jar) +} + diff --git a/plugins/android-extensions/android-extensions-idea/build.gradle.kts b/plugins/android-extensions/android-extensions-idea/build.gradle.kts new file mode 100644 index 00000000000..528b3c2197e --- /dev/null +++ b/plugins/android-extensions/android-extensions-idea/build.gradle.kts @@ -0,0 +1,63 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + + compile(project(":compiler:util")) + compile(project(":compiler:light-classes")) + compile(project(":idea:idea-core")) + compile(project(":idea")) + compile(project(":plugins:android-extensions-compiler")) + compile(ideaPluginDeps("android", "sdk-tools", "sdk-common", plugin = "android")) + compile(ideaPluginDeps("Groovy", plugin = "Groovy")) + testCompile(project(":compiler.tests-common")) + testCompile(project(":compiler:cli")) + testCompile(project(":compiler:frontend.java")) + testCompile(project(":idea:idea-test-framework")) { isTransitive = false } + testCompile(projectTests(":idea")) + testCompile(projectTests(":idea:idea-android")) + testCompile(project(":kotlin-test:kotlin-test-jvm")) + testRuntime(project(":plugins:android-extensions-jps")) + testRuntime(project(":plugins:sam-with-receiver-ide")) + testRuntime(project(":plugins:noarg-ide")) + testRuntime(project(":plugins:allopen-ide")) + testRuntime(ideaSdkDeps("*.jar")) + testRuntime(ideaPluginDeps("idea-junit", "resources_en", plugin = "junit")) + testRuntime(ideaPluginDeps("IntelliLang", plugin = "IntelliLang")) + testRuntime(ideaPluginDeps("jcommander", "testng", "testng-plugin", "resources_en", plugin = "testng")) + testRuntime(ideaPluginDeps("copyright", plugin = "copyright")) + testRuntime(ideaPluginDeps("properties", "resources_en", plugin = "properties")) + testRuntime(ideaPluginDeps("java-i18n", plugin = "java-i18n")) + testRuntime(ideaPluginDeps("*.jar", plugin = "gradle")) + testRuntime(ideaPluginDeps("*.jar", plugin = "Groovy")) + testRuntime(ideaPluginDeps("coverage", "jacocoant", plugin = "coverage")) + testRuntime(ideaPluginDeps("java-decompiler", plugin = "java-decompiler")) + testRuntime(ideaPluginDeps("*.jar", plugin = "maven")) + testRuntime(ideaPluginDeps("*.jar", plugin = "android")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectTestsDefault() + +testsJar {} + + +tasks.withType { + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} + +val jar: Jar by tasks + +ideaPlugin { + from(jar) +} diff --git a/plugins/android-extensions/android-extensions-jps/build.gradle.kts b/plugins/android-extensions/android-extensions-jps/build.gradle.kts new file mode 100644 index 00000000000..a63ccd2f776 --- /dev/null +++ b/plugins/android-extensions/android-extensions-jps/build.gradle.kts @@ -0,0 +1,14 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":jps-plugin")) + compile(project(":plugins:android-extensions-compiler")) + compile(ideaPluginDeps("android-jps-plugin", plugin = "android", subdir = "lib/jps")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/plugins/annotation-based-compiler-plugins-ide-support/build.gradle.kts b/plugins/annotation-based-compiler-plugins-ide-support/build.gradle.kts new file mode 100644 index 00000000000..9c359a4661d --- /dev/null +++ b/plugins/annotation-based-compiler-plugins-ide-support/build.gradle.kts @@ -0,0 +1,22 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:cli-common")) + compile(project(":idea")) + compile(project(":idea:idea-jps-common")) + compileOnly(ideaPluginDeps("maven", "maven-server-api", plugin = "maven")) + compileOnly(ideaPluginDeps("gradle-tooling-api", "gradle", plugin = "gradle")) + compileOnly(ideaSdkDeps("openapi", "idea")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/plugins/kapt3/build.gradle.kts b/plugins/kapt3/build.gradle.kts new file mode 100644 index 00000000000..9e7d96ebe49 --- /dev/null +++ b/plugins/kapt3/build.gradle.kts @@ -0,0 +1,31 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + compile(project(":compiler:util")) + compile(project(":compiler:cli")) + compile(project(":compiler:backend")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:plugin-api")) + testCompile(project(":compiler.tests-common")) + testCompile(commonDep("junit:junit")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectTestsDefault() + +testsJar {} + +tasks.withType { + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} + diff --git a/plugins/lint/build.gradle.kts b/plugins/lint/build.gradle.kts new file mode 100644 index 00000000000..9a5daf8ecde --- /dev/null +++ b/plugins/lint/build.gradle.kts @@ -0,0 +1,25 @@ + +apply { + plugin("kotlin") + plugin("java") +} + +dependencies { + val compile by configurations + compile(project(":compiler:frontend")) + compile(project(":idea")) + compile(project(":idea:idea-core")) + compile(project(":idea:idea-android")) + compile(project(":plugins:uast-kotlin")) + compile(preloadedDeps("uast-common", "uast-java")) + compile(ideaPluginDeps("android", "android-common", "common", "sdk-common", "sdklib", "sdk-tools", "repository", "lombok-ast", "kxml2", plugin = "android")) + compile(ideaSdkCoreDeps("intellij-core", "util")) + compile(ideaSdkDeps("guava")) +} + +configureKotlinProjectSources("android-annotations/src", + "lint-api/src", + "lint-checks/src", + "lint-idea/src") +configureKotlinProjectNoTests() + diff --git a/plugins/noarg/noarg-cli/build.gradle.kts b/plugins/noarg/noarg-cli/build.gradle.kts new file mode 100644 index 00000000000..c64acc9f42a --- /dev/null +++ b/plugins/noarg/noarg-cli/build.gradle.kts @@ -0,0 +1,32 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:backend")) + compile(project(":compiler:util")) + compile(project(":compiler:plugin-api")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin NoArg Compiler Plugin") + from(fileTree("$projectDir/src")) { include("META-INF/**") } + archiveName = "noarg-compiler-plugin.jar" +} + +dist { + from(jar) +} + +ideaPlugin { + from(jar) +} + diff --git a/plugins/noarg/noarg-ide/build.gradle.kts b/plugins/noarg/noarg-ide/build.gradle.kts new file mode 100644 index 00000000000..6b803dfbf86 --- /dev/null +++ b/plugins/noarg/noarg-ide/build.gradle.kts @@ -0,0 +1,32 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":plugins:noarg-cli")) + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:backend")) + compile(project(":compiler:cli-common")) + compile(project(":idea")) + compile(project(":idea:idea-jps-common")) + compile(project(":plugins:annotation-based-compiler-plugins-ide-support")) + compile(ideaSdkDeps("openapi", "idea")) + compile(ideaPluginDeps("maven", plugin = "maven")) + compile(ideaPluginDeps("gradle-tooling-api", "gradle", plugin = "gradle")) +} + + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + + +val jar: Jar by tasks + +ideaPlugin { + from(jar) +} + diff --git a/plugins/plugins-tests/build.gradle.kts b/plugins/plugins-tests/build.gradle.kts new file mode 100644 index 00000000000..1bfb97ecfe9 --- /dev/null +++ b/plugins/plugins-tests/build.gradle.kts @@ -0,0 +1,51 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + testCompile(project(":compiler:util")) + testCompile(project(":compiler:backend")) + testCompile(project(":compiler:cli")) + testCompile(project(":compiler.tests-common")) + testCompile(project(":plugins:android-extensions-compiler")) + testCompile(project(":plugins:android-extensions-idea")) + testCompile(project(":plugins:allopen-ide")) { isTransitive = false } + testCompile(project(":plugins:allopen-cli")) + testCompile(project(":plugins:noarg-ide")) { isTransitive = false } + testCompile(project(":plugins:noarg-cli")) + testCompile(project(":plugins:annotation-based-compiler-plugins-ide-support")) { isTransitive = false } + testCompile(project(":plugins:sam-with-receiver-ide")) { isTransitive = false } + testCompile(project(":plugins:sam-with-receiver-cli")) + testCompile(project(":idea:idea-android")) { isTransitive = false } + testCompile(project(":plugins:lint")) { isTransitive = false } + testCompile(project(":plugins:uast-kotlin")) + testCompile(project(":kotlin-test:kotlin-test-jvm")) + testCompile(projectTests(":jps-plugin")) + testCompileOnly(ideaSdkDeps("jps-builders")) + testCompile(ideaSdkDeps("jps-build-test", subdir = "jps/test")) + testCompile(ideaPluginDeps("*.jar", plugin = "android", subdir = "lib/jps")) + testRuntime(project(":jps-plugin")) + testRuntime(ideaSdkDeps("*.jar")) + testRuntime(ideaPluginDeps("idea-junit", "resources_en", plugin = "junit")) + testRuntime(ideaPluginDeps("*.jar", plugin = "gradle")) + testRuntime(ideaPluginDeps("*.jar", plugin = "android")) +} + +configureKotlinProjectSources() +configureKotlinProjectTestsDefault() + +testsJar {} + +val test: Test by tasks +test.apply { + dependsOnTaskIfExistsRec("dist", project = rootProject) + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} + diff --git a/plugins/sam-with-receiver/sam-with-receiver-cli/build.gradle.kts b/plugins/sam-with-receiver/sam-with-receiver-cli/build.gradle.kts new file mode 100644 index 00000000000..3f1223c4ad3 --- /dev/null +++ b/plugins/sam-with-receiver/sam-with-receiver-cli/build.gradle.kts @@ -0,0 +1,30 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:plugin-api")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin SamWithReceiver Compiler Plugin") + from(fileTree("$projectDir/src")) { include("META-INF/**") } + archiveName = "sam-with-receiver-compiler-plugin.jar" +} + +dist { + from(jar) +} + +ideaPlugin { + from(jar) +} + diff --git a/plugins/sam-with-receiver/sam-with-receiver-ide/build.gradle.kts b/plugins/sam-with-receiver/sam-with-receiver-ide/build.gradle.kts new file mode 100644 index 00000000000..8f0f87bed35 --- /dev/null +++ b/plugins/sam-with-receiver/sam-with-receiver-ide/build.gradle.kts @@ -0,0 +1,26 @@ +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":plugins:sam-with-receiver-cli")) + compile(project(":plugins:annotation-based-compiler-plugins-ide-support")) + compile(project(":compiler:util")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":idea:idea-core")) + compile(project(":idea:idea-android")) + compile(project(":idea")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + + +val jar: Jar by tasks + +ideaPlugin { + from(jar) +} + diff --git a/plugins/source-sections/source-sections-compiler/build.gradle.kts b/plugins/source-sections/source-sections-compiler/build.gradle.kts new file mode 100644 index 00000000000..98454073034 --- /dev/null +++ b/plugins/source-sections/source-sections-compiler/build.gradle.kts @@ -0,0 +1,48 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.script")) + compile(project(":compiler:plugin-api")) + testCompile(project(":compiler.tests-common")) + testCompile(commonDep("junit:junit")) + testCompile(project(":compiler:util")) + testCompile(project(":compiler:cli")) + testCompile(project(":compiler:cli-common")) + testCompile(project(":compiler:frontend.java")) + testCompile(project(":compiler:daemon-common")) + testCompile(project(":compiler:daemon-client")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectResources("src") { + include("META-INF/**") +} +configureKotlinProjectTestsDefault() + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin SourceSections Compiler Plugin") + archiveName = "kotlin-source-sections-compiler-plugin.jar" +} + +dist { + from(jar) +} + +tasks.withType { + dependsOnTaskIfExistsRec("dist", project = rootProject) + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} + diff --git a/plugins/uast-kotlin-idea/build.gradle.kts b/plugins/uast-kotlin-idea/build.gradle.kts new file mode 100644 index 00000000000..19127a6349c --- /dev/null +++ b/plugins/uast-kotlin-idea/build.gradle.kts @@ -0,0 +1,18 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":kotlin-stdlib")) + compile(project(":core:util.runtime")) + compile(project(":compiler:backend")) + compile(project(":compiler:frontend.java")) + compile(project(":idea:ide-common")) + compile(project(":plugins:uast-kotlin")) + compile(preloadedDeps("uast-common", "uast-java")) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + diff --git a/plugins/uast-kotlin/build.gradle.kts b/plugins/uast-kotlin/build.gradle.kts new file mode 100644 index 00000000000..22fd6482322 --- /dev/null +++ b/plugins/uast-kotlin/build.gradle.kts @@ -0,0 +1,39 @@ + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + val compileOnly by configurations + val testCompile by configurations + val testCompileOnly by configurations + val testRuntime by configurations + compile(project(":kotlin-stdlib")) + compile(project(":core:util.runtime")) + compile(project(":compiler:backend")) + compile(project(":compiler:frontend")) + compile(project(":compiler:frontend.java")) + compile(project(":compiler:light-classes")) + compile(preloadedDeps("uast-common", "uast-java")) + buildVersion() + testCompile(project(":kotlin-test:kotlin-test-jvm")) + testCompile(project(":compiler.tests-common")) + testCompile(commonDep("junit:junit")) + testCompile(project(":compiler:util")) + testCompile(project(":compiler:cli")) + testCompile(project(":idea:idea-android")) + testCompile(preloadedDeps("uast-tests")) + testRuntime(ideaSdkDeps("*.jar")) +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectTestsDefault() + +testsJar {} + + +tasks.withType { + workingDir = rootDir + systemProperty("idea.is.unit.test", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + ignoreFailures = true +} diff --git a/prepare/android-lint/build.gradle.kts b/prepare/android-lint/build.gradle.kts new file mode 100644 index 00000000000..f637e328cfe --- /dev/null +++ b/prepare/android-lint/build.gradle.kts @@ -0,0 +1,31 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("java") } + +val projectsToShadow = listOf( + ":plugins:lint", + ":plugins:uast-kotlin", + ":plugins:uast-kotlin-idea") + +tasks.withType { + setupRuntimeJar("Kotlin Android Lint") + archiveName = "android-lint.jar" + projectsToShadow.forEach { + dependsOn("$it:classes") + project(it).let { p -> + p.pluginManager.withPlugin("java") { + from(p.the().sourceSets.getByName("main").output) + } + } + } +} + +configureKotlinProjectSources() // no sources +configureKotlinProjectNoTests() + +val jar: Jar by tasks + +ideaPlugin { + from(jar) +} diff --git a/prepare/build.version/build.gradle.kts b/prepare/build.version/build.gradle.kts new file mode 100644 index 00000000000..41f4c3c9e86 --- /dev/null +++ b/prepare/build.version/build.gradle.kts @@ -0,0 +1,28 @@ + +import java.io.File + +val buildVersionFilePath = "${rootProject.extra["distDir"]}/build.txt" + +val mainCfg = configurations.create("default") + +artifacts.add(mainCfg.name, file(buildVersionFilePath)) + +val mainTask = task("prepare") { + val versionString = rootProject.extra["build.number"].toString() + val versionFile = File(buildVersionFilePath) + outputs.file(buildVersionFilePath) + outputs.upToDateWhen { + (versionFile.exists() && versionFile.readText().trim() == versionString).apply { + if (!this) { + println("!!! not up-to-date $versionFile: ${versionFile.takeIf { it.exists() }?.readText()?.trim()}") + } + } + } + doLast { + versionFile.parentFile.mkdirs() + versionFile.writeText(versionString) + } +} + +defaultTasks(mainTask.name) + diff --git a/prepare/compiler-embeddable/build.gradle.kts b/prepare/compiler-embeddable/build.gradle.kts new file mode 100644 index 00000000000..3bb8417620a --- /dev/null +++ b/prepare/compiler-embeddable/build.gradle.kts @@ -0,0 +1,59 @@ + +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3") + } +} + +val embedCfg = configurations.create("embed") +val mainCfg = configurations.create("default") + +val embeddableCompilerBaseName: String by rootProject.extra + +val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin" + +val packagesToRelocate = + listOf("com.intellij", + "com.google", + "com.sampullara", + "org.apache", + "org.jdom", + "org.picocontainer", + "jline", + "gnu", + "javax.inject", + "org.fusesource") + +dependencies { + embedCfg(project(":prepare:compiler", configuration = "default")) +} + +val embeddableTask = task("prepare") { + destinationDir = File(buildDir, "libs") + baseName = embeddableCompilerBaseName + configurations = listOf(mainCfg) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + dependsOn(":build-common:assemble", ":core:script.runtime:assemble") + from(embedCfg.files) + relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf") + packagesToRelocate.forEach { + relocate(it, "$kotlinEmbeddableRootPackage.$it") + } + relocate("org.fusesource", "$kotlinEmbeddableRootPackage.org.fusesource") { + // TODO: remove "it." after #KT-12848 get addressed + exclude("org.fusesource.jansi.internal.CLibrary") + } +} + +defaultTasks(embeddableTask.name) + +artifacts.add(mainCfg.name, embeddableTask.outputs.files.singleFile) { + builtBy(embeddableTask) + classifier = "" +} diff --git a/prepare/compiler/build.gradle.kts b/prepare/compiler/build.gradle.kts new file mode 100644 index 00000000000..032c48518a0 --- /dev/null +++ b/prepare/compiler/build.gradle.kts @@ -0,0 +1,118 @@ + +import java.io.File +import proguard.gradle.ProGuardTask +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.file.DuplicatesStrategy + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3") + classpath("net.sf.proguard:proguard-gradle:5.3.1") + } +} + +apply { plugin("maven") } + +// Set to false to disable proguard run on kotlin-compiler.jar. Speeds up the build +val shrink = true +val bootstrapBuild = false + +val compilerManifestClassPath = + if (bootstrapBuild) "kotlin-runtime-internal-bootstrap.jar kotlin-reflect-internal-bootstrap.jar kotlin-script-runtime-internal-bootstrap.jar" + else "kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar" + +val ideaSdkCoreCfg = configurations.create("ideaSdk-core") +val otherDepsCfg = configurations.create("other-deps") +val proguardLibraryJarsCfg = configurations.create("library-jars") +val mainCfg = configurations.create("default_") +val packedCfg = configurations.create("packed") +//val withBootstrapRuntimeCfg = configurations.create("withBootstrapRuntime") + +val compilerBaseName: String by rootProject.extra + +val outputJar = File(buildDir, "libs", "$compilerBaseName.jar") + +val javaHome = System.getProperty("java.home") + +val compilerProject = project(":compiler") + +dependencies { + ideaSdkCoreCfg(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) + ideaSdkCoreCfg(ideaSdkDeps("jna-platform", "oromatcher")) + ideaSdkCoreCfg(ideaSdkDeps("jps-model.jar", subdir = "jps")) + otherDepsCfg(commonDep("javax.inject")) + otherDepsCfg(commonDep("jline")) + otherDepsCfg(protobufFull()) + otherDepsCfg(commonDep("com.github.spullara.cli-parser", "cli-parser")) + otherDepsCfg(commonDep("com.google.code.findbugs", "jsr305")) + otherDepsCfg(commonDep("io.javaslang","javaslang")) + otherDepsCfg(preloadedDeps("json-org")) + buildVersion() + proguardLibraryJarsCfg(files("$javaHome/lib/rt.jar".takeIf { File(it).exists() } ?: "$javaHome/../Classes/classes.jar", + "$javaHome/lib/jsse.jar".takeIf { File(it).exists() } ?: "$javaHome/../Classes/jsse.jar")) + proguardLibraryJarsCfg(kotlinDep("stdlib")) + proguardLibraryJarsCfg(kotlinDep("script-runtime")) + proguardLibraryJarsCfg(kotlinDep("reflect")) + proguardLibraryJarsCfg(files("${System.getProperty("java.home")}/../lib/tools.jar")) +// proguardLibraryJarsCfg(project(":prepare:runtime", configuration = "default").apply { isTransitive = false }) +// proguardLibraryJarsCfg(project(":prepare:reflect", configuration = "default").apply { isTransitive = false }) +// proguardLibraryJarsCfg(project(":core:script.runtime").apply { isTransitive = false }) +} + +val packCompilerTask = task("internal.pack-compiler") { + configurations = listOf(packedCfg) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + destinationDir = File(buildDir, "libs") + baseName = compilerBaseName + "-before-shrink" + dependsOn(protobufFullTask) + setupRuntimeJar("Kotlin Compiler") + (rootProject.extra["compilerModules"] as Array).forEach { + dependsOn("$it:classes") + from(project(it).getCompiledClasses()) + } + from(ideaSdkCoreCfg.files) + from(otherDepsCfg.files) + from(project(":core:builtins").getResourceFiles()) { include("kotlin/**") } + + manifest.attributes.put("Class-Path", compilerManifestClassPath) + manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") +} + +val proguardTask = task("internal.proguard-compiler") { + dependsOn(packCompilerTask) + configuration("$rootDir/compiler/compiler.pro") + + inputs.files(packCompilerTask.outputs.files.singleFile) + outputs.file(outputJar) + + // TODO: remove after dropping compatibility with ant build + doFirst { + System.setProperty("kotlin-compiler-jar-before-shrink", packCompilerTask.outputs.files.singleFile.canonicalPath) + System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath) + } + + proguardLibraryJarsCfg.files.forEach { jar -> + libraryjars(jar) + } + printconfiguration("$buildDir/compiler.pro.dump") +} + +dist { + if (shrink) { + from(proguardTask) + } else { + from(packCompilerTask) + rename("-before-shrink", "") + } +} + +artifacts.add(mainCfg.name, proguardTask.outputs.files.singleFile) { + builtBy(proguardTask) + classifier = "" +} + + diff --git a/prepare/formatter/build.gradle.kts b/prepare/formatter/build.gradle.kts new file mode 100644 index 00000000000..6e7c5e84fe1 --- /dev/null +++ b/prepare/formatter/build.gradle.kts @@ -0,0 +1,20 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("java") } + +tasks.withType { + setupRuntimeJar("Kotlin Formatter") + archiveName = "kotlin-formatter.jar" + dependsOn(":idea:formatter:classes") + project(":idea:formatter").let { p -> + p.pluginManager.withPlugin("java") { + from(p.the().sourceSets.getByName("main").output) + } + } + from(fileTree("$rootDir/idea/formatter")) { include("src/**") } // Eclipse formatter sources navigation depends on this +} + +configureKotlinProjectSources() // no sources +configureKotlinProjectNoTests() + diff --git a/prepare/ide-lazy-resolver/build.gradle.kts b/prepare/ide-lazy-resolver/build.gradle.kts new file mode 100644 index 00000000000..9461ce74a05 --- /dev/null +++ b/prepare/ide-lazy-resolver/build.gradle.kts @@ -0,0 +1,20 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("java") } + +tasks.withType { + setupRuntimeJar("Kotlin IDE Lazy Resolver") + archiveName = "kotlin-ide-common.jar" + dependsOn(":idea:ide-common:classes") + project(":idea:ide-common").let { p -> + p.pluginManager.withPlugin("java") { + from(p.the().sourceSets.getByName("main").output) + } + } + from(fileTree("$rootDir/idea/ide-common")) { include("src/**") } // Eclipse formatter sources navigation depends on this +} + +configureKotlinProjectSources() // no sources +configureKotlinProjectNoTests() + diff --git a/prepare/jps-plugin/build.gradle.kts b/prepare/jps-plugin/build.gradle.kts new file mode 100644 index 00000000000..6fdae2e9951 --- /dev/null +++ b/prepare/jps-plugin/build.gradle.kts @@ -0,0 +1,47 @@ + +import org.gradle.jvm.tasks.Jar + +apply { plugin("java") } + +val projectsToShadow = listOf( + ":build-common", + ":compiler:cli-common", + ":compiler:compiler-runner", + ":compiler:daemon-client", + ":compiler:daemon-common", + ":core", + ":idea:idea-jps-common", + ":jps-plugin", + ":compiler:preloader", + ":compiler:util", + ":core:util.runtime", + ":plugins:android-extensions-jps") + +dependencies {} + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin JPS plugin") + manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.runner.Main") + manifest.attributes.put("Class-Path", "kotlin-runtime.jar") + archiveName = "kotlin-jps-plugin.jar" + projectsToShadow.forEach { + dependsOn("$it:classes") + project(it).let { p -> + p.pluginManager.withPlugin("java") { + from(p.the().sourceSets.getByName("main").output) + } + } + } + from(fileTree("$rootDir/jps-plugin/src")) { include("META-INF/**") } + from(files("$rootDir/resources/kotlinManifest.properties")) + from(zipTree("$rootDir/dependencies/native-platform-uberjar.jar")) +} + +configureKotlinProjectSources() // no sources +configureKotlinProjectNoTests() + +ideaPlugin("lib/jps") { + from(jar) +} + diff --git a/prepare/kotlin-plugin/build.gradle.kts b/prepare/kotlin-plugin/build.gradle.kts new file mode 100644 index 00000000000..9824980fcc6 --- /dev/null +++ b/prepare/kotlin-plugin/build.gradle.kts @@ -0,0 +1,86 @@ + +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3") + } +} + +val projectsToShadow = listOf( + ":core:builtins", + ":plugins:annotation-based-compiler-plugins-ide-support", + ":compiler:backend", + ":compiler:backend-common", + ":build-common", + ":compiler:cli-common", + ":compiler:container", + ":compiler:daemon-common", + ":core", + ":eval4j", + ":idea:formatter", + ":compiler:frontend", + ":compiler:frontend.java", + ":compiler:frontend.script", + ":idea:ide-common", + ":idea", + ":idea:idea-android", + ":idea:idea-android-output-parser", + ":idea:idea-core", + ":idea:idea-jps-common", + //":idea-ultimate", + ":compiler:ir.psi2ir", + ":compiler:ir.tree", + ":j2k", + ":js:js.ast", + ":js:js.frontend", + ":js:js.parser", + ":js:js.serializer", + ":compiler:light-classes", + ":compiler:plugin-api", + ":compiler:preloader", + ":compiler:resolution", + ":compiler:serialization", + ":compiler:util", + ":core:util.runtime") + +val packedJars by configurations.creating +val sideJars by configurations.creating + +dependencies { + packedJars(commonDep("com.github.spullara.cli-parser", "cli-parser")) + packedJars(preloadedDeps("protobuf-${rootProject.extra["versions.protobuf-java"]}")) + sideJars(project(":kotlin-script-runtime")) + sideJars(commonDep("io.javaslang", "javaslang")) + sideJars(commonDep("javax.inject")) + sideJars(preloadedDeps("markdown", "kotlinx-coroutines-core", "kotlinx-coroutines-jdk8", "uast-java")) +} + +val targetJar = File(buildDir, "libs", "kotlin-plugin.jar") + +val shadowTask = task("shadowJar") { + setupRuntimeJar("Kotlin IDEA plugin") + archiveName = targetJar.canonicalPath + projectsToShadow.forEach { + dependsOn("$it:classes") + project(it).let { p -> + p.pluginManager.withPlugin("java") { + from(p.the().sourceSets.getByName("main").output) + } + } + } + from(files("$rootDir/resources/kotlinManifest.properties")) + from(packedJars.files) +} + +ideaPlugin { + dependsOn(shadowTask) + from(targetJar) + dependsOn(":kotlin-script-runtime:jar") + from(sideJars) +} + diff --git a/prepare/mock-runtime-for-test/build.gradle.kts b/prepare/mock-runtime-for-test/build.gradle.kts new file mode 100644 index 00000000000..14532652513 --- /dev/null +++ b/prepare/mock-runtime-for-test/build.gradle.kts @@ -0,0 +1,42 @@ + +import org.gradle.jvm.tasks.Jar +import org.gradle.api.internal.HasConvention +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet + +apply { plugin("kotlin") } + +dependencies { + val compile by configurations + compile(project(":kotlin-stdlib")) +} + +val jar: Jar by tasks +jar.apply { + setupRuntimeJar("Kotlin Mock Runtime for Tests") + from(fileTree("${rootProject.extra["distDir"]}/builtins")) { include("kotlin/**") } + archiveName = "kotlin-mock-runtime-for-test.jar" +} + +configure { + sourceSets["main"].apply { + (this as HasConvention).convention.getPlugin().kotlin.apply { + srcDir(File(rootDir, "core", "runtime.jvm", "src")) + .include("kotlin/TypeAliases.kt", + "kotlin/text/TypeAliases.kt") + srcDir(File(rootDir, "libraries", "stdlib", "src")) + .include("kotlin/collections/TypeAliases.kt", + "kotlin/jvm/JvmVersion.kt", + "kotlin/util/Standard.kt", + "kotlin/internal/Annotations.kt") + } + } +} + +configureKotlinProjectNoTests() + + +task("dist") { + into(rootProject.extra["distDir"].toString()) + from(jar) +} + diff --git a/prepare/reflect/build.gradle.kts b/prepare/reflect/build.gradle.kts new file mode 100644 index 00000000000..4d1c7e5b63d --- /dev/null +++ b/prepare/reflect/build.gradle.kts @@ -0,0 +1,131 @@ + +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.Project +import org.jetbrains.org.objectweb.asm.* +import org.gradle.jvm.tasks.Jar +import java.io.BufferedOutputStream +import java.io.File +import java.io.FileOutputStream +import java.util.jar.JarFile +import java.util.zip.ZipOutputStream + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3") + classpath(ideaSdkDeps("asm-all")) + } +} + +apply { plugin("com.github.johnrengelman.shadow") } + +// Set to false to prevent relocation and metadata stripping on kotlin-reflect.jar and reflection sources. Use to debug reflection +val obfuscateReflect = true + +val classesFromProjectsCfg = configurations.create("classes-from-projects") +val otherDepsCfg = configurations.create("other-deps") +val mainCfg = configurations.create("default") + +val outputReflectJarFileBase = "$buildDir/libs/kotlin-reflect" + +val coreProjectName = ":core" +val reflectionProjectName = ":core:reflection.jvm" + +artifacts.add(mainCfg.name, File(outputReflectJarFileBase + ".jar")) + +dependencies { + classesFromProjectsCfg.name(projectDepIntransitive(coreProjectName)) + classesFromProjectsCfg.name(projectDepIntransitive(":core:util.runtime")) + classesFromProjectsCfg.name(projectDepIntransitive(reflectionProjectName)) + otherDepsCfg.name(protobufLite()) + otherDepsCfg.name(commonDep("javax.inject")) + buildVersion() +} + +val prePackReflectTask = task("pre-pack-reflect") { + classifier = if (obfuscateReflect) outputReflectJarFileBase + "_beforeStrip" else outputReflectJarFileBase + configurations = listOf(mainCfg) + setupRuntimeJar("Kotlin Reflect") + dependsOn("$coreProjectName:assemble", "$reflectionProjectName:assemble", protobufLiteTask) + from(project(reflectionProjectName).getCompiledClasses()) + from(project(coreProjectName).getCompiledClasses()) + from(project(":core:util.runtime").getCompiledClasses()) + from(project(coreProjectName).file("descriptor.loader.java/src")) { + include("META-INF/services/**") + } + from(otherDepsCfg.files) + manifest.attributes.put("Class-Path", "kotlin-runtime.jar") + + if (obfuscateReflect) { + relocate("org.jetbrains.kotlin", "kotlin.reflect.jvm.internal.impl") + relocate("javax.inject", "kotlin.reflect.jvm.internal.impl.javax.inject") + } +} + +val mainTask = task("prepare") { + dependsOn(prePackReflectTask) + val inFile = File(outputReflectJarFileBase + "_beforeStrip.jar") + val outFile = File(outputReflectJarFileBase + ".jar") + inputs.file(inFile) + outputs.file(outFile) + val annotationRegex = "kotlin/Metadata".toRegex() + val classRegex = "kotlin/reflect/jvm/internal/impl/.*".toRegex() + doLast { + println("Stripping annotations from all classes in $inFile") + println("Input file size: ${inFile.length()} bytes") + + fun transform(entryName: String, bytes: ByteArray): ByteArray { + if (!entryName.endsWith(".class")) return bytes + if (!classRegex.matches(entryName.removeSuffix(".class"))) return bytes + + var changed = false + val classWriter = ClassWriter(0) + val classVisitor = object : ClassVisitor(Opcodes.ASM5, classWriter) { + override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? { + if (annotationRegex.matches(Type.getType(desc).internalName)) { + changed = true + return null + } + return super.visitAnnotation(desc, visible) + } + } + ClassReader(bytes).accept(classVisitor, 0) + if (!changed) return bytes + + return classWriter.toByteArray() + } + + ZipOutputStream(BufferedOutputStream(FileOutputStream(outFile))).use { outJar -> + val inJar = JarFile(inFile) + try { + for (entry in inJar.entries()) { + if (entry.isDirectory) continue + val inBytes = inJar.getInputStream(entry).readBytes() + val outBytes = transform(entry.name, inBytes) + + if (inBytes.size < outBytes.size) { + error("Size increased for ${entry.name}: was ${inBytes.size} bytes, became ${outBytes.size} bytes") + } + + entry.compressedSize = -1L + outJar.putNextEntry(entry) + outJar.write(outBytes) + outJar.closeEntry() + } + } + finally { + // Yes, JarFile does not extend Closeable on JDK 6 so we can't use "use" here + inJar.close() + } + } + + println("Output written to $outFile") + println("Output file size: ${outFile.length()} bytes") + } +} + +defaultTasks(mainTask.name) + diff --git a/prepare/runtime/build.gradle.kts b/prepare/runtime/build.gradle.kts new file mode 100644 index 00000000000..b2ea5c7ee99 --- /dev/null +++ b/prepare/runtime/build.gradle.kts @@ -0,0 +1,39 @@ + +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import java.io.File + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3") + classpath(ideaSdkDeps("asm-all")) + } +} + +apply { plugin("com.github.johnrengelman.shadow") } + +val mainCfg = configurations.create("default") + +val outputRuntimeJarFileBase = "$buildDir/libs/kotlin-runtime" + +artifacts.add(mainCfg.name, File(outputRuntimeJarFileBase + ".jar")) + +dependencies { + mainCfg.name(projectDepIntransitive(":core:builtins")) + mainCfg.name(projectDepIntransitive(":kotlin-stdlib")) + buildVersion() +} + +val mainTask = task("prepare") { + classifier = outputRuntimeJarFileBase + configurations = listOf(mainCfg) + dependsOn(":core:builtins:assemble", ":kotlin-stdlib:assemble") + setupRuntimeJar("Kotlin Runtime") + from(mainCfg.files) +} + +defaultTasks(mainTask.name) + diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000000..9d9014782c9 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,162 @@ +// modules +include 'buildSrc' // this fixes import into idea, so buildsrc is not longer imported with different gradle version +include "build-common" +include "compiler" +include "compiler:util" +include "compiler:daemon-common" +include "compiler:daemon-client" +include "compiler:preloader" +include "compiler:cli-runner" +include "compiler:container" +include "compiler:resolution" +include "compiler:serialization" +include "compiler:frontend" +include "compiler:frontend.java" +include "compiler:frontend.script" +include "compiler:compiler-runner" +include "compiler:cli-common" +include "compiler:ir.tree" +include "compiler:ir.psi2ir" +include "compiler:ir.ir2cfg" +include "compiler:backend-common" +include "compiler:backend" +include "compiler:plugin-api" +include "compiler:light-classes" +include "compiler:cli" +include "compiler:incremental-compilation-impl" +include "compiler:android-tests" +include "compiler.tests-common" +include "js:js.ast" +include "js:js.serializer" +include "js:js.parser" +include "js:js.frontend" +include "js:js.translator" +include "js:js.dce" +include "js:js.tests" +include "jps-plugin" +include "core" +include "core:builtins" +include "core:reflection.jvm" +include "core:script.runtime" +include "core:util.runtime" +include "custom-dependencies:protobuf-lite" +include "idea:idea-jps-common" +include "idea:formatter" +include "idea:ide-common" +include "idea:idea-core" +include "idea:kotlin-gradle-tooling" +include "idea:idea-android" +include "idea:idea-android-output-parser" +include "idea:idea-test-framework" +include "idea" +include "eval4j" +include "j2k" +include "plugins:lint" +include "plugins:android-extensions-compiler" +include "plugins:android-extensions-idea" +include "plugins:android-extensions-jps" +include "plugins:allopen-cli" +include "plugins:allopen-ide" +include "plugins:noarg-cli" +include "plugins:noarg-ide" +include "plugins:sam-with-receiver-cli" +include "plugins:sam-with-receiver-ide" +include "plugins:source-sections-compiler" +include "plugins:uast-kotlin" +include "plugins:uast-kotlin-idea" +include "plugins:annotation-based-compiler-plugins-ide-support" +include "plugins:kapt3" +include "plugins:plugins-tests" +include "kotlin-script-runtime" +include "kotlin-runtime" +include "kotlin-test:kotlin-test-common" +include "kotlin-test:kotlin-test-jvm" +include "kotlin-test:kotlin-test-junit" +include "kotlin-test:kotlin-test-js" +include "kotlin-stdlib-common" +include "kotlin-stdlib" +include "kotlin-stdlib-js" +include "kotlin-stdlib-jre7" +include "kotlin-stdlib-jre8" +include "kotlin-stdlib:samples" +include "prepare:build.version" +//include "prepare:compiler" +//include "prepare:compiler-embeddable" +//include "prepare:reflect" +//include "prepare:runtime" +include "prepare:jps-plugin" +include "prepare:formatter" +include "prepare:ide-lazy-resolver" +include "prepare:kotlin-plugin" +include "prepare:android-lint" +include "prepare:mock-runtime-for-test" +include "kotlin-reflect" +include "ant" +include "compiler:tests-java8" +include "generators" +include 'tools:binary-compatibility-validator' +include 'tools:kotlin-stdlib-js-merger' +include 'tools:kotlin-stdlib-gen' +include ':kotlin-gradle-plugin-api', + ':kotlin-gradle-plugin', + ':kotlin-gradle-plugin-integration-tests', + ':kotlin-allopen', + ':kotlin-noarg', + ':kotlin-sam-with-receiver', + ':kotlin-gradle-subplugin-example' + +include ':examples:annotation-processor-example' + +rootProject.name = "kotlin" + +project(':kotlin-runtime').projectDir = "$rootDir/libraries/tools/runtime" as File +project(':kotlin-script-runtime').projectDir = "$rootDir/libraries/tools/script-runtime" as File +project(':kotlin-test:kotlin-test-common').projectDir = "$rootDir/libraries/kotlin.test/common" as File +project(':kotlin-test:kotlin-test-jvm').projectDir = "$rootDir/libraries/kotlin.test/jvm" as File +project(':kotlin-test:kotlin-test-junit').projectDir = "$rootDir/libraries/kotlin.test/junit" as File +project(':kotlin-test:kotlin-test-js').projectDir = "$rootDir/libraries/kotlin.test/js" as File +project(':kotlin-stdlib-common').projectDir = "$rootDir/libraries/stdlib/common" as File +project(':kotlin-stdlib').projectDir = "$rootDir/libraries/stdlib" as File +project(':kotlin-stdlib-js').projectDir = "$rootDir/libraries/stdlib/js" as File +project(':kotlin-stdlib-jre7').projectDir = "$rootDir/libraries/stdlib/jre7" as File +project(':kotlin-stdlib-jre8').projectDir = "$rootDir/libraries/stdlib/jre8" as File +project(':kotlin-stdlib:samples').projectDir = "$rootDir/libraries/stdlib/samples" as File +project(':kotlin-reflect').projectDir = "$rootDir/libraries/tools/kotlin-reflect" as File +project(':compiler:cli-common').projectDir = "$rootDir/compiler/cli/cli-common" as File +project(':compiler:cli-runner').projectDir = "$rootDir/compiler/cli/cli-runner" as File +project(':compiler:daemon-common').projectDir = "$rootDir/compiler/daemon/daemon-common" as File +project(':compiler:daemon-client').projectDir = "$rootDir/compiler/daemon/daemon-client" as File +project(':compiler:ir.tree').projectDir = "$rootDir/compiler/ir/ir.tree" as File +project(':compiler:ir.psi2ir').projectDir = "$rootDir/compiler/ir/ir.psi2ir" as File +project(':compiler:ir.ir2cfg').projectDir = "$rootDir/compiler/ir/ir.ir2cfg" as File +project(':idea:idea-android-output-parser').projectDir = "$rootDir/idea/idea-android/idea-android-output-parser" as File +project(':plugins:android-extensions-compiler').projectDir = "$rootDir/plugins/android-extensions/android-extensions-compiler" as File +project(':plugins:android-extensions-idea').projectDir = "$rootDir/plugins/android-extensions/android-extensions-idea" as File +project(':plugins:android-extensions-jps').projectDir = "$rootDir/plugins/android-extensions/android-extensions-jps" as File +project(':plugins:allopen-cli').projectDir = "$rootDir/plugins/allopen/allopen-cli" as File +project(':plugins:allopen-ide').projectDir = "$rootDir/plugins/allopen/allopen-ide" as File +project(':plugins:noarg-cli').projectDir = "$rootDir/plugins/noarg/noarg-cli" as File +project(':plugins:noarg-ide').projectDir = "$rootDir/plugins/noarg/noarg-ide" as File +project(':plugins:sam-with-receiver-cli').projectDir = "$rootDir/plugins/sam-with-receiver/sam-with-receiver-cli" as File +project(':plugins:sam-with-receiver-ide').projectDir = "$rootDir/plugins/sam-with-receiver/sam-with-receiver-ide" as File +project(':plugins:source-sections-compiler').projectDir = "$rootDir/plugins/source-sections/source-sections-compiler" as File +project(':tools:binary-compatibility-validator').projectDir = "$rootDir/libraries/tools/binary-compatibility-validator" as File +project(':tools:kotlin-stdlib-js-merger').projectDir = "$rootDir/libraries/tools/kotlin-stdlib-js-merger" as File +project(':tools:kotlin-stdlib-gen').projectDir = "$rootDir/libraries/tools/kotlin-stdlib-gen" as File +project(':kotlin-gradle-plugin-api').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-api" as File +project(':kotlin-gradle-plugin').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin" as File +project(':kotlin-gradle-plugin-integration-tests').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-integration-tests" as File +project(':kotlin-allopen').projectDir = "$rootDir/libraries/tools/kotlin-allopen" as File +project(':kotlin-noarg').projectDir = "$rootDir/libraries/tools/kotlin-noarg" as File +project(':kotlin-sam-with-receiver').projectDir = "$rootDir/libraries/tools/kotlin-sam-with-receiver" as File +project(':kotlin-gradle-subplugin-example').projectDir = "$rootDir/libraries/examples/kotlin-gradle-subplugin-example" as File +project(':examples:annotation-processor-example').projectDir = "$rootDir/libraries/examples/annotation-processor-example" as File + +def setBuildFile(ProjectDescriptor project) { + if (project.projectDir.listFiles().any { file -> file.name == "build.gradle.kts"}) { + project.buildFileName = "build.gradle.kts" + } + project.children.each { p -> setBuildFile(p) } +} + +setBuildFile(rootProject)