Skip to content

Commit

Permalink
Run './gradlew formatKotlin'
Browse files Browse the repository at this point in the history
  • Loading branch information
veyndan committed Aug 11, 2022
1 parent ea72d14 commit 3053770
Show file tree
Hide file tree
Showing 66 changed files with 763 additions and 490 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ interface HostApi : ZiplineService {
/** Decodes the response as a string and returns it. */
suspend fun httpCall(url: String, headers: Map<String, String>): String
}

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class RealTriviaService : TriviaService {
)
)


override fun games() = gameWithAnswersList.map { it.game }

override fun answer(gameId: Int, questionId: Int, answer: String) =
Expand Down
28 changes: 14 additions & 14 deletions zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/atoms.kt
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,18 @@ private val BUILT_IN_ATOMS: List<JsString> = listOf(
"TypeError",
"URIError",
"InternalError",
"<brand>", // Symbols
"Symbol.toPrimitive", // Symbols
"Symbol.iterator", // Symbols
"Symbol.match", // Symbols
"Symbol.matchAll", // Symbols
"Symbol.replace", // Symbols
"Symbol.search", // Symbols
"Symbol.split", // Symbols
"Symbol.toStringTag", // Symbols
"Symbol.isConcatSpreadable", // Symbols
"Symbol.hasInstance", // Symbols
"Symbol.species", // Symbols
"Symbol.unscopables", // Symbols
"Symbol.asyncIterator", // Symbols
"<brand>", // Symbols
"Symbol.toPrimitive", // Symbols
"Symbol.iterator", // Symbols
"Symbol.match", // Symbols
"Symbol.matchAll", // Symbols
"Symbol.replace", // Symbols
"Symbol.search", // Symbols
"Symbol.split", // Symbols
"Symbol.toStringTag", // Symbols
"Symbol.isConcatSpreadable", // Symbols
"Symbol.hasInstance", // Symbols
"Symbol.species", // Symbols
"Symbol.unscopables", // Symbols
"Symbol.asyncIterator", // Symbols
).map { it.toJsString() }
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class ApplySourceMapToBytecodeTest {
|}
""".trimMargin()


@After fun tearDown() {
quickJs.close()
}
Expand Down Expand Up @@ -109,21 +108,23 @@ class ApplySourceMapToBytecodeTest {
val exception = assertFailsWith<Exception> {
quickJs.evaluate("demo.sayHello()")
}
assertThat(exception.stackTraceToString()).startsWith("""
assertThat(exception.stackTraceToString()).startsWith(
"""
|app.cash.zipline.QuickJsException: boom!
| at JavaScript.goBoom1(throwException.kt)
| at JavaScript.goBoom2(throwException.kt:9)
| at JavaScript.goBoom3(throwException.kt:6)
| at JavaScript.sayHello(throwException.kt:3)
| at JavaScript.<eval>(?)
|""".trimMargin())
""".trimMargin()
)
}

@Test fun functionWithNoInstructions() {
val js = """
|function doNothing() {
|}
|""".trimMargin()
""".trimMargin()

// Just confirm the empty function can be transformed successfully.
val bytecode = quickJs.compile(js, "demo.js")
Expand All @@ -145,7 +146,7 @@ class ApplySourceMapToBytecodeTest {
| : b + c + d + Array(e-d.length+1).join(0);
| });
|}
|""".trimMargin()
""".trimMargin()

val bytecode = quickJs.compile(js, "demo.js")
val bytecodeWithSourceMap = applySourceMapToBytecode(bytecode, emptySourceMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class JsObjectEncodingTest {
|function greet(name) {
| return "hello, " + name;
|}
""".trimMargin(), "hello.js"
""".trimMargin(),
"hello.js"
)

assertThat(evalFunction.name).isEqualTo("<eval>")
Expand Down
15 changes: 10 additions & 5 deletions zipline-cli/src/main/kotlin/app/cash/zipline/cli/Download.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,29 @@ import picocli.CommandLine.Command
import picocli.CommandLine.Option

@Command(
name = NAME, description = ["Recursively download Zipline code to a directory from a URL."],
mixinStandardHelpOptions = true, versionProvider = Main.VersionProvider::class
name = NAME,
description = ["Recursively download Zipline code to a directory from a URL."],
mixinStandardHelpOptions = true,
versionProvider = Main.VersionProvider::class
)
class Download : Runnable {
@Option(
names = ["-A", "--application-name"],
description = ["Application name for the Zipline Manifest."], required = true
description = ["Application name for the Zipline Manifest."],
required = true
)
lateinit var applicationName: String

@Option(
names = ["-M", "--manifest-url"],
description = ["URL to the Zipline Manifest for the code to download."], required = true
description = ["URL to the Zipline Manifest for the code to download."],
required = true
)
lateinit var manifestUrl: String

@Option(
names = ["-D", "--download-dir"], description = ["Directory where code will be downloaded to."],
names = ["-D", "--download-dir"],
description = ["Directory where code will be downloaded to."],
required = true
)
lateinit var downloadDir: File
Expand Down
4 changes: 3 additions & 1 deletion zipline-cli/src/main/kotlin/app/cash/zipline/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import picocli.CommandLine.Option
import picocli.CommandLine.ParameterException
import picocli.CommandLine.Spec

@Command(name = NAME, description = ["Use Zipline without Gradle."],
@Command(
name = NAME,
description = ["Use Zipline without Gradle."],
mixinStandardHelpOptions = true,
synopsisSubcommandLabel = "COMMAND",
subcommands = [Download::class, HelpCommand::class],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ abstract class ZiplineCompileTask @Inject constructor(

ZiplineCompiler.incrementalCompile(
outputDir = outputDirFile,
modifiedFiles = filterByChangeType { changeType -> changeType == ChangeType.MODIFIED },
addedFiles = filterByChangeType { changeType -> changeType == ChangeType.ADDED },
removedFiles = filterByChangeType { changeType -> changeType == ChangeType.REMOVED },
modifiedFiles = filterByChangeType { changeType -> changeType == ChangeType.MODIFIED },
addedFiles = filterByChangeType { changeType -> changeType == ChangeType.ADDED },
removedFiles = filterByChangeType { changeType -> changeType == ChangeType.REMOVED },
mainFunction = mainFunction,
mainModuleId = mainModuleId,
manifestSigner = manifestSigner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ object ZiplineCompiler {
// Get the current manifest and remove any removed or modified modules
val manifestFile = File(outputDir.path, MANIFEST_FILE_NAME)
val manifest = Json.decodeFromString<ZiplineManifest>(manifestFile.readText())
modules.putAll(manifest.modules.filter { (k, _) ->
val moduleFileName = k.removePrefix(MODULE_PATH_PREFIX)
moduleFileName !in removedFileNames && moduleFileName !in modifiedFileNames
})
modules.putAll(
manifest.modules.filter { (k, _) ->
val moduleFileName = k.removePrefix(MODULE_PATH_PREFIX)
moduleFileName !in removedFileNames && moduleFileName !in modifiedFileNames
}
)

// Delete Zipline files for any removed JS files
removedFileNames.forEach { File(outputDir.path + "/" + it.removeSuffix(".js") + ZIPLINE_EXTENSION).delete()}
removedFileNames.forEach { File(outputDir.path + "/" + it.removeSuffix(".js") + ZIPLINE_EXTENSION).delete() }

// Compile the newly added or modified files and add them into the module list
val addedOrModifiedFiles = getJsFiles(addedFiles) + getJsFiles(modifiedFiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ZiplineCompilerTest {
| at JavaScript.goBoom3(throwException.kt:6)
| at JavaScript.sayHello(throwException.kt:3)
| at JavaScript.<eval>(test.js)
|""".trimMargin()
""".trimMargin()
)
}
}
Expand All @@ -80,9 +80,11 @@ class ZiplineCompilerTest {
@Test
fun `js with imports and exports`() {
assertZiplineCompile("src/test/resources/jsWithImportsExports/", false) {
quickJs.execute(it.source().buffer().use { source ->
ZiplineFile.read(source)
}.quickjsBytecode.toByteArray())
quickJs.execute(
it.source().buffer().use { source ->
ZiplineFile.read(source)
}.quickjsBytecode.toByteArray()
)
}
}

Expand All @@ -98,18 +100,24 @@ class ZiplineCompilerTest {

// Start with base compile to generate manifest and starting files
assertZiplineCompile("$rootProject/base", false) {
quickJs.execute(it.source().buffer().use { source ->
ZiplineFile.read(source)
}.quickjsBytecode.toByteArray())
quickJs.execute(
it.source().buffer().use { source ->
ZiplineFile.read(source)
}.quickjsBytecode.toByteArray()
)
}

assertZiplineIncrementalCompile("$rootProject/base",
assertZiplineIncrementalCompile(
"$rootProject/base",
addedFiles = File("$rootProject/added").listFiles()!!.asList(),
modifiedFiles = File("$rootProject/modified").listFiles()!!.asList(),
removedFiles = File("$rootProject/removed").listFiles()!!.asList()){
quickJs.execute(it.source().buffer().use { source ->
ZiplineFile.read(source)
}.quickjsBytecode.toByteArray())
removedFiles = File("$rootProject/removed").listFiles()!!.asList()
) {
quickJs.execute(
it.source().buffer().use { source ->
ZiplineFile.read(source)
}.quickjsBytecode.toByteArray()
)
}

// Jello file was removed
Expand Down Expand Up @@ -217,9 +225,11 @@ class ZiplineCompilerTest {
manifest.modules.keys.forEach { ziplineFilePath ->
// Ignore the Zipline Manifest JSON file
if (!ziplineFilePath.endsWith(".zipline.json")) nonManifestFileAssertions(
File(outputDir, ziplineFilePath
.removePrefix("./")
.replace(".js", ".zipline")
File(
outputDir,
ziplineFilePath
.removePrefix("./")
.replace(".js", ".zipline")
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class ZiplineGradleDownloaderTest {
assertTrue(fileSystem.exists(downloadDirPath / testFixtures.alphaSha256Hex))
assertEquals(
testFixtures.alphaByteString,
fileSystem.read(downloadDirPath / testFixtures.alphaSha256Hex) { readByteString() })
fileSystem.read(downloadDirPath / testFixtures.alphaSha256Hex) { readByteString() }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package app.cash.zipline.tests
import app.cash.zipline.Zipline
import app.cash.zipline.loader.ZiplineHttpClient
import app.cash.zipline.loader.ZiplineLoader
import java.util.concurrent.Executors
import java.time.Instant
import java.util.concurrent.Executors
import kotlin.system.exitProcess
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.asCoroutineDispatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ internal interface UnusedService : ZiplineService {
fun main() {
val zipline = Zipline.create(Dispatchers.Default)
zipline.take<UnusedService>("takenService")
zipline.bind<UnusedService>("boundService", object : UnusedService {
override fun unusedMethod() {
zipline.bind<UnusedService>(
"boundService",
object : UnusedService {
override fun unusedMethod() {
}
}
})
)

// If we reach this line without crashing, bind() and take() were rewritten. (If the Zipline
// plugin is not installed we'll get an error like "is the Zipline plugin configured?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,19 @@ internal class AdapterGenerator(
typeArguments = adapterClass.typeParameters.map { it.defaultType },
).apply {
type = ziplineFunctionT
putValueArgument(0, irCall(ziplineApis.listOfFunction).apply {
putTypeArgument(0, ziplineApis.kSerializer.starProjectedType)
putValueArgument(0,
irVararg(
ziplineApis.kSerializer.starProjectedType,
bridgedFunction.owner.valueParameters.map { irGet(serializers[it.type]!!) }
putValueArgument(
0,
irCall(ziplineApis.listOfFunction).apply {
putTypeArgument(0, ziplineApis.kSerializer.starProjectedType)
putValueArgument(
0,
irVararg(
ziplineApis.kSerializer.starProjectedType,
bridgedFunction.owner.valueParameters.map { irGet(serializers[it.type]!!) }
)
)
)
})
}
)
val returnType = bridgedFunction.owner.returnType
val resultSerializerType = when {
bridgedFunction.isSuspend -> ziplineApis.suspendCallback.typeWith(returnType)
Expand All @@ -427,15 +431,18 @@ internal class AdapterGenerator(
// ZiplineFunction0(...),
// ZiplineFunction1(...),
// )
+irReturn(irCall(ziplineApis.listOfFunction).apply {
putTypeArgument(0, ziplineFunctionT)
putValueArgument(0,
irVararg(
ziplineFunctionT,
expressions,
+irReturn(
irCall(ziplineApis.listOfFunction).apply {
putTypeArgument(0, ziplineFunctionT)
putValueArgument(
0,
irVararg(
ziplineFunctionT,
expressions,
)
)
)
})
}
)
}

return ziplineFunctionsFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,13 @@ internal class BridgedInterface(
callee = ziplineApis.serializerFunctionValueParam,
type = ziplineApis.kSerializer.starProjectedType,
).apply {
putValueArgument(0, irCall(ziplineApis.listGetFunction).apply {
dispatchReceiver = irGet(typesExpression)
putValueArgument(0, irInt(typeIndex))
})
putValueArgument(
0,
irCall(ziplineApis.listGetFunction).apply {
dispatchReceiver = irGet(typesExpression)
putValueArgument(0, irInt(typeIndex))
}
)
extensionReceiver = irGet(serializersModuleParameter)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
/** Inspired by [org.jetbrains.kotlin.ir.backend.js.utils.asString]. */
fun IrSimpleType.asString(): String =
classifier.asString() +
(arguments.ifNotEmpty {
joinToString(separator = ",", prefix = "<", postfix = ">") { it.asString() }
} ?: "") +
(
arguments.ifNotEmpty {
joinToString(separator = ",", prefix = "<", postfix = ">") { it.asString() }
} ?: ""
) +
(if (hasQuestionMark) "?" else "")

/** Copied from [org.jetbrains.kotlin.ir.backend.js.utils.asString]. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package app.cash.zipline.loader
import android.content.Context
import app.cash.zipline.EventListener
import app.cash.zipline.loader.internal.cache.SqlDriverFactory
import app.cash.zipline.loader.internal.fetcher.HttpFetcher
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.modules.EmptySerializersModule
import kotlinx.serialization.modules.SerializersModule
import okhttp3.OkHttpClient
import app.cash.zipline.loader.internal.fetcher.HttpFetcher

@OptIn(ExperimentalSerializationApi::class) // Zipline must track changes to EmptySerializersModule.
fun ZiplineLoader(
Expand Down
Loading

0 comments on commit 3053770

Please sign in to comment.