diff --git a/README.md b/README.md index 3a02097..88ed30e 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,7 @@ src/main/ registry.mbt OCI registry ops: tags, resolve, cached manifests, fetch, publish, login index.mbt channel index: build, publish, read (+ tests) index_cache.mbt local copies of channel listings for search (+ tests) + details.mbt package details shown by install and info (+ tests) solver.mbt lazy Resolvo-style CDCL SAT solver & UNSAT explainer (+ tests) ops.mbt SAT-backed global install/upgrade, remove/rollback/gc/search project.mbt orbit.toml, orbit.lock, .orbit/ environments, project CLI (+ tests) @@ -305,5 +306,5 @@ Fixes needed for current MoonBit, kept here in case you build with an older comp - There's no lock file for concurrent runs, and no install hooks, by design. - `orbit gc` only preserves global current and rollback builds (run `orbit install` / `orbit sync` in a project to re-populate missing store entries from its `orbit.lock`). -- `orbit info ` reads globally installed package details without contacting the registry. Use `orbit versions ` to check published versions. +- `orbit info ` reads installed package details (the project's, then the global ones) without contacting the registry. Use `orbit versions ` to check published versions. - `search` needs a channel index or the registry's catalog API (Gitea has it, also without a login). Otherwise use `orbit versions `. diff --git a/planning/y4x2r-show-package-details-on-install.md b/planning/y4x2r-show-package-details-on-install.md new file mode 100644 index 0000000..ab4de8b --- /dev/null +++ b/planning/y4x2r-show-package-details-on-install.md @@ -0,0 +1,11 @@ +--- +data: + priority: normal + status: done + type: feature +id: y4x2r +title: Show package details on install +--- +Installing a package should show its paths and the commands it exposes, and `orbit info` should show the same. + +Outcome: `install`, `add`, `sync` and `upgrade` print each new build's description, channel, digest, store path, linked bins, dependencies and conflicts (`src/main/details.mbt`). `orbit info` prints the same, and in a project also covers the locked packages. `orbit run` still syncs silently. diff --git a/src/main/details.mbt b/src/main/details.mbt new file mode 100644 index 0000000..35c1285 --- /dev/null +++ b/src/main/details.mbt @@ -0,0 +1,118 @@ +// What install and info print about a package. + +///| +/// Label and values. Each value after the first gets its own line. +type Detail = (String, Array[String]) + +///| +/// Align details in columns, dropping empty ones. Values may come from a +/// registry, so control characters are blanked. +fn detail_lines(details : Array[Detail], indent : String) -> Array[String] { + let lines : Array[String] = [] + for detail in details { + let (label, values) = detail + let mut head = label + ":" + for v in values { + if v != "" { + lines.push(indent + pad_right(head, 13) + printable(v)) + head = "" + } + } + } + lines +} + +///| +fn print_details(details : Array[Detail], indent : String) -> Unit { + for line in detail_lines(details, indent) { + println(line) + } +} + +///| +/// The details of a build that install and info share. `bin_dir` is where its +/// commands are linked, `store` where its files are. +fn package_details( + m : Manifest, + channel~ : String, + digest~ : String, + store~ : String, + bin_dir~ : String, +) -> Array[Detail] { + let bins = m.bins.map(b => bin_dir + "/" + basename(b) + " -> " + b) + if bins.is_empty() { + bins.push("(none)") + } + let specs = fn(reqs : Map[String, String]) { + let out : Array[String] = [] + for n, c in reqs { + out.push(n + "@" + c) + } + join(out, " ") + } + [ + ("description", [m.description]), + ("channel", [channel]), + ("digest", [digest]), + ("path", [store]), + ("bin", bins), + ("depends", [specs(m.depends)]), + ("conflicts", [specs(m.conflicts)]), + ] +} + +///| +fn installed_details(ctx : Ctx, p : Installed) -> Array[Detail] { + package_details( + manifest_of_installed(p), + channel=p.channel, + digest=p.digest, + store=store_dir(ctx, p.name, p.digest), + bin_dir=bin_dir(ctx), + ) +} + +///| +fn locked_details( + ctx : Ctx, + project_dir : String, + p : LockedPkg, +) -> Array[Detail] { + package_details( + manifest_of_locked(p), + channel=p.channel, + digest=p.digest, + store=store_dir(ctx, p.name, p.digest), + bin_dir=project_env_dir(project_dir) + "/bin", + ) +} + +///| +test "package details show paths and every bin" { + let m = parse_manifest( + "{\"name\":\"t\",\"version\":\"1.0.0\",\"description\":\"A\\u001btool\",\"bin\":[\"bin/a\",\"libexec/b\"],\"depends\":{\"x\":\"^1\"},\"conflicts\":{\"y\":\"*\"}}", + ) + let details = package_details( + m, + channel="main", + digest="sha256:ab", + store="/o/store/t/ab", + bin_dir="/o/bin", + ) + assert_eq(detail_lines(details, " "), [ + " description: A tool", " channel: main", " digest: sha256:ab", " path: /o/store/t/ab", + " bin: /o/bin/a -> bin/a", " /o/bin/b -> libexec/b", " depends: x@^1", + " conflicts: y@*", + ]) + let bare = package_details( + parse_manifest("{\"name\":\"t\",\"version\":\"1.0.0\"}"), + channel="main", + digest="sha256:ab", + store="/o/store/t/ab", + bin_dir="/o/bin", + ) + assert_eq(detail_lines(bare, ""), [ + "channel: main", "digest: sha256:ab", "path: /o/store/t/ab", + "bin: (none)", + ]) +} diff --git a/src/main/main.mbt b/src/main/main.mbt index 11e3d7e..d03677a 100644 --- a/src/main/main.mbt +++ b/src/main/main.mbt @@ -41,7 +41,8 @@ let usage : String = #| orbit upgrade [-g] [name...] jointly upgrade within constraints #| orbit rollback switch to the previous global build #| orbit list [-g] installed global packages - #| orbit info [channel::] installed package details (local only) + #| orbit info [-g] [channel::] details of an installed package: paths, + #| bins, dependencies (local only) #| orbit versions published versions #| orbit search [--refresh] [term] list packages (cached for an hour) #| orbit gc delete unused builds from the store @@ -349,7 +350,10 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError { } "info" => { need(pos, 1, "info [channel::]") - cmd_info(load_ctx(), pos[0]) + match resolve_project_or_none(force_global, manifest_path) { + Some(mf) => cmd_project_info(load_ctx(), mf, pos[0]) + None => cmd_info(load_ctx(), pos[0]) + } } "versions" => { need(pos, 1, "versions ") diff --git a/src/main/ops.mbt b/src/main/ops.mbt index c847700..dc64a04 100644 --- a/src/main/ops.mbt +++ b/src/main/ops.mbt @@ -384,6 +384,7 @@ async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError { link_bins(ctx, dir, st.manifest.bins) // Persist after each package so a later failure leaves accurate state. save_state(ctx) + print_details(installed_details(ctx, ctx.state[st.name]), " ") } ///| @@ -765,32 +766,15 @@ fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError { raise OrbitError("\{spec} is not installed (installed from '\{p.channel}')") } println("\{name} \{p.version} (installed)") - if p.description != "" { - println(" description: \{p.description}") - } - println(" channel: \{p.channel}") - println(" digest: \{p.digest}") - println(" constraint: \{p.constraint}") - println(" bin: \{join(p.bins, " ")}") - let deps : Array[String] = [] - for d, c in p.depends { - deps.push(d + "@" + c) - } - println(" depends: \{join(deps, " ")}") - if !p.conflicts.is_empty() { - let cs : Array[String] = [] - for n, c in p.conflicts { - cs.push(n + "@" + c) - } - println(" conflicts: \{join(cs, " ")}") - } - let rd = reverse_deps(ctx, name) - println(" needed by: \{join(rd, " ")}") - let hist : Array[String] = [] - for g in p.history { - hist.push(g.version) - } - println(" rollback: \{join(hist, " ")}") + print_details(installed_details(ctx, p), " ") + print_details( + [ + ("constraint", [p.constraint]), + ("needed by", [join(reverse_deps(ctx, name), " ")]), + ("rollback", [join(p.history.map(g => g.version), " ")]), + ], + " ", + ) } ///| diff --git a/src/main/project.mbt b/src/main/project.mbt index 9066b7b..036fee1 100644 --- a/src/main/project.mbt +++ b/src/main/project.mbt @@ -1065,6 +1065,7 @@ async fn sync_project_env( root : String, project_dir : String, lock : Lockfile, + show? : Bool = false, ) -> Int32 raise OrbitError { let bin_owners : Map[String, String] = Map([]) for lp in lock.packages { @@ -1155,6 +1156,14 @@ async fn sync_project_env( } } write_text_atomic(env_path, env_json_text(desired_pkgs)) + if show { + for lp in lock.packages { + if prev_pkgs.get(lp.name) != Some(lp.digest) { + println(" \{lp.name} \{lp.version} installed") + print_details(locked_details(store_ctx, project_dir, lp), " ") + } + } + } if changed == 0 { 1 } else { @@ -1272,7 +1281,7 @@ async fn ensure_project_synced( solved } } - let synced = sync_project_env(ctx.root, project_dir, lock) + let synced = sync_project_env(ctx.root, project_dir, lock, show=!quiet) if !quiet { if synced == 0 { println("environment is up to date") @@ -1351,7 +1360,7 @@ async fn cmd_project_add( ignore(parse_project_manifest(updated_toml, m.name)) write_text_atomic(manifest_file, updated_toml) write_text_atomic(lock_path, lockfile_to_toml(lock)) - ignore(sync_project_env(ctx.root, project_dir, lock)) + ignore(sync_project_env(ctx.root, project_dir, lock, show=true)) for name in added_names { match solved_by_name.get(name) { Some(lp) => @@ -1426,7 +1435,7 @@ async fn cmd_project_update( upgrade_all, ) write_text_atomic(lock_path, lockfile_to_toml(lock)) - let synced = sync_project_env(ctx.root, project_dir, lock) + let synced = sync_project_env(ctx.root, project_dir, lock, show=true) if synced == 0 { println("already up to date") } else { @@ -1557,6 +1566,56 @@ async fn cmd_project_list( } } +///| +/// Details of a package in the project's lockfile, or else of a global one. +async fn cmd_project_info( + ctx : Ctx, + manifest_file : String, + spec : String, +) -> Unit raise OrbitError { + let (project_dir, m, _) = load_project(manifest_file, ctx.channels) + let (pin, name) = split_channel(spec) + let packages = match read_existing_lock(project_dir + "/orbit.lock") { + Some(lock) => lock.packages + None => [] + } + for p in packages { + if p.name != name || (pin is Some(channel) && channel != p.channel) { + continue + } + let env = match read_text(project_env_dir(project_dir) + "/env.json") { + Some(t) => read_env_packages(t) + None => Map([]) + } + let status = if env.get(name) == Some(p.digest) { + "installed in \{m.name}" + } else { + "locked in \{m.name}, not installed" + } + println("\{name} \{p.version} (\{status})") + print_details(locked_details(ctx, project_dir, p), " ") + let constraint = match m.dependencies.get(name) { + Some(d) => d.constraint + None => "" + } + let users : Array[String] = [] + for other in packages { + for dep, _ in other.depends { + if parse_dep_key(dep).1 == name { + users.push(other.name) + break + } + } + } + print_details( + [("constraint", [constraint]), ("needed by", [join(users, " ")])], + " ", + ) + return + } + cmd_info(ctx, spec) +} + ///| fn cmd_project_env(ctx : Ctx, manifest_file : String) -> Unit { let project_dir = path_dirname(manifest_file)