Skip to content

Commit

Permalink
Rework exe configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Oct 24, 2024
1 parent 3b27de7 commit 6319972
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 31 deletions.
4 changes: 2 additions & 2 deletions crates/cli/src/commands/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub async fn bin(session: ProtoSession, args: BinArgs) -> AppResult {
tool.symlink_bins(true).await?;

for bin in tool.resolve_bin_locations().await? {
if bin.primary {
if bin.config.primary {
println!("{}", bin.path.display());
return Ok(None);
}
Expand All @@ -52,7 +52,7 @@ pub async fn bin(session: ProtoSession, args: BinArgs) -> AppResult {
tool.generate_shims(true).await?;

for shim in tool.resolve_shim_locations().await? {
if shim.primary {
if shim.config.primary {
println!("{}", shim.path.display());
return Ok(None);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/commands/plugin/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub async fn info(session: ProtoSession, args: InfoPluginArgs) -> AppResult {
format!(
"{} {}",
color::path(bin.path),
if bin.primary {
if bin.config.primary {
color::muted_light("(primary)")
} else {
"".into()
Expand All @@ -144,7 +144,7 @@ pub async fn info(session: ProtoSession, args: InfoPluginArgs) -> AppResult {
format!(
"{} {}",
color::path(shim.path),
if shim.primary {
if shim.config.primary {
format_value("(primary)")
} else {
"".into()
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/flow/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Tool {
shim_entry.env_vars.extend(env_vars);
}

if !shim.primary {
if !shim.config.primary {
shim_entry.parent = Some(self.id.to_string());

// Only use --alt when the secondary executable exists
Expand Down
99 changes: 73 additions & 26 deletions crates/core/src/flow/locate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct ExecutableLocation {
pub config: ExecutableConfig,
pub name: String,
pub path: PathBuf,
pub primary: bool,
}

impl Tool {
Expand All @@ -36,13 +35,27 @@ impl Tool {
pub async fn resolve_primary_exe_location(&self) -> miette::Result<Option<ExecutableLocation>> {
let output = self.call_locate_executables().await?;

if let Some(primary) = output.primary {
for (name, config) in output.exes {
if config.primary {
if let Some(exe_path) = &config.exe_path {
return Ok(Some(ExecutableLocation {
path: self.get_product_dir().join(exe_path),
name,
config,
}));
}
}
}

#[allow(deprecated)]
if let Some(mut primary) = output.primary {
if let Some(exe_path) = &primary.exe_path {
primary.primary = true;

return Ok(Some(ExecutableLocation {
path: self.get_product_dir().join(exe_path),
name: self.id.to_string(),
config: primary,
primary: true,
}));
}
}
Expand All @@ -55,17 +68,33 @@ impl Tool {
let output = self.call_locate_executables().await?;
let mut locations = vec![];

for (name, secondary) in output.secondary {
if let Some(exe_path) = &secondary.exe_path {
for (name, config) in output.exes {
if config.primary {
continue;
}

if let Some(exe_path) = &config.exe_path {
locations.push(ExecutableLocation {
path: self.get_product_dir().join(exe_path),
name,
config: secondary,
primary: false,
config,
});
}
}

if locations.is_empty() {
#[allow(deprecated)]
for (name, secondary) in output.secondary {
if let Some(exe_path) = &secondary.exe_path {
locations.push(ExecutableLocation {
path: self.get_product_dir().join(exe_path),
name,
config: secondary,
});
}
}
}

Ok(locations)
}

Expand All @@ -76,7 +105,7 @@ impl Tool {
let output = self.call_locate_executables().await?;
let mut locations = vec![];

let mut add = |name: &str, config: ExecutableConfig, primary: bool| {
let mut add = |name: String, config: ExecutableConfig| {
if !config.no_bin
&& config
.exe_link_path
Expand All @@ -85,20 +114,29 @@ impl Tool {
.is_some()
{
locations.push(ExecutableLocation {
path: self.proto.store.bin_dir.join(get_exe_file_name(name)),
name: name.to_owned(),
path: self.proto.store.bin_dir.join(get_exe_file_name(&name)),
name,
config,
primary,
});
}
};

if let Some(primary) = output.primary {
add(&self.id, primary, true);
}
if output.exes.is_empty() {
#[allow(deprecated)]
if let Some(mut primary) = output.primary {
primary.primary = true;

for (name, secondary) in output.secondary {
add(&name, secondary, false);
add(self.id.to_string(), primary);
}

#[allow(deprecated)]
for (name, secondary) in output.secondary {
add(name, secondary);
}
} else {
for (name, config) in output.exes {
add(name, config);
}
}

Ok(locations)
Expand All @@ -111,23 +149,32 @@ impl Tool {
let output = self.call_locate_executables().await?;
let mut locations = vec![];

let mut add = |name: &str, config: ExecutableConfig, primary: bool| {
let mut add = |name: String, config: ExecutableConfig| {
if !config.no_shim {
locations.push(ExecutableLocation {
path: self.proto.store.shims_dir.join(get_shim_file_name(name)),
name: name.to_owned(),
config: config.clone(),
primary,
path: self.proto.store.shims_dir.join(get_shim_file_name(&name)),
name,
config,
});
}
};

if let Some(primary) = output.primary {
add(&self.id, primary, true);
}
if output.exes.is_empty() {
#[allow(deprecated)]
if let Some(mut primary) = output.primary {
primary.primary = true;

add(self.id.to_string(), primary);
}

for (name, secondary) in output.secondary {
add(&name, secondary, false);
#[allow(deprecated)]
for (name, secondary) in output.secondary {
add(name, secondary);
}
} else {
for (name, config) in output.exes {
add(name, config);
}
}

Ok(locations)
Expand Down

0 comments on commit 6319972

Please sign in to comment.