1- #[ cfg( target_os = "linux" ) ]
2- use crate :: error:: SkipStep ;
3- use crate :: error:: TopgradeError ;
1+ use crate :: error:: { SkipStep , TopgradeError } ;
42use crate :: execution_context:: ExecutionContext ;
53use crate :: executor:: { CommandExt , Executor , ExecutorExitStatus , RunType } ;
64use 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) ]
2523pub enum BrewVariant {
26- Linux ,
24+ Path ,
2725 MacIntel ,
2826 MacArm ,
2927}
3028
3129impl 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
7078pub fn run_fisher ( base_dirs : & BaseDirs , run_type : RunType ) -> Result < ( ) > {
@@ -178,7 +186,16 @@ pub fn upgrade_gnome_extensions(ctx: &ExecutionContext) -> Result<()> {
178186}
179187
180188pub 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" ) ]
199216pub 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