Introduce -Xoutput-imports mode of JVM compiler

In this mode, instead of analyzing files and generating bytecode for
them, compiler just saves imports of each file in JSON map of form

'<path to file> -> [<import1>, <import2>, ...]'

It is needed for some external tools, notably for Google3 toolchain.
This commit is contained in:
Dmitry Savvinov
2018-04-04 14:59:09 +03:00
parent bec1ae3d94
commit 70622ff668
27 changed files with 167 additions and 5 deletions
+1
View File
@@ -32,6 +32,7 @@ where advanced options include:
-Xno-optimize Disable optimizations
-Xno-param-assertions Don't generate not-null assertions on parameters of methods accessible from Java
-Xno-receiver-assertions Don't generate not-null assertion for extension receiver arguments of platform types
-Xoutput-imports=<path> Output imports from all compiled files to the specified file in JSON format
-Xscript-resolver-environment=<key=value[,]>
Script resolver environment in key-value pairs (the value could be quoted and escaped)
-Xsingle-module Combine modules for source files and binary dependencies into a single module
+4
View File
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/importsProducer
-d
$TEMP_DIR$
-Xoutput-imports=$TESTDATA_DIR$/importsProducerDump.txt
+1
View File
@@ -0,0 +1 @@
OK
+7
View File
@@ -0,0 +1,7 @@
package a
import c.JavaC
class A1 {
val j: JavaC = JavaC()
}
+5
View File
@@ -0,0 +1,5 @@
package a
class A2 {
val a1: A1? = null
}
+10
View File
@@ -0,0 +1,10 @@
package b
import a.*
class B1 {
companion object {
val a1: A1 = A1()
val a2: A2 = A2()
}
}
@@ -0,0 +1,7 @@
package b.nestedB
import a.A1 as AliasedA1
import a.A1
fun foo(x: AliasedA1): Int = TODO()
fun bar(x: A1): Int = TODO()
+16
View File
@@ -0,0 +1,16 @@
package c
import a.A1
import a.A2
import b.B1.Companion.a2
import b.nestedB.bar
import b.nestedB.foo
class C1 {
val x = foo(TODO())
val y = bar(TODO())
val z: A1? = null
val t: A2? = a2
}
+13
View File
@@ -0,0 +1,13 @@
package c;
import a.A1;
import b.B1;
import b.nestedB.B2Kt;
public class JavaC {
private void doStuff() {
C1 c1 = new C1();
B1 b1 = new B1();
B2Kt.bar(new A1());
}
}
+1
View File
@@ -0,0 +1 @@
{"\/home\/dsavvinov\/Repos\/kotlin-fork\/kotlin\/compiler\/testData\/cli\/jvm\/importsProducer\/a\/A1.kt":["import c.JavaC"],"\/home\/dsavvinov\/Repos\/kotlin-fork\/kotlin\/compiler\/testData\/cli\/jvm\/importsProducer\/a\/A2.kt":[],"\/home\/dsavvinov\/Repos\/kotlin-fork\/kotlin\/compiler\/testData\/cli\/jvm\/importsProducer\/b\/B1.kt":["import a.*"],"\/home\/dsavvinov\/Repos\/kotlin-fork\/kotlin\/compiler\/testData\/cli\/jvm\/importsProducer\/b\/nestedB\/B2.kt":["import a.A1 as AliasedA1","import a.A1"],"\/home\/dsavvinov\/Repos\/kotlin-fork\/kotlin\/compiler\/testData\/cli\/jvm\/importsProducer\/c\/C1.kt":["import a.A1","import a.A2","import b.B1.Companion.a2","import b.nestedB.bar","import b.nestedB.foo"]}