Skip to content

Commit 8c3661c

Browse files
committed
build.xml: add option to skip jarjar of reflect
1 parent 078a53e commit 8c3661c

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

build.xml

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<!-- Set to false to disable compiler's javadoc generation. Speeds up the build -->
77
<property name="generate.javadoc" value="true"/>
88

9+
<!-- Set to false to prevent jarjar and metadata stripping on kotlin-reflect.jar and reflection sources. Use to debug reflection -->
10+
<property name="obfuscate.reflect" value="true"/>
11+
912
<property name="max.heap.size.for.forked.jvm" value="1024m"/>
1013

1114
<property name="bootstrap.home" value="${basedir}/dependencies/bootstrap-compiler"/>
@@ -908,31 +911,46 @@
908911
</jar>
909912

910913
<delete file="${output}/kotlin-reflect-jarjar.jar" failonerror="false"/>
911-
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="dependencies/jarjar.jar"/>
912-
<jarjar jarfile="${output}/kotlin-reflect-jarjar.jar" filesonly="true" filesetmanifest="merge">
913-
<zipfileset src="${output}/kotlin-reflect-before-jarjar.jar"/>
914-
<rule pattern="org.jetbrains.kotlin.**" result="kotlin.reflect.jvm.internal.impl.@1"/>
915-
<rule pattern="com.google.protobuf.**" result="kotlin.reflect.jvm.internal.impl.com.google.protobuf.@1"/>
916-
<rule pattern="javax.inject.**" result="kotlin.reflect.jvm.internal.impl.javax.inject.@1"/>
917-
</jarjar>
918-
919-
<kotlinc src="${basedir}/generators/infrastructure/strip-kotlin-annotations.kts" output="">
920-
<compilerarg value="-script"/>
921-
<compilerarg value="kotlin/jvm/internal/.*"/> <!-- Annotations to strip -->
922-
<compilerarg value="kotlin/reflect/jvm/internal/impl/.*"/> <!-- Classes to strip from -->
923-
<compilerarg value="${output}/kotlin-reflect-jarjar.jar"/>
924-
<compilerarg value="${kotlin-home}/lib/kotlin-reflect.jar"/>
925-
<classpath>
926-
<pathelement location="${idea.sdk}/lib/asm-all.jar"/>
927-
</classpath>
928-
</kotlinc>
914+
915+
<sequential if:true="${obfuscate.reflect}">
916+
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="dependencies/jarjar.jar"/>
917+
<jarjar jarfile="${output}/kotlin-reflect-jarjar.jar" filesonly="true" filesetmanifest="merge">
918+
<zipfileset src="${output}/kotlin-reflect-before-jarjar.jar"/>
919+
<rule pattern="org.jetbrains.kotlin.**" result="kotlin.reflect.jvm.internal.impl.@1"/>
920+
<rule pattern="com.google.protobuf.**" result="kotlin.reflect.jvm.internal.impl.com.google.protobuf.@1"/>
921+
<rule pattern="javax.inject.**" result="kotlin.reflect.jvm.internal.impl.javax.inject.@1"/>
922+
</jarjar>
923+
924+
<kotlinc src="${basedir}/generators/infrastructure/strip-kotlin-annotations.kts" output="">
925+
<compilerarg value="-script"/>
926+
<compilerarg value="kotlin/jvm/internal/.*"/> <!-- Annotations to strip -->
927+
<compilerarg value="kotlin/reflect/jvm/internal/impl/.*"/> <!-- Classes to strip from -->
928+
<compilerarg value="${output}/kotlin-reflect-jarjar.jar"/>
929+
<compilerarg value="${kotlin-home}/lib/kotlin-reflect.jar"/>
930+
<classpath>
931+
<pathelement location="${idea.sdk}/lib/asm-all.jar"/>
932+
</classpath>
933+
</kotlinc>
934+
</sequential>
935+
936+
<sequential unless:true="${obfuscate.reflect}">
937+
<echo message="Obfuscation of kotlin-reflect is disabled"/>
938+
<copy file="${output}/kotlin-reflect-before-jarjar.jar" tofile="${output}/kotlin-reflect-jarjar.jar" overwrite="true"/>
939+
<copy file="${output}/kotlin-reflect-before-jarjar.jar" tofile="${kotlin-home}/lib/kotlin-reflect.jar" overwrite="true"/>
940+
</sequential>
929941
</target>
930942

931943
<target name="pack-runtime-sources">
932-
933-
<!-- Rename packages in the sources of reflection impl (core) -->
934944
<delete dir="${output}/core.src" failonerror="false"/>
935-
<copy todir="${output}/core.src/kotlin/reflect/jvm/internal/impl">
945+
946+
<local name="runtime.sources.base.dir"/>
947+
<condition property="runtime.sources.base.dir"
948+
value="${output}/core.src/kotlin/reflect/jvm/internal/impl"
949+
else="${output}/core.src/org/jetbrains/kotlin">
950+
<istrue value="${obfuscate.reflect}"/>
951+
</condition>
952+
953+
<copy todir="${runtime.sources.base.dir}">
936954
<fileset dir="core">
937955
<include name="descriptor.loader.java/src/**"/>
938956
<include name="descriptors/src/**"/>
@@ -942,9 +960,13 @@
942960
</fileset>
943961
<cutdirsmapper dirs="5"/> <!-- module/src/org/jetbrains/kotlin -->
944962
</copy>
945-
<replaceregexp match="org\.jetbrains\.kotlin" replace="kotlin.reflect.jvm.internal.impl" flags="g">
946-
<fileset dir="${output}/core.src"/>
947-
</replaceregexp>
963+
964+
<sequential if:true="${obfuscate.reflect}">
965+
<!-- Rename packages in the sources of reflection impl (core) -->
966+
<replaceregexp match="org\.jetbrains\.kotlin" replace="kotlin.reflect.jvm.internal.impl" flags="g">
967+
<fileset dir="${output}/core.src"/>
968+
</replaceregexp>
969+
</sequential>
948970

949971
<pack-runtime-jar jar-name="kotlin-runtime-sources.jar" implementation-title="${manifest.impl.title.kotlin.jvm.runtime.sources}">
950972
<jar-content>

0 commit comments

Comments
 (0)