Download and build intellij-markdown when ABI version changes

This commit is contained in:
Alexander Udalov
2015-05-21 22:58:52 +03:00
parent 9ba6d91e2e
commit 79ee91c048
2 changed files with 153 additions and 14 deletions
@@ -0,0 +1,85 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.infrastructure
import java.io.File
import java.util.jar.JarFile
import org.jetbrains.org.objectweb.asm.*
/**
* Checks that the two given Kotlin libraries have the same ABI version.
* If versions are equal, returns with exit code 0, otherwise returns with exit code 3.
* Some additional information is printed to stderr
*/
fun loadAbiVersionOfClass(bytes: ByteArray): Int? {
var result: Int? = null
ClassReader(bytes).accept(object : ClassVisitor(Opcodes.ASM5) {
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
if (desc == "Lkotlin/jvm/internal/KotlinClass;") {
return object : AnnotationVisitor(Opcodes.ASM5) {
override fun visit(name: String, value: Any) {
if (name == "abiVersion") {
result = value as Int
}
}
}
}
return null
}
}, 0)
return result
}
fun loadVersion(library: File): Int {
val jarFile = JarFile(library)
try {
for (entry in jarFile.entries()) {
if (entry.getName().endsWith(".class")) {
val classBytes = jarFile.getInputStream(entry).readBytes()
loadAbiVersionOfClass(classBytes)?.let { return it }
}
}
}
finally {
// Yes, JarFile does not extend Closeable on JDK 6 so we can't use "use" here
jarFile.close()
}
error("No Kotlin classes were found in $library")
}
fun main(args: Array<String>) {
if (args.size() != 2) {
error("Usage: kotlinc -script check-library-abi-version.kts <jar-1> <jar-2>")
}
val library1 = File(args[0])
val library2 = File(args[1])
val v1 = loadVersion(library1)
val v2 = loadVersion(library2)
if (v1 != v2) {
System.err.println("ABI versions differ:")
System.err.println(" $library1 has version $v1")
System.err.println(" $library2 has version $v2")
System.exit(3)
}
}
main(args)
+68 -14
View File
@@ -25,6 +25,10 @@
</and>
</condition>
<condition property="kotlinc.executable.path" value="kotlinc.bat" else="kotlinc">
<os family="windows"/>
</condition>
<property name="idea.sdk.fetch.needed" value="true"/>
<property name="dependencies.info.file" value="dependencies/dependencies.properties"/>
@@ -276,16 +280,7 @@
</then>
</if>
<!-- Markdown parser -->
<download_teamcity_artifact
teamcity.server.url="https://teamcity.jetbrains.com"
build.locator.request="${markdown.locator}"
artifact.path="markdown_jar/markdown.jar"
dest="dependencies/markdown.jar"
usetimestamp="true"
build.number.pattern="\d+\s-\sKotlin\s[\d\.]+"
/>
<download-or-build-markdown-parser/>
</target>
<macrodef name="get_android_sdk">
@@ -347,10 +342,6 @@
<macrodef name="build-protobuf-java-lite">
<sequential>
<condition property="kotlinc.executable.path" value="kotlinc.bat" else="kotlinc">
<os family="windows"/>
</condition>
<exec executable="dependencies/bootstrap-compiler/Kotlin/kotlinc/bin/${kotlinc.executable.path}" failonerror="true">
<arg value="-script"/>
<arg value="generators/infrastructure/build-protobuf-lite.kts"/>
@@ -360,6 +351,69 @@
</sequential>
</macrodef>
<macrodef name="download-or-build-markdown-parser">
<sequential>
<download_teamcity_artifact
teamcity.server.url="https://teamcity.jetbrains.com"
build.locator.request="${markdown.locator}"
artifact.path="markdown_jar/markdown.jar"
dest="dependencies/markdown.jar"
usetimestamp="true"
build.number.pattern="\d+\s-\sKotlin\s[\d\.]+"
/>
<!-- When ABI version changes, the second build should compile markdown-parser manually instead of using the old version -->
<exec executable="dependencies/bootstrap-compiler/Kotlin/kotlinc/bin/${kotlinc.executable.path}" failonerror="false"
resultproperty="markdown.abi.incompatible">
<arg value="-cp"/>
<arg value="dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-compiler.jar"/>
<arg value="-script"/>
<arg value="generators/infrastructure/check-library-abi-version.kts"/>
<arg value="${basedir}/dependencies/markdown.jar"/>
<arg value="${basedir}/dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-runtime.jar"/>
</exec>
<if>
<not>
<equals arg1="${markdown.abi.incompatible}" arg2="0"/>
</not>
<then>
<echo message="Recompiling intellij-markdown manually"/>
<length file="dependencies/markdown.jar" property="old.markdown.size"/>
<echo message="Size of the incompatible jar: ${old.markdown.size} bytes"/>
<get src="https://github.com/valich/intellij-markdown/archive/master.zip"
dest="dependencies/download/markdown-sources.zip" usetimestamp="true"/>
<delete dir="dependencies/intellij-markdown-master" failonerror="false"/>
<unzip src="dependencies/download/markdown-sources.zip" dest="dependencies"/>
<exec executable="dependencies/bootstrap-compiler/Kotlin/kotlinc/bin/${kotlinc.executable.path}" failonerror="true">
<arg value="dependencies/intellij-markdown-master/src"/>
<arg value="-d"/>
<arg value="dependencies/intellij-markdown-master/out"/>
</exec>
<javac srcdir="dependencies/intellij-markdown-master/src"
destdir="dependencies/intellij-markdown-master/out" includeantruntime="false">
<classpath>
<path location="dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-runtime.jar"/>
</classpath>
</javac>
<delete file="dependencies/markdown.jar" failonerror="false"/>
<jar jarfile="dependencies/markdown.jar">
<fileset dir="dependencies/intellij-markdown-master/out" includes="**"/>
</jar>
<echo message="Compilation of intellij-markdown finished"/>
<length file="dependencies/markdown.jar" property="new.markdown.size"/>
<echo message="Size of the new jar: ${new.markdown.size} bytes"/>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="get-asm-sources-and-rename-packages">
<attribute name="asm.version"/>
<sequential>