From a104d539198efcf65d644d57bc684f6d6ac96106 Mon Sep 17 00:00:00 2001 From: Mario Krehl Date: Sat, 14 Apr 2018 01:47:55 +0200 Subject: [PATCH] build script for shell completion works again --- bin/Cargo.toml | 40 ------------------- bin/build.rs | 90 ------------------------------------------ bin/core/imag/build.rs | 34 +++++++++------- 3 files changed, 20 insertions(+), 144 deletions(-) delete mode 100644 bin/Cargo.toml delete mode 100644 bin/build.rs diff --git a/bin/Cargo.toml b/bin/Cargo.toml deleted file mode 100644 index 76cc0636..00000000 --- a/bin/Cargo.toml +++ /dev/null @@ -1,40 +0,0 @@ -[package] -name = "imag" -version = "0.2.0" -authors = ["Matthias Beyer "] - -description = "Part of the imag core distribution: imag command" - -keywords = ["imag", "PIM", "personal", "information", "management"] -readme = "../README.md" -license = "LGPL-2.1" - -documentation = "https://matthiasbeyer.github.io/imag/imag_documentation/index.html" -repository = "https://github.com/matthiasbeyer/imag" -homepage = "http://imag-pim.org" - -build = "build.rs" - -[build-dependencies] -clap = ">=2.16.1" -version = "2.0" -libimagrt = { path = "../libimagrt" } -libimagentrytag = { path = "../libimagentrytag" } -libimagutil = { path = "../libimagutil" } - -[profile.dev] -codegen-units = 2 - -[dependencies] -version = "2.0" -walkdir = "0.1" -crossbeam = "0.2" -clap = "2.*" -log = "0.3" - -[dependencies.libimagrt] -path = "../libimagrt" - -[dependencies.libimagerror] -path = "../libimagerror" - diff --git a/bin/build.rs b/bin/build.rs deleted file mode 100644 index a7d44a20..00000000 --- a/bin/build.rs +++ /dev/null @@ -1,90 +0,0 @@ -extern crate clap; -extern crate libimagrt; -extern crate libimagentrytag; -extern crate libimagutil; -#[macro_use] extern crate version; - -use clap::Shell; -use libimagrt::runtime::Runtime; - -/// This macro generates mods with the given '$modulename', -/// whose content is the file given with `$path`. -/// In this case, It is used specifically to include the -/// `ui.rs` files of the imag binaries. -/// The imag project (accidentally?) followed the convention -/// to write a `ui.rs` containing the function -/// `fn build_ui(app : App) -> App`. -/// This macro allows us to use the same named functions by -/// putting them each into their own module. -macro_rules! gen_mods_buildui { - ($(($path:expr, $modulename:ident)$(,)*)*) => ( - $( - mod $modulename { - include!($path); - } - )* - ) -} - -/// This macro reduces boilerplate code. -/// -/// For example: `build_subcommand!("counter", imagcounter)` -/// will result in the following code: -/// ```ignore -/// imagcounter::build_ui(Runtime::get_default_cli_builder( -/// "counter", -/// &version!()[..], -/// "counter")) -/// ``` -/// As for the `&version!()[..]` part, it does not matter -/// which version the subcommand is getting here, as the -/// output of this script is a completion script, which -/// does not contain information about the version at all. -macro_rules! build_subcommand { - ($name:expr, $module:ident) => ( - $module::build_ui(Runtime::get_default_cli_builder( - $name, - &version!()[..], - $name)) - ) -} - -// Actually generates the module. -gen_mods_buildui!( - ("../imag-bookmark/src/ui.rs", imagbookmark), - ("../imag-counter/src/ui.rs", imagcounter), - ("../imag-diary/src/ui.rs", imagdiary), - ("../imag-link/src/ui.rs", imaglink), - ("../imag-notes/src/ui.rs", imagnotes), - ("../imag-ref/src/ui.rs", imagref), - ("../imag-store/src/ui.rs", imagstore), - ("../imag-tag/src/ui.rs", imagtag), - ("../imag-todo/src/ui.rs", imagtodo), - ("../imag-view/src/ui.rs", imagview) -); - -fn main() { - // Make the `imag`-App... - let mut app = Runtime::get_default_cli_builder( - "imag", - &version!()[..], - "imag") - // and add all the subapps as subcommands. - .subcommand(build_subcommand!("bookmark", imagbookmark)) - .subcommand(build_subcommand!("counter", imagcounter)) - .subcommand(build_subcommand!("diary", imagdiary)) - .subcommand(build_subcommand!("link", imaglink)) - .subcommand(build_subcommand!("notes", imagnotes)) - .subcommand(build_subcommand!("ref", imagref)) - .subcommand(build_subcommand!("store", imagstore)) - .subcommand(build_subcommand!("tag", imagtag)) - .subcommand(build_subcommand!("todo", imagtodo)) - .subcommand(build_subcommand!("view", imagview)); - - // Actually generates the completion files - app.gen_completions("imag", Shell::Bash, env!("OUT_DIR")); - app.gen_completions("imag", Shell::Fish, env!("OUT_DIR")); - app.gen_completions("imag", Shell::Zsh, env!("OUT_DIR")); - -} - diff --git a/bin/core/imag/build.rs b/bin/core/imag/build.rs index 4c9c8a21..57aca212 100644 --- a/bin/core/imag/build.rs +++ b/bin/core/imag/build.rs @@ -7,6 +7,13 @@ extern crate libimagutil; use clap::Shell; use libimagrt::runtime::Runtime; +mod toplevelbuildscript { + include!("../../../build.rs"); + pub fn build() { + self::main(); + } +} + /// This macro generates mods with the given '$modulename', /// whose content is the file given with `$path`. /// In this case, It is used specifically to include the @@ -48,16 +55,15 @@ macro_rules! build_subcommand { // Actually generates the module. gen_mods_buildui!( - ("../imag-bookmark/src/ui.rs", imagbookmark), - ("../imag-counter/src/ui.rs", imagcounter), - ("../imag-diary/src/ui.rs", imagdiary), - ("../imag-link/src/ui.rs", imaglink), - ("../imag-notes/src/ui.rs", imagnotes), - ("../imag-ref/src/ui.rs", imagref), - ("../imag-store/src/ui.rs", imagstore), - ("../imag-tag/src/ui.rs", imagtag), - ("../imag-todo/src/ui.rs", imagtodo), - ("../imag-view/src/ui.rs", imagview) + ("../../../bin/domain/imag-bookmark/src/ui.rs", imagbookmark), + ("../../../bin/domain/imag-diary/src/ui.rs", imagdiary), + ("../../../bin/core/imag-link/src/ui.rs", imaglink), + ("../../../bin/domain/imag-notes/src/ui.rs", imagnotes), + ("../../../bin/core/imag-ref/src/ui.rs", imagref), + ("../../../bin/core/imag-store/src/ui.rs", imagstore), + ("../../../bin/core/imag-tag/src/ui.rs", imagtag), + ("../../../bin/domain/imag-todo/src/ui.rs", imagtodo), + ("../../../bin/core/imag-view/src/ui.rs", imagview) ); fn main() { @@ -68,7 +74,6 @@ fn main() { "imag") // and add all the subapps as subcommands. .subcommand(build_subcommand!("bookmark", imagbookmark)) - .subcommand(build_subcommand!("counter", imagcounter)) .subcommand(build_subcommand!("diary", imagdiary)) .subcommand(build_subcommand!("link", imaglink)) .subcommand(build_subcommand!("notes", imagnotes)) @@ -79,9 +84,10 @@ fn main() { .subcommand(build_subcommand!("view", imagview)); // Actually generates the completion files - app.gen_completions("imag", Shell::Bash, env!("OUT_DIR")); - app.gen_completions("imag", Shell::Fish, env!("OUT_DIR")); - app.gen_completions("imag", Shell::Zsh, env!("OUT_DIR")); + app.gen_completions("imag", Shell::Bash, "./"); + app.gen_completions("imag", Shell::Fish, "./"); + app.gen_completions("imag", Shell::Zsh, "./"); + toplevelbuildscript::build(); }