Skip to content

Commit d571365

Browse files
authored
fix: skip Form B packages in template name resolution (#266)
Form B packages (mcpp = { ... }) have no physical mcpp.toml or templates/ directory — their manifest is synthesized from the index descriptor. The template fetch path now detects this via extract_mcpp_field() and skips to the next namespace candidate. Refs #265 (hardening)
1 parent b5dece0 commit d571365

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/scaffold/create.cppm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ fetch_template_package(const mcpp::scaffold::TemplateSpec& spec) {
4444
std::optional<std::string> lua;
4545
for (std::string cand : {std::string{}, std::string{"compat"}}) {
4646
if (auto l = fetcher.read_xpkg_lua(cand, spec.pkg)) {
47+
// Form B packages (mcpp = { ... }) are build recipes without
48+
// a source tree — no physical mcpp.toml or templates/.
49+
auto field = mcpp::manifest::extract_mcpp_field(*l);
50+
if (field.kind == mcpp::manifest::McppField::TableBody) {
51+
continue;
52+
}
4753
lua = std::move(*l);
4854
break;
4955
}

tests/e2e/69_package_templates.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,31 @@ grep -qi "not found in the index" out5.log || { cat out5.log; echo "missing inde
133133
"$MCPP" new app6 --template gui > out6.log 2>&1 || { cat out6.log; echo "gui builtin broke"; exit 1; }
134134
grep -qi "deprecated" out6.log || { cat out6.log; echo "missing gui deprecation"; exit 1; }
135135

136+
# 7. Form B (mcpp = { ... }) compat package → skipped, "not found in the index".
137+
mkdir -p "$MCPP_HOME/registry/data/mcpplibs/pkgs/c"
138+
cat > "$MCPP_HOME/registry/data/mcpplibs/pkgs/c/compat.tpl-repro.lua" <<'EOF'
139+
package = {
140+
spec = "1",
141+
namespace = "compat",
142+
name = "compat.tpl-repro",
143+
type = "package",
144+
xpm = {
145+
linux = { ["0.1.0"] = { url = "https://example.invalid/x.tar.gz", sha256 = "0" } },
146+
macosx = { ["0.1.0"] = { url = "https://example.invalid/x.tar.gz", sha256 = "0" } },
147+
windows = { ["0.1.0"] = { url = "https://example.invalid/x.tar.gz", sha256 = "0" } },
148+
},
149+
mcpp = {
150+
language = "c++23",
151+
include_dirs = {"*"},
152+
sources = {"*.cpp"},
153+
targets = { tpl_repro = { kind = "lib" } },
154+
},
155+
}
156+
EOF
157+
mkdir -p "$MCPP_HOME/registry/data/xpkgs/compat-x-compat.tpl-repro/0.1.0"
158+
if "$MCPP" new app7 --template tpl-repro > out7.log 2>&1; then
159+
cat out7.log; echo "L7: Form B template must fail"; exit 1
160+
fi
161+
grep -qi "not found in the index" out7.log || { cat out7.log; echo "L7: wrong error for Form B skip"; exit 1; }
162+
136163
echo "OK"

0 commit comments

Comments
 (0)