Support mutable/immutable compiler arguments

This commit is contained in:
Alexey Sedunov
2017-07-27 15:21:53 +03:00
parent 2984a5a19f
commit 40163868af
14 changed files with 157 additions and 107 deletions
@@ -37,7 +37,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<version>",
description = "Provide source compatibility with specified language version"
)
var languageVersion: String? = null
var languageVersion: String? by FreezableVar(null)
@GradleOption(DefaultValues.LanguageVersions::class)
@Argument(
@@ -45,22 +45,22 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<version>",
description = "Allow to use declarations only from the specified version of bundled libraries"
)
var apiVersion: String? = null
var apiVersion: String? by FreezableVar(null)
@Argument(
value = "-kotlin-home",
valueDescription = "<path>",
description = "Path to Kotlin compiler home directory, used for runtime libraries discovery"
)
var kotlinHome: String? = null
var kotlinHome: String? by FreezableVar(null)
@Argument(value = "-P", valueDescription = PLUGIN_OPTION_FORMAT, description = "Pass an option to a plugin")
var pluginOptions: Array<String>? = null
var pluginOptions: Array<String>? by FreezableVar(null)
// Advanced options
@Argument(value = "-Xno-inline", description = "Disable method inlining")
var noInline: Boolean = false
var noInline: Boolean by FreezableVar(false)
// TODO Remove in 1.0
@Argument(
@@ -68,42 +68,42 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<count>",
description = "Repeat compilation (for performance analysis)"
)
var repeat: String? = null
var repeat: String? by FreezableVar(null)
@Argument(
value = "-Xskip-metadata-version-check",
description = "Load classes with bad metadata version anyway (incl. pre-release classes)"
)
var skipMetadataVersionCheck: Boolean = false
var skipMetadataVersionCheck: Boolean by FreezableVar(false)
@Argument(value = "-Xallow-kotlin-package", description = "Allow compiling code in package 'kotlin'")
var allowKotlinPackage: Boolean = false
var allowKotlinPackage: Boolean by FreezableVar(false)
@Argument(value = "-Xreport-output-files", description = "Report source to output files mapping")
var reportOutputFiles: Boolean = false
var reportOutputFiles: Boolean by FreezableVar(false)
@Argument(value = "-Xplugin", valueDescription = "<path>", description = "Load plugins from the given classpath")
var pluginClasspaths: Array<String>? = null
var pluginClasspaths: Array<String>? by FreezableVar(null)
@Argument(value = "-Xmulti-platform", description = "Enable experimental language support for multi-platform projects")
var multiPlatform: Boolean = false
var multiPlatform: Boolean by FreezableVar(false)
@Argument(value = "-Xno-check-impl", description = "Do not check presence of 'impl' modifier in multi-platform projects")
var noCheckImpl: Boolean = false
var noCheckImpl: Boolean by FreezableVar(false)
@Argument(
value = "-Xintellij-plugin-root",
valueDescription = "<path>",
description = "Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found"
)
var intellijPluginRoot: String? = null
var intellijPluginRoot: String? by FreezableVar(null)
@Argument(
value = "-Xcoroutines",
valueDescription = "{enable|warn|error}",
description = "Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier"
)
var coroutinesState: String? = WARN
var coroutinesState: String? by FreezableVar(WARN)
open fun configureAnalysisFlags(): MutableMap<AnalysisFlag<*>, Any> {
return HashMap<AnalysisFlag<*>, Any>().apply {
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.cli.common.arguments
import org.jetbrains.kotlin.utils.SmartList
import java.io.Serializable
abstract class CommonToolArguments : Serializable {
abstract class CommonToolArguments : Freezable(), Serializable {
companion object {
@JvmStatic private val serialVersionUID = 0L
}
@@ -29,19 +29,19 @@ abstract class CommonToolArguments : Serializable {
@Transient var errors: ArgumentParseErrors = ArgumentParseErrors()
@Argument(value = "-help", shortName = "-h", description = "Print a synopsis of standard options")
var help: Boolean = false
var help: Boolean by FreezableVar(false)
@Argument(value = "-X", description = "Print a synopsis of advanced options")
var extraHelp: Boolean = false
var extraHelp: Boolean by FreezableVar(false)
@Argument(value = "-version", description = "Display compiler version")
var version: Boolean = false
var version: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-verbose", description = "Enable verbose logging output")
var verbose: Boolean = false
var verbose: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-nowarn", description = "Generate no warnings")
var suppressWarnings: Boolean = false
var suppressWarnings: Boolean by FreezableVar(false)
}
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.cli.common.arguments
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
abstract class Freezable {
protected inner class FreezableVar<T>(private var value: T) : ReadWriteProperty<Any, T> {
override fun getValue(thisRef: Any, property: KProperty<*>) = value
override fun setValue(thisRef: Any, property: KProperty<*>, value: T) {
if (frozen) throw IllegalStateException("Instance of ${this::class} is frozen")
this.value = value
}
}
private var frozen: Boolean = false
private fun getInstanceWithFreezeStatus(value: Boolean) = if (value == frozen) this else copyBean(this).apply { frozen = value }
fun frozen() = getInstanceWithFreezeStatus(true)
fun unfrozen() = getInstanceWithFreezeStatus(false)
}
@@ -26,33 +26,33 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
@GradleOption(DefaultValues.StringNullDefault::class)
@Argument(value = "-output", valueDescription = "<path>", description = "Output file path")
var outputFile: String? = null
var outputFile: String? by FreezableVar(null)
@GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-no-stdlib", description = "Don't use bundled Kotlin stdlib")
var noStdlib: Boolean = false
var noStdlib: Boolean by FreezableVar(false)
@Argument(
value = "-libraries",
valueDescription = "<path>",
description = "Paths to Kotlin libraries with .meta.js and .kjsm files, separated by system path separator"
)
var libraries: String? = null
var libraries: String? by FreezableVar(null)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-source-map", description = "Generate source map")
var sourceMap: Boolean = false
var sourceMap: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.StringNullDefault::class)
@Argument(value = "-source-map-prefix", description = "Prefix for paths in a source map")
var sourceMapPrefix: String? = null
var sourceMapPrefix: String? by FreezableVar(null)
@Argument(
value = "-source-map-source-roots",
valueDescription = "<path>",
description = "Base directories which are used to calculate relative paths to source files in source map"
)
var sourceMapSourceRoots: String? = null
var sourceMapSourceRoots: String? by FreezableVar(null)
@GradleOption(DefaultValues.JsSourceMapContentModes::class)
@Argument(
@@ -60,15 +60,15 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
valueDescription = "{ always, never, inlining }",
description = "Embed source files into source map"
)
var sourceMapEmbedSources: String? = null
var sourceMapEmbedSources: String? by FreezableVar(null)
@GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-meta-info", description = "Generate .meta.js and .kjsm files with metadata. Use to create a library")
var metaInfo: Boolean = false
var metaInfo: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.JsEcmaVersions::class)
@Argument(value = "-target", valueDescription = "{ v5 }", description = "Generate JS files for specific ECMA version")
var target: String? = null
var target: String? by FreezableVar(null)
@GradleOption(DefaultValues.JsModuleKinds::class)
@Argument(
@@ -76,40 +76,40 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
valueDescription = "{ plain, amd, commonjs, umd }",
description = "Kind of a module generated by compiler"
)
var moduleKind: String? = K2JsArgumentConstants.MODULE_PLAIN
var moduleKind: String? by FreezableVar(K2JsArgumentConstants.MODULE_PLAIN)
@GradleOption(DefaultValues.JsMain::class)
@Argument(value = "-main", valueDescription = "{$CALL,$NO_CALL}", description = "Whether a main function should be called")
var main: String? = null
var main: String? by FreezableVar(null)
@Argument(
value = "-output-prefix",
valueDescription = "<path>",
description = "Path to file which will be added to the beginning of output file"
)
var outputPrefix: String? = null
var outputPrefix: String? by FreezableVar(null)
@Argument(
value = "-output-postfix",
valueDescription = "<path>",
description = "Path to file which will be added to the end of output file"
)
var outputPostfix: String? = null
var outputPostfix: String? by FreezableVar(null)
// Advanced options
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-Xtyped-arrays", description = "Translate primitive arrays to JS typed arrays")
var typedArrays: Boolean = false
var typedArrays: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-Xfriend-modules-disabled", description = "Disable internal declaration export")
var friendModulesDisabled: Boolean = false
var friendModulesDisabled: Boolean by FreezableVar(false)
@Argument(
value = "-Xfriend-modules",
valueDescription = "<path>",
description = "Paths to friend modules"
)
var friendModules: String? = null
var friendModules: String? by FreezableVar(null)
}
@@ -26,18 +26,18 @@ class K2JSDceArguments : CommonToolArguments() {
valueDescription = "<path>",
description = "Output directory"
)
var outputDirectory: String? = null
var outputDirectory: String? by FreezableVar(null)
@Argument(
value = "-keep",
valueDescription = "<fully.qualified.name[,]>",
description = "List of fully-qualified names of declarations that shouldn't be eliminated"
)
var declarationsToKeep: Array<String>? = null
var declarationsToKeep: Array<String>? by FreezableVar(null)
@Argument(
value = "-Xprint-reachability-info",
description = "Print declarations marked as reachable"
)
var printReachabilityInfo: Boolean = false
var printReachabilityInfo: Boolean by FreezableVar(false)
}
@@ -26,14 +26,14 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
}
@Argument(value = "-d", valueDescription = "<directory|jar>", description = "Destination for generated class files")
var destination: String? = null
var destination: String? by FreezableVar(null)
@Argument(value = "-classpath", shortName = "-cp", valueDescription = "<path>", description = "Paths where to find user class files")
var classpath: String? = null
var classpath: String? by FreezableVar(null)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-include-runtime", description = "Include Kotlin runtime in to resulting .jar")
var includeRuntime: Boolean = false
var includeRuntime: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.StringNullDefault::class)
@Argument(
@@ -41,32 +41,32 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>",
description = "Path to JDK home directory to include into classpath, if differs from default JAVA_HOME"
)
var jdkHome: String? = null
var jdkHome: String? by FreezableVar(null)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-no-jdk", description = "Don't include Java runtime into classpath")
var noJdk: Boolean = false
var noJdk: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-no-stdlib", description = "Don't include Kotlin runtime into classpath")
var noStdlib: Boolean = false
var noStdlib: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-no-reflect", description = "Don't include Kotlin reflection implementation into classpath")
var noReflect: Boolean = false
var noReflect: Boolean by FreezableVar(false)
@Argument(value = "-script", description = "Evaluate the script file")
var script: Boolean = false
var script: Boolean by FreezableVar(false)
@Argument(
value = "-script-templates",
valueDescription = "<fully qualified class name[,]>",
description = "Script definition template classes"
)
var scriptTemplates: Array<String>? = null
var scriptTemplates: Array<String>? by FreezableVar(null)
@Argument(value = "-module-name", description = "Module name")
var moduleName: String? = null
var moduleName: String? by FreezableVar(null)
@GradleOption(DefaultValues.JvmTargetVersions::class)
@Argument(
@@ -74,16 +74,16 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "<version>",
description = "Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6"
)
var jvmTarget: String? = JvmTarget.DEFAULT.description
var jvmTarget: String? by FreezableVar(JvmTarget.DEFAULT.description)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-java-parameters", description = "Generate metadata for Java 1.8 reflection on method parameters")
var javaParameters: Boolean = false
var javaParameters: Boolean by FreezableVar(false)
// Advanced options
@Argument(value = "-Xmodule-path", valueDescription = "<path>", description = "Paths where to find Java 9+ modules")
var javaModulePath: String? = null
var javaModulePath: String? by FreezableVar(null)
@Argument(
value = "-Xadd-modules",
@@ -91,78 +91,78 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
description = "Root modules to resolve in addition to the initial modules,\n" +
"or all modules on the module path if <module> is ALL-MODULE-PATH"
)
var additionalJavaModules: Array<String>? = null
var additionalJavaModules: Array<String>? by FreezableVar(null)
@Argument(value = "-Xno-call-assertions", description = "Don't generate not-null assertion after each invocation of method returning not-null")
var noCallAssertions: Boolean = false
var noCallAssertions: Boolean by FreezableVar(false)
@Argument(value = "-Xno-param-assertions", description = "Don't generate not-null assertions on parameters of methods accessible from Java")
var noParamAssertions: Boolean = false
var noParamAssertions: Boolean by FreezableVar(false)
@Argument(value = "-Xno-optimize", description = "Disable optimizations")
var noOptimize: Boolean = false
var noOptimize: Boolean by FreezableVar(false)
@Argument(value = "-Xreport-perf", description = "Report detailed performance statistics")
var reportPerf: Boolean = false
var reportPerf: Boolean by FreezableVar(false)
@Argument(value = "-Xbuild-file", deprecatedName = "-module", valueDescription = "<path>", description = "Path to the .xml build file to compile")
var buildFile: String? = null
var buildFile: String? by FreezableVar(null)
@Argument(value = "-Xmultifile-parts-inherit", description = "Compile multifile classes as a hierarchy of parts and facade")
var inheritMultifileParts: Boolean = false
var inheritMultifileParts: Boolean by FreezableVar(false)
@Argument(value = "-Xskip-runtime-version-check", description = "Allow Kotlin runtime libraries of incompatible versions in the classpath")
var skipRuntimeVersionCheck: Boolean = false
var skipRuntimeVersionCheck: Boolean by FreezableVar(false)
@Argument(
value = "-Xuse-old-class-files-reading",
description = "Use old class files reading implementation " +
"(may slow down the build and should be used in case of problems with the new implementation)"
)
var useOldClassFilesReading: Boolean = false
var useOldClassFilesReading: Boolean by FreezableVar(false)
@Argument(
value = "-Xdump-declarations-to",
valueDescription = "<path>",
description = "Path to JSON file to dump Java to Kotlin declaration mappings"
)
var declarationsOutputPath: String? = null
var declarationsOutputPath: String? by FreezableVar(null)
@Argument(value = "-Xsingle-module", description = "Combine modules for source files and binary dependencies into a single module")
var singleModule: Boolean = false
var singleModule: Boolean by FreezableVar(false)
@Argument(value = "-Xadd-compiler-builtins", description = "Add definitions of built-in declarations to the compilation classpath (useful with -no-stdlib)")
var addCompilerBuiltIns: Boolean = false
var addCompilerBuiltIns: Boolean by FreezableVar(false)
@Argument(value = "-Xload-builtins-from-dependencies", description = "Load definitions of built-in declarations from module dependencies, instead of from the compiler")
var loadBuiltInsFromDependencies: Boolean = false
var loadBuiltInsFromDependencies: Boolean by FreezableVar(false)
@Argument(
value = "-Xscript-resolver-environment",
valueDescription = "<key=value[,]>",
description = "Script resolver environment in key-value pairs (the value could be quoted and escaped)"
)
var scriptResolverEnvironment: Array<String>? = null
var scriptResolverEnvironment: Array<String>? by FreezableVar(null)
// Javac options
@Argument(value = "-Xuse-javac", description = "Use javac for Java source and class files analysis")
var useJavac: Boolean = false
var useJavac: Boolean by FreezableVar(false)
@Argument(
value = "-Xjavac-arguments",
valueDescription = "<option[,]>",
description = "Java compiler arguments")
var javacArguments: Array<String>? = null
var javacArguments: Array<String>? by FreezableVar(null)
@Argument(
value = "-Xjsr305-annotations",
valueDescription = "{ignore|enable}",
description = "Specify global behavior for JSR-305 nullability annotations: ignore, or treat as other supported nullability annotations"
)
var jsr305GlobalReportLevel: String? = Jsr305State.DEFAULT.description
var jsr305GlobalReportLevel: String? by FreezableVar(Jsr305State.DEFAULT.description)
// Paths to output directories for friend modules.
var friendPaths: Array<String>? = null
var friendPaths: Array<String>? by FreezableVar(null)
override fun configureAnalysisFlags(): MutableMap<AnalysisFlag<*>, Any> {
val result = super.configureAnalysisFlags()
@@ -22,7 +22,7 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() {
}
@Argument(value = "-d", valueDescription = "<directory|jar>", description = "Destination for generated .kotlin_metadata files")
var destination: String? = null
var destination: String? by FreezableVar(null)
@Argument(
value = "-classpath",
@@ -30,5 +30,5 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>",
description = "Paths where to find library .kotlin_metadata files"
)
var classpath: String? = null
var classpath: String? by FreezableVar(null)
}