@@ -20,7 +20,6 @@ use serde::{Deserialize, Deserializer, Serialize};
2020use tree_sitter:: { Language , QueryError , QueryErrorKind } ;
2121use tree_sitter_highlight:: HighlightConfiguration ;
2222use tree_sitter_tags:: { Error as TagsError , TagsConfiguration } ;
23- use which:: which;
2423
2524pub const EMSCRIPTEN_TAG : & str = concat ! ( "docker.io/emscripten/emsdk:" , env!( "EMSCRIPTEN_VERSION" ) ) ;
2625
@@ -712,62 +711,43 @@ impl Loader {
712711 ) -> Result < ( ) , Error > {
713712 #[ derive( PartialEq , Eq ) ]
714713 enum EmccSource {
715- Native ( PathBuf ) ,
714+ Native ,
716715 Docker ,
717716 Podman ,
718717 }
719718
720- fn path_of_bin (
721- name : & str ,
722- test : impl Fn ( & Path ) -> std:: io:: Result < std:: process:: Output > ,
723- ) -> Option < PathBuf > {
724- let bin_path = which ( name) . ok ( ) ?;
725- if test ( & bin_path) . is_ok ( ) {
726- Some ( bin_path)
727- } else {
728- None
729- }
730- }
719+ let emcc_name = if cfg ! ( windows) { "emcc.bat" } else { "emcc" } ;
731720
732721 // Order of preference: emscripten > docker > podman > error
733- let source = if force_docker {
734- None
722+ let source = if !force_docker && Command :: new ( emcc_name) . output ( ) . is_ok ( ) {
723+ EmccSource :: Native
724+ } else if Command :: new ( "docker" )
725+ . arg ( "info" )
726+ . output ( )
727+ . map_or ( false , |out| out. status . success ( ) )
728+ {
729+ EmccSource :: Docker
730+ } else if Command :: new ( "podman" )
731+ . arg ( "--version" )
732+ . output ( )
733+ . map_or ( false , |out| out. status . success ( ) )
734+ {
735+ EmccSource :: Podman
735736 } else {
736- path_of_bin ( if cfg ! ( windows) { "emcc.bat" } else { "emcc" } , |p| {
737- Command :: new ( p) . output ( )
738- } )
739- . map ( EmccSource :: Native )
740- }
741- . or_else ( || {
742- path_of_bin ( "docker" , |docker| {
743- // `docker info` should succeed iff the daemon is running
744- // see https://docs.docker.com/config/daemon/troubleshoot/#check-whether-docker-is-running
745- Command :: new ( docker) . args ( [ "info" ] ) . output ( )
746- } )
747- . map ( |_| EmccSource :: Docker )
748- } )
749- . or_else ( || {
750- path_of_bin ( "podman" , |podman| {
751- Command :: new ( podman) . arg ( "--version" ) . output ( )
752- } )
753- . map ( |_| EmccSource :: Podman )
754- } ) ;
755-
756- let Some ( cmd) = source else {
757737 return Err ( anyhow ! (
758- "You must have either emcc or docker on your PATH to run this command"
738+ "You must have either emcc, docker, or podman on your PATH to run this command"
759739 ) ) ;
760740 } ;
761741
762- let mut command = match cmd {
763- EmccSource :: Native ( emcc_path ) => {
764- let mut command = Command :: new ( emcc_path ) ;
742+ let mut command = match source {
743+ EmccSource :: Native => {
744+ let mut command = Command :: new ( emcc_name ) ;
765745 command. current_dir ( src_path) ;
766746 command
767747 }
768748
769749 EmccSource :: Docker | EmccSource :: Podman => {
770- let mut command = match cmd {
750+ let mut command = match source {
771751 EmccSource :: Docker => Command :: new ( "docker" ) ,
772752 EmccSource :: Podman => Command :: new ( "podman" ) ,
773753 _ => unreachable ! ( ) ,
@@ -798,7 +778,7 @@ impl Loader {
798778 fn getuid ( ) -> u32 ;
799779 }
800780 // don't need to set user for podman since PODMAN_USERNS=keep-id is already set
801- if cmd == EmccSource :: Docker {
781+ if source == EmccSource :: Docker {
802782 let user_id = unsafe { getuid ( ) } ;
803783 command. args ( [ "--user" , & user_id. to_string ( ) ] ) ;
804784 }
0 commit comments