Skip to content

Commit

Permalink
fix builds on android
Browse files Browse the repository at this point in the history
Since Canop#803 introduced a dependency on the trash crate, broot does not
compile any more on Android. This change makes the trash crate only
pulled in on platforms which support it, and otherwise the trash command
displays an error.
  • Loading branch information
dead10ck committed May 7, 2024
1 parent 100de92 commit 690ef58
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ termimad = "0.29.2"
terminal-clipboard = { version = "0.4.1", optional = true }
terminal-light = "1.4.0"
toml = "0.8"
trash = "3.1.2"
umask = "2.1.0"
unicode-width = "0.1.10"
which = "4.4.0"
Expand All @@ -78,6 +77,11 @@ uzers = "0.11.3"
[target.'cfg(windows)'.dependencies]
is_executable = "1.0.1"

# Unfortunately, we can't use the `trash_supported` attribute for dependency
# resolution
[target.'cfg(any(target_os = "macos", target_os = "windows", all(unix, not(target_os = "android"))))'.dependencies]
trash = "3.1.2"

[build-dependencies]
clap = { version = "4.4", features = ["derive", "cargo"] }
clap_complete = "4.4"
Expand Down
32 changes: 21 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
use {
clap::CommandFactory,
clap_complete::{Generator, Shell},
std::{
env,
ffi::OsStr,
},
std::{env, ffi::OsStr},
};

include!("src/cli/args.rs");
Expand All @@ -19,15 +16,14 @@ include!("src/cli/args.rs");
/// so this generation is usually not needed
pub const BUILD_MAN_PAGE: bool = false;

fn write_completions_file<G: Generator + Copy, P: AsRef<OsStr>>(generator: G, out_dir: P) {
fn write_completions_file<G: Generator + Copy, P: AsRef<OsStr>>(
generator: G,
out_dir: P,
) {
let mut args = Args::command();
for name in &["broot", "br"] {
clap_complete::generate_to(
generator,
&mut args,
name.to_string(),
&out_dir,
).expect("clap complete generation failed");
clap_complete::generate_to(generator, &mut args, name.to_string(), &out_dir)
.expect("clap complete generation failed");
}
}

Expand Down Expand Up @@ -57,10 +53,24 @@ fn build_man_page() -> std::io::Result<()> {
Ok(())
}

fn platform_flags() {
if cfg!(any(
target_os = "macos",
target_os = "windows",
all(unix, not(target_os = "android"))
)) {
println!("cargo:rustc-cfg=trash_supported");
}
}

fn main() -> std::io::Result<()> {
build_completion_scripts();

if BUILD_MAN_PAGE {
build_man_page()?;
}

platform_flags();

Ok(())
}
5 changes: 5 additions & 0 deletions src/browser/browser_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,18 @@ impl PanelState for BrowserState {
Internal::trash => {
let path = self.displayed_tree().selected_line().path.to_path_buf();
info!("trash {:?}", &path);

#[cfg(trash_supported)]
match trash::delete(&path) {
Ok(()) => CmdResult::RefreshState { clear_cache: true },
Err(e) => {
warn!("trash error: {:?}", &e);
CmdResult::DisplayError(format!("trash error: {:?}", &e))
}
}

#[cfg(not(trash_supported))]
CmdResult::DisplayError("platform does not support trash".into())
}
Internal::quit => CmdResult::Quit,
_ => self.on_internal_generic(
Expand Down
5 changes: 5 additions & 0 deletions src/stage/stage_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,18 @@ impl PanelState for StageState {
}
Internal::trash => {
info!("trash {} staged files", app_state.stage.len());

#[cfg(trash_supported)]
match trash::delete_all(app_state.stage.paths()) {
Ok(()) => CmdResult::RefreshState { clear_cache: true },
Err(e) => {
warn!("trash error: {:?}", &e);
CmdResult::DisplayError(format!("trash error: {:?}", &e))
}
}

#[cfg(not(trash_supported))]
CmdResult::DisplayError("platform does not support trash".into())
}
_ => self.on_internal_generic(
w,
Expand Down

0 comments on commit 690ef58

Please sign in to comment.