|
| 1 | +use crate::{LanguageMethods, Runner, Verify}; |
| 2 | +use anyhow::{bail, Result}; |
| 3 | +use std::process::Command; |
| 4 | + |
| 5 | +pub struct Kotlin; |
| 6 | + |
| 7 | +impl LanguageMethods for Kotlin { |
| 8 | + fn display(&self) -> &str { |
| 9 | + "kotlin" |
| 10 | + } |
| 11 | + |
| 12 | + fn comment_prefix_for_test_config(&self) -> Option<&str> { |
| 13 | + Some("//@") |
| 14 | + } |
| 15 | + |
| 16 | + fn prepare(&self, runner: &mut Runner) -> Result<()> { |
| 17 | + println!("Testing if ktfmt is available..."); |
| 18 | + let test_crate = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 19 | + let wit_bindgen_root = test_crate.parent().unwrap().parent().unwrap(); |
| 20 | + let ktfmt_jar = wit_bindgen_root.join("ktfmt-0.47-jar-with-dependencies.jar"); |
| 21 | + if !ktfmt_jar.exists() { |
| 22 | + bail!( |
| 23 | + "ktfmt jar not found at `{}`", |
| 24 | + ktfmt_jar.display() |
| 25 | + ); |
| 26 | + } |
| 27 | + runner.run_command(Command::new("java").arg("-version"))?; |
| 28 | + Ok(()) |
| 29 | + } |
| 30 | + |
| 31 | + fn default_bindgen_args_for_codegen(&self) -> &[&str] { |
| 32 | + &["--generate-stubs"] |
| 33 | + } |
| 34 | + |
| 35 | + fn compile(&self, _runner: &Runner, _compile: &crate::Compile) -> Result<()> { |
| 36 | + bail!("compiling Kotlin to a wasm component is not yet supported") |
| 37 | + } |
| 38 | + |
| 39 | + fn should_fail_verify( |
| 40 | + &self, |
| 41 | + name: &str, |
| 42 | + config: &crate::config::WitConfig, |
| 43 | + _args: &[String], |
| 44 | + ) -> bool { |
| 45 | + config.error_context |
| 46 | + // TODO: fix these codegen failures, and organize them better (e.g. add as a failure condition config.async_ here, once we have real verification) |
| 47 | + || matches!( |
| 48 | + name, |
| 49 | + "future-same-type-different-names.wit" |
| 50 | + | "futures.wit" |
| 51 | + | "import-and-export-resource-alias.wit" |
| 52 | + | "import-and-export-resource.wit" |
| 53 | + | "import-export-future.wit" |
| 54 | + | "import-export-stream.wit" |
| 55 | + | "issue-1432.wit" |
| 56 | + | "issue-1544.wit" |
| 57 | + | "issue1515-special-in-comment.wit" |
| 58 | + | "issue573.wit" |
| 59 | + | "issue929-only-methods.wit" |
| 60 | + | "issue929.wit" |
| 61 | + | "keywords-in-interfaces-and-worlds.wit" |
| 62 | + | "named-fixed-length-list.wit" |
| 63 | + | "rename-interface.wit" |
| 64 | + | "resource-alias.wit" |
| 65 | + | "resource-borrow-in-record.wit" |
| 66 | + | "resource-fallible-constructor.wit" |
| 67 | + | "resource-local-alias.wit" |
| 68 | + | "resource-own-in-other-interface.wit" |
| 69 | + | "resources-in-aggregates.wit" |
| 70 | + | "resources-with-futures.wit" |
| 71 | + | "resources-with-lists.wit" |
| 72 | + | "resources-with-streams.wit" |
| 73 | + | "resources.wit" |
| 74 | + | "return-resource-from-export.wit" |
| 75 | + | "smoke-export.wit" |
| 76 | + | "smoke.wit" |
| 77 | + | "streams.wit" |
| 78 | + | "unused-import.wit" |
| 79 | + | "use-across-interfaces.wit" |
| 80 | + ) |
| 81 | + } |
| 82 | + |
| 83 | + fn verify(&self, runner: &Runner, verify: &Verify) -> Result<()> { |
| 84 | + let test_crate = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 85 | + let wit_bindgen_root = test_crate.parent().unwrap().parent().unwrap(); |
| 86 | + let ktfmt_jar = wit_bindgen_root.join("ktfmt-0.47-jar-with-dependencies.jar"); |
| 87 | + |
| 88 | + let mut cmd = Command::new("java"); |
| 89 | + cmd.arg("-jar") |
| 90 | + .arg(&ktfmt_jar) |
| 91 | + .arg(verify.bindings_dir.file_name().unwrap()) |
| 92 | + .current_dir(verify.bindings_dir.parent().unwrap()); |
| 93 | + runner.run_command(&mut cmd) |
| 94 | + |
| 95 | + // TODO actually compile the bindings to verify compilation |
| 96 | + } |
| 97 | +} |
0 commit comments