task: Spawn static tasks in separate shell (#8827)

That way one can use environment variables in task definitions.

Fixes: #8660

/cc @SomeoneToIgnore it looks like we don't ever set `separate_shell` to
false anymore, it might be worth streamlining?

Release Notes:

- Fixed static tasks not being run under a separate shell.
- Removed `separate_shell` setting from task definitions. It is now a default for tasks defined in tasks.json file.
This commit is contained in:
Piotr Osiewicz 2024-03-04 15:57:30 +01:00 committed by GitHub
parent 6121c286b7
commit 98a1e87fbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 19 deletions

View file

@ -34,8 +34,6 @@ pub struct SpawnInTerminal {
pub use_new_terminal: bool, pub use_new_terminal: bool,
/// Whether to allow multiple instances of the same task to be run, or rather wait for the existing ones to finish. /// Whether to allow multiple instances of the same task to be run, or rather wait for the existing ones to finish.
pub allow_concurrent_runs: bool, pub allow_concurrent_runs: bool,
/// Whether the command should be spawned in a separate shell instance.
pub separate_shell: bool,
} }
/// Represents a short lived recipe of a task, whose main purpose /// Represents a short lived recipe of a task, whose main purpose

View file

@ -47,7 +47,6 @@ impl Task for OneshotTask {
env: Default::default(), env: Default::default(),
use_new_terminal: Default::default(), use_new_terminal: Default::default(),
allow_concurrent_runs: Default::default(), allow_concurrent_runs: Default::default(),
separate_shell: true,
}) })
} }
} }

View file

@ -34,7 +34,6 @@ impl Task for StaticTask {
command: self.definition.command.clone(), command: self.definition.command.clone(),
args: self.definition.args.clone(), args: self.definition.args.clone(),
env: self.definition.env.clone(), env: self.definition.env.clone(),
separate_shell: false,
}) })
} }

View file

@ -303,9 +303,8 @@ impl TerminalPanel {
args: spawn_in_terminal.args.clone(), args: spawn_in_terminal.args.clone(),
env: spawn_in_terminal.env.clone(), env: spawn_in_terminal.env.clone(),
}; };
if spawn_in_terminal.separate_shell { // Set up shell args unconditionally, as tasks are always spawned inside of a shell.
let Some((shell, mut user_args)) = (match TerminalSettings::get_global(cx).shell.clone() let Some((shell, mut user_args)) = (match TerminalSettings::get_global(cx).shell.clone() {
{
Shell::System => std::env::var("SHELL").ok().map(|shell| (shell, vec![])), Shell::System => std::env::var("SHELL").ok().map(|shell| (shell, vec![])),
Shell::Program(shell) => Some((shell, vec![])), Shell::Program(shell) => Some((shell, vec![])),
Shell::WithArguments { program, args } => Some((program, args)), Shell::WithArguments { program, args } => Some((program, args)),
@ -313,13 +312,16 @@ impl TerminalPanel {
return; return;
}; };
let command = std::mem::take(&mut spawn_task.command); let mut command = std::mem::take(&mut spawn_task.command);
let args = std::mem::take(&mut spawn_task.args); let args = std::mem::take(&mut spawn_task.args);
for arg in args {
command.push(' ');
command.push_str(&arg);
}
spawn_task.command = shell; spawn_task.command = shell;
user_args.extend(["-i".to_owned(), "-c".to_owned(), command]); user_args.extend(["-i".to_owned(), "-c".to_owned(), command]);
user_args.extend(args);
spawn_task.args = user_args; spawn_task.args = user_args;
}
let working_directory = spawn_in_terminal.cwd.clone(); let working_directory = spawn_in_terminal.cwd.clone();
let allow_concurrent_runs = spawn_in_terminal.allow_concurrent_runs; let allow_concurrent_runs = spawn_in_terminal.allow_concurrent_runs;
let use_new_terminal = spawn_in_terminal.use_new_terminal; let use_new_terminal = spawn_in_terminal.use_new_terminal;