Skip to content

Commit

Permalink
Resolved failing test when building binary tarball from crate
Browse files Browse the repository at this point in the history
  • Loading branch information
nick42d committed Aug 18, 2024
1 parent 4b595bc commit a675cff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,29 @@ impl<'a> CrateFile<'a> {
}

impl<'a> BuiltCrate<'a> {
/// Create a tarball of the built crate in the `cargo_target` directory.
/// Create a tarball of the built crate in the `output` directory.
/// Returns a reference to the path of the LICENSE file inside the
/// tarball - it won't simply be ./LICENSE.
pub fn tarball(self, cargo_target: &Path, output: &Path) -> Result<Option<DirEntry>, Error> {
/// tarball - it won't always be ./LICENSE.
pub fn tarball(self, output: &Path) -> Result<Option<DirEntry>, Error> {
let license = if crate::must_copy_license(&self.config.package.license) {
p("LICENSE file will be installed manually.".bold().yellow());
Some(self.license_file()?)
} else {
None
};
// Possible refactor target with super::work
let env_cargo_target: PathBuf = match std::env::var_os("CARGO_TARGET_DIR") {
Some(p) => PathBuf::from(p),
None => PathBuf::from("target"),
};
let cargo_target = self
.tempdir_handle
.path()
.join(self.crate_file_prefix)
.join(env_cargo_target);
super::tarball(
self.musl,
cargo_target,
cargo_target.as_ref(),
output,
license.as_ref(),
self.config,
Expand Down Expand Up @@ -262,8 +272,6 @@ mod tests {
// Ensure the target folder exists. Otherwise the `tar` operation
// will fail.
std::fs::create_dir_all(&output).unwrap();
build
.tarball(&cargo_target, &output)
.expect("Expected tarball to succeed");
build.tarball(&output).expect("Expected tarball to succeed");
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn work(args: Args) -> Result<(), Error> {
(Source::CratesIo, false) => {
let crate_file = crates::CrateFile::download_new(&config)?;
let built_crate_file = crate_file.build(args.musl)?;
let license = built_crate_file.tarball(&cargo_target, &output)?;
let license = built_crate_file.tarball(&cargo_target)?;
let sha256 = sha256sum(&config.package, &output)?;
(sha256, license)
}
Expand Down

0 comments on commit a675cff

Please sign in to comment.