Skip to content

Commit

Permalink
fix(cargo-link): Patch all packages (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Aug 9, 2024
1 parent d3cfd10 commit e0bc2f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/cargo-link2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = { workspace = true }
license = { workspace = true }
name = "cargo-link2"
repository = { workspace = true }
version = "0.1.3"
version = "0.1.4"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
21 changes: 12 additions & 9 deletions apps/cargo-link2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn list_of_crates(target_dir: &Path) -> Result<Vec<PatchPkg>> {
.collect())
}

fn add_patch_section(working_dir: &Path, link_candidates: &[PatchPkg]) -> Result<Vec<String>> {
fn add_patch_section(working_dir: &Path, link_candidates: &[PatchPkg]) -> Result<Vec<PatchPkg>> {
let md = MetadataCommand::new()
.current_dir(working_dir)
.exec()
Expand Down Expand Up @@ -112,7 +112,7 @@ fn add_patch_section(working_dir: &Path, link_candidates: &[PatchPkg]) -> Result
)
})?;

let (crates_to_link, all_deps) = find_used_crates(&md, link_candidates)
let (_, all_deps) = find_used_crates(&md, link_candidates)
.with_context(|| format!("failed to find used crates in '{}'", working_dir.display()))?;

if doc.get("patch").is_none() {
Expand All @@ -126,7 +126,7 @@ fn add_patch_section(working_dir: &Path, link_candidates: &[PatchPkg]) -> Result

let crates_io = patch["crates-io"].as_table_mut().unwrap();

for PatchPkg { name, path } in &crates_to_link {
for PatchPkg { name, path } in &all_deps {
let mut v = toml_edit::table();
v["path"] = toml_edit::value(path.display().to_string());
crates_io[&**name] = v;
Expand All @@ -150,7 +150,7 @@ fn find_root_manifest_path(md: &Metadata) -> Result<PathBuf> {
fn find_used_crates(
md: &Metadata,
link_candidates: &[PatchPkg],
) -> Result<(Vec<PatchPkg>, Vec<String>)> {
) -> Result<(Vec<PatchPkg>, Vec<PatchPkg>)> {
let mut direct_deps = HashSet::new();
let mut all_deps = HashSet::new();

Expand All @@ -176,19 +176,22 @@ fn find_used_crates(
let mut direct_deps = direct_deps.into_iter().collect::<Vec<_>>();
direct_deps.sort();

let mut all_deps = all_deps.into_iter().collect::<Vec<_>>();
all_deps.sort();
let all_pkgs = link_candidates
.iter()
.filter(|c| all_deps.contains(&c.name))
.cloned()
.collect::<Vec<_>>();

Ok((direct_deps, all_deps))
Ok((direct_deps, all_pkgs))
}

fn run_cargo_update(dir: &PathBuf, crates: &[String]) -> Result<()> {
fn run_cargo_update(dir: &PathBuf, crates: &[PatchPkg]) -> Result<()> {
let mut cmd = std::process::Command::new(cargo_bin());
cmd.current_dir(dir);
cmd.arg("update");
for pkg in crates {
cmd.arg("--package");
cmd.arg(pkg);
cmd.arg(&pkg.name);
}

eprintln!("Running: {:?}", cmd);
Expand Down

0 comments on commit e0bc2f3

Please sign in to comment.