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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ comline-core = { git = "https://github.com/ComlineProject/core", rev = "868e8310
# `comline-codegen`'s types, so the rev below must be byte-identical to the
# one *they* pin - Cargo only unifies a git dependency across identical rev
# strings, and two copies of `GenRequest` are two incompatible types.
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "da81b688c949a0ebad4f213d6fdb648920cf641d" }
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "922847b608764687b9d75020ff46a3f24d43b5bd" }
# The official Markdown and HTML documentation renderers (`comline doc`),
# linked in like the official generators. Same generation rev as
# `comline-codegen`.
comline-doc-markdown = { git = "https://github.com/ComlineProject/generation", rev = "da81b688c949a0ebad4f213d6fdb648920cf641d" }
comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "da81b688c949a0ebad4f213d6fdb648920cf641d" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "6db2757b6d1e7df44df8c47adc8cad5bec1559c1", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "bcec31dd13320613bcc1dcb10dcbc72f9a1011f9", optional = true }
comline-doc-markdown = { git = "https://github.com/ComlineProject/generation", rev = "922847b608764687b9d75020ff46a3f24d43b5bd" }
comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "922847b608764687b9d75020ff46a3f24d43b5bd" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "ac7fd8b3deaa334d353485414264eb9336500bb9", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "4db92c26b00211aabf90e4ef1b2f55977274d761", optional = true }
# `comline conformance`: the conformance runner (corpus loading, judging,
# profile proofs) and its case format, a public spec. Pinned by git rev.
comline-runtime-conformance = { git = "https://github.com/ComlineProject/runtime", rev = "8f8c0cb6fb0bc3a734aafbdbbf187fb9da73e00d" }
Expand Down
13 changes: 12 additions & 1 deletion src/lang_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,20 @@ pub fn check_declared(context: &ProjectContext, registry: &Registry) -> eyre::Re
}
}

// The names the package gives its dependencies, the way `comline
// generation` fills `GenerateRequest::dependencies`: a dependency's
// protocols aren't on the package's connection.
let dependencies: Vec<String> = context
.dependency_configs
.iter()
.map(|(name, _)| name.clone())
.collect();

// JSON-RPC protocols on one connection whose bare method names a side
// couldn't tell apart: no generator can emit them.
for clash in comline_codegen::checks::method_name_clashes(&schemas, &framings) {
for clash in
comline_codegen::checks::method_name_clashes_among(&schemas, &dependencies, &framings)
{
problems.push(format!("every target: {}", clash.message));
}

Expand Down
43 changes: 43 additions & 0 deletions tests/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,49 @@ fn refuses_bare_jsonrpc_names_that_would_clash_on_a_connection() {
build(&project).success();
}

/// A dependency's protocol isn't on the package's connection, so its
/// function names are no clash for the package's own (generation#147). The
/// package has a client-provided protocol, which puts its jsonrpc protocols
/// on a connection.
#[test]
fn a_dependencys_jsonrpc_method_name_is_no_clash_for_the_packages_own() {
let allow_framing = "\nsettings = {\n annotations = {\n framing = {\n allowed = true\n }\n }\n}\n";
let temp = tempfile::tempdir().unwrap();
let shared = temp.path().join("shared");
std::fs::create_dir_all(shared.join("src")).unwrap();
std::fs::write(
shared.join("config.idp"),
with_bounds(&format!(
"congregation shared\nspecification_version = 1\n{allow_framing}"
)),
)
.unwrap();
std::fs::write(
shared.join("src/chat.ids"),
"struct Message {\n text: string\n}\n\n\
@framing = \"jsonrpc\"\nprotocol Chat {\n function send(text: string) -> u64;\n}\n",
)
.unwrap();

let project = declaring(
temp.path(),
"rust#1.85.0 = {}",
&format!(
"{allow_framing}dependencies = {{\n shared = {{\n path = \"../shared\"\n }}\n}}\n"
),
);
std::fs::write(
project.join("src/admin.ids"),
"use shared::chat::Message\n\nstruct Note {\n message: Message\n}\n\n\
@framing = \"jsonrpc\"\nprotocol Admin {\n function send(text: string) -> u64;\n}\n\n\
@provider = Client\n@framing = \"jsonrpc\"\nprotocol Events {\n function ping();\n}\n",
)
.unwrap();

build(&project).success();
assert!(project.join(".comline").is_dir());
}

/// A project from before bounds (core#98): every unbounded position is an
/// error, and the build says what to add to config.idp, without guessing
/// the maxima.
Expand Down
90 changes: 90 additions & 0 deletions tests/cli/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,3 +1534,93 @@ fn a_built_versions_dependency_protocol_is_left_alone_too() {
}
assert!(app.join("generated/rust/0.1.0/holder.rs").exists());
}

// -------- protocols in nested schemas (generation#148) --------

/// A package with no dependencies, on the defaults (`datagram@3` and
/// `comline@2`), whose protocol is in `src/chat/admin.ids`: its namespace is
/// `chat/admin` in the generation request and `chat::admin` in the facts the
/// build recorded, and the two have to meet. Declares Rust and TypeScript.
fn package_with_a_nested_protocol(root: &std::path::Path) -> std::path::PathBuf {
comline_cmd()
.current_dir(root)
.args(["new", "chat"])
.assert()
.success();
let project = root.join("chat");
let config = fs::read_to_string(project.join("config.idp"))
.unwrap()
.replace(
"// wire = { format = \"packed@1\" framing = \"datagram@3\" }",
"wire = { format = \"packed@1\" framing = \"datagram@3\" }\n\
handshake = { name = \"comline@2\" newer_consumer = \"refuse\" }",
)
.replace(
"rust#1.85.0 = {}",
"rust#1.85.0 = {}\n typescript#5.0 = {}",
);
fs::write(project.join("config.idp"), config).unwrap();
fs::create_dir_all(project.join("src/chat")).unwrap();
fs::write(
project.join("src/chat/admin.ids"),
"protocol Admin {\n function kick(user: char[max 32]) -> u32;\n \
function ban(user: char[max 32]) -> u32;\n}\n",
)
.unwrap();
project
}

/// The protocol is addressed by the facts the build recorded for
/// `chat::admin`, found from the request's `chat/admin`: before
/// generation#148 this was "the package's facts have none for it".
#[test]
fn a_protocol_in_a_nested_schema_finds_its_facts() {
let temp = tempfile::tempdir().unwrap();
let project = package_with_a_nested_protocol(temp.path());
comline_cmd()
.current_dir(&project)
.arg("build")
.assert()
.success();

for target in ["rust", "typescript"] {
generate_for(&project, target);
}
let rust = fs::read_to_string(project.join("generated/rust/chat/admin.rs")).unwrap();
for call in ["Call::new(0, \"kick\")", "Call::new(1, \"ban\")"] {
assert!(rust.contains(call), "missing `{call}` in:\n{rust}");
}
assert!(project.join("generated/typescript/chat/admin.ts").exists());
}

/// The same from a built version: the facts come from the version's own
/// record.
#[test]
fn a_built_versions_nested_protocol_finds_its_facts_too() {
let temp = tempfile::tempdir().unwrap();
let project = package_with_a_nested_protocol(temp.path());
comline_cmd()
.current_dir(&project)
.arg("build")
.assert()
.success();
comline_cmd()
.current_dir(&project)
.arg("release")
.assert()
.success();
fs::write(
project.join("comline.toml"),
"[generate]\npackage_versions = \"all\"\n\
layout = \"{{language}}/{{package_version}}/{{namespace}}.{{ext}}\"\n",
)
.unwrap();

for target in ["rust", "typescript"] {
generate_for(&project, target);
}
assert!(project.join("generated/rust/0.1.0/chat/admin.rs").exists());
assert!(project
.join("generated/typescript/0.1.0/chat/admin.ts")
.exists());
}
Loading