feat: update depot version to 0.5.0 and add lib32 support for post-configure and post-compile hooks
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
project(
|
project(
|
||||||
'depot',
|
'depot',
|
||||||
version: '0.1.0',
|
version: '0.5.0',
|
||||||
meson_version: '>=0.60.0',
|
meson_version: '>=0.60.0',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+75
-4
@@ -76,6 +76,26 @@ impl Hook {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn lib32_candidate_names(self) -> Vec<String> {
|
||||||
|
let canonical = self.canonical_name();
|
||||||
|
let dashed = canonical.replace('_', "-");
|
||||||
|
let compact = canonical.replace('_', "");
|
||||||
|
vec![
|
||||||
|
format!("{canonical}-lib32"),
|
||||||
|
format!("{canonical}-lib32.sh"),
|
||||||
|
format!("{dashed}-lib32"),
|
||||||
|
format!("{dashed}-lib32.sh"),
|
||||||
|
format!("{compact}-lib32"),
|
||||||
|
format!("{compact}-lib32.sh"),
|
||||||
|
format!("lib32-{canonical}"),
|
||||||
|
format!("lib32-{canonical}.sh"),
|
||||||
|
format!("lib32-{dashed}"),
|
||||||
|
format!("lib32-{dashed}.sh"),
|
||||||
|
format!("lib32-{compact}"),
|
||||||
|
format!("lib32-{compact}.sh"),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
fn legacy_root_candidate_names(self) -> [String; 2] {
|
fn legacy_root_candidate_names(self) -> [String; 2] {
|
||||||
let compact = self.canonical_name().replace('_', "");
|
let compact = self.canonical_name().replace('_', "");
|
||||||
[compact.clone(), format!("{}.sh", compact)]
|
[compact.clone(), format!("{}.sh", compact)]
|
||||||
@@ -203,7 +223,7 @@ pub fn run_hook_if_present(
|
|||||||
rootfs: &Path,
|
rootfs: &Path,
|
||||||
pkg_name: &str,
|
pkg_name: &str,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let Some(script_path) = resolve_hook_script(script_dir, hook)? else {
|
let Some(script_path) = resolve_hook_script(script_dir, hook, pkg_name)? else {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -280,7 +300,7 @@ fn run_script_with_rootfs_context(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_hook_script(script_dir: &Path, hook: Hook) -> Result<Option<PathBuf>> {
|
fn resolve_hook_script(script_dir: &Path, hook: Hook, pkg_name: &str) -> Result<Option<PathBuf>> {
|
||||||
if !script_dir.exists() {
|
if !script_dir.exists() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
@@ -292,9 +312,29 @@ fn resolve_hook_script(script_dir: &Path, hook: Hook) -> Result<Option<PathBuf>>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_lib32_package(pkg_name) {
|
||||||
|
let label = format!("{} (lib32)", hook.canonical_name());
|
||||||
|
if let Some(path) =
|
||||||
|
resolve_hook_from_candidates(script_dir, &label, hook.lib32_candidate_names())?
|
||||||
|
{
|
||||||
|
return Ok(Some(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve_hook_from_candidates(script_dir, hook.canonical_name(), hook.candidate_names())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolve_hook_from_candidates<I>(
|
||||||
|
script_dir: &Path,
|
||||||
|
hook_label: &str,
|
||||||
|
candidates: I,
|
||||||
|
) -> Result<Option<PathBuf>>
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = String>,
|
||||||
|
{
|
||||||
let mut found = Vec::new();
|
let mut found = Vec::new();
|
||||||
|
|
||||||
for candidate in hook.candidate_names() {
|
for candidate in candidates {
|
||||||
let path = script_dir.join(&candidate);
|
let path = script_dir.join(&candidate);
|
||||||
let metadata = match path.symlink_metadata() {
|
let metadata = match path.symlink_metadata() {
|
||||||
Ok(meta) => meta,
|
Ok(meta) => meta,
|
||||||
@@ -324,7 +364,7 @@ fn resolve_hook_script(script_dir: &Path, hook: Hook) -> Result<Option<PathBuf>>
|
|||||||
.join(", ");
|
.join(", ");
|
||||||
bail!(
|
bail!(
|
||||||
"Ambiguous lifecycle hook '{}': multiple script candidates found: {}",
|
"Ambiguous lifecycle hook '{}': multiple script candidates found: {}",
|
||||||
hook.canonical_name(),
|
hook_label,
|
||||||
names
|
names
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -332,6 +372,10 @@ fn resolve_hook_script(script_dir: &Path, hook: Hook) -> Result<Option<PathBuf>>
|
|||||||
Ok(found.into_iter().next())
|
Ok(found.into_iter().next())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_lib32_package(pkg_name: &str) -> bool {
|
||||||
|
pkg_name.starts_with("lib32-")
|
||||||
|
}
|
||||||
|
|
||||||
fn collect_legacy_root_hooks(spec_dir: &Path) -> Result<Vec<(Hook, PathBuf)>> {
|
fn collect_legacy_root_hooks(spec_dir: &Path) -> Result<Vec<(Hook, PathBuf)>> {
|
||||||
let mut found = Vec::new();
|
let mut found = Vec::new();
|
||||||
|
|
||||||
@@ -674,6 +718,33 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn run_hook_if_present_prefers_lib32_specific_script_name() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let scripts = tmp.path().join("scripts");
|
||||||
|
let rootfs = tmp.path().join("root");
|
||||||
|
std::fs::create_dir_all(&scripts).unwrap();
|
||||||
|
std::fs::create_dir_all(&rootfs).unwrap();
|
||||||
|
|
||||||
|
std::fs::write(
|
||||||
|
scripts.join("post_install"),
|
||||||
|
"echo generic > \"$DEPOT_ROOTFS/hook.out\"\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
scripts.join("post_install-lib32"),
|
||||||
|
"echo lib32 > \"$DEPOT_ROOTFS/hook.out\"\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let ran = run_hook_if_present(&scripts, Hook::PostInstall, &rootfs, "lib32-foo").unwrap();
|
||||||
|
assert!(ran);
|
||||||
|
assert_eq!(
|
||||||
|
std::fs::read_to_string(rootfs.join("hook.out")).unwrap(),
|
||||||
|
"lib32\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_hook_if_present_rejects_ambiguous_names() {
|
fn run_hook_if_present_rejects_ambiguous_names() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
|||||||
@@ -91,6 +91,12 @@ fn make_lib32_build_spec(base: &package::PackageSpec) -> package::PackageSpec {
|
|||||||
if !flags.configure_lib32.is_empty() {
|
if !flags.configure_lib32.is_empty() {
|
||||||
flags.configure = flags.configure_lib32.clone();
|
flags.configure = flags.configure_lib32.clone();
|
||||||
}
|
}
|
||||||
|
if !flags.post_configure_lib32.is_empty() {
|
||||||
|
flags.post_configure = flags.post_configure_lib32.clone();
|
||||||
|
}
|
||||||
|
if !flags.post_compile_lib32.is_empty() {
|
||||||
|
flags.post_compile = flags.post_compile_lib32.clone();
|
||||||
|
}
|
||||||
if !flags.post_install_lib32.is_empty() {
|
if !flags.post_install_lib32.is_empty() {
|
||||||
flags.post_install = flags.post_install_lib32.clone();
|
flags.post_install = flags.post_install_lib32.clone();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -526,6 +526,17 @@ impl PackageSpec {
|
|||||||
self.build.flags.post_configure = vec![s.to_string()];
|
self.build.flags.post_configure = vec![s.to_string()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"post_configure_lib32" | "post_configure-lib32" | "post-configure-lib32" => {
|
||||||
|
if let Some(arr) = v.as_array() {
|
||||||
|
self.build.flags.post_configure_lib32 = arr
|
||||||
|
.iter()
|
||||||
|
.filter_map(|x| x.as_str())
|
||||||
|
.map(String::from)
|
||||||
|
.collect();
|
||||||
|
} else if let Some(s) = v.as_str() {
|
||||||
|
self.build.flags.post_configure_lib32 = vec![s.to_string()];
|
||||||
|
}
|
||||||
|
}
|
||||||
"post_compile" | "post-compile" => {
|
"post_compile" | "post-compile" => {
|
||||||
if let Some(arr) = v.as_array() {
|
if let Some(arr) = v.as_array() {
|
||||||
self.build.flags.post_compile = arr
|
self.build.flags.post_compile = arr
|
||||||
@@ -537,6 +548,17 @@ impl PackageSpec {
|
|||||||
self.build.flags.post_compile = vec![s.to_string()];
|
self.build.flags.post_compile = vec![s.to_string()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"post_compile_lib32" | "post_compile-lib32" | "post-compile-lib32" => {
|
||||||
|
if let Some(arr) = v.as_array() {
|
||||||
|
self.build.flags.post_compile_lib32 = arr
|
||||||
|
.iter()
|
||||||
|
.filter_map(|x| x.as_str())
|
||||||
|
.map(String::from)
|
||||||
|
.collect();
|
||||||
|
} else if let Some(s) = v.as_str() {
|
||||||
|
self.build.flags.post_compile_lib32 = vec![s.to_string()];
|
||||||
|
}
|
||||||
|
}
|
||||||
"post_install" | "post-install" => {
|
"post_install" | "post-install" => {
|
||||||
if let Some(arr) = v.as_array() {
|
if let Some(arr) = v.as_array() {
|
||||||
self.build.flags.post_install = arr
|
self.build.flags.post_install = arr
|
||||||
@@ -680,6 +702,18 @@ impl PackageSpec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"post_configure_lib32" | "post_configure-lib32" | "post-configure-lib32" => {
|
||||||
|
for v in values {
|
||||||
|
if let Some(arr) = v.as_array() {
|
||||||
|
self.build
|
||||||
|
.flags
|
||||||
|
.post_configure_lib32
|
||||||
|
.extend(arr.iter().filter_map(|x| x.as_str()).map(String::from));
|
||||||
|
} else if let Some(s) = v.as_str() {
|
||||||
|
self.build.flags.post_configure_lib32.push(s.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
"post_compile" | "post-compile" => {
|
"post_compile" | "post-compile" => {
|
||||||
for v in values {
|
for v in values {
|
||||||
if let Some(arr) = v.as_array() {
|
if let Some(arr) = v.as_array() {
|
||||||
@@ -692,6 +726,18 @@ impl PackageSpec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"post_compile_lib32" | "post_compile-lib32" | "post-compile-lib32" => {
|
||||||
|
for v in values {
|
||||||
|
if let Some(arr) = v.as_array() {
|
||||||
|
self.build
|
||||||
|
.flags
|
||||||
|
.post_compile_lib32
|
||||||
|
.extend(arr.iter().filter_map(|x| x.as_str()).map(String::from));
|
||||||
|
} else if let Some(s) = v.as_str() {
|
||||||
|
self.build.flags.post_compile_lib32.push(s.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
"post_install" | "post-install" => {
|
"post_install" | "post-install" => {
|
||||||
for v in values {
|
for v in values {
|
||||||
if let Some(arr) = v.as_array() {
|
if let Some(arr) = v.as_array() {
|
||||||
@@ -1883,6 +1929,8 @@ type = "autotools"
|
|||||||
"CFLAGS-lib32" = ["-mstackrealign"]
|
"CFLAGS-lib32" = ["-mstackrealign"]
|
||||||
"CXXFLAGS-lib32" = ["-fno-rtti"]
|
"CXXFLAGS-lib32" = ["-fno-rtti"]
|
||||||
"configure-lib32" = ["--disable-static"]
|
"configure-lib32" = ["--disable-static"]
|
||||||
|
"post_configure-lib32" = ["echo configured lib32"]
|
||||||
|
"post_compile-lib32" = ["echo compiled lib32"]
|
||||||
"post_install-lib32" = ["echo lib32"]
|
"post_install-lib32" = ["echo lib32"]
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
@@ -1893,6 +1941,14 @@ type = "autotools"
|
|||||||
assert_eq!(spec.build.flags.cflags_lib32, vec!["-mstackrealign"]);
|
assert_eq!(spec.build.flags.cflags_lib32, vec!["-mstackrealign"]);
|
||||||
assert_eq!(spec.build.flags.cxxflags_lib32, vec!["-fno-rtti"]);
|
assert_eq!(spec.build.flags.cxxflags_lib32, vec!["-fno-rtti"]);
|
||||||
assert_eq!(spec.build.flags.configure_lib32, vec!["--disable-static"]);
|
assert_eq!(spec.build.flags.configure_lib32, vec!["--disable-static"]);
|
||||||
|
assert_eq!(
|
||||||
|
spec.build.flags.post_configure_lib32,
|
||||||
|
vec!["echo configured lib32"]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
spec.build.flags.post_compile_lib32,
|
||||||
|
vec!["echo compiled lib32"]
|
||||||
|
);
|
||||||
assert_eq!(spec.build.flags.post_install_lib32, vec!["echo lib32"]);
|
assert_eq!(spec.build.flags.post_install_lib32, vec!["echo lib32"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2566,9 +2622,25 @@ pub struct BuildFlags {
|
|||||||
/// Commands to run after configure/setup step, before compile/build step.
|
/// Commands to run after configure/setup step, before compile/build step.
|
||||||
#[serde(default, alias = "post-configure")]
|
#[serde(default, alias = "post-configure")]
|
||||||
pub post_configure: Vec<String>,
|
pub post_configure: Vec<String>,
|
||||||
|
/// Commands to run after configure/setup for the lib32 build variant.
|
||||||
|
#[serde(
|
||||||
|
default,
|
||||||
|
alias = "post-configure-lib32",
|
||||||
|
alias = "post_configure-lib32",
|
||||||
|
alias = "post_configure_lib32"
|
||||||
|
)]
|
||||||
|
pub post_configure_lib32: Vec<String>,
|
||||||
/// Commands to run after compile (after make, before make install).
|
/// Commands to run after compile (after make, before make install).
|
||||||
#[serde(default, alias = "post-compile")]
|
#[serde(default, alias = "post-compile")]
|
||||||
pub post_compile: Vec<String>,
|
pub post_compile: Vec<String>,
|
||||||
|
/// Commands to run after compile for the lib32 build variant.
|
||||||
|
#[serde(
|
||||||
|
default,
|
||||||
|
alias = "post-compile-lib32",
|
||||||
|
alias = "post_compile-lib32",
|
||||||
|
alias = "post_compile_lib32"
|
||||||
|
)]
|
||||||
|
pub post_compile_lib32: Vec<String>,
|
||||||
/// Commands to run after install (after make install)
|
/// Commands to run after install (after make install)
|
||||||
#[serde(default, alias = "post-install")]
|
#[serde(default, alias = "post-install")]
|
||||||
pub post_install: Vec<String>,
|
pub post_install: Vec<String>,
|
||||||
@@ -2754,7 +2826,9 @@ impl Default for BuildFlags {
|
|||||||
libc: String::new(),
|
libc: String::new(),
|
||||||
rootfs: default_rootfs(),
|
rootfs: default_rootfs(),
|
||||||
post_configure: Vec::new(),
|
post_configure: Vec::new(),
|
||||||
|
post_configure_lib32: Vec::new(),
|
||||||
post_compile: Vec::new(),
|
post_compile: Vec::new(),
|
||||||
|
post_compile_lib32: Vec::new(),
|
||||||
post_install: Vec::new(),
|
post_install: Vec::new(),
|
||||||
post_install_lib32: Vec::new(),
|
post_install_lib32: Vec::new(),
|
||||||
makefile_commands: Vec::new(),
|
makefile_commands: Vec::new(),
|
||||||
|
|||||||
Reference in New Issue
Block a user