@tokamakdev/platform-android-arm64 0.1.1-beta.155 → 0.1.1-beta.157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,9 @@ set -euo pipefail
4
4
  # The CLI runs the entrypoint from the pack root.
5
5
  pack=$PWD
6
6
 
7
- # The build tools of apps and of describing plugins. Coroutines are the version
8
- # androidx.lifecycle brings, so plugins' coroutines add no code.
7
+ # The build tools of apps and of describing plugins.
9
8
  agp_version=8.7.3
10
9
  kotlin_version=2.1.0
11
- coroutines_version=1.9.0
12
10
 
13
11
  # The start of a Gradle project's settings.gradle: the repositories it
14
12
  # resolves plugins and dependencies from.
@@ -22,7 +20,6 @@ pluginManagement {
22
20
  }
23
21
  }
24
22
  dependencyResolutionManagement {
25
- repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
26
23
  repositories {
27
24
  google()
28
25
  mavenCentral()
@@ -32,7 +29,10 @@ EOF
32
29
  }
33
30
 
34
31
  # The start of a Gradle project's build.gradle: the build tools its modules
35
- # apply.
32
+ # apply, and the Kotlin options every module compiles with. Interface default
33
+ # methods compile into the interface, not into each implementing class, which
34
+ # incremental builds do not recompile when a Tokamak interface in another
35
+ # module gains or changes one.
36
36
  gradle_plugins() {
37
37
  cat <<EOF
38
38
  plugins {
@@ -40,18 +40,30 @@ plugins {
40
40
  id 'com.android.library' version '$agp_version' apply false
41
41
  id 'org.jetbrains.kotlin.android' version '$kotlin_version' apply false
42
42
  }
43
+
44
+ subprojects {
45
+ plugins.withId('org.jetbrains.kotlin.android') {
46
+ kotlin {
47
+ jvmToolchain(17)
48
+ compilerOptions {
49
+ freeCompilerArgs.add('-Xjvm-default=all')
50
+ }
51
+ }
52
+ }
53
+ }
43
54
  EOF
44
55
  }
45
56
 
46
- # Describes the methods PLUGIN/android/Exports.kt exports into
57
+ # Describes the methods REGISTRATION, the plugin's Exports.kt, exports into
47
58
  # OUTPUT/description.json, with the dispatch that serves them,
48
- # OUTPUT/Exports.generated.kt. A JVM unit test of the plugin, compiled with
49
- # the plugin API and its dependencies, runs the registration and reflects on
50
- # the methods it lists.
59
+ # OUTPUT/Exports.generated.kt. A JVM unit test, which depends on the plugin's
60
+ # module, runs the registration and reflects on the methods it lists. The
61
+ # plugin's module builds outside its directory, without the dispatch
62
+ # describing regenerates.
51
63
  describe() {
52
- local plugin=$1 output=$2
53
- if [[ $# -ne 3 || $3 != android ]]; then
54
- echo "Android plugins run on android, not ${*:3}" >&2
64
+ local plugin=$1 registration=$2 output=$3
65
+ if [[ $# -ne 4 || $4 != android ]]; then
66
+ echo "Android plugins run on android, not ${*:4}" >&2
55
67
  exit 2
56
68
  fi
57
69
  local sdk=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-}}
@@ -62,15 +74,28 @@ describe() {
62
74
  # Global, for the exit trap.
63
75
  temporary=$(mktemp -d "${TMPDIR:-/tmp}/tokamak-describe.XXXXXX")
64
76
  trap 'rm -rf "$temporary"' EXIT
65
- local module=$temporary/plugin
66
- mkdir -p "$module"
77
+ local describer=$temporary/describer plugin_build=$temporary/plugin-build
78
+ mkdir -p "$describer"
67
79
  {
68
80
  gradle_repositories
69
- printf '%s\n' "rootProject.name = 'tokamak-describe'" "include ':plugin'"
81
+ printf '%s\n' "rootProject.name = 'tokamak-describe'" "include ':tokamak-plugin', ':plugin', ':describer'"
82
+ printf "project(':tokamak-plugin').projectDir = file('%s')\n" "$pack/plugin-api"
83
+ printf "project(':plugin').projectDir = file('%s')\n" "$plugin/android"
70
84
  } > "$temporary/settings.gradle"
71
- gradle_plugins > "$temporary/build.gradle"
85
+ {
86
+ gradle_plugins
87
+ cat <<EOF
88
+
89
+ project(':plugin') {
90
+ layout.buildDirectory.set(file('$plugin_build'))
91
+ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
92
+ exclude { it.file == file('${registration%/*}/Exports.generated.kt') }
93
+ }
94
+ }
95
+ EOF
96
+ } > "$temporary/build.gradle"
72
97
  printf '%s\n' 'android.useAndroidX=true' > "$temporary/gradle.properties"
73
- cat > "$module/build.gradle" <<EOF
98
+ cat > "$describer/build.gradle" <<EOF
74
99
  plugins {
75
100
  id 'com.android.library'
76
101
  id 'org.jetbrains.kotlin.android'
@@ -79,9 +104,7 @@ plugins {
79
104
  android {
80
105
  namespace 'tokamak.describe'
81
106
  compileSdk 35
82
- // The plugin's own files, so compiler errors name them.
83
107
  sourceSets {
84
- main.kotlin.srcDirs = ['$pack/native-shell/plugin', '$plugin/android']
85
108
  test.kotlin.srcDirs = ['$pack/describer']
86
109
  }
87
110
  defaultConfig {
@@ -91,35 +114,22 @@ android {
91
114
  unitTests.returnDefaultValues = true
92
115
  unitTests.all {
93
116
  systemProperty 'tokamak.output', '$output'
94
- systemProperty 'tokamak.classes', layout.buildDirectory.dir('tmp/kotlin-classes/debug').get().asFile.path
117
+ systemProperty 'tokamak.classes', '$plugin_build/tmp/kotlin-classes/debug'
95
118
  outputs.upToDateWhen { false }
96
119
  }
97
120
  }
98
121
  }
99
122
 
100
- kotlin {
101
- jvmToolchain(17)
102
- compilerOptions {
103
- freeCompilerArgs.add('-Xjvm-default=all')
104
- }
105
- }
106
-
107
- // The dispatch describing regenerates.
108
- tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
109
- exclude '**/Exports.generated.kt'
110
- }
111
-
112
- def manifest = new groovy.json.JsonSlurper().parse(file('$plugin/tokamak-plugin.json'))
113
123
  dependencies {
114
- implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version'
115
- (manifest.platforms?.android?.dependencies ?: []).each { implementation it }
124
+ testImplementation project(':tokamak-plugin')
125
+ testImplementation project(':plugin')
116
126
  testImplementation 'junit:junit:4.13.2'
117
127
  testImplementation 'org.jetbrains.kotlin:kotlin-reflect:$kotlin_version'
118
128
  // android.jar's org.json is stubs; the describer writes JSON with the reference implementation.
119
129
  testImplementation 'org.json:json:20250517'
120
130
  }
121
131
  EOF
122
- gradle --quiet --project-dir "$temporary" :plugin:testDebugUnitTest
132
+ gradle --quiet --project-dir "$temporary" :describer:testDebugUnitTest
123
133
  if [[ -f "$output/error" ]]; then
124
134
  cat "$output/error" >&2
125
135
  rm "$output/error"
@@ -132,7 +142,7 @@ if [[ $# -ge 1 && $1 == describe ]]; then
132
142
  fi
133
143
 
134
144
  if [[ $# -ne 3 || $1 != build ]]; then
135
- echo "usage: entrypoint build INPUT OUTPUT | entrypoint describe PLUGIN OUTPUT android" >&2
145
+ echo "usage: entrypoint build INPUT OUTPUT | entrypoint describe PLUGIN REGISTRATION OUTPUT android" >&2
136
146
  exit 2
137
147
  fi
138
148
 
@@ -197,6 +207,7 @@ assets=$app/src/main/assets/app
197
207
  kotlin=$app/src/main/kotlin/com/tokamak/runtime
198
208
  plugin_api=$project/tokamak-plugin
199
209
  plugin_modules=$project/plugins
210
+ generated_modules=$project/generated
200
211
  # The oldest Android API level the app supports.
201
212
  min_sdk=$(<"$pack/build/min-sdk")
202
213
 
@@ -269,26 +280,12 @@ xml_escape() {
269
280
  -e "s/'/\&apos;/g"
270
281
  }
271
282
 
272
- rm -rf "$app/src/main/assets" "$app/src/main/jniLibs" "$app/src/main/kotlin" "$app/src/main/res" "$app/user" "$plugin_api" "$plugin_modules" "$output"
273
- mkdir -p "$native" "$assets" "$kotlin" "$app/src/main/res" "$plugin_api/src/main/kotlin"
283
+ rm -rf "$app/src/main/assets" "$app/src/main/jniLibs" "$app/src/main/kotlin" "$app/src/main/res" "$app/user" "$plugin_api" "$plugin_modules" "$generated_modules" "$output"
284
+ mkdir -p "$native" "$assets" "$kotlin" "$app/src/main/res" "$plugin_modules" "$generated_modules"
274
285
  cp -R "$input/app/." "$assets/"
275
286
  link_runtime
276
287
  cp -R "$pack/native-shell/app/." "$kotlin/"
277
- cp -R "$pack/native-shell/plugin/." "$plugin_api/src/main/kotlin/"
278
- cat > "$plugin_api/build.gradle" <<EOF
279
- plugins {
280
- id 'com.android.library'
281
- id 'org.jetbrains.kotlin.android'
282
- }
283
-
284
- android {
285
- namespace 'com.tokamak.runtime.plugin'
286
- }
287
-
288
- dependencies {
289
- api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version'
290
- }
291
- EOF
288
+ cp -R "$pack/plugin-api" "$plugin_api"
292
289
 
293
290
  has_icon=false
294
291
  if [[ -n "$icon" ]]; then
@@ -302,44 +299,47 @@ if [[ -n "$icon" ]]; then
302
299
  has_icon=true
303
300
  fi
304
301
 
305
- # Each plugin is a library module, so its manifest merges below the app's and
306
- # its dependencies stay its own. Its class is a Kotlin class name in a package,
307
- # which the registry creates, and its dependencies are Maven coordinates.
302
+ # Each plugin's Gradle module is a library module of the app, so its manifest
303
+ # merges below the app's and its dependencies resolve with the app's. Its class
304
+ # is a Kotlin class name in a package, which the registry creates. The
305
+ # manifest and raw resources its build script generates are a library module of
306
+ # their own.
308
307
  kotlin_class='^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)+$'
309
- maven_coordinate='^[A-Za-z0-9._-]+:[A-Za-z0-9._-]+:[A-Za-z0-9._-]+$'
310
308
  registry=$kotlin/TokamakPluginRegistry.kt
311
309
  printf '%s\n\n%s\n%s\n' 'package com.tokamak.runtime' 'internal fun tokamakPlugins(app: TokamakApplication): List<TokamakPlugin> =' ' listOf(' > "$registry"
312
310
  shopt -s nullglob
313
311
  raw_names=" "
314
- plugin_includes=
315
- plugin_dependencies=
312
+ module_includes=
313
+ module_dependencies=
314
+ # Includes the module $1 in the build, as a dependency of the app.
315
+ include_module() {
316
+ module_includes+="include '$1'"$'\n'
317
+ module_dependencies+=" implementation project('$1')"$'\n'
318
+ }
316
319
  for plugin in "$input/plugins"/*/; do
317
320
  plugin_id=$(basename "$plugin")
318
- plugin_includes+="include ':plugins:$plugin_id'"$'\n'
319
- plugin_dependencies+=" implementation project(':plugins:$plugin_id')"$'\n'
320
321
  class=$(cat "$plugin/class" 2>/dev/null || true)
321
322
  if [[ ! "$class" =~ $kotlin_class ]]; then
322
323
  echo "plugin '$plugin_id' has invalid android class '$class'" >&2
323
324
  exit 1
324
325
  fi
326
+ if [[ ! -f "$plugin/native/build.gradle.kts" && ! -f "$plugin/native/build.gradle" ]]; then
327
+ echo "plugin '$plugin_id' has no Gradle module, android/build.gradle.kts" >&2
328
+ exit 1
329
+ fi
330
+ cp -R "$plugin/native" "$plugin_modules/$plugin_id"
331
+ include_module ":plugins:$plugin_id"
325
332
  # A plugin that exports methods runs behind the dispatch generated for it,
326
333
  # whose companion object converts its values for its host.
327
- if [[ -f "$plugin/native/Exports.kt" ]]; then
334
+ if [[ -n "$(find "$plugin/native" -name Exports.kt -print -quit)" ]]; then
328
335
  printf ' %sDispatch(app.host("%s", %sDispatch)),\n' "$class" "$plugin_id" "$class" >> "$registry"
329
336
  else
330
337
  printf ' %s(app.host("%s")),\n' "$class" "$plugin_id" >> "$registry"
331
338
  fi
332
- module=$plugin_modules/$plugin_id
333
- mkdir -p "$module/src/main/kotlin"
334
- if [[ -d "$plugin/native" ]]; then
335
- while IFS= read -r -d '' source; do
336
- relative=${source#"$plugin/native/"}
337
- mkdir -p "$module/src/main/kotlin/$(dirname "$relative")"
338
- cp "$source" "$module/src/main/kotlin/$relative"
339
- done < <(find "$plugin/native" -name '*.kt' -print0)
340
- fi
339
+ generated=$generated_modules/$plugin_id
341
340
  if [[ -f "$plugin/manifest" ]]; then
342
- cp "$plugin/manifest" "$module/src/main/AndroidManifest.xml"
341
+ mkdir -p "$generated/src/main"
342
+ cp "$plugin/manifest" "$generated/src/main/AndroidManifest.xml"
343
343
  fi
344
344
  for resource in "$plugin/raw"/*; do
345
345
  [[ -f "$resource" ]] || continue
@@ -351,56 +351,60 @@ for plugin in "$input/plugins"/*/; do
351
351
  exit 1
352
352
  fi
353
353
  raw_names+=" ${name%%.*} "
354
- mkdir -p "$module/src/main/res/raw"
355
- cp "$resource" "$module/src/main/res/raw/$name"
354
+ mkdir -p "$generated/src/main/res/raw"
355
+ cp "$resource" "$generated/src/main/res/raw/$name"
356
356
  done
357
- {
358
- printf '%s\n' 'plugins {' " id 'com.android.library'" " id 'org.jetbrains.kotlin.android'"
359
- printf '%s\n\n' '}'
360
- printf '%s\n' 'android {'
361
- printf " namespace 'tokamak.plugins.%s'\n" "${plugin_id//-/_}"
362
- printf '%s\n\n' '}'
363
- printf '%s\n' 'dependencies {' " implementation project(':tokamak-plugin')"
364
- for dependency in "$plugin/dependencies"/*; do
365
- coordinate=$(cat "$dependency")
366
- if [[ ! "$coordinate" =~ $maven_coordinate ]]; then
367
- echo "plugin '$plugin_id' has invalid android dependency '$coordinate'; use group:artifact:version" >&2
368
- exit 1
369
- fi
370
- printf " implementation '%s'\n" "$coordinate"
371
- done
372
- printf '%s\n' '}'
373
- } > "$module/build.gradle"
357
+ if [[ -d "$generated" ]]; then
358
+ cat > "$generated/build.gradle" <<EOF
359
+ plugins {
360
+ id 'com.android.library'
361
+ }
362
+
363
+ android {
364
+ namespace 'tokamak.generated.${plugin_id//-/_}'
365
+ compileSdk 35
366
+ defaultConfig {
367
+ minSdk $min_sdk
368
+ }
369
+ }
370
+ EOF
371
+ include_module ":generated:$plugin_id"
372
+ fi
374
373
  done
375
374
  printf '%s\n' ' )' >> "$registry"
376
375
 
377
376
  {
378
377
  gradle_repositories
379
378
  printf '%s\n' "rootProject.name = 'tokamak'" "include ':app', ':tokamak-plugin'"
380
- printf '%s' "$plugin_includes"
379
+ printf '%s' "$module_includes"
381
380
  } > "$project/settings.gradle"
382
381
 
382
+ # Every module's dependencies resolve to at least the versions the app's lock
383
+ # pins, in Gradle's lock files. The lock is lenient because Gradle can resolve
384
+ # a locked build differently from the build that wrote the lock
385
+ # (gradle/gradle#21396). Without a lock, the build writes one, resolving every
386
+ # module's compile and runtime classpaths, which debug and release builds use.
387
+ lock=$input/lock
388
+ gradle_arguments=("-Ptokamak.version=$version" ":app:lint$task" ":app:assemble$task")
389
+ if [[ ! -d "$lock" ]]; then
390
+ gradle_arguments+=(--write-locks tokamakLockDependencies)
391
+ mkdir -p "$lock"
392
+ fi
383
393
  {
384
394
  gradle_plugins
385
395
  cat <<EOF
386
396
 
387
397
  subprojects {
388
398
  plugins.withType(com.android.build.gradle.api.AndroidBasePlugin) {
389
- android {
390
- compileSdk 35
391
- defaultConfig {
392
- minSdk $min_sdk
393
- }
399
+ dependencyLocking {
400
+ lockAllConfigurations()
401
+ lockMode = LockMode.LENIENT
402
+ lockFile = file('$lock/' + path.substring(1).replace(':', '.') + '.lockfile')
394
403
  }
395
- }
396
- plugins.withId('org.jetbrains.kotlin.android') {
397
- kotlin {
398
- jvmToolchain(17)
399
- // Interface default methods compile into the interface, not into each
400
- // implementing class, which incremental builds do not recompile when a
401
- // Tokamak interface in another module gains or changes one.
402
- compilerOptions {
403
- freeCompilerArgs.add('-Xjvm-default=all')
404
+ tasks.register('tokamakLockDependencies') {
405
+ def classpaths = configurations.matching { it.name.endsWith('CompileClasspath') || it.name.endsWith('RuntimeClasspath') }
406
+ doLast {
407
+ classpaths.each { it.incoming.resolutionResult.root }
404
408
  }
405
409
  }
406
410
  }
@@ -408,7 +412,9 @@ subprojects {
408
412
  EOF
409
413
  } > "$project/build.gradle"
410
414
 
411
- printf '%s\n' 'android.useAndroidX=true' > "$project/gradle.properties"
415
+ # Lint and R8 run in the Gradle daemon, whose default 512 MiB heap runs out
416
+ # when they analyse an app with several plugin modules.
417
+ printf '%s\n' 'android.useAndroidX=true' 'org.gradle.jvmargs=-Xmx4g' > "$project/gradle.properties"
412
418
  cat > "$project/app/build.gradle" <<EOF
413
419
  plugins {
414
420
  id 'com.android.application'
@@ -417,9 +423,11 @@ plugins {
417
423
 
418
424
  android {
419
425
  namespace 'com.tokamak.runtime'
426
+ compileSdk 35
420
427
 
421
428
  defaultConfig {
422
429
  applicationId '$identifier'
430
+ minSdk $min_sdk
423
431
  targetSdk 35
424
432
  versionCode 1
425
433
  versionName providers.gradleProperty('tokamak.version').get()
@@ -450,7 +458,7 @@ dependencies {
450
458
  implementation 'androidx.webkit:webkit:1.12.1'
451
459
  implementation project(':tokamak-plugin')
452
460
  EOF
453
- printf '%s}\n' "$plugin_dependencies" >> "$project/app/build.gradle"
461
+ printf '%s}\n' "$module_dependencies" >> "$project/app/build.gradle"
454
462
 
455
463
  if [[ -n "$user_manifest" ]]; then
456
464
  mkdir -p "$app/user"
@@ -499,6 +507,6 @@ printf '%s\n' \
499
507
  '-keepclassmembers class * implements com.tokamak.runtime.TokamakRuntime$Plugins { *; }' \
500
508
  > "$app/tokamak-rules.pro"
501
509
 
502
- gradle --no-daemon "-Ptokamak.version=$version" ":app:lint$task" ":app:assemble$task" --project-dir "$project"
510
+ gradle --no-daemon "${gradle_arguments[@]}" --project-dir "$project"
503
511
  mkdir -p "$(dirname "$output")"
504
512
  cp "$app/build/outputs/apk/$variant/app-$variant.apk" "$output"
@@ -68,7 +68,7 @@ private fun registration(classes: File): TokamakExports<*> {
68
68
  .filter { TokamakExports::class.java.isAssignableFrom(it) && !it.isInterface }
69
69
  .toList()
70
70
  val registration = registrations.singleOrNull()
71
- ?: throw DescribeError("android/Exports.kt declares one object that implements TokamakExports, not ${registrations.size}")
71
+ ?: throw DescribeError("Exports.kt declares one object that implements TokamakExports, not ${registrations.size}")
72
72
  return registration.kotlin.objectInstance as? TokamakExports<*>
73
73
  ?: throw DescribeError("${registration.simpleName} is an object")
74
74
  }
@@ -139,10 +139,10 @@ class TokamakApplication : Application(), TokamakPlugins {
139
139
 
140
140
  override fun <T : Any> fromJson(json: Any?, type: KClass<T>): T = codec(::unregistered).fromJson(json, type)
141
141
 
142
- /** The plugin's codec, or else the error [missing] gives: a plugin without `android/Exports.kt` has none. */
142
+ /** The plugin's codec, or else the error [missing] gives: a plugin without `Exports.kt` has none. */
143
143
  private fun codec(missing: () -> TokamakPluginError): TokamakCodec = codec ?: throw missing()
144
144
 
145
- private fun unregistered() = TokamakPluginError.typeError("$id has no android/Exports.kt")
145
+ private fun unregistered() = TokamakPluginError.typeError("$id has no Exports.kt")
146
146
 
147
147
  override fun fetch(path: String, timeoutMillis: Long): ByteArray =
148
148
  withRuntime(timeoutMillis) { runtime, remainingMillis -> runtime.fetch(path, remainingMillis) }
@@ -25,7 +25,6 @@
25
25
  },
26
26
  "pluginKeys": {
27
27
  "class": "string",
28
- "dependencies": "strings",
29
28
  "manifest": "path",
30
29
  "raw": "paths"
31
30
  }
@@ -0,0 +1,23 @@
1
+ // The plugin API, which plugins' modules depend on as project(":tokamak-plugin"). Its minimum SDK
2
+ // is the pack's. Coroutines are the version androidx.lifecycle brings, so plugins' coroutines add
3
+ // no code.
4
+ plugins {
5
+ id("com.android.library")
6
+ id("org.jetbrains.kotlin.android")
7
+ }
8
+
9
+ android {
10
+ namespace = "com.tokamak.runtime.plugin"
11
+ compileSdk = 35
12
+ defaultConfig {
13
+ minSdk = 31
14
+ }
15
+ }
16
+
17
+ kotlin {
18
+ jvmToolchain(17)
19
+ }
20
+
21
+ dependencies {
22
+ api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0")
23
+ }
@@ -17,7 +17,7 @@ import org.json.JSONArray
17
17
  import org.json.JSONObject
18
18
 
19
19
  /**
20
- * The methods a plugin's `android/Exports.kt` lists for the Worker to call, and the events the Worker
20
+ * The methods a plugin's `Exports.kt` lists for the Worker to call, and the events the Worker
21
21
  * receives. `tok plugin generate android` runs [exports] to write the plugin's dispatch and
22
22
  * TypeScript API; the app never does.
23
23
  */
@@ -35,32 +35,38 @@ enum class TokamakOverflow {
35
35
  }
36
36
 
37
37
  /** Records the methods a plugin exports, with their options, and the events it emits. */
38
- class TokamakExporter<P : TokamakPlugin> internal constructor() {
39
- internal class Export(val kind: String, val method: KFunction<*>, val doc: String, val overflow: TokamakOverflow)
38
+ class TokamakExporter<P : TokamakPlugin> {
39
+ class Export(val kind: String, val method: KFunction<*>, val doc: String, val overflow: TokamakOverflow)
40
40
 
41
- internal class Event(val name: String, val type: KClass<*>, val reply: KClass<*>?, val doc: String)
41
+ class Event(val name: String, val type: KClass<*>, val reply: KClass<*>?, val doc: String)
42
42
 
43
- internal val exports = mutableListOf<Export>()
44
- internal val events = mutableListOf<Event>()
43
+ private val listedExports = mutableListOf<Export>()
44
+ private val listedEvents = mutableListOf<Event>()
45
+
46
+ /** The methods exported, in order. */
47
+ val exports: List<Export> get() = listedExports
48
+
49
+ /** The events listed, in order. */
50
+ val events: List<Event> get() = listedEvents
45
51
 
46
52
  /** Lists the event [name], whose listeners receive a [type] and may reply with a [reply]. */
47
53
  fun event(name: String, type: KClass<*>, reply: KClass<*>? = null, doc: String = "") {
48
- events += Event(name, type, reply, doc)
54
+ listedEvents += Event(name, type, reply, doc)
49
55
  }
50
56
 
51
57
  /** Exports [method], which returns once. */
52
58
  fun call(method: KFunction<*>, doc: String = "") {
53
- exports += Export("call", method, doc, TokamakOverflow.ERROR)
59
+ listedExports += Export("call", method, doc, TokamakOverflow.ERROR)
54
60
  }
55
61
 
56
62
  /** Exports [method], whose values the Worker reads until it cancels. */
57
63
  fun stream(method: KFunction<Flow<*>>, overflow: TokamakOverflow = TokamakOverflow.ERROR, doc: String = "") {
58
- exports += Export("stream", method, doc, overflow)
64
+ listedExports += Export("stream", method, doc, overflow)
59
65
  }
60
66
 
61
67
  /** Exports [method], which returns a native object the Worker holds as a `NativeReference`. */
62
68
  fun resource(method: KFunction<Any>, doc: String = "") {
63
- exports += Export("resource", method, doc, TokamakOverflow.ERROR)
69
+ listedExports += Export("resource", method, doc, TokamakOverflow.ERROR)
64
70
  }
65
71
  }
66
72
 
@@ -99,16 +105,16 @@ class TokamakListeners<T>(private val holding: Boolean = false) {
99
105
  }
100
106
 
101
107
  /**
102
- * Converts the values a plugin's `android/Exports.kt` uses to and from JSON: its data classes and
108
+ * Converts the values a plugin's `Exports.kt` uses to and from JSON: its data classes and
103
109
  * sealed types, and its events and their replies. Each generated dispatch's companion object is
104
110
  * one, which the plugin's host uses, even while the plugin is being created.
105
111
  */
106
112
  interface TokamakCodec {
107
113
  /** [value] as the JSON org.json writes. */
108
- fun encodeValue(value: Any): Any = throw TokamakPluginError.typeError("android/Exports.kt uses no ${value.javaClass.simpleName}")
114
+ fun encodeValue(value: Any): Any = throw TokamakPluginError.typeError("Exports.kt uses no ${value.javaClass.simpleName}")
109
115
 
110
116
  /** [json] as a [type]. */
111
- fun decodeValue(json: TokamakValue, type: KClass<*>): Any = throw TokamakPluginError.typeError("android/Exports.kt uses no ${type.simpleName}")
117
+ fun decodeValue(json: TokamakValue, type: KClass<*>): Any = throw TokamakPluginError.typeError("Exports.kt uses no ${type.simpleName}")
112
118
 
113
119
  /** The JSON [json], as org.json reads it, as a [type], which [decodeValue] decodes. */
114
120
  fun <T : Any> fromJson(json: Any?, type: KClass<T>): T {
@@ -116,10 +122,10 @@ interface TokamakCodec {
116
122
  return type.castOrNull(value) ?: throw TokamakPluginError.typeError("json is ${value.javaClass.simpleName}, not ${type.simpleName}")
117
123
  }
118
124
 
119
- /** [event] as the JSON payload of the event [name], which `android/Exports.kt` lists. */
125
+ /** [event] as the JSON payload of the event [name], which `Exports.kt` lists. */
120
126
  fun eventPayload(name: String, event: Any): ByteArray = throw TokamakPluginError.unlistedEvent(name)
121
127
 
122
- /** The listeners' [reply] to the event [name], which `android/Exports.kt` lists with a reply, as its type. */
128
+ /** The listeners' [reply] to the event [name], which `Exports.kt` lists with a reply, as its type. */
123
129
  fun eventReply(name: String, reply: TokamakValue): Any = throw TokamakPluginError.unlistedReply(name)
124
130
 
125
131
  /** The listeners' encoded [payload] in reply to the event [name] as a [type], or null when none replied. */
@@ -231,7 +237,7 @@ class TokamakValue(private val json: Any?, private val path: String) {
231
237
  }
232
238
 
233
239
  /**
234
- * A plugin with the dispatch generated from its `android/Exports.kt`. The app's registry creates the
240
+ * A plugin with the dispatch generated from its `Exports.kt`. The app's registry creates the
235
241
  * generated subclass in place of [plugin], which plugins find with `tokamakPlugin(id)`.
236
242
  */
237
243
  abstract class TokamakDispatch<P : TokamakPlugin>(val plugin: P, protected val host: TokamakHost) : TokamakPlugin by plugin {
@@ -30,10 +30,10 @@ class TokamakPluginError(
30
30
  fun needsUI() = TokamakPluginError("NeedsUIError", "The app cannot show UI while it is in the background")
31
31
 
32
32
  /** The plugin emitted an event its registration does not list. */
33
- fun unlistedEvent(name: String) = typeError("android/Exports.kt lists no event $name")
33
+ fun unlistedEvent(name: String) = typeError("Exports.kt lists no event $name")
34
34
 
35
35
  /** The plugin asked for the reply to an event its registration lists without one. */
36
- fun unlistedReply(name: String) = typeError("android/Exports.kt lists no reply to event $name")
36
+ fun unlistedReply(name: String) = typeError("Exports.kt lists no reply to event $name")
37
37
  }
38
38
  }
39
39
 
@@ -195,7 +195,7 @@ interface TokamakHost {
195
195
 
196
196
  /**
197
197
  * Delivers [event] to the Worker's listeners of the plugin's event [name], which
198
- * `android/Exports.kt` lists. Starts the runtime when it is not running. Blocks, so call it off
198
+ * `Exports.kt` lists. Starts the runtime when it is not running. Blocks, so call it off
199
199
  * the main thread; throws unless the listeners return within [timeoutMillis], which includes
200
200
  * runtime startup.
201
201
  */
@@ -205,13 +205,13 @@ interface TokamakHost {
205
205
  fun <R : Any> emit(name: String, event: Any, reply: KClass<R>, timeoutMillis: Long): R?
206
206
 
207
207
  /**
208
- * [value], of a data class or sealed type `android/Exports.kt`'s methods and events use, as
208
+ * [value], of a data class or sealed type `Exports.kt`'s methods and events use, as
209
209
  * the JSON the Worker receives, which org.json writes, for a value the plugin stores.
210
210
  */
211
211
  fun json(value: Any): Any
212
212
 
213
213
  /**
214
- * The JSON [json], as org.json reads it, as a data class or sealed [type] `android/Exports.kt`'s
214
+ * The JSON [json], as org.json reads it, as a data class or sealed [type] `Exports.kt`'s
215
215
  * methods and events use, for a value the plugin stored with [json].
216
216
  */
217
217
  fun <T : Any> fromJson(json: Any?, type: KClass<T>): T
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/platform-android-arm64",
3
- "version": "0.1.1-beta.155",
3
+ "version": "0.1.1-beta.157",
4
4
  "description": "The tokamak platform pack for android-arm64",
5
5
  "repository": {
6
6
  "type": "git",