diff --git a/Cargo.lock b/Cargo.lock index 2462e33..6c93f99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -515,7 +515,7 @@ source = "git+https://github.com/ComlineProject/runtime?rev=8f8c0cb6fb0bc3a734aa [[package]] name = "comline-codegen" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=05771e0679ff514da3ba73a3b0b94643e5262fe5#05771e0679ff514da3ba73a3b0b94643e5262fe5" +source = "git+https://github.com/ComlineProject/generation?rev=da81b688c949a0ebad4f213d6fdb648920cf641d#da81b688c949a0ebad4f213d6fdb648920cf641d" dependencies = [ "comline-core", "eyre", @@ -529,7 +529,7 @@ dependencies = [ [[package]] name = "comline-codegen-rust" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-rust?rev=df91e2e0a416cab594303f11d44a6555a72f891b#df91e2e0a416cab594303f11d44a6555a72f891b" +source = "git+https://github.com/ComlineProject/comline-rust?rev=6db2757b6d1e7df44df8c47adc8cad5bec1559c1#6db2757b6d1e7df44df8c47adc8cad5bec1559c1" dependencies = [ "comline-codegen", "comline-core", @@ -539,7 +539,7 @@ dependencies = [ [[package]] name = "comline-codegen-typescript" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-typescript?rev=8d829be859feac26d775f4877f098fedc38fdd9f#8d829be859feac26d775f4877f098fedc38fdd9f" +source = "git+https://github.com/ComlineProject/comline-typescript?rev=bcec31dd13320613bcc1dcb10dcbc72f9a1011f9#bcec31dd13320613bcc1dcb10dcbc72f9a1011f9" dependencies = [ "comline-codegen", "comline-core", @@ -584,7 +584,7 @@ source = "git+https://github.com/ComlineProject/core?rev=868e8310e33df317e3cba4f [[package]] name = "comline-doc-html" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=05771e0679ff514da3ba73a3b0b94643e5262fe5#05771e0679ff514da3ba73a3b0b94643e5262fe5" +source = "git+https://github.com/ComlineProject/generation?rev=da81b688c949a0ebad4f213d6fdb648920cf641d#da81b688c949a0ebad4f213d6fdb648920cf641d" dependencies = [ "comline-codegen", "eyre", @@ -595,7 +595,7 @@ dependencies = [ [[package]] name = "comline-doc-markdown" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=05771e0679ff514da3ba73a3b0b94643e5262fe5#05771e0679ff514da3ba73a3b0b94643e5262fe5" +source = "git+https://github.com/ComlineProject/generation?rev=da81b688c949a0ebad4f213d6fdb648920cf641d#da81b688c949a0ebad4f213d6fdb648920cf641d" dependencies = [ "comline-codegen", "eyre", diff --git a/Cargo.toml b/Cargo.toml index 8f29862..46fc6f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/docs/cli.md b/docs/cli.md index 5b4db67..f27f469 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -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 ``` diff --git a/src/commands/add.rs b/src/commands/add.rs index 405d1f7..d4d7e14 100644 --- a/src/commands/add.rs +++ b/src/commands/add.rs @@ -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", @@ -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() { diff --git a/src/commands/generation.rs b/src/commands/generation.rs index 814e461..a1ecc0e 100644 --- a/src/commands/generation.rs +++ b/src/commands/generation.rs @@ -74,6 +74,11 @@ struct GenVersion { package_version: String, schemas: Vec<(String, Vec)>, // (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, + /// The version's own `wire.format`: a built version keeps the format it /// was built with. wire_format: String, @@ -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 = 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(); @@ -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 )) } @@ -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) @@ -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", @@ -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!( @@ -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 @@ -518,6 +542,7 @@ fn expand_versions( spec: &VersionSpec, work_dir: &Path, live: &[(String, Vec)], + live_dependencies: &[String], live_config: &[ConfigUnit], ) -> Result> { match spec { @@ -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, }]) @@ -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 = 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), }) @@ -611,7 +648,7 @@ fn facts_for( request: &GenerateRequest, source: &FactsSource, ) -> Result> { - if !comline_codegen::facts::needed(&request.schemas, &request.encodings) { + if !comline_codegen::facts::needed_in(request) { return Ok(None); } let facts = match source { diff --git a/src/commands/pin.rs b/src/commands/pin.rs index 68c655d..986a42a 100644 --- a/src/commands/pin.rs +++ b/src/commands/pin.rs @@ -56,6 +56,7 @@ pub fn run(work_dir: &Path, name: &str, to: Option, accept_unverified: boo } _ => {} } + for value in [commit_of(&dependency), version_of(&dependency)] .into_iter() .flatten() @@ -68,17 +69,20 @@ pub fn run(work_dir: &Path, name: &str, to: Option, 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); @@ -105,6 +109,7 @@ pub fn run(work_dir: &Path, name: &str, to: Option, 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())); diff --git a/tests/cli/doc.rs b/tests/cli/doc.rs index bf18165..de52a08 100644 --- a/tests/cli/doc.rs +++ b/tests/cli/doc.rs @@ -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}" ); diff --git a/tests/cli/generation.rs b/tests/cli/generation.rs index 1620a18..64a7332 100644 --- a/tests/cli/generation.rs +++ b/tests/cli/generation.rs @@ -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()); +}