Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit dcf5891

Browse files
authored
Mac OS fails to upgrade Homebrew in custom location (#930)
Fixes #673
1 parent af3f5dd commit dcf5891

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

.vscode/topgrade.code-snippets

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"scope": "rust",
2020
"prefix": "skipstep",
2121
"body": [
22-
"return Err(SkipStep(format!(\"$1\").into()));"
22+
"return Err(SkipStep(format!(\"$1\")).into());"
2323
]
2424
},
2525
"Step": {
@@ -31,5 +31,12 @@
3131
" Ok(())",
3232
"}"
3333
]
34+
},
35+
"macos": {
36+
"scope": "rust",
37+
"prefix": "macos",
38+
"body": [
39+
"#[cfg(target_os = \"macos\")]"
40+
]
3441
}
3542
}

src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn run() -> Result<()> {
153153
runner.execute(Step::ConfigUpdate, "config-update", || linux::run_config_update(&ctx))?;
154154

155155
runner.execute(Step::BrewFormula, "Brew", || {
156-
unix::run_brew_formula(&ctx, unix::BrewVariant::Linux)
156+
unix::run_brew_formula(&ctx, unix::BrewVariant::Path)
157157
})?;
158158
}
159159

@@ -172,12 +172,18 @@ fn run() -> Result<()> {
172172
runner.execute(Step::BrewFormula, "Brew (Intel)", || {
173173
unix::run_brew_formula(&ctx, unix::BrewVariant::MacIntel)
174174
})?;
175+
runner.execute(Step::BrewFormula, "Brew", || {
176+
unix::run_brew_formula(&ctx, unix::BrewVariant::Path)
177+
})?;
175178
runner.execute(Step::BrewCask, "Brew Cask (ARM)", || {
176179
unix::run_brew_cask(&ctx, unix::BrewVariant::MacArm)
177180
})?;
178181
runner.execute(Step::BrewCask, "Brew Cask (Intel)", || {
179182
unix::run_brew_cask(&ctx, unix::BrewVariant::MacIntel)
180183
})?;
184+
runner.execute(Step::BrewCask, "Brew Cask", || {
185+
unix::run_brew_cask(&ctx, unix::BrewVariant::Path)
186+
})?;
181187
runner.execute(Step::Macports, "MacPorts", || macos::run_macports(&ctx))?;
182188
}
183189

src/steps/os/unix.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#[cfg(target_os = "linux")]
2-
use crate::error::SkipStep;
3-
use crate::error::TopgradeError;
1+
use crate::error::{SkipStep, TopgradeError};
42
use crate::execution_context::ExecutionContext;
53
use crate::executor::{CommandExt, Executor, ExecutorExitStatus, RunType};
64
use crate::terminal::print_separator;
@@ -23,20 +21,25 @@ const ARM_BREW: &str = "/opt/homebrew/bin/brew";
2321
#[derive(Copy, Clone, Debug)]
2422
#[allow(dead_code)]
2523
pub enum BrewVariant {
26-
Linux,
24+
Path,
2725
MacIntel,
2826
MacArm,
2927
}
3028

3129
impl BrewVariant {
3230
fn binary_name(self) -> &'static str {
3331
match self {
34-
BrewVariant::Linux => "brew",
32+
BrewVariant::Path => "brew",
3533
BrewVariant::MacIntel => INTEL_BREW,
3634
BrewVariant::MacArm => ARM_BREW,
3735
}
3836
}
3937

38+
#[cfg(target_os = "macos")]
39+
fn is_path(&self) -> bool {
40+
matches!(self, BrewVariant::Path)
41+
}
42+
4043
fn both_both_exist() -> bool {
4144
Path::new(INTEL_BREW).exists() && Path::new(ARM_BREW).exists()
4245
}
@@ -65,6 +68,11 @@ impl BrewVariant {
6568
_ => run_type.execute(self.binary_name()),
6669
}
6770
}
71+
72+
#[cfg(target_os = "macos")]
73+
fn is_macos_custom(binary_name: PathBuf) -> bool {
74+
!(binary_name.as_os_str() == INTEL_BREW || binary_name.as_os_str() == ARM_BREW)
75+
}
6876
}
6977

7078
pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
@@ -178,7 +186,16 @@ pub fn upgrade_gnome_extensions(ctx: &ExecutionContext) -> Result<()> {
178186
}
179187

180188
pub fn run_brew_formula(ctx: &ExecutionContext, variant: BrewVariant) -> Result<()> {
181-
require(variant.binary_name())?;
189+
#[allow(unused_variables)]
190+
let binary_name = require(variant.binary_name())?;
191+
192+
#[cfg(target_os = "macos")]
193+
{
194+
if variant.is_path() && !BrewVariant::is_macos_custom(binary_name) {
195+
return Err(SkipStep("Not a custom brew for macOS".to_string()).into());
196+
}
197+
}
198+
182199
print_separator(variant.step_title());
183200
let run_type = ctx.run_type();
184201

@@ -197,7 +214,10 @@ pub fn run_brew_formula(ctx: &ExecutionContext, variant: BrewVariant) -> Result<
197214

198215
#[cfg(target_os = "macos")]
199216
pub fn run_brew_cask(ctx: &ExecutionContext, variant: BrewVariant) -> Result<()> {
200-
require(variant.binary_name())?;
217+
let binary_name = require(variant.binary_name())?;
218+
if variant.is_path() && !BrewVariant::is_macos_custom(binary_name) {
219+
return Err(SkipStep("Not a custom brew for macOS".to_string()).into());
220+
}
201221
print_separator(format!("{} - Cask", variant.step_title()));
202222
let run_type = ctx.run_type();
203223

0 commit comments

Comments
 (0)