build.rs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // This file is part of Substrate.
  2. // Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
  3. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. fn main() {
  15. #[cfg(feature = "cli")]
  16. cli::main();
  17. }
  18. #[cfg(feature = "cli")]
  19. mod cli {
  20. include!("src/cli.rs");
  21. use sc_cli::structopt::clap::Shell;
  22. use std::{env, fs, path::Path};
  23. use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};
  24. pub fn main() {
  25. build_shell_completion();
  26. generate_cargo_keys();
  27. rerun_if_git_head_changed();
  28. }
  29. /// Build shell completion scripts for all known shells
  30. /// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123
  31. fn build_shell_completion() {
  32. for shell in &[
  33. Shell::Bash,
  34. Shell::Fish,
  35. Shell::Zsh,
  36. Shell::Elvish,
  37. Shell::PowerShell,
  38. ] {
  39. build_completion(shell);
  40. }
  41. }
  42. /// Build the shell auto-completion for a given Shell
  43. fn build_completion(shell: &Shell) {
  44. let outdir = match env::var_os("OUT_DIR") {
  45. None => return,
  46. Some(dir) => dir,
  47. };
  48. let path = Path::new(&outdir)
  49. .parent()
  50. .unwrap()
  51. .parent()
  52. .unwrap()
  53. .parent()
  54. .unwrap()
  55. .join("completion-scripts");
  56. fs::create_dir(&path).ok();
  57. Cli::clap().gen_completions("joystream-node", *shell, &path);
  58. }
  59. }