Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kotlinc to v1.6.21 and implement Incremental compilation #141

Merged
merged 16 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Build with gradle
uses: gradle/gradle-build-action@v2.2.1
with:
arguments: clean build
arguments: assembleDebug

- name: Upload debug apk
uses: actions/upload-artifact@v3
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ If you have any questions, ideas, need help or want to propose a change just ope
- [Akash Yadav](https://github.com/Itsaky) for [nb-javac-android](https://github.com/Itsaky/nb-javac-android)

- [ShineM](https://github.com/shineM) for [TreeView](https://github.com/ShineM/TreeView)

- [QuinnWilton](https://github.com/QuinnWilton) for [Smali Grammers](https://github.com/QuinnWilton/sublime-smali)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GoogleJavaFormatter(input: String) {
val options =
JavaFormatterOptions.builder()
.style(JavaFormatterOptions.Style.AOSP) // Use AOSP formatting style
.formatJavadoc(true) // Format Javadoc with code
.formatJavadoc(true) // Format Javadoc
.build()
val formatter = Formatter(options)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class D8Task() : Task {
if (files != null) {
for (f in files) {
if (f.isFile()) {
paths.add(f.toPath())
if (f.getName().endsWith(".class")) {
paths.add(f.toPath())
}
} else {
paths.addAll(getClassFiles(f))
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.pranav.android.task.java

import android.content.Context
import android.content.SharedPreferences

import com.pranav.android.exception.CompilationFailedException
import com.pranav.android.interfaces.*
import com.pranav.common.util.FileUtil
import com.pranav.project.mode.JavaProject

import org.eclipse.jdt.internal.compiler.batch.Main

import java.io.File
import java.io.IOException
import java.io.OutputStream
import java.io.PrintWriter
import java.util.ArrayList

class ECJCompilationTask(preferences: SharedPreferences) : Task {

private val errs = StringBuilder()
private val prefs: SharedPreferences

init {
prefs = preferences
}

override fun getTaskName(): String {
return "ECJ Compilation Task"
}

@Throws(Exception::class)
override fun doFullTask(project: JavaProject) {

val writer =
PrintWriter(
object : OutputStream() {
override fun write(p1: Int) {
errs.append(p1.toChar())
}
})

val main = Main(writer, writer, false, null, null)

val output = File(project.getBinDirPath(), "classes")

val classpath = StringBuilder()
classpath.append(FileUtil.getClasspathDir() + "android.jar")
classpath.append(File.pathSeparator)
classpath.append(FileUtil.getClasspathDir() + "core-lambda-stubs.jar")
classpath.append(File.pathSeparator)
classpath.append(FileUtil.getClasspathDir() + "kotlin-stdlib-1.7.10.jar")
classpath.append(File.pathSeparator)
classpath.append(output)
val clspath = prefs.getString("classpath", "")
if (!clspath!!.isEmpty() && classpath.length > 0) {
classpath.append(":")
classpath.append(clspath)
}

val args = arrayListOf<String>(
"-g",
"-" + prefs.getString("version", "7"),
"-d",
output.getAbsolutePath(),
"-cp",
classpath.toString(),
"-proc:none",
"-sourcepath",
" ",
project.getSrcDirPath()
)

main.compile(args.toTypedArray())

if (main.globalErrorsCount > 0 || !output.exists()) {
throw CompilationFailedException(errs.toString())
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.incremental.*
import org.jetbrains.kotlin.incremental.makeIncrementally
import java.io.File

import com.pranav.common.util.FileUtil
Expand All @@ -18,7 +18,7 @@ class KotlinCompiler() : Task {
override fun doFullTask(project: JavaProject) {
val sourceFiles = getSourceFiles(File(project.getSrcDirPath()))
if (!sourceFiles.any {
it.absolutePath.endsWith(".kt")
it.endsWith(".kt")
}) {
return;
}
Expand Down Expand Up @@ -47,10 +47,14 @@ class KotlinCompiler() : Task {
.joinToString(System.lineSeparator().repeat(2)) { it.toString() }
}

val arguments = mutableListOf<String>().apply {
// Classpath
add("-cp")
add(
val args = K2JVMCompilerArguments().apply {
useJavac = false
compileJava = false
includeRuntime = false
noJdk = true
noReflect = true
noStdlib = true
classpath =
FileUtil.getClasspathDir() +
"android.jar" +
File.pathSeparator +
Expand All @@ -59,25 +63,18 @@ class KotlinCompiler() : Task {
File.pathSeparator +
FileUtil.getClasspathDir() +
"kotlin-stdlib-1.7.10.jar"
)

// Sources (.java & .kt)
add(project.getSrcDirPath())
}

val args = K2JVMCompilerArguments().apply {
compileJava = true
includeRuntime = false
noJdk = true
noReflect = true
noStdlib = true
kotlinHome = mKotlinHome.absolutePath
destination = mClassOutput.absolutePath
javaSourceRoots = sourceFiles.filter {
it.endsWith(".java")
}.toTypedArray()
// incremental compiler needs this somewhy
moduleName = "project-kotlin"
}

val cacheDir = File(project.getBinDirPath(), "caches")

IncrementalJvmCompilerRunnerKt.makeIncrementally(
makeIncrementally(
cacheDir,
listOf(File(project.getSrcDirPath())),
args,
Expand All @@ -90,16 +87,17 @@ class KotlinCompiler() : Task {
// File(mClassOutput, "META-INF").deleteRecursively()
}

fun getSourceFiles(path: File): ArrayList<File> {
val sourceFiles = arrayListOf<File>()
fun getSourceFiles(path: File): ArrayList<String> {
val sourceFiles = arrayListOf<String>()
val files = path.listFiles()
if (files == null) {
return arrayListOf<File>()
return arrayListOf<String>()
}
for (file in files) {
if (file.isFile()) {
if (file.getName().endsWith(".java") || file.getName().endsWith(".kt")) {
sourceFiles.add(file)
val path = file.absolutePath
if (path.endsWith(".java") || path.endsWith(".kt")) {
sourceFiles.add(path)
}
} else {
sourceFiles.addAll(getSourceFiles(file))
Expand All @@ -117,5 +115,4 @@ class KotlinCompiler() : Task {
val message: String,
val location: CompilerMessageSourceLocation?
)

}
}
Loading