Skip to content

Commit 3c90b68

Browse files
committed
refactor(package): attach path info to GeneratedFile
This is needed for `cargo package --list` JSON message to access the orignal file path information for the generated file kind
1 parent bea12f6 commit 3c90b68

File tree

1 file changed

+17
-7
lines changed
  • src/cargo/ops/cargo_package

1 file changed

+17
-7
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,13 @@ enum FileContents {
107107

108108
enum GeneratedFile {
109109
/// Generates `Cargo.toml` by rewriting the original.
110-
Manifest,
111-
/// Generates `Cargo.lock` in some cases (like if there is a binary).
112-
Lockfile,
110+
///
111+
/// Associated path is the original manifest path.
112+
Manifest(PathBuf),
113+
/// Generates `Cargo.lock`.
114+
///
115+
/// Associated path is the path to the original lock file, if existing.
116+
Lockfile(Option<PathBuf>),
113117
/// Adds a `.cargo_vcs_info.json` file if in a git repo.
114118
VcsInfo(vcs::VcsInfo),
115119
}
@@ -482,7 +486,9 @@ fn build_ar_list(
482486
.push(ArchiveFile {
483487
rel_path: PathBuf::from("Cargo.toml"),
484488
rel_str: "Cargo.toml".to_string(),
485-
contents: FileContents::Generated(GeneratedFile::Manifest),
489+
contents: FileContents::Generated(GeneratedFile::Manifest(
490+
pkg.manifest_path().to_owned(),
491+
)),
486492
});
487493
} else {
488494
ws.gctx().shell().warn(&format!(
@@ -492,14 +498,16 @@ fn build_ar_list(
492498
}
493499

494500
if include_lockfile {
501+
let lockfile_path = ws.lock_root().as_path_unlocked().join(LOCKFILE_NAME);
502+
let lockfile_path = lockfile_path.exists().then_some(lockfile_path);
495503
let rel_str = "Cargo.lock";
496504
result
497505
.entry(UncasedAscii::new(rel_str))
498506
.or_insert_with(Vec::new)
499507
.push(ArchiveFile {
500508
rel_path: PathBuf::from(rel_str),
501509
rel_str: rel_str.to_string(),
502-
contents: FileContents::Generated(GeneratedFile::Lockfile),
510+
contents: FileContents::Generated(GeneratedFile::Lockfile(lockfile_path)),
503511
});
504512
}
505513

@@ -818,8 +826,10 @@ fn tar(
818826
}
819827
FileContents::Generated(generated_kind) => {
820828
let contents = match generated_kind {
821-
GeneratedFile::Manifest => publish_pkg.manifest().to_normalized_contents()?,
822-
GeneratedFile::Lockfile => build_lock(ws, &publish_pkg, local_reg)?,
829+
GeneratedFile::Manifest(_) => {
830+
publish_pkg.manifest().to_normalized_contents()?
831+
}
832+
GeneratedFile::Lockfile(_) => build_lock(ws, &publish_pkg, local_reg)?,
823833
GeneratedFile::VcsInfo(ref s) => serde_json::to_string_pretty(s)?,
824834
};
825835
header.set_entry_type(EntryType::file());

0 commit comments

Comments
 (0)