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

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

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ eyre = "0.6.8"
# needs real I/O (git fetch, filesystem), so it's off by default for
# `comline-core`'s wasm32 consumers (the playground editor, the language
# server); the CLI is the one consumer that actually runs `comline build`.
comline-core = { git = "https://github.com/ComlineProject/core", rev = "263e58378bb7efcaa466542ca644228ad14e2884", features = ["deps"] }
comline-core = { git = "https://github.com/ComlineProject/core", rev = "e2d68a5fa4ee20bb50392c259f732e2d0f2300ba", features = ["deps"] }
# All three pinned to revs that agree on one `comline-codegen`, and bumped
# together: comline-rust and comline-typescript's codegen crates consume
# `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 = "3ad2c79f48242f7de4bed3e8bc23c5673a381a2e" }
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "8e7dca84ed42f1b785fdb2470a2e94773e2fcef6" }
# 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 = "3ad2c79f48242f7de4bed3e8bc23c5673a381a2e" }
comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "3ad2c79f48242f7de4bed3e8bc23c5673a381a2e" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "349763589f16fcee43a9b8bc3e2d9af8674fef00", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "20bad456df0334b0197ddefdc1460f96c7ff33ae", optional = true }
comline-doc-markdown = { git = "https://github.com/ComlineProject/generation", rev = "8e7dca84ed42f1b785fdb2470a2e94773e2fcef6" }
comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "8e7dca84ed42f1b785fdb2470a2e94773e2fcef6" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "3e6864d31fa6e933d34dde186256be6ae2ad1ff9", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "b5fc2438028e6a37487993c9f86397403e4e4ff0", 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 = "3b9cc9dc53a83fb2830d91b267bd5f477f0a1e51" }
comline-runtime-conformance = { git = "https://github.com/ComlineProject/runtime", rev = "8f8c0cb6fb0bc3a734aafbdbbf187fb9da73e00d" }
# `comline doc open` / `--open`: the system's default handler for a file (a
# browser for HTML). Exact pin; no default features (`reveal` pulls in D-Bus).
opener = { version = "=0.9.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ resolves to, with their parameters and where each came from:
| `from @framing` / `from @handshake` | the protocol's own annotation |
| `from config.idp ...` | the package's `wire.format`, `wire.framing` or `handshake` |
| `core's default` | nothing named one: `packed@1`, `datagram@3`, `comline@2` (`comline@1` on any framing but `datagram@3`) |
| `JSON-RPC's format` | the framing is JSON-RPC and the package names no format |
| `JSON-RPC's format` | the framing implies a format (JSON-RPC's is JSON, and the line names the framing by its title) and the package names no format |

Then one row per guarantee (schema agreement, encoding agreement, encoding
conformance, version honesty), held or given up. A given-up row says why, and
Expand Down
46 changes: 46 additions & 0 deletions src/changes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Rendering for `comline_core`'s [`SchemaChanges`], shared by `build` and `diff`.

use comline_core::package::build::cas::build::UnseenConfig;
use comline_core::package::build::VersionBump;
use comline_core::package::config::ir::diff::{ConfigChange, ConfigChanges};
use comline_core::schema::ir::diff::{BreakingChange, Modification, NewFeature, SchemaChanges};
Expand Down Expand Up @@ -50,6 +51,34 @@ pub fn render_config(changes: &ConfigChanges) {
}
}

/// Print the configs the comparison couldn't see, if any: they count as
/// changed, so they're why a build with nothing else to show still moves
/// the version.
pub fn render_unseen(unseen: &[UnseenConfig]) {
if unseen.is_empty() {
return;
}
ui::group(heading("❔", "Configs not compared", unseen.len()));
for config in unseen {
ui::detail(unseen_line(config));
}
}

fn unseen_line(config: &UnseenConfig) -> String {
let whose = match config {
UnseenConfig::Own => "The package's config".to_string(),
UnseenConfig::Dependency(name) => format!("Dependency `{name}`'s config"),
};
mark(
"❔",
"?",
format!(
"{whose} isn't stored in an older build, so it counts as changed (at least a \
patch); `comline build` stores it from now on"
),
)
}

fn config_line(change: &ConfigChange) -> String {
let arrow = ui::arrow();
match change {
Expand Down Expand Up @@ -494,3 +523,20 @@ fn modification_line(modification: &Modification) -> String {
),
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn an_unseen_config_says_it_counts_as_changed_and_how_it_stops() {
let own = unseen_line(&UnseenConfig::Own);
assert!(own.contains("The package's config isn't stored in an older build"));
assert!(own.contains("counts as changed (at least a patch)"));
assert!(own.contains("`comline build` stores it from now on"));

let dependency = unseen_line(&UnseenConfig::Dependency("shared_types".into()));
assert!(dependency.contains("Dependency `shared_types`'s config isn't stored"));
assert!(dependency.contains("`comline build` stores it from now on"));
}
}
11 changes: 10 additions & 1 deletion src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use std::path::Path;

use comline_core::package::build::cas::object_store::StoreError;
use comline_core::package::build::cas::objects::Commit;
use comline_core::package::build::cas::reconcile::{self, Heads};
use comline_core::package::build::cas::{main_ref, read_ref, ref_exists, Hash, ObjectStore};
Expand All @@ -17,6 +18,7 @@ use crate::bounds_migration;
use crate::changes;
use crate::commands::generation::generator_registry;
use crate::commands::{core_err, ensure_project};
use crate::error;
use crate::lang_targets;
use crate::ui;
use crate::watch;
Expand Down Expand Up @@ -116,6 +118,11 @@ fn build_once(work_dir: &Path, offer_migration: bool) -> Result<()> {

let result = match result {
Ok(result) => result,
// A store core refuses (another IR format, no stamp) is a
// precondition, reported as core words it, with nothing written.
Err(e) if e.downcast_ref::<StoreError>().is_some() => {
return Err(error::from_core("build failed", e));
}
Err(e) => {
let detail = format!("{e:#}");
let unbounded = bounds_migration::Unbounded::of(&detail);
Expand Down Expand Up @@ -164,7 +171,8 @@ fn build_once(work_dir: &Path, offer_migration: bool) -> Result<()> {
.map(|c| !c.is_empty())
.unwrap_or(false)
|| !result.dependency_changes.is_empty()
|| !result.config_changes.is_empty();
|| !result.config_changes.is_empty()
|| !result.unseen.is_empty();

if !has_changes {
ui::detail(pkg(format!(
Expand All @@ -186,6 +194,7 @@ fn build_once(work_dir: &Path, offer_migration: bool) -> Result<()> {
changes::render(&dependency.changes);
}
changes::render_config(&result.config_changes);
changes::render_unseen(&result.unseen);
ui::detail(changes::bump_line(result.version_bump));
next_release_line(&result);

Expand Down
1 change: 1 addition & 0 deletions src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn run(work_dir: &Path, old: &str, new: &str) -> Result<()> {
changes::render(&dependency.changes);
}
changes::render_config(&comparison.config_changes);
changes::render_unseen(&comparison.unseen);
ui::detail(changes::bump_line(comparison.bump));
Ok(())
}
Expand Down
86 changes: 64 additions & 22 deletions src/commands/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ fn facts_for(
}
FactsSource::WorkingTree => comline_core::compat::facts_of_working_tree(work_dir, context),
}
.map_err(|e| miette!("working out the package's facts: {e:#}"))?;
.map_err(|e| crate::error::from_core("working out the package's facts", e))?;
// The same fields under the same names: the generator protocol's mirror.

let facts = serde_json::to_value(&facts)
Expand All @@ -628,9 +628,10 @@ fn facts_for(

/// `async = true` changes only protocols on a connection; with none, the
/// output is the same as without it, which looks like the setting did nothing.
/// Every protocol is on one by default, so that's a package whose protocols
/// are all lockstep: on the `datagram` framing, or on JSON-RPC with none of
/// them client-provided.
/// A protocol is on one by default when its framing's frames go both ways and
/// name the protocol, so that's a package whose protocols are all lockstep:
/// each on a framing that keeps it off a connection
/// ([`connections::why_lockstep`]), which the warning names.
fn warn_async_unused(language: &str, request: &GenerateRequest) {
if !request.async_api {
return;
Expand All @@ -641,14 +642,65 @@ fn warn_async_unused(language: &str, request: &GenerateRequest) {
return;
}

let lockstep: Vec<String> = framings_in_use(request)
.iter()
.filter_map(|framing| lockstep_description(framing))
.collect();

let why = if lockstep.is_empty() {
"the package has no protocols".to_owned()
} else {
format!(
"every protocol here is lockstep: on {}",
lockstep.join(" or ")
)
};

ui::warn(format!(
"`{language}`: `async = true`, but no protocol runs on a connection, so the output \
is the same as without it - every protocol here is lockstep: on the `datagram` \
framing (the default, `datagram@3`, is a connection), or on JSON-RPC with none of \
the package's JSON-RPC protocols client-provided"
is the same as without it - {why}"
));
}

/// The framings the package's protocols are on, canonical (`jsonrpc`,
/// `datagram@2`, `com.acme.lines@1`), once each.
fn framings_in_use(request: &GenerateRequest) -> std::collections::BTreeSet<String> {
let mut framings = std::collections::BTreeSet::new();
for (_, units) in &request.schemas {
for unit in units {
if let FrozenUnit::Protocol { parameters, .. } = unit {
framings.insert(connections::framing_name(parameters));
}
}
}

framings
}

/// A framing for a message about protocols that aren't on a connection: its
/// title, and why its protocols stay off one unless the client provides
/// them. `None` for a framing that has no such reason (its frames go both
/// ways and name the protocol), where a protocol is on a connection already.
fn lockstep_description(framing: &str) -> Option<String> {
let reason = match connections::why_lockstep(framing)? {
connections::Lockstep::OneDirection => {
"its frames go one way, so the server can't call the client"
}
connections::Lockstep::UnnamedServerProvided => {
"its frames don't name the protocol, and none of its protocols is client-provided"
}
connections::Lockstep::Unknown => {
"a framing of the package's own: a protocol on it is on a connection only when \
the client provides it"
}
};

Some(format!(
"{} ({reason})",
connections::framing_title(framing)
))
}

/// 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.
Expand Down Expand Up @@ -676,27 +728,17 @@ fn note_no_connection_protocols(
request: &GenerateRequest,
connections_doc: Option<&str>,
) {
let mut framings = std::collections::BTreeSet::new();
for (_, units) in &request.schemas {
for unit in units {
if let FrozenUnit::Protocol { parameters, .. } = unit {
framings.insert(connections::framing_name(parameters));
}
}
}
let framings = framings_in_use(request);

if framings.is_empty() {
return;
}

// Each framing's title and why it keeps its protocols off a connection;
// one with no such reason (not expected here) is just its title.
let framings: Vec<String> = framings
.into_iter()
.map(|f| match f.as_str() {
"jsonrpc" => "JSON-RPC (with none of its protocols client-provided)".to_owned(),
// Canonical, `datagram` is the lockstep `datagram@1`.
"datagram" => "`datagram@1`".to_owned(),
_ => format!("`{f}`"),
})
.iter()
.map(|f| lockstep_description(f).unwrap_or_else(|| connections::framing_title(f)))
.collect();

let page = connections_doc
Expand Down
Loading
Loading