Skip to content

Commit

Permalink
Add exe check.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 21, 2023
1 parent 84db7a3 commit c86c382
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
3 changes: 1 addition & 2 deletions crates/cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ use crate::commands::task::TaskArgs;
use crate::enums::{CacheMode, LogLevel};
use clap::builder::styling::{Color, Style, Styles};
use clap::{Parser, Subcommand};
use moon_common::consts::BIN_NAME;
use starbase::State;
use starbase_styles::color::Color as ColorType;
use std::path::PathBuf;

pub const BIN_NAME: &str = if cfg!(windows) { "moon.exe" } else { "moon" };

#[derive(Clone, Debug, Subcommand)]
pub enum DockerCommands {
#[command(
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::app::BIN_NAME;
use crate::helpers::create_progress_bar;
use bytes::Buf;
use itertools::Itertools;
use miette::{miette, IntoDiagnostic};
use moon_api::Launchpad;
use moon_cache::CacheEngine;
use moon_common::consts::BIN_NAME;
use moon_utils::{get_workspace_root, semver::Version};
use starbase::system;
use starbase_utils::{dirs, fs};
Expand Down
3 changes: 1 addition & 2 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ use app::App as CLI;
use clap::Parser;
use commands::migrate::FromTurborepoArgs;
use enums::{CacheMode, LogLevel};
use moon_common::consts::BIN_NAME;
use starbase::{tracing::TracingOptions, App, AppResult};
use starbase_styles::color;
use starbase_utils::string_vec;
use std::env;
use std::ffi::OsString;
use tracing::debug;

pub use app::BIN_NAME;

fn setup_logging(level: &LogLevel) {
env::set_var("MOON_APP_LOG", level.to_string());

Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use miette::IntoDiagnostic;
use mimalloc::MiMalloc;
use moon_cli::{run_cli, BIN_NAME};
use moon_common::consts::CONFIG_DIRNAME;
use moon_cli::run_cli;
use moon_common::consts::{BIN_NAME, CONFIG_DIRNAME};
use moon_node_lang::{
node::{extract_canonical_node_module_bin, BinFile},
NODE,
Expand Down
10 changes: 4 additions & 6 deletions crates/rust/platform/src/rust_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
find_cargo_lock, get_cargo_home, target_hash::RustTargetHash, toolchain_hash::RustToolchainHash,
};
use moon_action_context::ActionContext;
use moon_common::{is_ci, Id};
use moon_common::{is_ci, path::exe_name, Id};
use moon_config::{
BinEntry, HasherConfig, PlatformType, ProjectConfig, ProjectsAliasesMap, ProjectsSourcesMap,
RustConfig, UnresolvedVersionSpec,
Expand Down Expand Up @@ -282,9 +282,7 @@ impl Platform for RustPlatform {
let globals_dir = self.get_globals_dir(Some(tool));

// Install cargo-binstall if it does not exist
if !globals_dir.join("cargo-binstall").exists()
&& !globals_dir.join("cargo-binstall.exe").exists()
{
if !globals_dir.join(exe_name("cargo-binstall")).exists() {
debug!(
target: LOG_TARGET,
"{} does not exist, installing",
Expand Down Expand Up @@ -525,10 +523,10 @@ impl Platform for RustPlatform {
// Binary may be installed to ~/.cargo/bin
_ => {
let globals_dir = self.get_globals_dir(self.toolchain.get().ok());
let global_bin_path = globals_dir.join(&task.command);
let global_bin_path = globals_dir.join(exe_name(&task.command));

let cargo_bin = task.command.strip_prefix("cargo-").unwrap_or(&task.command);
let cargo_bin_path = globals_dir.join(format!("cargo-{}", cargo_bin));
let cargo_bin_path = globals_dir.join(exe_name(format!("cargo-{}", cargo_bin)));

// Must run through cargo
if cargo_bin_path.exists() {
Expand Down
13 changes: 13 additions & 0 deletions nextgen/common/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,16 @@ pub fn to_string<T: AsRef<Path>>(path: T) -> miette::Result<String> {
pub fn to_virtual_string<T: AsRef<Path>>(path: T) -> miette::Result<String> {
Ok(standardize_separators(to_string(path)?))
}

#[inline]
pub fn exe_name<T: AsRef<str>>(name: T) -> String {
#[cfg(windows)]
{
format!("{}.exe", name.as_ref())
}

#[cfg(not(windows))]
{
name.as_ref().into()
}
}

0 comments on commit c86c382

Please sign in to comment.