Skip to content

Commit cbdf17e

Browse files
committed
publish: a sibling's own version, archives and descriptors by identity, --tag, the index's descriptor shape, --workspace and -p with SHA256SUMS (#947)
1 parent 1f58e2f commit cbdf17e

8 files changed

Lines changed: 313 additions & 94 deletions

File tree

‎src/cli.cppm‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,14 @@ int run(int argc, char** argv) {
970970
.description("Publish package to default registry")
971971
.option(cl::Option("dry-run").help("Print xpkg.lua without uploading"))
972972
.option(cl::Option("allow-dirty").help("Allow uncommitted changes"))
973+
.option(cl::Option("tag").takes_value().value_name("TEMPLATE")
974+
.help("The release's tag, of {version}, {name} and {namespace} (default: v{version})"))
975+
.option(cl::Option("package").short_name('p').takes_value().multiple().value_name("NAME")
976+
.help("Publish the named workspace member; repeat to publish several under one tag"))
977+
.option(cl::Option("workspace")
978+
.help("Publish every workspace member: one archive and one descriptor each, and SHA256SUMS"))
979+
.option(cl::Option("exclude").takes_value().multiple().value_name("NAME")
980+
.help("With --workspace: leave the named member out; repeatable"))
973981
.action(cmd_publish))
974982
.subcommand(cl::App("pack")
975983
// "archive", not "tarball": a Windows target produces a .zip, and

‎src/cli/cmd_publish.cppm‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,24 @@ static int refuse_shared_exact_pins() {
131131
}
132132

133133
export int cmd_publish(const mcpplibs::cmdline::ParsedArgs& parsed) {
134-
if (int rc = refuse_shared_exact_pins(); rc != 0) return rc;
135-
return mcpp::publish::publish_package(
136-
parsed.is_flag_set("dry-run"), parsed.is_flag_set("allow-dirty"));
134+
mcpp::publish::PublishRequest req;
135+
req.dryRun = parsed.is_flag_set("dry-run");
136+
req.allowDirty = parsed.is_flag_set("allow-dirty");
137+
req.tag = parsed.value("tag").value_or("");
138+
// The members `-p` and `--workspace` name, read as every command reads
139+
// them (mcpp#947): each is published as the package it is, into the
140+
// workspace's `target/dist`.
141+
const auto asked = mcpp::cli::member_request(parsed);
142+
if (asked.all || !asked.packages.empty() || !asked.excludes.empty()) {
143+
auto sel = mcpp::cli::select_members(asked);
144+
if (!sel) { mcpp::ui::error(sel.error()); return 2; }
145+
if (!*sel) { mcpp::ui::error("-p and --workspace name members of a workspace, and this directory is not in one"); return 2; }
146+
req.workspaceRoot = (*sel)->root;
147+
req.members = (*sel)->members;
148+
} else if (int rc = refuse_shared_exact_pins(); rc != 0) {
149+
return rc;
150+
}
151+
return mcpp::publish::publish_package(req);
137152
}
138153

139154
// `mcpp place-dlls --output <stamp> --depfile <d> <program> <dir>...`

‎src/pm/publisher.cppm‎

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,27 @@ ReleaseInfo placeholder_release(std::string_view version);
4444
// Compute the convention-based GitHub Release tarball URL for a package:
4545
// "<repo>/releases/download/v<version>/<name>-<version>.tar.gz"
4646
// Returns empty string if `repo` is empty or doesn't look like a https URL.
47+
// `name` is the archive's name: the package's identity (`archive_identity`).
48+
// `tag` empty: `v<version>`.
4749
std::string release_tarball_url(std::string_view repo,
4850
std::string_view name,
49-
std::string_view version);
51+
std::string_view version,
52+
std::string_view tag = {});
53+
54+
// THE NAMES A PUBLISHED PACKAGE IS FILED UNDER (mcpp#947). Several packages of
55+
// one repository are released under one tag, and two of them may share a short
56+
// name across namespaces (`omui.core`, `hanim.core`): the archive and its
57+
// directory are named by the identity, `<namespace>.<name>`; a package with
58+
// no namespace keeps its name.
59+
std::string archive_identity(std::string_view ns, std::string_view name);
60+
// The descriptor's file in an index: `<name>.lua` in the default namespace,
61+
// `<namespace>.<name>.lua` in another.
62+
std::string descriptor_file_name(std::string_view ns, std::string_view name);
63+
// The tag a release is published under, from a template of `{version}`,
64+
// `{name}` and `{namespace}`; empty template: `v{version}`. An unknown
65+
// placeholder is an error.
66+
std::expected<std::string, std::string> release_tag(std::string_view tmpl, std::string_view ns,
67+
std::string_view name, std::string_view version);
5068

5169
// Compute SHA-256 of `file` by shelling out to `sha256sum` (universally
5270
// available on Linux). Returns empty string on failure.
@@ -203,14 +221,18 @@ std::string emit_xpkg(const mcpp::manifest::Manifest& manifest,
203221
// carries the "AUTO-GENERATED … do not edit by hand" banner). Emitting the
204222
// FQN here closes the generator half of that loop; `mcpp xpkg parse` closes
205223
// the lint half. Design: 2026-06-26 §4.5 prescribed this and it never landed.
224+
//
225+
// THE NAME IS ONE SEGMENT AND THE NAMESPACE CARRIES THE PATH (SPEC-001
226+
// §3.2; mcpp#947): the shape the index files and its lint asks for. The
227+
// fully-qualified name written here before stays readable.
206228
if (!manifest.package.namespace_.empty()) {
207229
auto prefix = manifest.package.namespace_ + ".";
208-
auto fqn = manifest.package.name.starts_with(prefix)
209-
? manifest.package.name
210-
: prefix + manifest.package.name;
230+
auto shortName = manifest.package.name.starts_with(prefix)
231+
? manifest.package.name.substr(prefix.size())
232+
: manifest.package.name;
211233
out += std::format(" namespace = {},\n",
212234
lua_escape(manifest.package.namespace_));
213-
out += std::format(" name = {},\n", lua_escape(fqn));
235+
out += std::format(" name = {},\n", lua_escape(shortName));
214236
} else {
215237
out += std::format(" name = {},\n", lua_escape(manifest.package.name));
216238
}
@@ -365,17 +387,51 @@ ReleaseInfo placeholder_release(std::string_view version) {
365387
return r;
366388
}
367389

390+
std::string archive_identity(std::string_view ns, std::string_view name) {
391+
if (ns.empty() || name.starts_with(std::string(ns) + ".")) return std::string(name);
392+
return std::format("{}.{}", ns, name);
393+
}
394+
395+
std::string descriptor_file_name(std::string_view ns, std::string_view name) {
396+
const auto identity = archive_identity(ns, name);
397+
constexpr std::string_view kDefault = "mcpplibs.";
398+
return std::format("{}.lua", identity.starts_with(kDefault) && identity.find('.', kDefault.size()) == std::string::npos
399+
? identity.substr(kDefault.size()) : identity);
400+
}
401+
402+
std::expected<std::string, std::string> release_tag(std::string_view tmpl, std::string_view ns,
403+
std::string_view name, std::string_view version) {
404+
if (tmpl.empty()) tmpl = "v{version}";
405+
std::string out;
406+
for (std::size_t i = 0; i < tmpl.size();) {
407+
if (tmpl[i] != '{') { out += tmpl[i++]; continue; }
408+
const auto end = tmpl.find('}', i);
409+
const auto word = end == std::string_view::npos ? std::string_view{} : tmpl.substr(i + 1, end - i - 1);
410+
if (word == "version") out += version;
411+
else if (word == "name") out += name;
412+
else if (word == "namespace") out += ns;
413+
else return std::unexpected(std::format(
414+
"--tag '{}': '{}' is not a placeholder; a tag names {{version}}, {{name}} and {{namespace}}",
415+
tmpl, tmpl.substr(i, end == std::string_view::npos ? std::string_view::npos : end - i + 1)));
416+
i = end + 1;
417+
}
418+
if (out.empty() || out.find_first_of(" \t~^:?*[\\") != std::string::npos)
419+
return std::unexpected(std::format("--tag '{}' gives '{}', which is not a tag's name", tmpl, out));
420+
return out;
421+
}
422+
368423
std::string release_tarball_url(std::string_view repo,
369424
std::string_view name,
370-
std::string_view version)
425+
std::string_view version,
426+
std::string_view tag)
371427
{
372428
// Strip trailing ".git" if present.
373429
std::string r{repo};
374430
if (r.ends_with(".git")) r.resize(r.size() - 4);
375431
if (r.empty()) return {};
376432
if (!r.starts_with("https://") && !r.starts_with("http://")) return {};
377-
return std::format("{}/releases/download/v{}/{}-{}.tar.gz",
378-
r, version, name, version);
433+
return std::format("{}/releases/download/{}/{}-{}.tar.gz",
434+
r, tag.empty() ? std::format("v{}", version) : std::string(tag), name, version);
379435
}
380436

381437
std::string sha256_of_file(const std::filesystem::path& file) {

‎src/publish/normalize.cppm‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ struct Walk {
241241
if (auto sib = mcpp::project::load_effective_manifest(target);
242242
sib && !sib->manifest.package.version.empty())
243243
version = sib->manifest.package.version;
244+
// A SIBLING IS PUBLISHED UNDER ITS OWN VERSION (mcpp#947): the
245+
// member's manifest states it, and the edge takes it, as the
246+
// refusal below wrote it for the author to copy. Measured on a
247+
// workspace of 150 members: 311 such edges among the 67 a
248+
// release publishes. A member with no version is still refused.
249+
if (version != "<version>") {
250+
spec["version"] = t::Value{version};
251+
spec.erase(std::string("path"));
252+
changed = true;
253+
return false;
254+
}
244255
return std::unexpected(std::format(
245256
"{}: [{}] '{}' reaches the workspace member '{}' by path, and "
246257
"the published archive contains only this package's directory. "

0 commit comments

Comments
 (0)