Skip to content

Commit

Permalink
cargo-coupler bundle: store package name in PackageInfo
Browse files Browse the repository at this point in the history
Store the package name directly in PackageInfo rather than storing an index and
later looking it up in cargo metadata.
  • Loading branch information
micahrj committed Jan 10, 2024
1 parent 54ea147 commit 1937c6f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cargo-coupler/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_metadata::{CargoOpt, Metadata, MetadataCommand};
use cargo_metadata::{CargoOpt, MetadataCommand};
use clap::{AppSettings, Args, Parser, Subcommand};
use serde::Deserialize;

Expand Down Expand Up @@ -178,7 +178,7 @@ impl FromStr for Target {
}

struct PackageInfo {
index: usize,
package_name: String,
name: String,
format: Format,
}
Expand Down Expand Up @@ -419,7 +419,7 @@ fn bundle(cmd: &Bundle) {
}

packages_to_build.push(PackageInfo {
index,
package_name,
name: coupler_metadata.name.as_ref().unwrap_or(&package.name).clone(),
format,
});
Expand All @@ -440,7 +440,7 @@ fn bundle(cmd: &Bundle) {
cargo.arg("build");

for package_info in &packages_to_build {
cargo.args(&["--package", &metadata.packages[package_info.index].name]);
cargo.args(&["--package", &package_info.package_name]);
}

cargo.arg("--lib");
Expand Down Expand Up @@ -524,17 +524,17 @@ fn bundle(cmd: &Bundle) {
for package_info in &packages_to_build {
match package_info.format {
Format::Clap => {
bundle_clap(package_info, &out_dir, &target, &metadata);
bundle_clap(package_info, &out_dir, &target);
}
Format::Vst3 => {
bundle_vst3(package_info, &out_dir, &target, &metadata);
bundle_vst3(package_info, &out_dir, &target);
}
}
}
}

fn bundle_clap(package_info: &PackageInfo, out_dir: &Path, target: &Target, metadata: &Metadata) {
let package_name = &metadata.packages[package_info.index].name;
fn bundle_clap(package_info: &PackageInfo, out_dir: &Path, target: &Target) {
let package_name = &package_info.package_name;
let crate_name = package_name.replace('-', "_");
let src = match target.os {
Os::Linux => out_dir.join(format!("lib{crate_name}.so")),
Expand Down Expand Up @@ -567,8 +567,8 @@ fn bundle_clap(package_info: &PackageInfo, out_dir: &Path, target: &Target, meta
}
}

fn bundle_vst3(package_info: &PackageInfo, out_dir: &Path, target: &Target, metadata: &Metadata) {
let package_name = &metadata.packages[package_info.index].name;
fn bundle_vst3(package_info: &PackageInfo, out_dir: &Path, target: &Target) {
let package_name = &package_info.package_name;
let crate_name = package_name.replace('-', "_");
let src = match target.os {
Os::Linux => out_dir.join(format!("lib{crate_name}.so")),
Expand Down

0 comments on commit 1937c6f

Please sign in to comment.