Skip to content

Commit

Permalink
Use proguard to remove unused symbols from kotlin-reflect.jar
Browse files Browse the repository at this point in the history
 #KT-16268 Fixed
  • Loading branch information
udalov committed Feb 15, 2017
1 parent 2e8bfde commit c105245
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 17 deletions.
42 changes: 25 additions & 17 deletions build.xml
Expand Up @@ -617,13 +617,6 @@
</target>

<target name="compiler">
<taskdef resource="proguard/ant/task.properties">
<classpath>
<pathelement path="${dependencies}/proguard.jar"/>
<pathelement path="${dependencies}/proguard-anttask.jar"/>
</classpath>
</taskdef>

<cleandir dir="${output}/classes/compiler"/>

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

<sequential if:true="${shrink}">
<shrink configuration="${basedir}/compiler/compiler.pro"/>
</sequential>

<pack-compiler-for-maven/>
</target>

<macrodef name="shrink">
<attribute name="configuration"/>

<sequential>
<taskdef resource="proguard/ant/task.properties">
<classpath>
<pathelement path="${dependencies}/proguard.jar"/>
<pathelement path="${dependencies}/proguard-anttask.jar"/>
</classpath>
</taskdef>

<available property="rtjar" value="${java.home}/lib/rt.jar" file="${java.home}/lib/rt.jar"/>
<available property="rtjar" value="${java.home}/../Classes/classes.jar" file="${java.home}/../Classes/classes.jar"/>

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

<proguard configuration="${basedir}/compiler/compiler.pro"/>
<proguard configuration="@{configuration}"/>
</sequential>

<pack-compiler-for-maven/>
</target>
</macrodef>

<macrodef name="pack-compiler-for-maven">
<sequential>
Expand Down Expand Up @@ -1224,11 +1232,10 @@
</manifest>
</jar>

<delete file="${output}/kotlin-reflect-jarjar.jar" failonerror="false"/>

<sequential if:true="${obfuscate.reflect}">
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="dependencies/jarjar.jar"/>
<jarjar jarfile="${output}/kotlin-reflect-jarjar.jar" filesonly="true" filesetmanifest="merge">
<delete file="${output}/kotlin-reflect-after-jarjar.jar" failonerror="false"/>
<jarjar jarfile="${output}/kotlin-reflect-after-jarjar.jar" filesonly="true" filesetmanifest="merge">
<zipfileset src="${output}/kotlin-reflect-before-jarjar.jar"/>
<rule pattern="org.jetbrains.kotlin.**" result="kotlin.reflect.jvm.internal.impl.@1"/>
<rule pattern="javax.inject.**" result="kotlin.reflect.jvm.internal.impl.javax.inject.@1"/>
Expand All @@ -1239,17 +1246,18 @@
<compilerarg value="-script"/>
<compilerarg value="kotlin/Metadata"/> <!-- Annotation to strip -->
<compilerarg value="kotlin/reflect/jvm/internal/impl/.*"/> <!-- Classes to strip from -->
<compilerarg value="${output}/kotlin-reflect-jarjar.jar"/>
<compilerarg value="${kotlin-home}/lib/kotlin-reflect.jar"/>
<compilerarg value="${output}/kotlin-reflect-after-jarjar.jar"/>
<compilerarg value="${output}/kotlin-reflect-before-proguard.jar"/>
<classpath>
<pathelement location="${idea.sdk}/lib/asm-all.jar"/>
</classpath>
</kotlinc>

<shrink configuration="${basedir}/core/reflection.jvm/reflection.pro"/>
</sequential>

<sequential unless:true="${obfuscate.reflect}">
<echo message="Obfuscation of kotlin-reflect is disabled"/>
<copy file="${output}/kotlin-reflect-before-jarjar.jar" tofile="${output}/kotlin-reflect-jarjar.jar" overwrite="true"/>
<copy file="${output}/kotlin-reflect-before-jarjar.jar" tofile="${kotlin-home}/lib/kotlin-reflect.jar" overwrite="true"/>
</sequential>
</target>
Expand Down
36 changes: 36 additions & 0 deletions core/reflection.jvm/reflection.pro
@@ -0,0 +1,36 @@
-injars '<output>/kotlin-reflect-before-proguard.jar'
-outjars '<kotlin-home>/lib/kotlin-reflect.jar'

-dontnote **

-libraryjars '<rtjar>'
-libraryjars '<kotlin-home>/lib/kotlin-runtime.jar'

-target 1.6
-dontoptimize
-dontobfuscate
# -dontshrink

-keep public class kotlin.reflect.* { *; }
-keep public class kotlin.reflect.jvm.* { *; }
-keep public class kotlin.reflect.full.* { *; }

-keepattributes SourceFile,LineNumberTable,InnerClasses,Signature,Deprecated,*Annotation*,EnclosingMethod

-keep class kotlin.reflect.jvm.internal.ReflectionFactoryImpl { public protected *; }

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keepclassmembers class * {
** toString();
}

# For tests on HashPMap, see compiler/testData/codegen/box/hashPMap
-keepclassmembers class kotlin.reflect.jvm.internal.pcollections.HashPMap {
public int size();
public boolean containsKey(java.lang.Object);
public kotlin.reflect.jvm.internal.pcollections.HashPMap minus(java.lang.Object);
}

0 comments on commit c105245

Please sign in to comment.