feat: add support for metapackages in interactive prompts and update git2 dependency features

This commit is contained in:
2026-02-25 20:09:19 -06:00
parent d9a30f5d56
commit 631ac73b3f
2 changed files with 268 additions and 210 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ ar = "0.9.0"
bzip2 = "0.6.1" bzip2 = "0.6.1"
clap = { version = "4.5.60", features = ["derive"] } clap = { version = "4.5.60", features = ["derive"] }
flate2 = "1.1.9" flate2 = "1.1.9"
git2 = { version = "0.20.4", features = ["vendored-libgit2"] } git2 = { version = "0.20.4", features = ["openssl-sys"] }
indicatif = "0.18.4" indicatif = "0.18.4"
nix = { version = "0.31.1", features = ["user"] } nix = { version = "0.31.1", features = ["user"] }
reqwest = { version = "0.13.2", features = ["blocking", "native-tls"] } reqwest = { version = "0.13.2", features = ["blocking", "native-tls"] }
+66 -8
View File
@@ -243,11 +243,13 @@ pub fn create_interactive() -> Result<PackageSpec> {
BuildType::Rust, BuildType::Rust,
BuildType::Custom, BuildType::Custom,
BuildType::Bin, BuildType::Bin,
BuildType::Meta,
]; ];
let build_type = Select::new("Build System:", build_types) let build_type = Select::new("Build System:", build_types)
.with_help_message("Select the build system used by the package (common choices)") .with_help_message("Select the build system used by the package (common choices)")
.prompt()?; .prompt()?;
let is_metapackage = matches!(build_type, BuildType::Meta);
// If the build system is Autotools, offer a convenience prompt for GNU-hosted tarballs. // If the build system is Autotools, offer a convenience prompt for GNU-hosted tarballs.
let mut gnu_source_default = String::new(); let mut gnu_source_default = String::new();
@@ -268,11 +270,19 @@ pub fn create_interactive() -> Result<PackageSpec> {
} }
// Ask whether to show advanced fields. // Ask whether to show advanced fields.
let show_advanced = Confirm::new("Show advanced options?") let show_advanced = if is_metapackage {
.with_help_message("Includes source subdir, toolchain overrides, hooks, and build tuning") false
} else {
Confirm::new("Show advanced options?")
.with_help_message(
"Includes source subdir, toolchain overrides, hooks, and build tuning",
)
.with_default(false) .with_default(false)
.prompt()?; .prompt()?
};
let mut sources = Vec::new();
if !is_metapackage {
let source_url = Text::new("Source URL:") let source_url = Text::new("Source URL:")
.with_help_message("URL to the source tarball or git repository") .with_help_message("URL to the source tarball or git repository")
.with_default(gnu_source_default.as_str()) .with_default(gnu_source_default.as_str())
@@ -323,8 +333,15 @@ pub fn create_interactive() -> Result<PackageSpec> {
)?; )?;
} }
let mut flags = BuildFlags::default(); sources.push(source);
} else {
crate::log_info!(
"Metapackage selected: skipping source/build prompts. Define runtime dependencies to pull in."
);
}
let mut flags = BuildFlags::default();
if !is_metapackage {
if !matches!(build_type, BuildType::Bin) { if !matches!(build_type, BuildType::Bin) {
flags.prefix = Text::new("Install prefix:") flags.prefix = Text::new("Install prefix:")
.with_help_message("Most packages should use /usr") .with_help_message("Most packages should use /usr")
@@ -389,7 +406,8 @@ pub fn create_interactive() -> Result<PackageSpec> {
"CFLAG", "CFLAG",
"One flag per entry, e.g. -O2, -fPIC, -D_GNU_SOURCE", "One flag per entry, e.g. -O2, -fPIC, -D_GNU_SOURCE",
)?; )?;
flags.ldflags = prompt_repeating_list("LDFLAG", "One flag per entry, e.g. -Wl,-z,relro")?; flags.ldflags =
prompt_repeating_list("LDFLAG", "One flag per entry, e.g. -Wl,-z,relro")?;
} }
if matches!( if matches!(
@@ -465,8 +483,10 @@ pub fn create_interactive() -> Result<PackageSpec> {
"Example: x86_64-unknown-linux-gnu", "Example: x86_64-unknown-linux-gnu",
)?; )?;
if show_advanced { if show_advanced {
flags.rustflags = flags.rustflags = prompt_repeating_list(
prompt_repeating_list("RUSTFLAG", "One flag per entry, e.g. -Ctarget-cpu=native")?; "RUSTFLAG",
"One flag per entry, e.g. -Ctarget-cpu=native",
)?;
flags.cargs = prompt_repeating_list( flags.cargs = prompt_repeating_list(
"Extra cargo arg", "Extra cargo arg",
"Examples: --locked, --features, serde, --no-default-features", "Examples: --locked, --features, serde, --no-default-features",
@@ -495,6 +515,7 @@ pub fn create_interactive() -> Result<PackageSpec> {
flags.post_install = flags.post_install =
prompt_repeating_list("post_install command", "Runs after install step")?; prompt_repeating_list("post_install command", "Runs after install step")?;
} }
}
let runtime_deps = let runtime_deps =
prompt_repeating_list("Runtime dependency", "Package name (e.g. zlib, openssl)")?; prompt_repeating_list("Runtime dependency", "Package name (e.g. zlib, openssl)")?;
@@ -517,7 +538,7 @@ pub fn create_interactive() -> Result<PackageSpec> {
packages: Vec::new(), packages: Vec::new(),
alternatives: Alternatives::default(), alternatives: Alternatives::default(),
manual_sources: Vec::new(), manual_sources: Vec::new(),
source: vec![source], source: sources,
build: Build { build_type, flags }, build: Build { build_type, flags },
dependencies: Dependencies { dependencies: Dependencies {
build: build_deps, build: build_deps,
@@ -1382,6 +1403,43 @@ mod tests {
assert_eq!(test_deps[1].as_str(), Some("bats")); assert_eq!(test_deps[1].as_str(), Some("bats"));
} }
#[test]
fn spec_to_minimal_toml_supports_metapackage_without_sources() {
let spec = PackageSpec {
package: PackageInfo {
name: "foo-meta".into(),
version: "1.0".into(),
revision: 1,
description: "Meta package".into(),
homepage: "".into(),
license: vec!["MIT".into()],
},
packages: Vec::new(),
alternatives: Alternatives::default(),
manual_sources: Vec::new(),
source: Vec::new(),
build: Build {
build_type: BuildType::Meta,
flags: BuildFlags::default(),
},
dependencies: Dependencies {
build: Vec::new(),
runtime: vec!["foo".into(), "bar".into()],
test: Vec::new(),
},
package_alternatives: Default::default(),
package_dependencies: Default::default(),
spec_dir: PathBuf::from("."),
};
let toml = spec_to_minimal_toml(&spec).unwrap();
assert!(toml.contains("type = \"meta\""));
assert!(!toml.contains("[[source]]"));
let val: toml::Value = toml::from_str(&toml).unwrap();
assert!(val.get("source").is_none());
}
#[test] #[test]
fn compute_sha256_for_local_path_and_file_url() { fn compute_sha256_for_local_path_and_file_url() {
use sha2::Digest as TestDigest; use sha2::Digest as TestDigest;