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 = "05771e0679ff514da3ba73a3b0b94643e5262fe5" }
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "da81b688c949a0ebad4f213d6fdb648920cf641d" }
# 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 = "05771e0679ff514da3ba73a3b0b94643e5262fe5" }
comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "05771e0679ff514da3ba73a3b0b94643e5262fe5" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "df91e2e0a416cab594303f11d44a6555a72f891b", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "8d829be859feac26d775f4877f098fedc38fdd9f", optional = true }
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 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
2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ formats = ["html", "markdown", "json"]
versions = { last = 5 } # or "all" (the default), { since = "0.3.0" }, { releases_only = true }
renderer = "renderers/my-renderer.wasm" # optional: an external renderer
timeout = 60 # seconds per call to `renderer`
links = { std = "https://comlineproject.github.io/docs/reference/schema/std/" }
links = { std = "https://comlineproject.github.io/docs/reference/package/schema/std/" }
changelog_from = "0.1.0" # with --version only
```

Expand Down
6 changes: 5 additions & 1 deletion src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ pub fn run(
// Before fetching anything: the entry has to be writable.
entry_fields(&dependency)?;

ui::step(format!("Resolving {name}{}", ui::at_path(work_dir)));
ui::step(format!("Resolving dependency '{name}'"));

let spinner = ui::spinner(match source {
Source::Path(_) => "compiling",
Source::Git { .. } => "fetching and compiling",
Expand All @@ -132,8 +133,11 @@ pub fn run(
let resolve = |dependency: &DependencyConfig| {
accept::quietly(|| deps::resolve(dependency, work_dir, &cache_dir))
};

let mut resolved = resolve(&dependency);

ui::finish_spinner(spinner);

// A dependency with `@unverified` protocols resolves only once they're
// accepted: show what they give up and ask, then try again.
if resolved.is_err() {
Expand Down
43 changes: 40 additions & 3 deletions src/commands/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ struct GenVersion {
package_version: String,
schemas: Vec<(String, Vec<FrozenUnit>)>, // (namespace path, frozen units)

/// The names the version gives its dependencies. A dependency's schemas
/// are among `schemas`, under its name as the namespace's first segment;
/// this is how a generator tells them from the package's own.
dependencies: Vec<String>,

/// The version's own `wire.format`: a built version keeps the format it
/// was built with.
wire_format: String,
Expand Down Expand Up @@ -162,6 +167,14 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo
})
.collect();

// The names the package gives its dependencies, the way core splits a
// package's schemas from its dependencies'.
let live_dependencies: Vec<String> = context
.dependency_configs
.iter()
.map(|(name, _)| name.clone())
.collect();

// External generators, described once each. A target that names one
// and no `language` takes the one language it offers.
let mut externals = Externals::default();
Expand All @@ -187,7 +200,7 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo
"lib" => Mode::Lib,
other => {
return Err(miette!(
"target `{}`: mode `{other}` is not supported yet (`code`, `lib`)",
"target `{}`: mode `{other}` is not supported (available: `code`, `lib`)",
t.language
))
}
Expand Down Expand Up @@ -232,7 +245,9 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo
));
}
}

let ext = info.ext.clone();

// The page the generator itself names for its connections.
let connections_doc = info.doc(Topic::Connections).map(str::to_owned);
(Source::External(generator), ext, connections_doc)
Expand Down Expand Up @@ -275,7 +290,13 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo
}
};

let versions = expand_versions(&t.versions, work_dir, &live_schemas, config_units)?;
let versions = expand_versions(
&t.versions,
work_dir,
&live_schemas,
&live_dependencies,
config_units,
)?;
if mode == Mode::Lib && versions.len() > 1 {
return Err(miette!(
"target `{}`: `lib` mode does not support multiple package versions yet",
Expand All @@ -296,11 +317,13 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo
"language: {}, version: {}, mode: {}",
t.language, t.lang_version, t.mode,
);

ui::detail(if ui::plain() {
label
} else {
format!("⚙️ {label}")
});

// A given-up guarantee, shown where it's given up.
if let Some(reason) = &t.validate_on_decode_off {
ui::note(format!(
Expand Down Expand Up @@ -335,6 +358,7 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo
// Filled just below.
encodings: Default::default(),
facts: None,
dependencies: gv.dependencies.clone(),
};
// The type each encoding the package uses maps to in this
// language: comline.toml's mapping, else the declaring package's
Expand Down Expand Up @@ -518,6 +542,7 @@ fn expand_versions(
spec: &VersionSpec,
work_dir: &Path,
live: &[(String, Vec<FrozenUnit>)],
live_dependencies: &[String],
live_config: &[ConfigUnit],
) -> Result<Vec<GenVersion>> {
match spec {
Expand All @@ -533,6 +558,7 @@ fn expand_versions(
Ok(vec![GenVersion {
package_version,
schemas: live.to_vec(),
dependencies: live_dependencies.to_vec(),
wire_format,
facts: FactsSource::WorkingTree,
}])
Expand Down Expand Up @@ -587,9 +613,20 @@ fn gen_version_from_commit(
.collect();

let config = history::load_config(store, commit)?;
// The dependencies the build vendored, by the names it stored them under.
let configs = history::load_stored_configs(store, commit)?;
let mut dependencies: Vec<String> = configs
.dependencies
.into_iter()
.map(|(name, _)| name)
.chain(configs.unstored)
.collect();
dependencies.sort();
dependencies.dedup();
Ok(GenVersion {
package_version: version.to_owned(),
schemas,
dependencies,
wire_format: frozen::wire_format(&config).to_string(),
facts: FactsSource::Commit(*hash),
})
Expand All @@ -611,7 +648,7 @@ fn facts_for(
request: &GenerateRequest,
source: &FactsSource,
) -> Result<Option<comline_codegen::facts::PackageFacts>> {
if !comline_codegen::facts::needed(&request.schemas, &request.encodings) {
if !comline_codegen::facts::needed_in(request) {
return Ok(None);
}
let facts = match source {
Expand Down
7 changes: 6 additions & 1 deletion src/commands/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn run(work_dir: &Path, name: &str, to: Option<Move>, accept_unverified: boo
}
_ => {}
}

for value in [commit_of(&dependency), version_of(&dependency)]
.into_iter()
.flatten()
Expand All @@ -68,17 +69,20 @@ pub fn run(work_dir: &Path, name: &str, to: Option<Move>, accept_unverified: boo
}
set_hash(&mut dependency, None);

ui::step(format!("Resolving {name}{}", ui::at_path(work_dir)));
ui::step(format!("Resolving dependency '{name}'"));

let spinner = ui::spinner(match dependency.source {
DependencySource::Git { .. } => "fetching and compiling",
_ => "compiling",
});

let cache_dir = work_dir.join(DEPS_CACHE_DIR);
// Resolving without a hash warns that it's trusted, and suggests the very
// pin this command writes: keep that out of a normal run.
let resolve = |dependency: &DependencyConfig| {
accept::quietly(|| deps::resolve(dependency, work_dir, &cache_dir))
};

let mut resolved = resolve(&dependency);
ui::finish_spinner(spinner);

Expand All @@ -105,6 +109,7 @@ pub fn run(work_dir: &Path, name: &str, to: Option<Move>, accept_unverified: boo
resolved = resolve(&dependency);
}
}

let resolved = resolved.map_err(|e| core_err("couldn't resolve the dependency", e))?;
let new_hash = format!("blake3:{}", resolved.content_hash.to_hex());
set_hash(&mut dependency, Some(new_hash.clone()));
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ fn dependencies_are_listed_apart_by_reach() {
let api = read(&site.join("html/0.1.0-dev.1/api.html"));
assert!(
api.contains(
"href=\"https://comlineproject.github.io/docs/reference/schema/std/http/#httpmethod\""
"href=\"https://comlineproject.github.io/docs/reference/package/schema/std/http/#httpmethod\""
),
"{api}"
);
Expand Down
96 changes: 96 additions & 0 deletions tests/cli/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,3 +1438,99 @@ fn datagram3_and_comline2_take_their_facts_from_the_last_build() {
assert!(code.contains(call), "missing `{call}` in:\n{code}");
}
}

// -------- a dependency's protocols the package doesn't reach (generation#143) --------

/// A package `app` that uses only the types of its dependency `greeting`,
/// which declares a protocol under `datagram@3` and `comline@2`. Returns
/// `app`'s directory, declaring Rust and TypeScript.
fn app_using_a_dependencys_types(root: &std::path::Path) -> std::path::PathBuf {
let greeting = root.join("greeting");
comline_cmd()
.current_dir(root)
.args(["new", "greeting"])
.assert()
.success();
let config = fs::read_to_string(greeting.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\" }",
);
fs::write(greeting.join("config.idp"), config).unwrap();
fs::write(
greeting.join("src/greeting.ids"),
"struct Hello {\n name: char[max 32]\n}\n\n\
protocol Greeter {\n function greet(name: char[max 32]) -> u32;\n}\n",
)
.unwrap();

let app = fixture_project(root);
let config = fs::read_to_string(app.join("config.idp")).unwrap().replace(
"rust#1.85.0 = {}",
"rust#1.85.0 = {}\n typescript#5.0 = {}",
);
fs::write(app.join("config.idp"), config).unwrap();
add_to_config(
&app,
"dependencies = {\n greeting = { path = \"../greeting\" }\n}",
);
fs::write(
app.join("src/holder.ids"),
"use greeting::greeting::Hello\n\nstruct Holder {\n hello: Hello\n}\n",
)
.unwrap();
app
}

fn generate_for(app: &std::path::Path, target: &str) {
comline_cmd()
.current_dir(app)
.args(["generation", "--target", target])
.assert()
.success();
}

/// The dependency's protocol isn't on the package's connection, and nothing
/// of it is addressed: the package has none of its own, so there's no
/// facts to take from a build either.
#[test]
fn a_dependencys_protocol_the_package_does_not_reach_is_left_alone() {
let temp = tempfile::tempdir().unwrap();
let app = app_using_a_dependencys_types(temp.path());

for target in ["rust", "typescript"] {
generate_for(&app, target);
}
assert!(app.join("generated/rust/holder.rs").exists());
}

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

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