From 843cd0001a42db85164af759abc472414176cc33 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Thu, 8 Aug 2019 16:19:33 +0700 Subject: [PATCH] Tests: Support two-stage compilation in external tests --- backend.native/tests/build.gradle | 19 ++++++++++++------ .../org/jetbrains/kotlin/KonanTest.groovy | 20 ++++++++++++++++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 502f90889c1..cf3b726321a 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -88,12 +88,15 @@ project.convention.plugins.executor = ExecutorServiceKt.create(project) // Do not generate run tasks for konan built artifacts ext.konanNoRun = true -// Enable two-stage compilation if the test_two_stage property is set. +// Enable two-stage test compilation if the test_two_stage property is set. ext.twoStageEnabled = project.hasProperty("test_two_stage") -if (twoStageEnabled) { - tasks.withType(KonanCompileNativeBinary.class) { - enableTwoStageCompilation = true - } + +tasks.withType(KonanCompileNativeBinary.class) { + enableTwoStageCompilation = twoStageEnabled +} + +tasks.withType(RunExternalTestGroup.class) { + enableTwoStageCompilation = twoStageEnabled } allprojects { @@ -240,10 +243,14 @@ task resultsTask() { } } -static boolean isExcluded(String dir) { +boolean isExcluded(String dir) { // List of tests that fail due to unresolved compiler bugs def excluded = [ "codegen/box/functions/bigArity" /* KT-26140 */ ] + if (project.twoStageEnabled) { + excluded += ["codegen/box/closures/captureInSuperConstructorCall", "codegen/box/enum"] // KT-33207. + } + boolean result = false excluded.forEach { if (dir.endsWith(it.replace("/", File.separator))) { diff --git a/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index a26b35e1941..3d888227d54 100644 --- a/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -16,6 +16,7 @@ package org.jetbrains.kotlin +import org.gradle.api.tasks.Input import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.TaskAction import org.gradle.process.ExecResult @@ -297,6 +298,14 @@ class RunExternalTestGroup extends OldKonanTest { */ public def inDevelopersRun = false + /** + * If true, the test executable will be built in two stages: + * 1. Build a klibrary from sources. + * 2. Build a final executable from this klibrary. + */ + @Input + public def enableTwoStageCompilation = false + def groupDirectory = "." def outputSourceSetName = "testOutputExternal" String filter = project.findProperty("filter") @@ -608,7 +617,16 @@ fun runTest() { compileList.add(project.file("testUtils.kt").absolutePath) compileList.add(project.file("helpers.kt").absolutePath) try { - runCompiler(compileList, buildExePath(), flags) + def exePath = buildExePath() + if (enableTwoStageCompilation) { + // Two-stage compilation. + def klibPath = "${exePath}.klib" + runCompiler(compileList, klibPath, flags + ["-p", "library"]) + runCompiler([], exePath, flags + ["-l", klibPath, "-Xsource-library=$klibPath"]) + } else { + // Regular compilation. + runCompiler(compileList, exePath, flags) + } } catch (Exception ex) { project.logger.quiet("ERROR: Compilation failed for test suite: $name with exception", ex) project.logger.quiet("The following files were unable to compile:")