Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/sigint #190

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ clap-verbosity-flag = "2.0.1"
clap_complete = "4.2.1"
console = { version = "0.15.5", features = ["windows-console-colors"] }
deno_task_shell = { git = "https://github.com/prefix-dev/deno_task_shell" }
# deno_task_shell = { path = "../deno_task_shell" }
dirs = "5.0.1"
dunce = "1.0.4"
futures = "0.3.28"
Expand Down Expand Up @@ -53,7 +54,7 @@ serde_spanned = "0.6.2"
serde_with = { version = "3.0.0", features = ["indexmap"] }
shlex = "1.1.0"
tempfile = "3.5.0"
tokio = { version = "1.27.0", features = ["macros", "rt-multi-thread"] }
tokio = { version = "1.27.0", features = ["macros", "rt-multi-thread", "signal"] }
toml_edit = { version = "0.19.10", features = ["serde"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
Expand Down
14 changes: 13 additions & 1 deletion src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ fn quote_arguments(args: impl IntoIterator<Item = impl AsRef<str>>) -> String {
}

/// CLI entry point for `pixi run`
/// When running the sigints are ignored and child can react to them. As it pleases.
pub async fn execute(args: Args) -> anyhow::Result<()> {
let project = Project::load_or_else_discover(args.manifest_path.as_deref())?;

Expand All @@ -190,8 +191,19 @@ pub async fn execute(args: Args) -> anyhow::Result<()> {

// Execute the commands in the correct order
while let Some((command, args)) = ordered_commands.pop_back() {
// Ignore CTRL+C
// Specifically so that the child is responsible for its own signal handling
// NOTE: one CTRL+C is registered it will always stay registered for the rest of the runtime of the program
// which is fine when using run in isolation, however if we start to use run in conjunction with
// some other command we might want to revaluate this.
let ctrl_c = tokio::spawn(async { while tokio::signal::ctrl_c().await.is_ok() {} });
let script = create_script(command, args).await?;
let status_code = execute_script(script, &project, &command_env).await?;
let status_code = tokio::select! {
code = execute_script(script, &project, &command_env) => code?,
// This should never exit
_ = ctrl_c => { unreachable!("Ctrl+C should not be triggered") }
};

if status_code != 0 {
std::process::exit(status_code);
}
Expand Down