[gradle-plugin] Support KONAN_ENABLE_OPTIMIZATIONS env variable

This commit is contained in:
Ilya Matveev
2018-03-12 14:15:21 +03:00
committed by ilmat192
parent 489b1a5708
commit 40f76419a2
3 changed files with 30 additions and 16 deletions
@@ -23,13 +23,18 @@ import java.io.File
/** /**
* The plugin allows an IDE to specify some building parameters. These parameters * The plugin allows an IDE to specify some building parameters. These parameters
* are passed to the plugin via environment variables. Two variables are supported: * are passed to the plugin via environment variables. Two variables are supported:
* - CONFIGURATION_BUILD_DIR - an absolute path to a destination directory for all compilation tasks. * - CONFIGURATION_BUILD_DIR - An absolute path to a destination directory for all compilation tasks.
* The IDE should take care about specifying different directories * The IDE should take care about specifying different directories
* for different targets. This setting has less priority than * for different targets. This setting has less priority than
* an explicitly specified destination directory in the build script. * an explicitly specified destination directory in the build script.
* - DEBUGGING_SYMBOLS - If YES, the debug support will be enabled for all artifacts. This option has less *
* priority than explicitly specified enableDebug option in the build script and * - DEBUGGING_SYMBOLS - If YES, the debug support will be enabled for all artifacts. This option has less
* enableDebug project property. * priority than explicitly specified enableDebug option in the build script and
* enableDebug project property.
*
* - KONAN_ENABLE_OPTIMIZATIONS - If YES, optimizations will be enabled for all artifacts by default. This option
* has less priority than explicitly specified enableOptimizations option in the
* build script.
* *
* Support for environment variables should be explicitly enabled by setting a project property: * Support for environment variables should be explicitly enabled by setting a project property:
* konan.useEnvironmentVariables = true. * konan.useEnvironmentVariables = true.
@@ -38,6 +43,7 @@ import java.io.File
internal interface EnvironmentVariables { internal interface EnvironmentVariables {
val configurationBuildDir: File? val configurationBuildDir: File?
val debuggingSymbols: Boolean val debuggingSymbols: Boolean
val enableOptimizations: Boolean
} }
internal class EnvironmentVariablesUnused: EnvironmentVariables { internal class EnvironmentVariablesUnused: EnvironmentVariables {
@@ -46,6 +52,9 @@ internal class EnvironmentVariablesUnused: EnvironmentVariables {
override val debuggingSymbols: Boolean override val debuggingSymbols: Boolean
get() = false get() = false
override val enableOptimizations: Boolean
get() = false
} }
internal class EnvironmentVariablesImpl: EnvironmentVariables { internal class EnvironmentVariablesImpl: EnvironmentVariables {
@@ -56,6 +65,9 @@ internal class EnvironmentVariablesImpl: EnvironmentVariables {
override val debuggingSymbols: Boolean override val debuggingSymbols: Boolean
get() = System.getenv("DEBUGGING_SYMBOLS")?.toUpperCase() == "YES" get() = System.getenv("DEBUGGING_SYMBOLS")?.toUpperCase() == "YES"
override val enableOptimizations: Boolean
get() = System.getenv("KONAN_ENABLE_OPTIMIZATIONS")?.toUpperCase() == "YES"
} }
internal val Project.useEnvironmentVariables: Boolean internal val Project.useEnvironmentVariables: Boolean
@@ -74,7 +74,7 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
@Input var noStdLib = false @Input var noStdLib = false
@Input var noMain = false @Input var noMain = false
@Input var enableOptimizations = false @Input var enableOptimizations = project.environmentVariables.enableOptimizations
@Input var enableAssertions = false @Input var enableAssertions = false
@Optional @Input var entryPoint: String? = null @Optional @Input var entryPoint: String? = null
@@ -53,7 +53,7 @@ class EnvVariableSpecification extends BaseKonanSpecification {
// Gradle TestKit doesn't support setting environment variables for runners. // Gradle TestKit doesn't support setting environment variables for runners.
// So we use the following hack: we create a gradle wrapper, start it as a separate // So we use the following hack: we create a gradle wrapper, start it as a separate
// process with custom environment variables and check its exit code. // process with custom environment variables and check its exit code and output.
runner.withArguments("wrapper").build() runner.withArguments("wrapper").build()
def classpath = runner.pluginClasspath.collect { "'${escapeBackSlashes(it.absolutePath)}'" }.join(", ") def classpath = runner.pluginClasspath.collect { "'${escapeBackSlashes(it.absolutePath)}'" }.join(", ")
@@ -113,8 +113,8 @@ class EnvVariableSpecification extends BaseKonanSpecification {
return "$prefix${baseName}.$suffix" return "$prefix${baseName}.$suffix"
} }
@Unroll("Plugin should support #action debug via an env variable") @Unroll("Plugin should support #action via an env variable")
def 'Plugin should support enabling/disabling debug via an env variable'() { def 'Plugin should support enabling/disabling debug/opt via an env variable'() {
when: when:
def project = createProjectWithWrapper() def project = createProjectWithWrapper()
project.buildFile.append("""\ project.buildFile.append("""\
@@ -126,12 +126,12 @@ class EnvVariableSpecification extends BaseKonanSpecification {
task assertEnableDebug { task assertEnableDebug {
doLast { doLast {
konanArtifacts.main.forEach { konanArtifacts.main.forEach {
$check if (!$assertion) throw new AssertionError("$message for \${it.name}")
} }
} }
} }
""".stripIndent()) """.stripIndent())
def result = runWrapper(project,"assertEnableDebug", ["DEBUGGING_SYMBOLS": value]) def result = runWrapper(project,"assertEnableDebug", [(variable): value])
.printStderr() .printStderr()
.getExitValue() .getExitValue()
@@ -139,9 +139,11 @@ class EnvVariableSpecification extends BaseKonanSpecification {
result == 0 result == 0
where: where:
action |value |check action |variable |value |assertion |message
"enabling" |"YES" |"if (!it.enableDebug) throw new AssertionError(\"Debug should be enabled for \${it.name}\")" "enabling debug" |"DEBUGGING_SYMBOLS" |"YES" |"it.enableDebug" |"Debug should be enabled"
"disabling" |"NO" |"if (it.enableDebug) throw new AssertionError(\"Debug should be disabled for \${it.name}\")" "disabling debug" |"DEBUGGING_SYMBOLS" |"NO" |"!it.enableDebug" |"Debug should be disabled"
"enabling opt" |"KONAN_ENABLE_OPTIMIZATIONS" |"YES" |"it.enableOptimizations" |"Opts should be enabled"
"disabling opt" |"KONAN_ENABLE_OPTIMIZATIONS" |"NO" |"!it.enableOptimizations" |"Opts should be disabled"
} }
def 'Plugin should support setting destination directory via an env variable'() { def 'Plugin should support setting destination directory via an env variable'() {