Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))?;

Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/cli/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading