From 6bee5699a09018983085fe9e6266c7dd6b6845a5 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Thu, 16 Nov 2017 21:41:54 +0300 Subject: [PATCH] Migrate node_utils.xml to Gradle --- .idea/ant.xml | 1 - build.gradle.kts | 1 + gradle/project-schema.json | 81 +++++++-- js/js.tests/build.gradle.kts | 29 ++++ js/js.translator/testData/package.json | 5 +- js/npm/build.gradle.kts | 96 +++++++++++ .../templates}/kotlin-compiler/README.md | 0 .../kotlin-compiler/bin/kotlinc-js-runner.js | 0 .../templates}/kotlin-compiler/package.json | 0 .../templates}/kotlin-test/README.md | 0 .../templates}/kotlin-test/package.json | 0 .../templates}/kotlin/README.md | 0 .../templates}/kotlin/package.json | 0 node_utils.xml | 158 ------------------ settings.gradle | 1 + update_dependencies.xml | 3 - 16 files changed, 199 insertions(+), 176 deletions(-) create mode 100644 js/npm/build.gradle.kts rename js/{npm.templates => npm/templates}/kotlin-compiler/README.md (100%) rename js/{npm.templates => npm/templates}/kotlin-compiler/bin/kotlinc-js-runner.js (100%) rename js/{npm.templates => npm/templates}/kotlin-compiler/package.json (100%) rename js/{npm.templates => npm/templates}/kotlin-test/README.md (100%) rename js/{npm.templates => npm/templates}/kotlin-test/package.json (100%) rename js/{npm.templates => npm/templates}/kotlin/README.md (100%) rename js/{npm.templates => npm/templates}/kotlin/package.json (100%) delete mode 100644 node_utils.xml diff --git a/.idea/ant.xml b/.idea/ant.xml index 455b5c0df03..ae4e3216647 100644 --- a/.idea/ant.xml +++ b/.idea/ant.xml @@ -18,6 +18,5 @@ - \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 61513c3ce0b..ad6cd83c605 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -343,6 +343,7 @@ tasks { "jsCompilerTest" { dependsOn(":js:js.tests:test") + dependsOn(":js:js.tests:runMocha") } "scriptingTest" { diff --git a/gradle/project-schema.json b/gradle/project-schema.json index 52efa7929c1..10d1f5609e4 100644 --- a/gradle/project-schema.json +++ b/gradle/project-schema.json @@ -90,8 +90,7 @@ "testJvm6ServerRuntime", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly", - "tests-jar" + "testRuntimeOnly" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -428,7 +427,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "tests-jar" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -619,6 +619,46 @@ "signing": "org.gradle.plugins.signing.SigningExtension" } }, + ":kotlin-annotation-processing-runtime": { + "conventions": { + "base": "org.gradle.api.plugins.BasePluginConvention", + "java": "org.gradle.api.plugins.JavaPluginConvention", + "maven": "org.gradle.api.plugins.MavenPluginConvention" + }, + "configurations": [ + "apiElements", + "archives", + "compile", + "compileClasspath", + "compileOnly", + "default", + "distJar", + "implementation", + "kapt", + "kaptTest", + "runtime", + "runtimeClasspath", + "runtimeElements", + "runtimeJar", + "runtimeOnly", + "signatures", + "testCompile", + "testCompileClasspath", + "testCompileOnly", + "testImplementation", + "testRuntime", + "testRuntimeClasspath", + "testRuntimeOnly" + ], + "extensions": { + "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", + "kotlin": "org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension", + "kapt": "org.jetbrains.kotlin.gradle.plugin.KaptExtension", + "defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet", + "reporting": "org.gradle.api.reporting.ReportingExtension", + "signing": "org.gradle.plugins.signing.SigningExtension" + } + }, ":kotlin-annotations-android": { "conventions": { "base": "org.gradle.api.plugins.BasePluginConvention", @@ -1223,7 +1263,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "tests-jar" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -1291,7 +1332,6 @@ "runtimeClasspath", "runtimeElements", "runtimeOnly", - "shadow", "shadows", "signatures", "testCompile", @@ -1304,7 +1344,6 @@ ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", - "shadow": "com.github.jengelman.gradle.plugins.shadow.ShadowExtension", "defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet", "reporting": "org.gradle.api.reporting.ReportingExtension", "signing": "org.gradle.plugins.signing.SigningExtension" @@ -1491,7 +1530,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "tests-jar" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -2235,7 +2275,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "tests-jar" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -2939,8 +2980,7 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly", - "tests-jar" + "testRuntimeOnly" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -3922,6 +3962,7 @@ ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", + "node": "com.moowork.gradle.node.NodeExtension", "kotlin": "org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension", "kapt": "org.jetbrains.kotlin.gradle.plugin.KaptExtension", "defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet", @@ -3964,6 +4005,20 @@ "reporting": "org.gradle.api.reporting.ReportingExtension" } }, + ":js:npm": { + "conventions": { + "base": "org.gradle.api.plugins.BasePluginConvention" + }, + "configurations": [ + "archives", + "default" + ], + "extensions": { + "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", + "node": "com.moowork.gradle.node.NodeExtension", + "defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet" + } + }, ":kotlin-allopen:plugin-marker": { "conventions": { "base": "org.gradle.api.plugins.BasePluginConvention", @@ -4323,7 +4378,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "tests-jar" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -4395,7 +4451,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "tests-jar" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", diff --git a/js/js.tests/build.gradle.kts b/js/js.tests/build.gradle.kts index a468813e700..bb2f013be3e 100644 --- a/js/js.tests/build.gradle.kts +++ b/js/js.tests/build.gradle.kts @@ -1,3 +1,14 @@ +import com.moowork.gradle.node.exec.ExecRunner +import com.moowork.gradle.node.npm.NpmExecRunner +import com.moowork.gradle.node.npm.NpmTask + +plugins { + id("com.moowork.node").version("1.2.0") +} + +node { + download = true +} apply { plugin("kotlin") } @@ -52,3 +63,21 @@ projectTest("quickTest") { } val generateTests by generator("org.jetbrains.kotlin.generators.tests.GenerateJsTestsKt") +val testDataDir = project(":js:js.translator").projectDir.resolve("testData") + +val install by task { + setWorkingDir(testDataDir) + setArgs(listOf("install")) +} + +val runMocha by task { + setWorkingDir(testDataDir) + + val target = if (project.hasProperty("teamcity")) "runOnTeamcity" else "test" + setArgs(listOf("run", target)) + + dependsOn(install, "test") + + val check by tasks + check.dependsOn(this) +} diff --git a/js/js.translator/testData/package.json b/js/js.translator/testData/package.json index 2ec8d68df11..a5be3334eae 100644 --- a/js/js.translator/testData/package.json +++ b/js/js.translator/testData/package.json @@ -7,6 +7,7 @@ "mocha-teamcity-reporter": "1.1.1" }, "scripts": { - "test": "mocha --reporter mocha-teamcity-reporter" + "runOnTeamcity": "mocha --reporter mocha-teamcity-reporter", + "test": "mocha" } -} \ No newline at end of file +} diff --git a/js/npm/build.gradle.kts b/js/npm/build.gradle.kts new file mode 100644 index 00000000000..ebec1de1924 --- /dev/null +++ b/js/npm/build.gradle.kts @@ -0,0 +1,96 @@ +import com.moowork.gradle.node.npm.NpmTask + +plugins { + id("com.moowork.node").version("1.2.0") + base +} + +description = "Node utils" + +node { + download = true +} + +val deployDir = "$buildDir/deploy_to_npm" +val templateDir = "$projectDir/templates" +val kotlincDir = rootProject.extra["distKotlinHomeDir"] as String + +fun getProperty(name: String, default: String = "") = findProperty(name)?.toString() ?: default + +val deployVersion = getProperty("kotlin.deploy.version", "0.0.0") +val deployTag = getProperty("kotlin.deploy.tag", "dev") +val authToken = getProperty("kotlin.npmjs.auth.token") +val dryRun = getProperty("dryRun", "false") // Pack instead of publish + +fun Project.createCopyTemplateTask(templateName: String): Copy { + return task("copy-$templateName-template") { + from("$templateDir/$templateName") + into("$deployDir/$templateName") + + expand(hashMapOf("version" to deployVersion)) + } +} + +fun Project.createCopyLibraryFilesTask(libraryName: String, fromJar: String): Copy { + return task("copy-$libraryName-library") { + from(zipTree(fromJar).matching { + include("$libraryName.js") + include("$libraryName.meta.js") + include("$libraryName.js.map") + include("$libraryName/**") + }) + + into("$deployDir/$libraryName") + } +} + +fun Project.createPublishToNpmTask(templateName: String): NpmTask { + return task("publish-$templateName-to-npm") { + val deployDir = File("$deployDir/$templateName") + setWorkingDir(deployDir) + + val deployArgs = listOf("publish", "--//registry.npmjs.org/:_authToken=$authToken", "--tag=$deployTag") + if (dryRun == "true") { + println("$deployDir \$ npm arguments: $deployArgs"); + setArgs(listOf("pack")) + } + else { + setArgs(deployArgs) + } + } +} + +fun sequential(first: Task, vararg tasks: Task): Task { + tasks.fold(first) { previousTask, currentTask -> + currentTask.dependsOn(previousTask) + } + return tasks.last() +} + +val publishKotlinJs = sequential( + createCopyTemplateTask("kotlin"), + createCopyLibraryFilesTask("kotlin", "$kotlincDir/lib/kotlin-stdlib-js.jar"), + createPublishToNpmTask("kotlin") +) + +val publishKotlinCompiler = sequential( + createCopyTemplateTask("kotlin-compiler"), + task("copy-kotlin-compiler") { + from(kotlincDir) + into("$deployDir/kotlin-compiler") + }, + task("chmod-kotlinc-bin") { + commandLine = listOf("chmod", "-R", "ugo+rx", "$deployDir/kotlin-compiler/bin") + }, + createPublishToNpmTask("kotlin-compiler") +) + +val publishKotlinTest = sequential( + createCopyTemplateTask("kotlin-test"), + createCopyLibraryFilesTask("kotlin-test", "$kotlincDir/lib/kotlin-test-js.jar"), + createPublishToNpmTask("kotlin-test") +) + +task("publishAll") { + dependsOn(publishKotlinJs, publishKotlinTest, publishKotlinCompiler) +} diff --git a/js/npm.templates/kotlin-compiler/README.md b/js/npm/templates/kotlin-compiler/README.md similarity index 100% rename from js/npm.templates/kotlin-compiler/README.md rename to js/npm/templates/kotlin-compiler/README.md diff --git a/js/npm.templates/kotlin-compiler/bin/kotlinc-js-runner.js b/js/npm/templates/kotlin-compiler/bin/kotlinc-js-runner.js similarity index 100% rename from js/npm.templates/kotlin-compiler/bin/kotlinc-js-runner.js rename to js/npm/templates/kotlin-compiler/bin/kotlinc-js-runner.js diff --git a/js/npm.templates/kotlin-compiler/package.json b/js/npm/templates/kotlin-compiler/package.json similarity index 100% rename from js/npm.templates/kotlin-compiler/package.json rename to js/npm/templates/kotlin-compiler/package.json diff --git a/js/npm.templates/kotlin-test/README.md b/js/npm/templates/kotlin-test/README.md similarity index 100% rename from js/npm.templates/kotlin-test/README.md rename to js/npm/templates/kotlin-test/README.md diff --git a/js/npm.templates/kotlin-test/package.json b/js/npm/templates/kotlin-test/package.json similarity index 100% rename from js/npm.templates/kotlin-test/package.json rename to js/npm/templates/kotlin-test/package.json diff --git a/js/npm.templates/kotlin/README.md b/js/npm/templates/kotlin/README.md similarity index 100% rename from js/npm.templates/kotlin/README.md rename to js/npm/templates/kotlin/README.md diff --git a/js/npm.templates/kotlin/package.json b/js/npm/templates/kotlin/package.json similarity index 100% rename from js/npm.templates/kotlin/package.json rename to js/npm/templates/kotlin/package.json diff --git a/node_utils.xml b/node_utils.xml deleted file mode 100644 index cbb63e409d6..00000000000 --- a/node_utils.xml +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/settings.gradle b/settings.gradle index 780e978f2ab..9ae802b4b06 100644 --- a/settings.gradle +++ b/settings.gradle @@ -47,6 +47,7 @@ include ":kotlin-build-common", ":js:js.translator", ":js:js.dce", ":js:js.tests", + ":js:npm", ":jps-plugin", ":kotlin-jps-plugin", ":core:descriptors", diff --git a/update_dependencies.xml b/update_dependencies.xml index 7800be3738b..bf58a9d3fd9 100644 --- a/update_dependencies.xml +++ b/update_dependencies.xml @@ -1,6 +1,5 @@ - @@ -270,8 +269,6 @@ build.number.pattern="\d+\s-\sKotlin\s[\w-+\.]+" /> - -