Skip to content
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
1 change: 1 addition & 0 deletions docs/usage/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ All keys are optional.
| `sign_with` | enum | `auto` | Where `debsign` runs (see below). |
| `sign_key` | string | — | GPG key ID/email for `debsign -k`. Required for container signing. |
| `clean` | bool | `false` | Run `debian/rules clean` before building. Disabled by default; incompatible with `incremental`. |
| `shell_on_failure` | bool | `false` | On build or test failure, drop into an interactive shell in the environment when stdout is a TTY. |

### `source_sync_mode`

Expand Down
30 changes: 26 additions & 4 deletions packages/debmagic/src/build_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct BuildIntentInput {
pub clean: Option<bool>,
pub no_clean: Option<bool>,
pub source_sync: Option<SourceSyncMode>,
pub shell_on_failure: bool,
pub shell_on_failure: Option<bool>,
pub driver_overrides: DriverOverrides,
}

Expand Down Expand Up @@ -124,11 +124,13 @@ pub fn resolve_build_intent(input: BuildIntentInput) -> anyhow::Result<BuildInte
config.driver.persistent = true;
}

let shell_on_failure = input.shell_on_failure.unwrap_or(config.shell_on_failure);

Ok(BuildIntent {
source_dir,
output_dir,
driver: input.driver,
shell_on_failure: input.shell_on_failure,
shell_on_failure,
config,
driver_overrides: input.driver_overrides,
})
Expand Down Expand Up @@ -167,7 +169,7 @@ mod tests {
clean: None,
no_clean: None,
source_sync: None,
shell_on_failure: false,
shell_on_failure: None,
driver_overrides: DriverOverrides {
apt_mirror: None,
proposed: None,
Expand Down Expand Up @@ -223,10 +225,30 @@ mod tests {
fn resolve_passes_through_shell_on_failure() -> anyhow::Result<()> {
let dir = std::env::temp_dir();
let mut input = base_input(dir);
input.shell_on_failure = true;
input.shell_on_failure = Some(true);

let intent = resolve_build_intent(input)?;
assert!(intent.shell_on_failure);
Ok(())
}

#[test]
fn resolve_shell_on_failure_from_config() -> anyhow::Result<()> {
let dir = std::env::temp_dir();
let mut input = base_input(dir);
input.config_file = None;
input.shell_on_failure = None;

let config_path = std::env::temp_dir().join(format!(
"debmagic-shell-on-failure-{}.toml",
std::process::id()
));
std::fs::write(&config_path, "shell_on_failure = true\n")?;
input.config_file = Some(config_path.clone());

let intent = resolve_build_intent(input)?;
assert!(intent.shell_on_failure);
std::fs::remove_file(config_path)?;
Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions packages/debmagic/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ pub struct CommonBuildArgs {
#[arg(
long = "shell-on-failure",
action = clap::ArgAction::SetTrue,
help = "On build failure, drop into an interactive shell in the build environment when stdout is a TTY"
help = "On build failure, drop into an interactive shell in the build environment when stdout is a TTY. Defaults to the 'shell_on_failure' setting in the config file (false if unset)."
)]
pub shell_on_failure: bool,
pub shell_on_failure: Option<bool>,

#[command(flatten)]
pub common: CommonCli,
Expand Down Expand Up @@ -266,9 +266,9 @@ pub struct TestSubcommandArgs {
#[arg(
long = "shell-on-failure",
action = clap::ArgAction::SetTrue,
help = "On test failure, drop into an interactive shell in the test environment when stdout is a TTY"
help = "On test failure, drop into an interactive shell in the test environment when stdout is a TTY. Defaults to the 'shell_on_failure' setting in the config file (false if unset)."
)]
pub shell_on_failure: bool,
pub shell_on_failure: Option<bool>,

#[command(flatten)]
pub common: CommonCli,
Expand Down
4 changes: 4 additions & 0 deletions packages/debmagic/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub struct Config {
/// builds already stage a clean source tree and incremental builds preserve
/// outputs intentionally.
pub clean: bool,
/// On build or test failure, drop into an interactive shell in the
/// environment when stdout is a TTY.
pub shell_on_failure: bool,
}

impl Default for Config {
Expand All @@ -46,6 +49,7 @@ impl Default for Config {
sign_with: SignWith::default(),
sign_key: None,
clean: false,
shell_on_failure: false,
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/debmagic/src/test/intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct TestIntentInput {
pub strict: bool,
pub changes: Option<PathBuf>,
pub allow_host_test: bool,
pub shell_on_failure: bool,
pub shell_on_failure: Option<bool>,
pub distro: Option<String>,
pub driver_overrides: DriverOverrides,
}
Expand Down Expand Up @@ -57,13 +57,15 @@ pub fn resolve_test_intent(input: TestIntentInput) -> anyhow::Result<TestIntent>
None
};

let shell_on_failure = input.shell_on_failure.unwrap_or(config.shell_on_failure);

Ok(TestIntent {
source_dir,
driver: input.driver,
strict: input.strict,
changes,
allow_host_test: input.allow_host_test,
shell_on_failure: input.shell_on_failure,
shell_on_failure,
distro: input.distro,
config,
driver_overrides: input.driver_overrides,
Expand Down Expand Up @@ -95,7 +97,7 @@ mod tests {
strict: false,
changes: None,
allow_host_test: false,
shell_on_failure: false,
shell_on_failure: None,
distro: None,
driver_overrides: DriverOverrides {
apt_mirror: None,
Expand Down Expand Up @@ -136,7 +138,7 @@ mod tests {
fn resolve_passes_through_shell_on_failure() -> anyhow::Result<()> {
let dir = std::env::temp_dir();
let mut input = base_input(dir);
input.shell_on_failure = true;
input.shell_on_failure = Some(true);

let intent = resolve_test_intent(input)?;
assert!(intent.shell_on_failure);
Expand Down
Loading