[gradle-plugin] Support KONAN_ENABLE_OPTIMIZATIONS env variable
This commit is contained in:
+19
-7
@@ -23,13 +23,18 @@ import java.io.File
|
||||
/**
|
||||
* The plugin allows an IDE to specify some building parameters. These parameters
|
||||
* 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.
|
||||
* The IDE should take care about specifying different directories
|
||||
* for different targets. This setting has less priority than
|
||||
* 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
|
||||
* enableDebug project property.
|
||||
* - CONFIGURATION_BUILD_DIR - An absolute path to a destination directory for all compilation tasks.
|
||||
* The IDE should take care about specifying different directories
|
||||
* for different targets. This setting has less priority than
|
||||
* 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
|
||||
* 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:
|
||||
* konan.useEnvironmentVariables = true.
|
||||
@@ -38,6 +43,7 @@ import java.io.File
|
||||
internal interface EnvironmentVariables {
|
||||
val configurationBuildDir: File?
|
||||
val debuggingSymbols: Boolean
|
||||
val enableOptimizations: Boolean
|
||||
}
|
||||
|
||||
internal class EnvironmentVariablesUnused: EnvironmentVariables {
|
||||
@@ -46,6 +52,9 @@ internal class EnvironmentVariablesUnused: EnvironmentVariables {
|
||||
|
||||
override val debuggingSymbols: Boolean
|
||||
get() = false
|
||||
|
||||
override val enableOptimizations: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
internal class EnvironmentVariablesImpl: EnvironmentVariables {
|
||||
@@ -56,6 +65,9 @@ internal class EnvironmentVariablesImpl: EnvironmentVariables {
|
||||
|
||||
override val debuggingSymbols: Boolean
|
||||
get() = System.getenv("DEBUGGING_SYMBOLS")?.toUpperCase() == "YES"
|
||||
|
||||
override val enableOptimizations: Boolean
|
||||
get() = System.getenv("KONAN_ENABLE_OPTIMIZATIONS")?.toUpperCase() == "YES"
|
||||
}
|
||||
|
||||
internal val Project.useEnvironmentVariables: Boolean
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
||||
|
||||
@Input var noStdLib = false
|
||||
@Input var noMain = false
|
||||
@Input var enableOptimizations = false
|
||||
@Input var enableOptimizations = project.environmentVariables.enableOptimizations
|
||||
@Input var enableAssertions = false
|
||||
|
||||
@Optional @Input var entryPoint: String? = null
|
||||
|
||||
+10
-8
@@ -53,7 +53,7 @@ class EnvVariableSpecification extends BaseKonanSpecification {
|
||||
|
||||
// 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
|
||||
// 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()
|
||||
|
||||
def classpath = runner.pluginClasspath.collect { "'${escapeBackSlashes(it.absolutePath)}'" }.join(", ")
|
||||
@@ -113,8 +113,8 @@ class EnvVariableSpecification extends BaseKonanSpecification {
|
||||
return "$prefix${baseName}.$suffix"
|
||||
}
|
||||
|
||||
@Unroll("Plugin should support #action debug via an env variable")
|
||||
def 'Plugin should support enabling/disabling debug via an env variable'() {
|
||||
@Unroll("Plugin should support #action via an env variable")
|
||||
def 'Plugin should support enabling/disabling debug/opt via an env variable'() {
|
||||
when:
|
||||
def project = createProjectWithWrapper()
|
||||
project.buildFile.append("""\
|
||||
@@ -126,12 +126,12 @@ class EnvVariableSpecification extends BaseKonanSpecification {
|
||||
task assertEnableDebug {
|
||||
doLast {
|
||||
konanArtifacts.main.forEach {
|
||||
$check
|
||||
if (!$assertion) throw new AssertionError("$message for \${it.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
""".stripIndent())
|
||||
def result = runWrapper(project,"assertEnableDebug", ["DEBUGGING_SYMBOLS": value])
|
||||
def result = runWrapper(project,"assertEnableDebug", [(variable): value])
|
||||
.printStderr()
|
||||
.getExitValue()
|
||||
|
||||
@@ -139,9 +139,11 @@ class EnvVariableSpecification extends BaseKonanSpecification {
|
||||
result == 0
|
||||
|
||||
where:
|
||||
action |value |check
|
||||
"enabling" |"YES" |"if (!it.enableDebug) throw new AssertionError(\"Debug should be enabled for \${it.name}\")"
|
||||
"disabling" |"NO" |"if (it.enableDebug) throw new AssertionError(\"Debug should be disabled for \${it.name}\")"
|
||||
action |variable |value |assertion |message
|
||||
"enabling debug" |"DEBUGGING_SYMBOLS" |"YES" |"it.enableDebug" |"Debug should be enabled"
|
||||
"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'() {
|
||||
|
||||
Reference in New Issue
Block a user