2.3 KiB
2.3 KiB
Package Module Generation
This document explains how harvested metadata is transformed into concrete
Rust modules under src/pkgs/by_name/.
Overview
- Harvest metadata – Use
metadata_indexer harvestto capture package data from the LFS/BLFS/GLFS books. Each record is written toai/metadata/packages/<book>/<slug>.json. - Refresh manifests – Run
metadata_indexer refreshto ensure the jhalfswget-listandmd5sumscaches are up to date. Harvesting relies on these caches for canonical source URLs and checksums. - Generate modules – Use
metadata_indexer generate --metadata <path> --output <by_name_dir>to turn a metadata file into a full Rust module that exposes aPackageDefinition.
Generated modules leverage the existing scaffolder logic, so the command will
create any missing prefix directories (e.g. bi/mod.rs) and populate the final
mod.rs file with the correct code template.
Command reference
# Harvest metadata from a book page
cargo run --bin metadata_indexer -- --base-dir . harvest \
--book mlfs \
--page chapter05/binutils-pass1 \
--output ai/metadata/packages/mlfs/binutils-pass-1.json
# Refresh jhalfs manifests (optional but recommended)
cargo run --bin metadata_indexer -- --base-dir . refresh
# Generate a module under the standard src tree
cargo run --bin metadata_indexer -- --base-dir . generate \
--metadata ai/metadata/packages/mlfs/binutils-pass-1.json \
--output src/pkgs/by_name \
--overwrite
Flags
--outputdefaults tosrc/pkgs/by_name. Point it to another directory if you want to stage modules elsewhere (e.g.target/generated/by_name).--overwritedeletes the existing module directory before scaffolding a new one.
After generation, run cargo fmt and cargo check to ensure the crate compiles
with the new modules.
Implementation notes
- Metadata fields such as
build,dependencies, andoptimizationsare mapped directly onto the scaffolder’sScaffoldRequesttype. - Source URLs and MD5 checksums are sourced from the harvested metadata (populated via the jhalfs manifests).
- The module slug is derived from
package.id(e.g.mlfs/binutils-pass-1→src/pkgs/by_name/bi/binutils_pass_1/mod.rs).
See the code in src/pkgs/generator.rs for the full translation logic.