javac-wrapper: -Xuse-javac -> -Xuse-javac and -Xcompile-java

This commit is contained in:
baratynskiy
2017-06-26 15:21:48 +03:00
committed by Alexander Baratynskiy
parent 2224720a90
commit 8494e54608
8 changed files with 22 additions and 5 deletions
@@ -148,6 +148,9 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
@Argument(value = "-Xuse-javac", description = "Use javac for Java source and class files analysis") @Argument(value = "-Xuse-javac", description = "Use javac for Java source and class files analysis")
var useJavac: Boolean by FreezableVar(false) var useJavac: Boolean by FreezableVar(false)
@Argument(value = "-Xcompile-java", description = "Reuse javac analysis and compile Java source files")
public boolean compileJava;
@Argument( @Argument(
value = "-Xjavac-arguments", value = "-Xjavac-arguments",
valueDescription = "<option[,]>", valueDescription = "<option[,]>",
@@ -242,7 +242,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
arguments: K2JVMCompilerArguments): Boolean { arguments: K2JVMCompilerArguments): Boolean {
if (arguments.useJavac) { if (arguments.useJavac) {
environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true) environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true)
return environment.registerJavac(arguments = arguments.javacArguments) return environment.registerJavac(compileJava = arguments.compileJava, arguments = arguments.javacArguments)
} }
return true return true
@@ -275,9 +275,10 @@ class KotlinCoreEnvironment private constructor(
fun registerJavac( fun registerJavac(
javaFiles: List<File> = allJavaFiles, javaFiles: List<File> = allJavaFiles,
kotlinFiles: List<KtFile> = sourceFiles, kotlinFiles: List<KtFile> = sourceFiles,
compileJava: Boolean = false,
arguments: Array<String>? = null arguments: Array<String>? = null
): Boolean { ): Boolean {
return JavacWrapperRegistrar.registerJavac(projectEnvironment.project, configuration, javaFiles, kotlinFiles, arguments) return JavacWrapperRegistrar.registerJavac(projectEnvironment.project, configuration, javaFiles, kotlinFiles, compileJava, arguments)
} }
private val applicationEnvironment: CoreApplicationEnvironment private val applicationEnvironment: CoreApplicationEnvironment
@@ -36,6 +36,7 @@ object JavacWrapperRegistrar {
configuration: CompilerConfiguration, configuration: CompilerConfiguration,
javaFiles: List<File>, javaFiles: List<File>,
kotlinFiles: List<KtFile>, kotlinFiles: List<KtFile>,
compileJava: Boolean,
arguments: Array<String>? arguments: Array<String>?
): Boolean { ): Boolean {
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
@@ -54,7 +55,7 @@ object JavacWrapperRegistrar {
val jvmClasspathRoots = configuration.jvmClasspathRoots val jvmClasspathRoots = configuration.jvmClasspathRoots
val outputDirectory = configuration.get(JVMConfigurationKeys.OUTPUT_DIRECTORY) val outputDirectory = configuration.get(JVMConfigurationKeys.OUTPUT_DIRECTORY)
val javacWrapper = JavacWrapper(javaFiles, kotlinFiles, arguments, jvmClasspathRoots, outputDirectory, context) val javacWrapper = JavacWrapper(javaFiles, kotlinFiles, arguments, jvmClasspathRoots, compileJava, outputDirectory, context)
project.registerService(JavacWrapper::class.java, javacWrapper) project.registerService(JavacWrapper::class.java, javacWrapper)
@@ -67,6 +67,7 @@ class JavacWrapper(
kotlinFiles: Collection<KtFile>, kotlinFiles: Collection<KtFile>,
arguments: Array<String>?, arguments: Array<String>?,
jvmClasspathRoots: List<File>, jvmClasspathRoots: List<File>,
private val compileJava: Boolean,
private val outputDirectory: File?, private val outputDirectory: File?,
private val context: Context private val context: Context
) : Closeable { ) : Closeable {
@@ -154,6 +155,7 @@ class JavacWrapper(
private val symbolBasedPackagesCache = hashMapOf<String, SymbolBasedPackage?>() private val symbolBasedPackagesCache = hashMapOf<String, SymbolBasedPackage?>()
fun compile(outDir: File? = null): Boolean = with(javac) { fun compile(outDir: File? = null): Boolean = with(javac) {
if (!compileJava) return true
if (errorCount() > 0) return false if (errorCount() > 0) return false
val javaFilesNumber = fileObjects.length() val javaFilesNumber = fileObjects.length()
+6
View File
@@ -22,6 +22,12 @@ where advanced options include:
-Xskip-runtime-version-check Allow Kotlin runtime libraries of incompatible versions in the classpath -Xskip-runtime-version-check Allow Kotlin runtime libraries of incompatible versions in the classpath
-Xuse-javac Use javac for Java source and class files analysis -Xuse-javac Use javac for Java source and class files analysis
-Xuse-old-class-files-reading Use old class files reading implementation (may slow down the build and should be used in case of problems with the new implementation) -Xuse-old-class-files-reading Use old class files reading implementation (may slow down the build and should be used in case of problems with the new implementation)
-Xcompile-java Reuse javac analysis and compile Java source files
-Xjavac-arguments=<option[,]> Java compiler arguments
-Xload-jsr305-annotations Load JSR-305 nullability annotations
-Xno-inline Disable method inlining
-Xrepeat=<count> Repeat compilation (for performance analysis)
-Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes)
-Xallow-kotlin-package Allow compiling code in package 'kotlin' -Xallow-kotlin-package Allow compiling code in package 'kotlin'
-Xcoroutines={enable|warn|error} -Xcoroutines={enable|warn|error}
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
@@ -98,7 +98,9 @@ abstract class AbstractCompileJavaAgainstKotlinTest : TestCaseWithTmpdir() {
environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true) environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true)
environment.configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, outDir) environment.configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, outDir)
environment.configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) environment.configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
environment.registerJavac(javaFiles, kotlinFiles = listOf(KotlinTestUtils.loadJetFile(environment.project, ktFiles.first()))) environment.registerJavac(javaFiles = javaFiles,
kotlinFiles = listOf(KotlinTestUtils.loadJetFile(environment.project, ktFiles.first())),
compileJava = true)
if (!ktFiles.isEmpty()) { if (!ktFiles.isEmpty()) {
LoadDescriptorUtil.compileKotlinToDirAndGetModule(ktFiles, outDir, environment) LoadDescriptorUtil.compileKotlinToDirAndGetModule(ktFiles, outDir, environment)
} }
@@ -79,7 +79,9 @@ abstract class AbstractCompileKotlinAgainstJavaTest : TestCaseWithTmpdir() {
val environment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable) val environment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable)
environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true) environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true)
environment.configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, outDir) environment.configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, outDir)
environment.registerJavac(javaFiles, kotlinFiles = listOf(KotlinTestUtils.loadJetFile(environment.project, ktFiles.first()))) environment.registerJavac(javaFiles = javaFiles,
kotlinFiles = listOf(KotlinTestUtils.loadJetFile(environment.project, ktFiles.first())),
compileJava = true)
if (!ktFiles.isEmpty()) { if (!ktFiles.isEmpty()) {
LoadDescriptorUtil.compileKotlinToDirAndGetModule(ktFiles, outDir, environment) LoadDescriptorUtil.compileKotlinToDirAndGetModule(ktFiles, outDir, environment)
} }