Skip to content

Commit bba19cb

Browse files
committed
directories fix
1 parent c39a77a commit bba19cb

11 files changed

Lines changed: 31 additions & 431 deletions

File tree

prebindgen-ext/src/jni/jni_ext.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
//! project.
2525
2626
use std::collections::HashMap;
27-
use std::path::PathBuf;
2827
use std::sync::Arc;
2928

3029
use proc_macro2::{Span, TokenStream};
@@ -201,10 +200,10 @@ pub struct JniExt {
201200
pub jni_class_path: String,
202201
/// Suffix appended to the wrapped fn name (e.g. `ViaJNI`).
203202
pub jni_method_suffix: String,
204-
/// Kotlin package callback fun-interfaces are emitted into.
203+
/// Kotlin package callback fun-interfaces are emitted into. Also
204+
/// drives the on-disk subdirectory under the `kotlin_root` passed
205+
/// to [`Self::write_kotlin`] (`a.b.c` → `a/b/c/`).
205206
pub kotlin_callback_package: String,
206-
/// On-disk directory the per-callback `.kt` files are written to.
207-
pub kotlin_callback_dir: PathBuf,
208207
/// Derived `<rust-type-canonical-string> → <kotlin FQN>` view —
209208
/// populated alongside [`Self::types`] by the structured builders
210209
/// ([`Self::kotlin_class`], [`Self::kotlin_value_type`],
@@ -256,7 +255,6 @@ impl JniExt {
256255
jni_class_path: "Java".to_string(),
257256
jni_method_suffix: String::new(),
258257
kotlin_callback_package: String::new(),
259-
kotlin_callback_dir: PathBuf::new(),
260258
kotlin_type_fqns: Vec::new(),
261259
types: HashMap::new(),
262260
into_sources_map: HashMap::new(),
@@ -298,10 +296,6 @@ impl JniExt {
298296
self.kotlin_callback_package = p.into();
299297
self
300298
}
301-
pub fn kotlin_callback_dir(mut self, d: impl Into<PathBuf>) -> Self {
302-
self.kotlin_callback_dir = d.into();
303-
self
304-
}
305299
// ── Structured type-conversion builders ──────────────────────────
306300

307301
/// Declare a typed Kotlin handle class backed by an opaque Rust

prebindgen-ext/src/jni/jni_kotlin_ext.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
//! `KotlinExt` impl for [`JniExt`].
22
//!
3-
//! Today's pipeline emits two kinds of Kotlin output:
4-
//! 1. One aggregated `JNINative.kt` (interface + data classes + external
5-
//! funs). This is currently produced by the existing
6-
//! [`crate::kotlin::KotlinInterfaceGenerator`] called separately from
7-
//! `build.rs`.
8-
//! 2. One `JNI<Stem>Callback.kt` per `impl Fn(args) + Send + Sync + 'static`
9-
//! type encountered. These get emitted here via `JniExt::write_kotlin`.
3+
//! [`JniExt::write_kotlin`] is the single entry point for every Kotlin
4+
//! file the JNI back-end emits. Given one `kotlin_root` it writes:
5+
//! * `NativeHandle.kt` (package `io.zenoh.jni`).
6+
//! * One typed-handle class per `kotlin_class` entry without
7+
//! `.suppress_kotlin_code()`.
8+
//! * `JNIWrappers.kt` — top-level safe wrappers for non-promoted fns.
9+
//! * One `JNI<Stem>Callback.kt` per `impl Fn(args) + Send + Sync +
10+
//! 'static` type (package = `kotlin_callback_package`). Callback
11+
//! types overridden via [`JniExt::callback_input`] /
12+
//! [`JniExt::callback_kotlin_name`] are skipped — the override
13+
//! points at a hand-written interface.
1014
//!
11-
//! The split is deliberate: the per-callback files are the new artifact
12-
//! introduced by the rewrite; the aggregated interface remains the
13-
//! responsibility of the existing generator and is not touched by JniExt.
15+
//! All emitters route through [`KotlinFile::write`], which translates
16+
//! `package` into a sub-path under `kotlin_root`.
1417
1518
use std::collections::{BTreeSet, HashSet};
1619
use std::path::{Path, PathBuf};
@@ -70,7 +73,7 @@ impl JniExt {
7073
kotlin_root: &Path,
7174
) -> Result<Vec<PathBuf>, WriteKotlinError> {
7275
let mut written = Vec::new();
73-
written.extend(self.emit_callback_files(registry)?);
76+
written.extend(self.emit_callback_files(registry, kotlin_root)?);
7477
written.push(self.write_native_handle(kotlin_root)?);
7578

7679
// Build the borrowed `TypedHandle<'_>` view from internal config.
@@ -111,14 +114,15 @@ impl JniExt {
111114
/// registry). Skips writes for `impl Fn(...)` keys whose Kotlin
112115
/// FQN was overridden via [`Self::callback_input`] — the override
113116
/// already points at a hand-maintained callback interface, so the
114-
/// auto-stub would be dead code.
117+
/// auto-stub would be dead code. Each emitted file is placed
118+
/// under `kotlin_root/<kotlin_callback_package as path>/`.
115119
pub(crate) fn emit_callback_files(
116120
&self,
117121
registry: &Registry<KotlinMeta>,
122+
kotlin_root: &Path,
118123
) -> Result<Vec<PathBuf>, WriteKotlinError> {
119124
let mut seen: HashSet<TypeKey> = HashSet::new();
120125
let mut written = Vec::new();
121-
let target_dir = self.kotlin_callback_dir.clone();
122126
for buckets in [&registry.input_types, &registry.output_types] {
123127
for bucket in buckets.iter() {
124128
for (key, slot) in bucket {
@@ -142,10 +146,7 @@ impl JniExt {
142146
continue;
143147
}
144148
let file = build_callback_kotlin_file(self, &args, registry);
145-
std::fs::create_dir_all(&target_dir)?;
146-
let path = target_dir.join(format!("{}.kt", file.class_name));
147-
std::fs::write(&path, &file.contents)?;
148-
written.push(path);
149+
written.push(file.write(kotlin_root)?);
149150
}
150151
}
151152
}

zenoh-jni-runtime/src/commonMain/kotlin/io/zenoh/jni/JNIMatchingListener.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

zenoh-jni-runtime/src/commonMain/kotlin/io/zenoh/jni/JNIPublisher.kt

Lines changed: 0 additions & 22 deletions
This file was deleted.

zenoh-jni-runtime/src/commonMain/kotlin/io/zenoh/jni/JNIQueryable.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

zenoh-jni-runtime/src/commonMain/kotlin/io/zenoh/jni/JNISampleMissListener.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

zenoh-jni-runtime/src/commonMain/kotlin/io/zenoh/jni/JNISubscriber.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)