Compile kotlin-runtime-minimal.jar, run proguard against it

ProGuard complains if we're trying to shrink compiler with the full runtime in
dependencies because for the compiler produced on the first step of bootstrap
these two jars contain conflicting classes. This won't matter in the final
distribution because we will strip 'core' modules from compiler.jar. But this
matters in the first step because core will be different in the compiler (used
to load compiled class files) and in the reflection (used to introspect symbols
at runtime).

kotlin-runtime-minimal.jar still contains the complete reflection API and some
stub implementations in module 'reflection.stub.jvm', but doesn't have core, so
it won't cause a proguard error
This commit is contained in:
Alexander Udalov
2014-12-09 17:03:48 +03:00
parent 6c145de39e
commit ffbae46e3c
10 changed files with 231 additions and 29 deletions
+1
View File
@@ -5,6 +5,7 @@
<excludeFromCompile>
<directory url="file://$PROJECT_DIR$/core/reflection" includeSubdirectories="true" />
<directory url="file://$PROJECT_DIR$/core/reflection.jvm" includeSubdirectories="true" />
<directory url="file://$PROJECT_DIR$/core/reflection.stub.jvm" includeSubdirectories="true" />
</excludeFromCompile>
<resourceExtensions />
<wildcardResourcePatterns>
+1
View File
@@ -43,6 +43,7 @@
<module fileurl="file://$PROJECT_DIR$/compiler/preloader/preloader.iml" filepath="$PROJECT_DIR$/compiler/preloader/preloader.iml" group="compiler/cli" />
<module fileurl="file://$PROJECT_DIR$/core/reflection/reflection.iml" filepath="$PROJECT_DIR$/core/reflection/reflection.iml" group="core" />
<module fileurl="file://$PROJECT_DIR$/core/reflection.jvm/reflection.jvm.iml" filepath="$PROJECT_DIR$/core/reflection.jvm/reflection.jvm.iml" group="core" />
<module fileurl="file://$PROJECT_DIR$/core/reflection.stub.jvm/reflection.stub.jvm.iml" filepath="$PROJECT_DIR$/core/reflection.stub.jvm/reflection.stub.jvm.iml" />
<module fileurl="file://$PROJECT_DIR$/core/runtime.jvm/runtime.jvm.iml" filepath="$PROJECT_DIR$/core/runtime.jvm/runtime.jvm.iml" group="core" />
<module fileurl="file://$PROJECT_DIR$/core/serialization/serialization.iml" filepath="$PROJECT_DIR$/core/serialization/serialization.iml" group="core" />
<module fileurl="file://$PROJECT_DIR$/core/serialization.java/serialization.java.iml" filepath="$PROJECT_DIR$/core/serialization.java/serialization.java.iml" group="core" />
+92 -29
View File
@@ -13,6 +13,7 @@
<property name="bootstrap.home" value="dependencies/bootstrap-compiler"/>
<property name="bootstrap.compiler.home" value="${bootstrap.home}/Kotlin/kotlinc"/>
<property name="bootstrap.runtime" value="${bootstrap.compiler.home}/lib/kotlin-runtime.jar"/>
<property name="bootstrap.runtime.minimal" value="${bootstrap.compiler.home}/lib/kotlin-runtime-minimal.jar"/>
<property name="output.relative" value="dist"/>
<property name="output" value="${basedir}/${output.relative}"/>
@@ -402,6 +403,15 @@
</else>
</if>
<!-- TODO: temporary, remove after bootstrap. Needed for proguard -->
<if>
<available file="${bootstrap.runtime.minimal}"/>
<then/>
<else>
<copy file="${bootstrap.runtime}" tofile="${bootstrap.runtime.minimal}"/>
</else>
</if>
<jar jarfile="@{jarfile}" compress="@{compress}" duplicate="preserve">
<zipfileset src="${bootstrap.runtime}">
<include name="**/*.class" if="${bootstrap.build.no.tests}"/>
@@ -526,7 +536,7 @@
-libraryjars '${rtjar}'
-libraryjars '${jssejar}'
-libraryjars '${bootstrap.runtime}'
-libraryjars '${bootstrap.runtime.minimal}'
-target 1.6
-dontoptimize
@@ -724,7 +734,6 @@
<include name="core/builtins/src"/>
<include name="core/runtime.jvm/src"/>
<include name="core/reflection/src"/>
<include name="core/reflection.jvm/src"/>
</src>
<class-path/>
</new-kotlinc>
@@ -741,43 +750,97 @@
</new-kotlinc>
</target>
<target name="reflection">
<new-kotlinc output="${output}/classes/reflection">
<src>
<include name="core/reflection.jvm/src"/>
</src>
<class-path>
<pathelement path="${output.relative}/classes/builtins"/>
<pathelement path="${output.relative}/classes/stdlib"/>
</class-path>
</new-kotlinc>
</target>
<target name="reflection-stub">
<new-kotlinc output="${output}/classes/reflection-stub">
<src>
<include name="core/reflection.stub.jvm/src"/>
</src>
<class-path>
<pathelement path="${output.relative}/classes/builtins"/>
</class-path>
</new-kotlinc>
</target>
<target name="pack-runtime">
<jar destfile="${kotlin-home}/lib/kotlin-runtime.jar">
<fileset dir="${output}/classes/builtins"/>
<fileset dir="${output}/classes/stdlib"/>
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
<macrodef name="do-pack-runtime">
<attribute name="reflection-module"/>
<attribute name="jar-name"/>
<attribute name="implementation-title"/>
<manifest>
<attribute name="Built-By" value="${manifest.impl.vendor}"/>
<sequential>
<jar destfile="${kotlin-home}/lib/@{jar-name}" duplicate="fail">
<fileset dir="${output}/classes/builtins"/>
<fileset dir="${output}/classes/stdlib"/>
<fileset dir="${output}/classes/@{reflection-module}"/>
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
<attribute name="Implementation-Vendor" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Title" value="${manifest.impl.title.kotlin.jvm.runtime}"/>
<attribute name="Implementation-Version" value="${build.number}"/>
</manifest>
</jar>
<manifest>
<attribute name="Built-By" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Vendor" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Title" value="@{implementation-title}"/>
<attribute name="Implementation-Version" value="${build.number}"/>
</manifest>
</jar>
</sequential>
</macrodef>
<do-pack-runtime reflection-module="reflection"
jar-name="kotlin-runtime.jar"
implementation-title="${manifest.impl.title.kotlin.jvm.runtime}"/>
<do-pack-runtime reflection-module="reflection-stub"
jar-name="kotlin-runtime-minimal.jar"
implementation-title="${manifest.impl.title.kotlin.jvm.runtime.minimal}"/>
</target>
<target name="pack-runtime-sources">
<jar destfile="${kotlin-home}/lib/kotlin-runtime-sources.jar" duplicate="fail">
<fileset dir="${basedir}/core/builtins/native" includes="**/*"/>
<fileset dir="${basedir}/core/builtins/src" includes="**/*"/>
<fileset dir="${basedir}/core/runtime.jvm/src" includes="**/*"/>
<fileset dir="${basedir}/core/reflection/src" includes="**/*"/>
<fileset dir="${basedir}/core/reflection.jvm/src" includes="**/*"/>
<fileset dir="${basedir}/libraries/stdlib/src" includes="**/*"/>
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
<macrodef name="do-pack-runtime-sources">
<attribute name="reflection-module"/>
<attribute name="jar-name"/>
<attribute name="implementation-title"/>
<manifest>
<attribute name="Built-By" value="${manifest.impl.vendor}"/>
<sequential>
<jar destfile="${kotlin-home}/lib/@{jar-name}" duplicate="fail">
<fileset dir="${basedir}/core/builtins/native" includes="**/*"/>
<fileset dir="${basedir}/core/builtins/src" includes="**/*"/>
<fileset dir="${basedir}/core/runtime.jvm/src" includes="**/*"/>
<fileset dir="${basedir}/core/reflection/src" includes="**/*"/>
<fileset dir="${basedir}/core/@{reflection-module}/src" includes="**/*"/>
<fileset dir="${basedir}/libraries/stdlib/src" includes="**/*"/>
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
<attribute name="Implementation-Vendor" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Title" value="${manifest.impl.title.kotlin.jvm.runtime.sources}"/>
<attribute name="Implementation-Version" value="${build.number}"/>
</manifest>
</jar>
<manifest>
<attribute name="Built-By" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Vendor" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Title" value="@{implementation-title}"/>
<attribute name="Implementation-Version" value="${build.number}"/>
</manifest>
</jar>
</sequential>
</macrodef>
<do-pack-runtime-sources reflection-module="reflection.jvm"
jar-name="kotlin-runtime-sources.jar"
implementation-title="${manifest.impl.title.kotlin.jvm.runtime.sources}"/>
<do-pack-runtime-sources reflection-module="reflection.stub.jvm"
jar-name="kotlin-runtime-minimal-sources.jar"
implementation-title="${manifest.impl.title.kotlin.jvm.runtime.minimal.sources}"/>
</target>
<target name="runtime" depends="builtins,stdlib,pack-runtime,pack-runtime-sources"/>
<target name="runtime" depends="builtins,stdlib,reflection,reflection-stub,pack-runtime,pack-runtime-sources"/>
<target name="dist"
depends="clean,init,prepare-dist,preloader,serialize-builtins,compiler,compiler-sources,ant-tools,jdk-annotations,android-sdk-annotations,runtime,kotlin-js-stdlib"
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="reflection" />
</component>
</module>
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.reflect.jvm;
public class KotlinReflectionNotSupportedError extends Error {
public KotlinReflectionNotSupportedError() {
super("Kotlin reflection implementation is not found at runtime. " +
"Make sure you do have kotlin-runtime.jar and do not have kotlin-runtime-minimal.jar in the classpath");
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.reflect.jvm.internal;
import kotlin.reflect.jvm.KotlinReflectionNotSupportedError;
public class InternalPackage {
public static KClassImpl foreignKotlinClass(Class jClass) {
throw new KotlinReflectionNotSupportedError();
}
public static KClassImpl kClassFromKotlin(Class jClass) {
return null;
}
public static KPackageImpl kPackage(Class c) {
return null;
}
}
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.reflect.jvm.internal;
import kotlin.reflect.KClass;
public abstract class KClassImpl implements KClass {
}
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.reflect.jvm.internal;
import kotlin.jvm.internal.FunctionImpl;
public abstract class KFunctionImpl extends FunctionImpl {
}
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.reflect.jvm.internal;
import kotlin.reflect.KPackage;
public abstract class KPackageImpl implements KPackage {
}
+2
View File
@@ -7,7 +7,9 @@ manifest.impl.title.kotlin.compiler.sources=Kotlin Compiler Sources
manifest.impl.title.kotlin.compiler.ant.task=Kotlin Compiler Ant Tasks
manifest.impl.title.kotlin.jvm.runtime=Kotlin Runtime
manifest.impl.title.kotlin.jvm.runtime.minimal=Kotlin Runtime Minimal
manifest.impl.title.kotlin.jvm.runtime.sources=Kotlin Runtime Sources
manifest.impl.title.kotlin.jvm.runtime.minimal.sources=Kotlin Runtime Minimal Sources
manifest.impl.title.kotlin.javascript.stdlib=Kotlin JavaScript StdLib
manifest.spec.title.kotlin.javascript.lib=Kotlin JavaScript Lib