2020-02-09 00:26:21 +00:00
/*
* meli - build . rs
*
* Copyright 2020 Manos Pitsidianakis
*
* This file is part of meli .
*
* meli is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* meli is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with meli . If not , see < http ://www.gnu.org/licenses/>.
* /
2020-06-20 20:28:50 +00:00
extern crate proc_macro ;
extern crate quote ;
extern crate syn ;
mod config_macros ;
2020-02-09 00:26:21 +00:00
fn main ( ) {
2020-02-09 18:46:39 +00:00
println! ( " cargo:rerun-if-changed=build.rs " ) ;
2020-06-20 20:28:50 +00:00
config_macros ::override_derive ( & [
( " src/conf/pager.rs " , " PagerSettings " ) ,
( " src/conf/listing.rs " , " ListingSettings " ) ,
( " src/conf/notifications.rs " , " NotificationsSettings " ) ,
( " src/conf/shortcuts.rs " , " Shortcuts " ) ,
( " src/conf/composing.rs " , " ComposingSettings " ) ,
( " src/conf/tags.rs " , " TagsSettings " ) ,
( " src/conf/pgp.rs " , " PGPSettings " ) ,
] ) ;
2020-02-09 00:26:21 +00:00
#[ cfg(feature = " cli-docs " ) ]
{
2020-10-17 17:50:29 +00:00
use flate2 ::Compression ;
use flate2 ::GzBuilder ;
2020-02-09 00:26:21 +00:00
const MANDOC_OPTS : & [ & 'static str ] = & [ " -T " , " utf8 " , " -I " , " os=Generated by mandoc(1) " ] ;
use std ::env ;
use std ::fs ::File ;
use std ::io ::prelude ::* ;
use std ::path ::Path ;
use std ::process ::Command ;
let out_dir = env ::var ( " OUT_DIR " ) . unwrap ( ) ;
let mut out_dir_path = Path ::new ( & out_dir ) . to_path_buf ( ) ;
2020-10-17 17:50:29 +00:00
out_dir_path . push ( " meli.txt.gz " ) ;
2020-02-09 00:26:21 +00:00
let output = Command ::new ( " mandoc " )
. args ( MANDOC_OPTS )
2020-09-20 11:11:22 +00:00
. arg ( " docs/meli.1 " )
2020-02-09 00:26:21 +00:00
. output ( )
2020-09-20 11:11:22 +00:00
. or_else ( | _ | Command ::new ( " man " ) . arg ( " -l " ) . arg ( " docs/meli.1 " ) . output ( ) )
2020-02-09 00:26:21 +00:00
. unwrap ( ) ;
2020-10-17 17:50:29 +00:00
let file = File ::create ( & out_dir_path ) . unwrap ( ) ;
let mut gz = GzBuilder ::new ( )
. comment ( output . stdout . len ( ) . to_string ( ) . into_bytes ( ) )
. write ( file , Compression ::default ( ) ) ;
gz . write_all ( & output . stdout ) . unwrap ( ) ;
gz . finish ( ) . unwrap ( ) ;
2020-02-09 00:26:21 +00:00
out_dir_path . pop ( ) ;
2020-10-17 17:50:29 +00:00
out_dir_path . push ( " meli.conf.txt.gz " ) ;
2020-02-09 00:26:21 +00:00
let output = Command ::new ( " mandoc " )
. args ( MANDOC_OPTS )
2020-09-20 11:11:22 +00:00
. arg ( " docs/meli.conf.5 " )
2020-02-09 00:26:21 +00:00
. output ( )
2020-09-20 11:11:22 +00:00
. or_else ( | _ | {
Command ::new ( " man " )
. arg ( " -l " )
. arg ( " docs/meli.conf.5 " )
. output ( )
} )
2020-02-09 00:26:21 +00:00
. unwrap ( ) ;
2020-10-17 17:50:29 +00:00
let file = File ::create ( & out_dir_path ) . unwrap ( ) ;
let mut gz = GzBuilder ::new ( )
. comment ( output . stdout . len ( ) . to_string ( ) . into_bytes ( ) )
. write ( file , Compression ::default ( ) ) ;
gz . write_all ( & output . stdout ) . unwrap ( ) ;
gz . finish ( ) . unwrap ( ) ;
2020-02-09 00:26:21 +00:00
out_dir_path . pop ( ) ;
2020-10-17 17:50:29 +00:00
out_dir_path . push ( " meli-themes.txt.gz " ) ;
2020-02-09 00:26:21 +00:00
let output = Command ::new ( " mandoc " )
. args ( MANDOC_OPTS )
2020-09-20 11:11:22 +00:00
. arg ( " docs/meli-themes.5 " )
2020-02-09 00:26:21 +00:00
. output ( )
2020-09-20 11:11:22 +00:00
. or_else ( | _ | {
Command ::new ( " man " )
. arg ( " -l " )
. arg ( " docs/meli-themes.5 " )
. output ( )
} )
2020-02-09 00:26:21 +00:00
. unwrap ( ) ;
2020-10-17 17:50:29 +00:00
let file = File ::create ( & out_dir_path ) . unwrap ( ) ;
let mut gz = GzBuilder ::new ( )
. comment ( output . stdout . len ( ) . to_string ( ) . into_bytes ( ) )
. write ( file , Compression ::default ( ) ) ;
gz . write_all ( & output . stdout ) . unwrap ( ) ;
gz . finish ( ) . unwrap ( ) ;
2020-02-09 00:26:21 +00:00
}
}