deb: consider package directories with version
Some checks failed
CI / build (push) Failing after 1m6s
Some checks failed
CI / build (push) Failing after 1m6s
This commit is contained in:
@@ -80,10 +80,16 @@ pub fn build(
|
|||||||
return Err("Could not install essential packages for the build".into());
|
return Err("Could not install essential packages for the build".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the actual package directory
|
||||||
|
let package_dir = crate::deb::find_package_directory(Path::new(build_root), package, version)?;
|
||||||
|
let package_dir_str = package_dir
|
||||||
|
.to_str()
|
||||||
|
.ok_or("Invalid package directory path")?;
|
||||||
|
|
||||||
// Install build dependencies
|
// Install build dependencies
|
||||||
log::debug!("Installing build dependencies...");
|
log::debug!("Installing build dependencies...");
|
||||||
let mut cmd = ctx.command("apt-get");
|
let mut cmd = ctx.command("apt-get");
|
||||||
cmd.current_dir(format!("{build_root}/{package}"))
|
cmd.current_dir(package_dir_str)
|
||||||
.envs(env.clone())
|
.envs(env.clone())
|
||||||
.arg("-y")
|
.arg("-y")
|
||||||
.arg("build-dep");
|
.arg("build-dep");
|
||||||
@@ -102,7 +108,7 @@ pub fn build(
|
|||||||
log::debug!("Building (debian/rules build) package...");
|
log::debug!("Building (debian/rules build) package...");
|
||||||
let status = ctx
|
let status = ctx
|
||||||
.command("debian/rules")
|
.command("debian/rules")
|
||||||
.current_dir(format!("{build_root}/{package}"))
|
.current_dir(package_dir_str)
|
||||||
.envs(env.clone())
|
.envs(env.clone())
|
||||||
.arg("build")
|
.arg("build")
|
||||||
.status()?;
|
.status()?;
|
||||||
@@ -113,7 +119,7 @@ pub fn build(
|
|||||||
// Run the 'binary' step to produce deb
|
// Run the 'binary' step to produce deb
|
||||||
let status = ctx
|
let status = ctx
|
||||||
.command("fakeroot")
|
.command("fakeroot")
|
||||||
.current_dir(format!("{build_root}/{package}"))
|
.current_dir(package_dir_str)
|
||||||
.envs(env.clone())
|
.envs(env.clone())
|
||||||
.arg("debian/rules")
|
.arg("debian/rules")
|
||||||
.arg("binary")
|
.arg("binary")
|
||||||
|
|||||||
@@ -85,6 +85,45 @@ pub fn build_binary_package(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Find the current package directory by trying both patterns:
|
||||||
|
/// - package/package
|
||||||
|
/// - package/package-origversion
|
||||||
|
pub(crate) fn find_package_directory(
|
||||||
|
parent_dir: &Path,
|
||||||
|
package: &str,
|
||||||
|
version: &str,
|
||||||
|
) -> Result<PathBuf, Box<dyn Error>> {
|
||||||
|
let ctx = context::current();
|
||||||
|
|
||||||
|
// Try package/package pattern first
|
||||||
|
let package_dir_pattern1 = parent_dir.join(package).join(package);
|
||||||
|
if ctx.exists(&package_dir_pattern1)? {
|
||||||
|
return Ok(package_dir_pattern1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute origversion from version: remove everything after first '-', after stripping epoch
|
||||||
|
let version_without_epoch = version.split_once(':').map(|(_, v)| v).unwrap_or(version);
|
||||||
|
let origversion = version_without_epoch
|
||||||
|
.split_once('-')
|
||||||
|
.map(|(v, _)| v)
|
||||||
|
.unwrap_or(version);
|
||||||
|
|
||||||
|
// Try package/package-origversion pattern
|
||||||
|
let package_dir_pattern2 = parent_dir
|
||||||
|
.join(package)
|
||||||
|
.join(format!("{}-{}", package, origversion));
|
||||||
|
if ctx.exists(&package_dir_pattern2)? {
|
||||||
|
return Ok(package_dir_pattern2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(format!(
|
||||||
|
"Could not find package directory for {} in {}",
|
||||||
|
package,
|
||||||
|
parent_dir.display()
|
||||||
|
)
|
||||||
|
.into())
|
||||||
|
}
|
||||||
|
|
||||||
fn find_dsc_file(
|
fn find_dsc_file(
|
||||||
build_root: &str,
|
build_root: &str,
|
||||||
package: &str,
|
package: &str,
|
||||||
@@ -135,7 +174,7 @@ mod tests {
|
|||||||
log::info!("Successfully pulled package {}", package);
|
log::info!("Successfully pulled package {}", package);
|
||||||
|
|
||||||
// Change directory to the package directory
|
// Change directory to the package directory
|
||||||
let cwd = cwd.join(package).join(package);
|
let cwd = crate::deb::find_package_directory(cwd, package, &package_info.stanza.version).expect("Cannot find package directory");
|
||||||
log::debug!("Package directory: {}", cwd.display());
|
log::debug!("Package directory: {}", cwd.display());
|
||||||
|
|
||||||
log::info!("Starting binary package build...");
|
log::info!("Starting binary package build...");
|
||||||
|
|||||||
@@ -2,18 +2,26 @@
|
|||||||
/// Call 'sbuild' with the dsc file to build the package with unshare
|
/// Call 'sbuild' with the dsc file to build the package with unshare
|
||||||
use crate::context;
|
use crate::context;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn build(
|
pub fn build(
|
||||||
package: &str,
|
package: &str,
|
||||||
_version: &str,
|
version: &str,
|
||||||
arch: &str,
|
arch: &str,
|
||||||
series: &str,
|
series: &str,
|
||||||
build_root: &str,
|
build_root: &str,
|
||||||
cross: bool,
|
cross: bool,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let ctx = context::current();
|
let ctx = context::current();
|
||||||
|
|
||||||
|
// Find the actual package directory
|
||||||
|
let package_dir = crate::deb::find_package_directory(Path::new(build_root), package, version)?;
|
||||||
|
let package_dir_str = package_dir
|
||||||
|
.to_str()
|
||||||
|
.ok_or("Invalid package directory path")?;
|
||||||
|
|
||||||
let mut cmd = ctx.command("sbuild");
|
let mut cmd = ctx.command("sbuild");
|
||||||
cmd.current_dir(format!("{}/{}", build_root, package));
|
cmd.current_dir(package_dir_str);
|
||||||
cmd.arg("--chroot-mode=unshare");
|
cmd.arg("--chroot-mode=unshare");
|
||||||
cmd.arg("--no-clean-source");
|
cmd.arg("--no-clean-source");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user