| 1 |
//! General build script used by bottom to generate completion files and set |
| 2 |
//! binary version. |
| 3 |
|
| 4 |
#![expect(clippy::unwrap_used)] |
| 5 |
|
| 6 |
#[expect(dead_code)] |
| 7 |
#[path = "src/options/args.rs"] |
| 8 |
mod argsrust-analyzer cargo bottom 0.14.9 args/; |
| 9 |
|
| 10 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 11 |
envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/, fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, |
| 12 |
pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#}, |
| 13 |
}; |
| 14 |
|
| 15 |
use claprust-analyzer cargo clap 4.6.6 crate/::{Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, CommandFactoryrust-analyzer cargo clap_builder 4.6.6 derive/CommandFactory#}; |
| 16 |
use clap_completerust-analyzer cargo clap_complete 4.6.9 crate/::{Generatorrust-analyzer cargo clap_complete 4.6.9 aot/generator/Generator#, generate_torust-analyzer cargo clap_complete 4.6.9 aot/generator/generate_to()., shellsrust-analyzer cargo clap_complete 4.6.9 shells/::Shellrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#}; |
| 17 |
use clap_complete_nushellrust-analyzer cargo clap_complete_nushell 4.6.1 crate/::Nushellrust-analyzer cargo clap_complete_nushell 4.6.1 Nushell#; |
| 18 |
|
| 19 |
use craterust-analyzer cargo bottom 0.14.9 crate/::argsrust-analyzer cargo bottom 0.14.9 args/::BottomArgsrust-analyzer cargo bottom 0.14.9 args/BottomArgs#; |
| 20 |
|
| 21 |
fn create_dirrust-analyzer cargo bottom 0.14.9 create_dir().(dir: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 22 |
fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::create_dir_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir_all().(dir).inspect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]inspect_err().(|err| { |
| 23 |
eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!( |
| 24 |
"Couldn't create a directory at {} ({:?}). Aborting.", |
| 25 |
dir.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), |
| 26 |
err |
| 27 |
) |
| 28 |
}) |
| 29 |
} |
| 30 |
|
| 31 |
fn generate_completionsrust-analyzer cargo bottom 0.14.9 generate_completions().<G>(to_generate: G, cmd: &mut Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, out_dir: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#> |
| 32 |
where |
| 33 |
G: Generatorrust-analyzer cargo clap_complete 4.6.9 aot/generator/Generator#, |
| 34 |
{ |
| 35 |
generate_torust-analyzer cargo clap_complete 4.6.9 aot/generator/generate_to().(to_generate, cmd, "btm", out_dir) |
| 36 |
} |
| 37 |
|
| 38 |
fn btm_generaterust-analyzer cargo bottom 0.14.9 btm_generate().() -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 39 |
const ENV_KEYrust-analyzer cargo bottom 0.14.9 ENV_KEY.: &str = "BTM_GENERATE"; |
| 40 |
|
| 41 |
match envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().(ENV_KEYrust-analyzer cargo bottom 0.14.9 ENV_KEY.) { |
| 42 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(var) if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().var.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]is_empty().() => { |
| 43 |
let completion_dir = |
| 44 |
option_envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/option_env!!("COMPLETION_DIR").unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("./target/tmp/bottom/completion/"); |
| 45 |
let manpage_dir = option_envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/option_env!!("MANPAGE_DIR").unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("./target/tmp/bottom/manpage/"); |
| 46 |
|
| 47 |
let completion_out_dir = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(completion_dir); |
| 48 |
let manpage_out_dir = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(manpage_dir); |
| 49 |
|
| 50 |
create_dirrust-analyzer cargo bottom 0.14.9 create_dir().(&completion_out_dir)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 51 |
create_dirrust-analyzer cargo bottom 0.14.9 create_dir().(&manpage_out_dir)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 52 |
|
| 53 |
// Generate completions |
| 54 |
let mut app = BottomArgsrust-analyzer cargo bottom 0.14.9 args/BottomArgs#::commandrust-analyzer cargo bottom 0.14.9 args/impl#[BottomArgs][CommandFactory]command().(); |
| 55 |
generate_completionsrust-analyzer cargo bottom 0.14.9 generate_completions().(Shellrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#::Bashrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#Bash#, &mut app, &completion_out_dir)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 56 |
generate_completionsrust-analyzer cargo bottom 0.14.9 generate_completions().(Shellrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#::Zshrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#Zsh#, &mut app, &completion_out_dir)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 57 |
generate_completionsrust-analyzer cargo bottom 0.14.9 generate_completions().(Shellrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#::Fishrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#Fish#, &mut app, &completion_out_dir)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 58 |
generate_completionsrust-analyzer cargo bottom 0.14.9 generate_completions().(Shellrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#::PowerShellrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#PowerShell#, &mut app, &completion_out_dir)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 59 |
generate_completionsrust-analyzer cargo bottom 0.14.9 generate_completions().(Shellrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#::Elvishrust-analyzer cargo clap_complete 4.6.9 aot/shells/shell/Shell#Elvish#, &mut app, &completion_out_dir)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 60 |
generate_completionsrust-analyzer cargo bottom 0.14.9 generate_completions().(Nushellrust-analyzer cargo clap_complete_nushell 4.6.1 Nushell#, &mut app, &completion_out_dir)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 61 |
|
| 62 |
// Generate manpage |
| 63 |
let app = app.namerust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]name().("btm"); |
| 64 |
let man = clap_mangenrust-analyzer cargo clap_mangen 0.3.2 crate/::Manrust-analyzer cargo clap_mangen 0.3.2 Man#::newrust-analyzer cargo clap_mangen 0.3.2 impl#[Man]new().(app); |
| 65 |
let mut buffer: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().(); |
| 66 |
man.renderrust-analyzer cargo clap_mangen 0.3.2 impl#[Man]render().(&mut buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 67 |
fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(manpage_out_dir.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("btm.1"), buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 68 |
} |
| 69 |
_ => {} |
| 70 |
} |
| 71 |
|
| 72 |
printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rerun-if-env-changed={ENV_KEY}"); |
| 73 |
|
| 74 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 75 |
} |
| 76 |
|
| 77 |
fn extract_sharust-analyzer cargo bottom 0.14.9 extract_sha().(sha: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> { |
| 78 |
sha.and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|sha: &str| sha.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]get().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#8)) |
| 79 |
} |
| 80 |
|
| 81 |
fn output_nightly_versionrust-analyzer cargo bottom 0.14.9 output_nightly_version().(version: &str, git_hash: &str) { |
| 82 |
printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rustc-env=NIGHTLY_VERSION={version}-nightly-{git_hash}"); |
| 83 |
} |
| 84 |
|
| 85 |
fn nightly_versionrust-analyzer cargo bottom 0.14.9 nightly_version().() { |
| 86 |
const ENV_KEYrust-analyzer cargo bottom 0.14.9 ENV_KEY.: &str = "BTM_BUILD_RELEASE_CALLER"; |
| 87 |
|
| 88 |
match envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().(ENV_KEYrust-analyzer cargo bottom 0.14.9 ENV_KEY.) { |
| 89 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(var) if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().var.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]is_empty().() && var rust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`PartialEq<&str>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`PartialEq<&str>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`PartialEq<&str>`]eq()."ci" => { |
| 90 |
let version = envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/env!!("CARGO_PKG_VERSION"); |
| 91 |
|
| 92 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(hash) = extract_sharust-analyzer cargo bottom 0.14.9 extract_sha().(option_envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/option_env!!("GITHUB_SHA")) { |
| 93 |
// May be set if we're building with GHA. |
| 94 |
output_nightly_versionrust-analyzer cargo bottom 0.14.9 output_nightly_version().(version, hash); |
| 95 |
} else if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(output) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("git") |
| 96 |
.argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]args().(["rev-parse", "--short=8", "HEAD"]) |
| 97 |
.outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().() |
| 98 |
{ |
| 99 |
// If we're not building in either, we do the lazy thing and fall back to |
| 100 |
// manually grabbing info using git as a command. |
| 101 |
let hash = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8().(output.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 102 |
output_nightly_versionrust-analyzer cargo bottom 0.14.9 output_nightly_version().(version, &hash); |
| 103 |
} |
| 104 |
} |
| 105 |
_ => {} |
| 106 |
} |
| 107 |
|
| 108 |
printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rerun-if-env-changed={ENV_KEY}"); |
| 109 |
} |
| 110 |
|
| 111 |
fn mainrust-analyzer cargo bottom 0.14.9 main().() -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 112 |
btm_generaterust-analyzer cargo bottom 0.14.9 btm_generate().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 113 |
nightly_versionrust-analyzer cargo bottom 0.14.9 nightly_version().(); |
| 114 |
|
| 115 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 116 |
} |