new: template manifests and registry infrastructure

Split the Template trait into a data half and a logic half. Every
template is now declared by a manifest under data/templates/<id>/
(CLI id, wizard label, detection markers, Build-Depends, architecture,
rules dh line, rules-extra body, control source fields, gitignore
entries and static file bodies with {placeholder} substitution),
embedded through the TEMPLATE_SOURCES index and parsed once into the
registry; the order of the index is the wizard menu order and the
detection priority at once. The logic half is the slim TemplateHooks
trait (probe, post_write, file-body overrides merged over the manifest
bodies by path shadowing, Build-Depends/architecture amendments and
extra context values), registered per template as a HOOKS static: a
template without hooks needs zero Rust.

- TemplateId becomes a Copy wrapper of the stable CLI string; the
  enum, its all/as_str/display_name/from_label matches and the old
  statics array collapse into the registry accessors.
- rust's rules overrides move to data/templates/rust/rules.extra.tpl
  with {locked}/{artifact} hook context; python's backend table,
  meson/cmake's pkg-config opt-in, autotools' gettext and python's
  C-extension hints become hook amendments over the manifest baseline.
- detect.rs drops its hardcoded marker cascade: the manifests'
  detect.files drive detection in registry order, with the shell
  single-script heuristic and the never-detected empty template kept
  as the code special cases they are. License sniffing is untouched.
- The template tests port to manifest validation: registry coverage
  and stable order, placeholder presence in the rendering context,
  rules composition, the Build-Depends/architecture/dh-line table now
  asserted against the manifest data, and the hook shadowing merge.

The static skeleton bodies of the shell/empty/makefile/go templates
stay in their Rust hooks for now; the next commit moves them into
their manifests.
This commit is contained in:
2026-09-18 14:46:28 +02:00
parent fc0d2f247e
commit 04a572cd77
26 changed files with 1477 additions and 716 deletions
+19
View File
@@ -0,0 +1,19 @@
## The `autotools` template: a C project with a configure.ac built through
## debhelper's auto-detection (dh runs autoreconf itself when it finds
## configure.ac, debhelper >= 10 — no override needed). The logic half —
## the AC_INIT probe, the skeleton bodies and the gettext detection
## (appended to Build-Depends) — lives in src/new/templates/autotools.rs.
##
## Schema: see src/new/templates/mod.rs.
id: autotools
label: C/C++ (Autotools)
detect:
files: [configure.ac]
build_depends:
- autoconf
- automake
- libtool
architecture: any
rules_dh_line: "dh $@"
files: []
+16
View File
@@ -0,0 +1,16 @@
## The `cmake` template: a C/C++ project built with CMake through the
## debhelper cmake buildsystem. The logic half — the project() probe, the
## skeleton bodies and the wizard's pkg-config opt-in (appended to
## Build-Depends) — lives in src/new/templates/cmake.rs.
##
## Schema: see src/new/templates/mod.rs.
id: cmake
label: C/C++ (CMake)
detect:
files: [CMakeLists.txt]
build_depends:
- cmake
architecture: any
rules_dh_line: "dh $@ --buildsystem=cmake"
files: []
+14
View File
@@ -0,0 +1,14 @@
## The `empty` template: a metapackage (non-empty Depends list) or an
## empty base package with no build system at all — pure `dh $@` plumbing
## as a starting point for hand-written rules.
##
## Schema: see src/new/templates/mod.rs.
id: empty
label: Metapackage / empty base (no build system)
detect:
files: []
build_depends: []
architecture: all
rules_dh_line: "dh $@"
files: []
+18
View File
@@ -0,0 +1,18 @@
## The `go` template: a Go module built through dh-golang. The logic half
## — the go.mod module-line probe and the `{go_import_path}` value below —
## lives in src/new/templates/go.rs.
##
## Schema: see src/new/templates/mod.rs.
id: go
label: Go module
detect:
files: [go.mod]
build_depends:
- golang-any
- dh-golang
architecture: any
rules_dh_line: "dh $@ --buildsystem=golang"
source_fields:
XS-Go-Import-Path: "{go_import_path}"
files: []
+17
View File
@@ -0,0 +1,17 @@
## The `makefile` template: a generic project driven by a plain Makefile.
## debhelper's makefile buildsystem runs `make` for the build and
## `make install DESTDIR=...` when the Makefile carries an `install:`
## target (missing targets are skipped gracefully), so plain `dh $@`
## plumbing is enough here.
##
## Schema: see src/new/templates/mod.rs.
id: makefile
label: Generic (Makefile)
detect:
files: [Makefile]
build_depends:
- build-essential
architecture: any
rules_dh_line: "dh $@"
files: []
+16
View File
@@ -0,0 +1,16 @@
## The `meson` template: a C/C++ project built with Meson through the
## debhelper meson buildsystem. The logic half — the project() probe, the
## skeleton bodies and the wizard's pkg-config opt-in (appended to
## Build-Depends) — lives in src/new/templates/meson.rs.
##
## Schema: see src/new/templates/mod.rs.
id: meson
label: C/C++ (Meson)
detect:
files: [meson.build]
build_depends:
- meson
architecture: any
rules_dh_line: "dh $@ --buildsystem=meson"
files: []
+21
View File
@@ -0,0 +1,21 @@
## The `python` template: a PEP 517 project built with pybuild. The logic
## half — the pyproject.toml/setup.py probe, the skeleton bodies and the
## Build-Depends/architecture resolution for existing projects (backend
## package, pyproject presence, C-extension hints) — lives in
## src/new/templates/python.rs; the lists below are the fresh-skeleton
## baseline it starts from.
##
## Schema: see src/new/templates/mod.rs.
id: python
label: Python (pyproject.toml / setup.py)
detect:
files: [pyproject.toml, setup.py, setup.cfg]
build_depends:
- dh-python
- python3-all
- pybuild-plugin-pyproject
- python3-setuptools
architecture: all
rules_dh_line: "dh $@ --with python3 --buildsystem=pybuild"
files: []
+26
View File
@@ -0,0 +1,26 @@
## The `rust` template: a vendored Cargo build (see the module docs of
## src/new/templates/rust.rs for the vendoring strategy). The logic half —
## the cargo vendor post-write hook, the Cargo.toml/src skeletons with
## their crate-name sanitizing, and the `{locked}` / `{artifact}` values of
## rules.extra.tpl — lives in that module.
##
## Schema: see src/new/templates/mod.rs.
id: rust
label: Rust (Cargo.toml)
detect:
files: [Cargo.toml]
build_depends:
- cargo:native
- rustc:native
architecture: any
rules_dh_line: "dh $@"
# The vendored-build overrides appended to debian/rules; `--locked` is only
# used when the packaged tree already carries a Cargo.lock (the vendoring
# hook patches it in once it creates the lockfile), and the built artifact
# of a fresh skeleton is named after its crate.
rules_extra_file: rules.extra.tpl
gitignore_entries:
- vendor/
- .cargo/config.toml
files: []
+19
View File
@@ -0,0 +1,19 @@
override_dh_auto_build:
cargo build --release --offline{locked}
override_dh_auto_install:
install -Dm755 target/release/{artifact} debian/{name}/usr/bin/{command}
override_dh_auto_test:
cargo test --release --offline{locked}
override_dh_update_autotools_config:
override_dh_clean:
# dh_clean unlinks `*.orig` patch backups, but vendored crates
# ship files like `Cargo.toml.orig` that cargo's per-file
# checksums require on cold builds (chroots, Launchpad).
dh_clean -X .orig
override_dh_auto_clean:
cargo clean
+16
View File
@@ -0,0 +1,16 @@
## The `shell` template: a single interpreted script installed to
## /usr/bin with plain `dh $@` plumbing. Detection is not marker-based: the
## single-script heuristic of src/new/detect.rs (a lone *.sh or shebang
## file) maps here. The probe pre-filling the wizard answers from the
## script file name lives in src/new/templates/shell.rs.
##
## Schema: see src/new/templates/mod.rs.
id: shell
label: Shell script / single interpreted file
detect:
files: []
build_depends: []
architecture: all
rules_dh_line: "dh $@"
files: []