removed kotlin.reflection dependency

optimized gradle build now using shadowjar
This commit is contained in:
Irmen de Jong 2019-07-09 07:24:43 +02:00
parent 3cf87536ff
commit 5b9cc9592f
7 changed files with 87 additions and 52 deletions

View File

@ -1,21 +1,36 @@
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.40"
id 'application'
id 'org.jetbrains.dokka' version "0.9.18"
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
plugins {
// id "org.jetbrains.kotlin.jvm" version $kotlinVersion
id 'application'
id 'org.jetbrains.dokka' version "0.9.18"
id 'com.github.johnrengelman.shadow' version '5.1.0'
id 'java'
}
apply plugin: "kotlin"
apply plugin: "java"
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
def kotlinVersion = '1.3.40'
sourceCompatibility = 1.8
def prog8version = rootProject.file('compiler/res/version.txt').text.trim()
dependencies {
implementation project(':parser')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
runtime "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
// implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
// runtime "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
runtime 'org.antlr:antlr4-runtime:4.7.2'
runtime project(':parser')
@ -50,41 +65,38 @@ sourceSets {
}
}
startScripts.enabled = false
startScripts.enabled = true
//application {
// mainClassName = 'prog8.CompilerMainKt'
// applicationName = 'p8compile'
//}
application {
mainClassName = 'prog8.CompilerMainKt'
applicationName = 'p8compile'
}
//task p8vmScript(type: CreateStartScripts) {
// mainClassName = "prog8.StackVmMainKt"
// applicationName = "p8vm"
// outputDir = new File(project.buildDir, 'scripts')
// classpath = jar.outputs.files + project.configurations.runtime
//}
artifacts {
archives shadowJar
}
//applicationDistribution.into("bin") {
// from(p8vmScript)
// fileMode = 0755
//}
task p8vmScript(type: CreateStartScripts) {
mainClassName = "prog8.vm.stackvm.MainKt"
applicationName = "p8vm"
outputDir = new File(project.buildDir, 'scripts')
classpath = jar.outputs.files + project.configurations.runtime
}
//task fatJar(type: Jar) {
// manifest {
// attributes 'Main-Class': 'prog8.CompilerMainKt'
// }
// archiveBaseName = 'prog8compiler'
// destinationDirectory = rootProject.projectDir
// from {
// project.configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
// }
// with jar
//}
// build.finalizedBy(fatJar)
applicationDistribution.into("bin") {
from(p8vmScript)
fileMode = 0755
}
// To create a fat-jar use the 'create_compiler_jar' script for now
// @todo investigate https://imperceptiblethoughts.com/shadow/introduction/
shadowJar {
baseName = 'prog8compiler'
version = prog8version
// minimize()
}
// Java target version
sourceCompatibility = 1.8
test {
// Enable JUnit 5 (Gradle 4.6+).

View File

@ -11,7 +11,6 @@
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" name="antlr-runtime-4.7.2" level="project" />
<orderEntry type="module" module-name="parser" />
<orderEntry type="library" name="unittest-libs" level="project" />

View File

@ -521,7 +521,7 @@ internal class AstChecker(private val program: Program,
checkValueTypeAndRange(decl.datatype, arraySpec, decl.value as LiteralValue, program.heap)
}
else -> {
err("var/const declaration needs a compile-time constant initializer value, or range, instead found: ${decl.value!!::class.simpleName}")
err("var/const declaration needs a compile-time constant initializer value, or range, instead found: ${decl.value!!.javaClass.simpleName}")
return super.visit(decl)
}
}
@ -544,7 +544,7 @@ internal class AstChecker(private val program: Program,
}
if(decl.value !is LiteralValue) {
err("value of memory var decl is not a literal (it is a ${decl.value!!::class.simpleName}).", decl.value?.position)
err("value of memory var decl is not a literal (it is a ${decl.value!!.javaClass.simpleName}).", decl.value?.position)
} else {
val value = decl.value as LiteralValue
if (value.asIntegerValue == null || value.asIntegerValue< 0 || value.asIntegerValue > 65535) {

View File

@ -110,7 +110,7 @@ internal class VarInitValueAndAddressOfCreator(private val namespace: INameScope
val variable = VarDecl(VarDeclType.VAR, strvalue.type, false, null, autoVarName, strvalue,
isArray = false, autoGenerated = false, position = strvalue.position)
addVarDecl(strvalue.definingScope(), variable)
println("MADE ANONVAR $variable") // XXX
// println("MADE ANONVAR $variable") // XXX
}
}
}

View File

@ -142,22 +142,33 @@ downloads.
Finally: a **C-64 emulator** (or a real C-64 ofcourse) to run the programs on. The compiler assumes the presence
of the `Vice emulator <http://vice-emu.sourceforge.net/>`_.
.. hint::
The compiler is almost completely written in Kotlin, but the packaged release version
only requires a Java runtime. All other needed libraries and files are embedded in the
packaged jar file.
.. important::
**Building the compiler itself:**
.. note::
Building the compiler itself:
(re)building the compiler itself requires a Kotlin SDK version 1.3.
(re)building the compiler itself requires a recent Kotlin SDK.
The compiler is developed using the `IntelliJ IDEA <https://www.jetbrains.com/idea/>`_
IDE from Jetbrains, with the Kotlin plugin (free community edition of this IDE is available).
But a bare Kotlin SDK installation should work just as well.
A shell script (``create_compiler_jar.sh``) is provided to build and package the compiler from the command line.
If you have the 'fat-jar' you can run it with ``java -jar prog8compiler.jar``.
You can also use the Gradle build system to build the compiler (it will take care of
downloading all required libraries for you) by typing ``gradle installDist`` for instance.
downloading all required libraries for you) by typing ``gradle build`` for instance.
The output of this gradle build will appear in the "./compiler/build/install/p8compile/" directory.
The most interesting gradle commands to run are probably:
``./gradlew check``
Builds the compiler code and runs all available checks and unit-tests.
``./gradlew installShadowDist``
Creates a 'fat-jar' that contains the compiler and all dependencies,
and a few start scripts to run it.
The output can be found in ``.compiler/build/install/compiler-shadow/``
and you can launch the compiler with the script
``./compiler/build/install/compiler-shadow/bin/p8compile``.
``./gradlew shadowDistZip``
Creates a zipfile with the above in it, for easy distribution.
This file can be found in ``./compiler/build/distributions/``
.. note::
Development and testing is done on Linux, but the compiler should run on most

View File

@ -3,3 +3,5 @@ org.gradle.console=rich
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2048M
org.gradle.daemon=true
kotlinVersion=1.3.41

View File

@ -7,12 +7,23 @@ repositories {
mavenCentral()
}
dependencies {
antlr('org.antlr:antlr4:4.7.2') {
exclude group: 'com.ibm.icu', module: 'icu4j'
configurations {
// strange antlr plugin issue, see https://github.com/gradle/gradle/issues/820
// this avoids linking in the complete antlr binary jar
compile {
extendsFrom = extendsFrom.findAll { it != configurations.antlr }
}
}
dependencies {
antlr 'org.antlr:antlr4:4.7.2'
compile 'org.antlr:antlr4-runtime:4.7.2'
// antlr('org.antlr:antlr4:4.7.2') {
// exclude group: 'com.ibm.icu', module: 'icu4j'
// }
}
compileJava {
dependsOn tasks.withType(AntlrTask)
}