diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe/src/event_dispatcher/event_dispatcher.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs | 48 |
2 files changed, 54 insertions, 4 deletions
diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs index ece83533..fb3ad5f4 100644 --- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs +++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs @@ -563,9 +563,10 @@ impl EventDispatcher { ); } if strpos(callable_str, "@composer ") == Some(0) { + // COMPOSER_BINARY is a native executable, so it is run directly instead + // of being passed to a PHP interpreter. let exec = format!( - "{} {} {}", - self.get_php_exec_command()?, + "{} {}", ProcessExecutor::escape( &Platform::get_env("COMPOSER_BINARY").unwrap_or_default() ), @@ -1012,9 +1013,10 @@ try {{ // resolution, even if bin-dir contains composer too because the project requires composer/composer // see https://github.com/composer/composer/issues/8748 if strpos(&exec, "composer ") == Some(0) { + // COMPOSER_BINARY is a native executable, so it is run directly instead + // of being passed to a PHP interpreter. exec = format!( - "{} {}{}", - self.get_php_exec_command()?, + "{}{}", ProcessExecutor::escape( &Platform::get_env("COMPOSER_BINARY").unwrap_or_default() ), diff --git a/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs b/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs index 90df0624..2c74768a 100644 --- a/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs +++ b/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs @@ -36,6 +36,7 @@ use shirabe_symfony_console::output::output_interface; fn tear_down() { Platform::clear_env("COMPOSER_SKIP_SCRIPTS"); Platform::clear_env("PHP_BINARY"); + Platform::clear_env("COMPOSER_BINARY"); } struct TearDown; @@ -977,3 +978,50 @@ fn test_dispatcher_outputs_error_on_failed_command() { ); assert_eq!(expected, io.borrow().get_output()); } + +/// Both `@composer <args>` and a bare `composer <args>` script re-enter the binary that is running +/// the script, taken from COMPOSER_BINARY. That binary is a native executable, so it is run +/// directly rather than being passed to a PHP interpreter. +#[test] +#[serial] +fn test_dispatcher_runs_composer_scripts_through_the_running_binary() { + let _tear_down = TearDown; + + Platform::put_env("COMPOSER_BINARY", "/path/to/shirabe"); + let binary = ProcessExecutor::escape("/path/to/shirabe"); + + let (process, _process_guard) = get_process_executor_mock( + vec![ + cmd(format!("{} install --no-dev", binary)), + cmd(format!("{} update", binary)), + ], + true, + MockHandler::default(), + ); + + let composer = create_composer_instance(); + let io = buffer_io_verbose(); + let io_dyn: std::rc::Rc<std::cell::RefCell<dyn IOInterface>> = io.clone(); + + let mut dispatcher = dispatcher_with_listeners( + &composer, + io_dyn, + process, + listeners_const(vec!["@composer install --no-dev", "composer update"]), + ); + + dispatcher + .dispatch_script( + ScriptEvents::POST_INSTALL_CMD, + false, + vec![], + IndexMap::new(), + ) + .unwrap(); + + let expected = format!( + "> post-install-cmd: @composer install --no-dev{eol}> post-install-cmd: composer update{eol}", + eol = PHP_EOL, + ); + assert_eq!(expected, io.borrow().get_output()); +} |
