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.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ toml = "0.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 = "ad2b3f582dabb4a27d616741e425699299fc84de", features = ["deps"] }
comline-core = { git = "https://github.com/ComlineProject/core", rev = "622500a39a49ad4118cdce9344531cf6f0f5978d", 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 = "2d824dded159efc862d2c6266c27c015542baa96" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "8f7e0baa81e1cf6350582148ace7c4fe86be830c", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "62bbf796eff54c2bd304004b7d29e854074d4396", optional = true }
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "350bbce6e88caf65e60449e3ebd0e1d45eb19179" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "bc1c4af956bfad9e110583620e6f85255a0dda42", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "4ad1c3574a342d974e83a94570d51d903ea32bbe", optional = true }

[features]
# Which language generators are compiled in. Drop one to shed its whole
Expand Down
163 changes: 159 additions & 4 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,116 @@ fn breaking_line(change: &BreakingChange) -> String {
mark("❌", "-", format!("Removed protocol `{name}`"))
}
BreakingChange::RemovedError { name } => mark("❌", "-", format!("Removed error `{name}`")),
BreakingChange::ChangedFieldOptionality {
type_name,
field_name,
now_optional,
} => {
let now = if *now_optional {
"optional"
} else {
"required"
};
mark(
"🔄",
"~",
format!("Made field `{type_name}.{field_name}` {now}"),
)
}
BreakingChange::RenamedEnumVariant {
enum_name,
old_name,
new_name,
} => mark(
"🔄",
"~",
format!(
"Renamed `{enum_name}::{old_name}` {} `{enum_name}::{new_name}`",
ui::arrow()
),
),
BreakingChange::RemovedThrownError {
protocol_name,
function_name,
error,
} => mark(
"❌",
"-",
format!("`{protocol_name}.{function_name}` no longer declares `! {error}`"),
),
BreakingChange::ChangedErrorOrdinal {
name,
old_ordinal,
new_ordinal,
} => mark(
"🔄",
"~",
format!(
"Error `{name}`'s ordinal moved: {old_ordinal} {} {new_ordinal}",
ui::arrow()
),
),
BreakingChange::RemovedConstant { name } => {
mark("❌", "-", format!("Removed constant `{name}`"))
}
BreakingChange::ChangedConstantType {
name,
old_type,
new_type,
} => mark(
"🔄",
"~",
format!(
"Changed constant `{name}`: {old_type} {} {new_type}",
ui::arrow()
),
),
BreakingChange::RemovedTypeAlias { name } => {
mark("❌", "-", format!("Removed type alias `{name}`"))
}
BreakingChange::ChangedTypeAliasTarget {
name,
old_target,
new_target,
} => mark(
"🔄",
"~",
format!(
"Changed type alias `{name}`: {old_target} {} {new_target}",
ui::arrow()
),
),
BreakingChange::RemovedValidator { name } => {
mark("❌", "-", format!("Removed validator `{name}`"))
}
BreakingChange::ChangedValidator { name } => {
mark("🔄", "~", format!("Changed validator `{name}`"))
}
BreakingChange::ValidationTightened { target } => {
mark("🔄", "~", format!("Validation tightened on `{target}`"))
}
BreakingChange::ChangedWireAnnotation {
target,
key,
old_value,
new_value,
} => mark(
"🔄",
"~",
format!(
"Changed `@{key}` on `{target}`: {}",
value_change(old_value, new_value)
),
),
}
}

/// `old → new`, with `(none)` for a side that has no value.
fn value_change(old: &Option<String>, new: &Option<String>) -> String {
let show = |v: &Option<String>| v.clone().unwrap_or_else(|| "(none)".to_string());
format!("{} {} {}", show(old), ui::arrow(), show(new))
}

fn feature_line(feature: &NewFeature) -> String {
match feature {
NewFeature::AddedStruct { name, field_count } => mark(
Expand Down Expand Up @@ -177,21 +284,69 @@ fn feature_line(feature: &NewFeature) -> String {
"+",
format!("Added error `{name}` ({})", count(*field_count, "field")),
),
NewFeature::AddedThrownError {
protocol_name,
function_name,
error,
} => mark(
"➕",
"+",
format!("`{protocol_name}.{function_name}` now declares `! {error}`"),
),
NewFeature::AddedConstant { name, ty } => {
mark("➕", "+", format!("Added constant `{name}`: {ty}"))
}
NewFeature::ChangedConstantValue {
name,
old_value,
new_value,
} => mark(
"🔧",
"~",
format!(
"Changed constant `{name}`'s value: {}",
value_change(old_value, new_value)
),
),
NewFeature::AddedTypeAlias { name, target } => {
mark("➕", "+", format!("Added type alias `{name}` = {target}"))
}
NewFeature::AddedValidator { name } => mark("➕", "+", format!("Added validator `{name}`")),
NewFeature::ValidationLoosened { target } => {
mark("🔧", "~", format!("Validation loosened on `{target}`"))
}
NewFeature::Deprecated { target } => mark("⚠️", "!", format!("Deprecated `{target}`")),
}
}

fn modification_line(modification: &Modification) -> String {
match modification {
Modification::FieldMadeOptional {
Modification::DocstringChanged { name } => {
mark("📝", "~", format!("Docstring changed on `{name}`"))
}
Modification::ChangedFieldDefault {
type_name,
field_name,
} => mark(
"🔧",
"~",
format!("Made field `{type_name}.{field_name}` optional"),
format!("Changed the default of `{type_name}.{field_name}`"),
),
Modification::DocstringChanged { name } => {
mark("📝", "~", format!("Docstring changed on `{name}`"))
Modification::ChangedErrorMessage { name } => {
mark("📝", "~", format!("Changed error `{name}`'s message"))
}
Modification::ChangedAnnotation {
target,
key,
old_value,
new_value,
} => mark(
"🔧",
"~",
format!(
"Changed `@{key}` on `{target}`: {}",
value_change(old_value, new_value)
),
),
}
}
7 changes: 6 additions & 1 deletion src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ fn build_once(work_dir: &Path, release: bool) -> Result<()> {
.schema_changes
.as_ref()
.map(|c| !c.is_empty())
.unwrap_or(false);
.unwrap_or(false)
|| !result.dependency_changes.is_empty();

if !has_changes {
ui::detail(pkg(format!(
Expand All @@ -62,6 +63,10 @@ fn build_once(work_dir: &Path, release: bool) -> Result<()> {
if let Some(changes) = &result.schema_changes {
changes::render(changes);
}
for dependency in &result.dependency_changes {
ui::group(format!("In dependency `{}`:", dependency.name));
changes::render(&dependency.changes);
}
ui::detail(bump_line(result.version_bump));

Ok(())
Expand Down
29 changes: 2 additions & 27 deletions src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::path::Path;

use comline_core::package::build::cas::objects::Commit;
use comline_core::package::build::cas::ObjectStore;
use comline_core::schema::ir::diff::{analyze_schema_changes, SchemaChanges};
use comline_core::schema::ir::frozen::unit::FrozenUnit;
use comline_core::schema::ir::diff::analyze_package_changes;
use miette::Result;

use crate::commands::ensure_project;
Expand Down Expand Up @@ -34,34 +33,10 @@ pub fn run(work_dir: &Path, old: &str, new: &str) -> Result<()> {

let old_schemas = history::load_schemas(&store, old_commit)?;
let new_schemas = history::load_schemas(&store, new_commit)?;
changes::render(&aggregate(&old_schemas, &new_schemas));
changes::render(&analyze_package_changes(&old_schemas, &new_schemas));
Ok(())
}

/// Diff schema-by-schema (paired by position) and merge the results, treating
/// added/removed schema files as wholesale additions/removals.
fn aggregate(old: &[Vec<FrozenUnit>], new: &[Vec<FrozenUnit>]) -> SchemaChanges {
let mut merged = SchemaChanges::default();
let common = old.len().min(new.len());

for i in 0..common {
extend(&mut merged, analyze_schema_changes(&old[i], &new[i]));
}
for schema in &new[common..] {
extend(&mut merged, analyze_schema_changes(&[], schema));
}
for schema in &old[common..] {
extend(&mut merged, analyze_schema_changes(schema, &[]));
}
merged
}

fn extend(into: &mut SchemaChanges, from: SchemaChanges) {
into.breaking_changes.extend(from.breaking_changes);
into.new_features.extend(from.new_features);
into.modifications.extend(from.modifications);
}

fn label(spec: &str, commit: &Commit) -> String {
if spec.eq_ignore_ascii_case("HEAD") {
format!("HEAD ({})", commit.version)
Expand Down
6 changes: 4 additions & 2 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ pub fn resolve<'a>(history: &'a [Entry], spec: &str) -> Result<&'a Commit> {
))
}

/// Load every schema's frozen units from a commit's root tree, in tree order.
/// Load every local schema's frozen units from a commit's root tree, in tree
/// order. Vendored dependencies (`dep_<name>` trees) aren't this package's
/// schemas and are skipped.
pub fn load_schemas(store: &ObjectStore, commit: &Commit) -> Result<Vec<Vec<FrozenUnit>>> {
let root_bytes = store
.read(&commit.tree)
Expand All @@ -88,7 +90,7 @@ pub fn load_schemas(store: &ObjectStore, commit: &Commit) -> Result<Vec<Vec<Froz

let mut schemas = Vec::new();
for entry in &root.entries {
if entry.mode != EntryMode::Tree {
if entry.mode != EntryMode::Tree || !entry.name.starts_with("schema_") {
continue;
}
let sub_bytes = store
Expand Down
34 changes: 34 additions & 0 deletions tests/cli/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,37 @@ fn rejects_an_unknown_ref() {
.code(1)
.stderr(predicate::str::contains("no built version matches"));
}

#[test]
fn a_new_schema_file_sorting_first_is_an_addition_not_a_break() {
let temp = tempfile::tempdir().unwrap();
let project = fixture_project(temp.path());

comline_cmd()
.current_dir(&project)
.arg("build")
.assert()
.success();

// `aaa` sorts before `api`: paired by position, `api`'s old schema would
// be compared with this file and reported as removed.
fs::write(
project.join("src/aaa.ids"),
"struct First {\n x: string\n}\n",
)
.unwrap();

comline_cmd()
.current_dir(&project)
.arg("build")
.assert()
.success();

comline_cmd()
.current_dir(&project)
.args(["diff", "0.0.1", "HEAD"])
.assert()
.success()
.stderr(predicate::str::contains("Added struct `First`"))
.stderr(predicate::str::contains("Breaking").not());
}
Loading