Skip to content

Commit c105245

Browse files
committed
Use proguard to remove unused symbols from kotlin-reflect.jar
#KT-16268 Fixed
1 parent 2e8bfde commit c105245

File tree

2 files changed

+61
-17
lines changed

2 files changed

+61
-17
lines changed

build.xml

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,6 @@
617617
</target>
618618

619619
<target name="compiler">
620-
<taskdef resource="proguard/ant/task.properties">
621-
<classpath>
622-
<pathelement path="${dependencies}/proguard.jar"/>
623-
<pathelement path="${dependencies}/proguard-anttask.jar"/>
624-
</classpath>
625-
</taskdef>
626-
627620
<cleandir dir="${output}/classes/compiler"/>
628621

629622
<javac2 destdir="${output}/classes/compiler" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false"
@@ -645,17 +638,32 @@
645638
unless:true="${shrink}" />
646639

647640
<sequential if:true="${shrink}">
641+
<shrink configuration="${basedir}/compiler/compiler.pro"/>
642+
</sequential>
643+
644+
<pack-compiler-for-maven/>
645+
</target>
646+
647+
<macrodef name="shrink">
648+
<attribute name="configuration"/>
649+
650+
<sequential>
651+
<taskdef resource="proguard/ant/task.properties">
652+
<classpath>
653+
<pathelement path="${dependencies}/proguard.jar"/>
654+
<pathelement path="${dependencies}/proguard-anttask.jar"/>
655+
</classpath>
656+
</taskdef>
657+
648658
<available property="rtjar" value="${java.home}/lib/rt.jar" file="${java.home}/lib/rt.jar"/>
649659
<available property="rtjar" value="${java.home}/../Classes/classes.jar" file="${java.home}/../Classes/classes.jar"/>
650660

651661
<available property="jssejar" value="${java.home}/lib/jsse.jar" file="${java.home}/lib/jsse.jar"/>
652662
<available property="jssejar" value="${java.home}/../Classes/jsse.jar" file="${java.home}/../Classes/jsse.jar"/>
653663

654-
<proguard configuration="${basedir}/compiler/compiler.pro"/>
664+
<proguard configuration="@{configuration}"/>
655665
</sequential>
656-
657-
<pack-compiler-for-maven/>
658-
</target>
666+
</macrodef>
659667

660668
<macrodef name="pack-compiler-for-maven">
661669
<sequential>
@@ -1224,11 +1232,10 @@
12241232
</manifest>
12251233
</jar>
12261234

1227-
<delete file="${output}/kotlin-reflect-jarjar.jar" failonerror="false"/>
1228-
12291235
<sequential if:true="${obfuscate.reflect}">
12301236
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="dependencies/jarjar.jar"/>
1231-
<jarjar jarfile="${output}/kotlin-reflect-jarjar.jar" filesonly="true" filesetmanifest="merge">
1237+
<delete file="${output}/kotlin-reflect-after-jarjar.jar" failonerror="false"/>
1238+
<jarjar jarfile="${output}/kotlin-reflect-after-jarjar.jar" filesonly="true" filesetmanifest="merge">
12321239
<zipfileset src="${output}/kotlin-reflect-before-jarjar.jar"/>
12331240
<rule pattern="org.jetbrains.kotlin.**" result="kotlin.reflect.jvm.internal.impl.@1"/>
12341241
<rule pattern="javax.inject.**" result="kotlin.reflect.jvm.internal.impl.javax.inject.@1"/>
@@ -1239,17 +1246,18 @@
12391246
<compilerarg value="-script"/>
12401247
<compilerarg value="kotlin/Metadata"/> <!-- Annotation to strip -->
12411248
<compilerarg value="kotlin/reflect/jvm/internal/impl/.*"/> <!-- Classes to strip from -->
1242-
<compilerarg value="${output}/kotlin-reflect-jarjar.jar"/>
1243-
<compilerarg value="${kotlin-home}/lib/kotlin-reflect.jar"/>
1249+
<compilerarg value="${output}/kotlin-reflect-after-jarjar.jar"/>
1250+
<compilerarg value="${output}/kotlin-reflect-before-proguard.jar"/>
12441251
<classpath>
12451252
<pathelement location="${idea.sdk}/lib/asm-all.jar"/>
12461253
</classpath>
12471254
</kotlinc>
1255+
1256+
<shrink configuration="${basedir}/core/reflection.jvm/reflection.pro"/>
12481257
</sequential>
12491258

12501259
<sequential unless:true="${obfuscate.reflect}">
12511260
<echo message="Obfuscation of kotlin-reflect is disabled"/>
1252-
<copy file="${output}/kotlin-reflect-before-jarjar.jar" tofile="${output}/kotlin-reflect-jarjar.jar" overwrite="true"/>
12531261
<copy file="${output}/kotlin-reflect-before-jarjar.jar" tofile="${kotlin-home}/lib/kotlin-reflect.jar" overwrite="true"/>
12541262
</sequential>
12551263
</target>

core/reflection.jvm/reflection.pro

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-injars '<output>/kotlin-reflect-before-proguard.jar'
2+
-outjars '<kotlin-home>/lib/kotlin-reflect.jar'
3+
4+
-dontnote **
5+
6+
-libraryjars '<rtjar>'
7+
-libraryjars '<kotlin-home>/lib/kotlin-runtime.jar'
8+
9+
-target 1.6
10+
-dontoptimize
11+
-dontobfuscate
12+
# -dontshrink
13+
14+
-keep public class kotlin.reflect.* { *; }
15+
-keep public class kotlin.reflect.jvm.* { *; }
16+
-keep public class kotlin.reflect.full.* { *; }
17+
18+
-keepattributes SourceFile,LineNumberTable,InnerClasses,Signature,Deprecated,*Annotation*,EnclosingMethod
19+
20+
-keep class kotlin.reflect.jvm.internal.ReflectionFactoryImpl { public protected *; }
21+
22+
-keepclassmembers enum * {
23+
public static **[] values();
24+
public static ** valueOf(java.lang.String);
25+
}
26+
27+
-keepclassmembers class * {
28+
** toString();
29+
}
30+
31+
# For tests on HashPMap, see compiler/testData/codegen/box/hashPMap
32+
-keepclassmembers class kotlin.reflect.jvm.internal.pcollections.HashPMap {
33+
public int size();
34+
public boolean containsKey(java.lang.Object);
35+
public kotlin.reflect.jvm.internal.pcollections.HashPMap minus(java.lang.Object);
36+
}

0 commit comments

Comments
 (0)