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 { buildscript {
id "org.jetbrains.kotlin.jvm" version "1.3.40" dependencies {
id 'application' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
id 'org.jetbrains.dokka' version "0.9.18" }
} }
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 { repositories {
mavenLocal()
mavenCentral() mavenCentral()
jcenter() jcenter()
} }
def kotlinVersion = '1.3.40' sourceCompatibility = 1.8
def prog8version = rootProject.file('compiler/res/version.txt').text.trim()
dependencies { dependencies {
implementation project(':parser') implementation project(':parser')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" // implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
runtime "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" // runtime "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
runtime 'org.antlr:antlr4-runtime:4.7.2' runtime 'org.antlr:antlr4-runtime:4.7.2'
runtime project(':parser') runtime project(':parser')
@ -50,41 +65,38 @@ sourceSets {
} }
} }
startScripts.enabled = false startScripts.enabled = true
//application { application {
// mainClassName = 'prog8.CompilerMainKt' mainClassName = 'prog8.CompilerMainKt'
// applicationName = 'p8compile' applicationName = 'p8compile'
//} }
//task p8vmScript(type: CreateStartScripts) { artifacts {
// mainClassName = "prog8.StackVmMainKt" archives shadowJar
// applicationName = "p8vm" }
// outputDir = new File(project.buildDir, 'scripts')
// classpath = jar.outputs.files + project.configurations.runtime
//}
//applicationDistribution.into("bin") { task p8vmScript(type: CreateStartScripts) {
// from(p8vmScript) mainClassName = "prog8.vm.stackvm.MainKt"
// fileMode = 0755 applicationName = "p8vm"
//} outputDir = new File(project.buildDir, 'scripts')
classpath = jar.outputs.files + project.configurations.runtime
}
//task fatJar(type: Jar) { applicationDistribution.into("bin") {
// manifest { from(p8vmScript)
// attributes 'Main-Class': 'prog8.CompilerMainKt' fileMode = 0755
// } }
// archiveBaseName = 'prog8compiler'
// destinationDirectory = rootProject.projectDir
// from {
// project.configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
// }
// with jar
//}
// build.finalizedBy(fatJar)
// 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 { test {
// Enable JUnit 5 (Gradle 4.6+). // Enable JUnit 5 (Gradle 4.6+).

View File

@ -11,7 +11,6 @@
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" /> <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <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="library" name="antlr-runtime-4.7.2" level="project" />
<orderEntry type="module" module-name="parser" /> <orderEntry type="module" module-name="parser" />
<orderEntry type="library" name="unittest-libs" level="project" /> <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) checkValueTypeAndRange(decl.datatype, arraySpec, decl.value as LiteralValue, program.heap)
} }
else -> { 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) return super.visit(decl)
} }
} }
@ -544,7 +544,7 @@ internal class AstChecker(private val program: Program,
} }
if(decl.value !is LiteralValue) { 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 { } else {
val value = decl.value as LiteralValue val value = decl.value as LiteralValue
if (value.asIntegerValue == null || value.asIntegerValue< 0 || value.asIntegerValue > 65535) { 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, val variable = VarDecl(VarDeclType.VAR, strvalue.type, false, null, autoVarName, strvalue,
isArray = false, autoGenerated = false, position = strvalue.position) isArray = false, autoGenerated = false, position = strvalue.position)
addVarDecl(strvalue.definingScope(), variable) 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 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/>`_. of the `Vice emulator <http://vice-emu.sourceforge.net/>`_.
.. hint:: .. important::
The compiler is almost completely written in Kotlin, but the packaged release version **Building the compiler itself:**
only requires a Java runtime. All other needed libraries and files are embedded in the
packaged jar file.
.. note:: (re)building the compiler itself requires a recent Kotlin SDK.
Building the compiler itself:
(re)building the compiler itself requires a Kotlin SDK version 1.3.
The compiler is developed using the `IntelliJ IDEA <https://www.jetbrains.com/idea/>`_ 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). 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. 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. 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 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 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:: .. note::
Development and testing is done on Linux, but the compiler should run on most 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.parallel=true
org.gradle.jvmargs=-Xmx2048M org.gradle.jvmargs=-Xmx2048M
org.gradle.daemon=true org.gradle.daemon=true
kotlinVersion=1.3.41

View File

@ -7,12 +7,23 @@ repositories {
mavenCentral() mavenCentral()
} }
dependencies { configurations {
antlr('org.antlr:antlr4:4.7.2') { // strange antlr plugin issue, see https://github.com/gradle/gradle/issues/820
exclude group: 'com.ibm.icu', module: 'icu4j' // 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 { compileJava {
dependsOn tasks.withType(AntlrTask) dependsOn tasks.withType(AntlrTask)
} }