Project cleanup and improved GitHub workflows
This commit is contained in:
@@ -2,27 +2,19 @@ name: Project Build
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4g -Dorg.gradle.daemon=false -Dkotlin.incremental=false"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
|
||||
- uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.gradle/caches
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
- run: ./gradlew build
|
||||
- run: cd sample && ./gradlew build browserDistribution || cd ..
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
name: lint
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
ktlint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Run ktlint
|
||||
uses: ScaCap/action-ktlint@1.1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
reporter: github-pr-check
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.bnorm.power
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.isSuspend
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
|
||||
import org.jetbrains.kotlin.ir.builders.irConcat
|
||||
@@ -27,10 +25,8 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
|
||||
data class IrStackVariable(
|
||||
val temporary: IrVariable,
|
||||
|
||||
+26
-22
@@ -17,6 +17,7 @@
|
||||
package com.bnorm.power
|
||||
|
||||
import com.bnorm.power.internal.ReturnableBlockTransformer
|
||||
import java.io.File
|
||||
import org.jetbrains.kotlin.backend.common.*
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.backend.common.ir.asSimpleLambda
|
||||
@@ -24,6 +25,7 @@ import org.jetbrains.kotlin.backend.common.ir.inline
|
||||
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
|
||||
import org.jetbrains.kotlin.backend.common.lower.at
|
||||
import org.jetbrains.kotlin.cli.common.messages.*
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||
@@ -39,7 +41,6 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.path
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionExpressionImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
@@ -48,8 +49,6 @@ import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import java.io.File
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
|
||||
fun FileLoweringPass.runOnFileInOrder(irFile: IrFile) {
|
||||
irFile.acceptVoid(object : IrElementVisitorVoid {
|
||||
@@ -74,7 +73,8 @@ class PowerAssertCallTransformer(
|
||||
|
||||
override fun lower(irFile: IrFile) {
|
||||
file = irFile
|
||||
fileSource = File(irFile.path).readText().replace("\r\n", "\n")
|
||||
fileSource = File(irFile.path).readText()
|
||||
.replace("\r\n", "\n") // https://youtrack.jetbrains.com/issue/KT-41888
|
||||
|
||||
irFile.transformChildrenVoid()
|
||||
}
|
||||
@@ -86,12 +86,9 @@ class PowerAssertCallTransformer(
|
||||
|
||||
// Find a valid delegate function or do not translate
|
||||
val delegate = findDelegate(fqName) ?: run {
|
||||
val line = fileSource.substring(expression.startOffset).count { it == '\n' } + 1
|
||||
val location = CompilerMessageLocation.create(file.path, line, -1, null)
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.WARNING,
|
||||
"Unable to find overload for function $fqName callable as $fqName(Boolean, String) or $fqName(Boolean, () -> String) for power-assertion transformation",
|
||||
location
|
||||
messageCollector.warn(
|
||||
expression,
|
||||
"Unable to find overload for function $fqName callable as $fqName(Boolean, String) or $fqName(Boolean, () -> String) for power-assert transformation"
|
||||
)
|
||||
return super.visitCall(expression)
|
||||
}
|
||||
@@ -103,13 +100,7 @@ class PowerAssertCallTransformer(
|
||||
// If the tree does not contain any children, the expression is not transformable
|
||||
val tree = buildAssertTree(assertionArgument)
|
||||
val root = tree.children.singleOrNull() ?: run {
|
||||
val line = fileSource.substring(expression.startOffset).count { it == '\n' } + 1
|
||||
val location = CompilerMessageLocation.create(file.path, line, -1, null)
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.INFO,
|
||||
"Expression is constant and will not be power-assertion transformed",
|
||||
location
|
||||
)
|
||||
messageCollector.info(expression, "Expression is constant and will not be power-assert transformed")
|
||||
return super.visitCall(expression)
|
||||
}
|
||||
|
||||
@@ -150,7 +141,7 @@ class PowerAssertCallTransformer(
|
||||
}
|
||||
|
||||
private fun findDelegate(fqName: FqName): FunctionDelegate? {
|
||||
return context.findOverloads(fqName)
|
||||
return context.referenceFunctions(fqName)
|
||||
.mapNotNull { overload ->
|
||||
// TODO allow other signatures than (Boolean, String) and (Boolean, () -> String)
|
||||
val parameters = overload.owner.valueParameters
|
||||
@@ -218,9 +209,22 @@ class PowerAssertCallTransformer(
|
||||
|
||||
private fun isStringSupertype(type: IrType): Boolean =
|
||||
context.irBuiltIns.stringType.isSubtypeOf(type, context.irBuiltIns)
|
||||
}
|
||||
|
||||
// TODO is this the best way to find overload functions?
|
||||
private fun IrPluginContext.findOverloads(fqName: FqName): List<IrFunctionSymbol> {
|
||||
return referenceFunctions(fqName).toList()
|
||||
private fun MessageCollector.info(expression: IrElement, message: String) {
|
||||
report(expression, CompilerMessageSeverity.INFO, message)
|
||||
}
|
||||
|
||||
private fun MessageCollector.warn(expression: IrElement, message: String) {
|
||||
report(expression, CompilerMessageSeverity.WARNING, message)
|
||||
}
|
||||
|
||||
private fun MessageCollector.report(expression: IrElement, severity: CompilerMessageSeverity, message: String) {
|
||||
report(severity, message, expression.toCompilerMessageLocation())
|
||||
}
|
||||
|
||||
private fun IrElement.toCompilerMessageLocation(): CompilerMessageLocation {
|
||||
val info = file.info(this)
|
||||
val lineContent = fileSource.substring(this)
|
||||
return CompilerMessageLocation.create(file.path, info.startLineNumber, info.startColumnNumber, lineContent)!!
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user