diff --git a/src/commands/generate.rs b/src/commands/generate.rs index 5433390..1e7bd03 100644 --- a/src/commands/generate.rs +++ b/src/commands/generate.rs @@ -12,7 +12,9 @@ use std::collections::BTreeMap; use std::path::{Path, PathBuf}; -use comline_codegen::{features, GenRequest, Mode, PackageMeta, Registry, Resolved, Unresolved}; +use comline_codegen::{ + connections, features, GenRequest, Mode, PackageMeta, Registry, Resolved, Unresolved, +}; use comline_core::package::build::{self, cas::ObjectStore}; use comline_core::package::config::ir::frozen::{self, FrozenUnit as ConfigUnit}; use comline_core::schema::idl::constants::SCHEMA_EXTENSION; @@ -236,6 +238,7 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo // nothing for the multi-line branch there to do. warn_ignored(&t.language, &request, &resolved); warn_async_unused(&t.language, &request); + warn_no_package_connection(&t.language, &request); let files = generator(&request).map_err(|e| miette!("`{}` generator: {e}", t.language))?; @@ -425,6 +428,18 @@ fn warn_async_unused(language: &str, request: &GenRequest) { )); } +/// The package's `serve` / `connect` need its protocols on one connection; +/// when they disagree on the framing or handshake, the generators leave them +/// out, which would otherwise look like they forgot. +fn warn_no_package_connection(language: &str, request: &GenRequest) { + if let Err(reason) = connections::package_connection(request.schemas) { + ui::warn(format!( + "`{language}`: no package `serve` / `connect` - {reason}; each protocol still has \ + its own" + )); + } +} + /// A warning per feature `request` uses that this generator ignores - it /// generates, but without the feature (a TypeScript target with /// `@validators` gets the types, not the checks). An unsupported feature diff --git a/tests/cli/generate.rs b/tests/cli/generate.rs index fc3dbe5..d5f41c2 100644 --- a/tests/cli/generate.rs +++ b/tests/cli/generate.rs @@ -263,6 +263,35 @@ fn without_a_wire_key_a_protocol_is_on_a_packed_connection() { assert!(connection.contains("pub struct Services<"), "{connection}"); } +/// Two protocols on connections of different framings can't share one, so +/// the package `serve` is left out, and generate says why. +#[test] +fn protocols_on_different_framings_get_no_package_serve() { + let temp = tempfile::tempdir().unwrap(); + let project = fixture_project(temp.path()); + add_to_config( + &project, + "settings = {\n annotations = {\n framing = {\n allowed = true\n }\n }\n}", + ); + fs::write( + project.join("src/link.ids"), + "protocol Link {\n function send(n: u32) -> u32;\n}\n\n\ + @provider = Client\n@framing = \"jsonrpc\"\nprotocol Push {\n function ping();\n}\n", + ) + .unwrap(); + + comline_cmd() + .current_dir(&project) + .args(["generate", "--target", "rust"]) + .assert() + .success() + .stderr(predicate::str::contains("no package `serve` / `connect`")) + .stderr(predicate::str::contains( + "`link::Link` is on a `datagram@2` connection", + )); + assert!(!project.join("generated/rust/connection.rs").exists()); +} + #[test] fn comline_toml_default_framing_says_it_moved() { let temp = tempfile::tempdir().unwrap();