@@ -15,18 +15,28 @@ use xshell::{cmd, Shell};
1515/// - test
1616/// - clippy
1717pub fn make ( sh : & Shell , flags : flags:: Make ) -> anyhow:: Result < ( ) > {
18- format:: format ( sh, flags:: Format { } ) ?;
19- build:: build (
20- sh,
21- flags:: Build {
22- release : flags. release ,
23- no_plugins : false ,
24- plugins_only : false ,
25- } ,
26- ) ?;
27- test:: test ( sh, flags:: Test { args : vec ! [ ] } ) ?;
28- clippy:: clippy ( sh, flags:: Clippy { } ) ?;
29- Ok ( ( ) )
18+ let err_context = || format ! ( "failed to run pipeline 'make' with args {flags:?}" ) ;
19+
20+ if flags. clean {
21+ crate :: cargo ( )
22+ . and_then ( |cargo| cmd ! ( sh, "{cargo} clean" ) . run ( ) . map_err ( anyhow:: Error :: new) )
23+ . with_context ( err_context) ?;
24+ }
25+
26+ format:: format ( sh, flags:: Format { check : false } )
27+ . and_then ( |_| {
28+ build:: build (
29+ sh,
30+ flags:: Build {
31+ release : flags. release ,
32+ no_plugins : false ,
33+ plugins_only : false ,
34+ } ,
35+ )
36+ } )
37+ . and_then ( |_| test:: test ( sh, flags:: Test { args : vec ! [ ] } ) )
38+ . and_then ( |_| clippy:: clippy ( sh, flags:: Clippy { } ) )
39+ . with_context ( err_context)
3040}
3141
3242/// Generate a runnable executable.
@@ -39,6 +49,8 @@ pub fn make(sh: &Shell, flags: flags::Make) -> anyhow::Result<()> {
3949/// - [`manpage`](build::manpage)
4050/// - Copy the executable to [target file](flags::Install::destination)
4151pub fn install ( sh : & Shell , flags : flags:: Install ) -> anyhow:: Result < ( ) > {
52+ let err_context = || format ! ( "failed to run pipeline 'install' with args {flags:?}" ) ;
53+
4254 // Build and optimize plugins
4355 build:: build (
4456 sh,
@@ -47,84 +59,85 @@ pub fn install(sh: &Shell, flags: flags::Install) -> anyhow::Result<()> {
4759 no_plugins : false ,
4860 plugins_only : true ,
4961 } ,
50- ) ?;
51-
52- // Build the main executable
53- build:: build (
54- sh,
55- flags:: Build {
56- release : true ,
57- no_plugins : true ,
58- plugins_only : false ,
59- } ,
60- ) ?;
61-
62- // Generate man page
63- build:: manpage ( sh) ?;
62+ )
63+ . and_then ( |_| {
64+ // Build the main executable
65+ build:: build (
66+ sh,
67+ flags:: Build {
68+ release : true ,
69+ no_plugins : true ,
70+ plugins_only : false ,
71+ } ,
72+ )
73+ } )
74+ . and_then ( |_| {
75+ // Generate man page
76+ build:: manpage ( sh)
77+ } )
78+ . with_context ( err_context) ?;
6479
6580 // Copy binary to destination
6681 let destination = if flags. destination . is_absolute ( ) {
67- flags. destination
82+ flags. destination . clone ( )
6883 } else {
6984 std:: env:: current_dir ( )
7085 . context ( "Can't determine current working directory" ) ?
71- . join ( flags. destination )
86+ . join ( & flags. destination )
7287 } ;
7388 sh. change_dir ( crate :: project_root ( ) ) ;
7489 sh. copy_file ( "target/release/zellij" , & destination)
75- . with_context ( || format ! ( "Failed to copy executable to '{}" , destination. display( ) ) ) ?;
76- Ok ( ( ) )
90+ . with_context ( err_context)
7791}
7892
7993/// Run zellij debug build.
8094pub fn run ( sh : & Shell , flags : flags:: Run ) -> anyhow:: Result < ( ) > {
95+ let err_context = || format ! ( "failed to run pipeline 'run' with args {flags:?}" ) ;
96+
8197 build:: build (
8298 sh,
8399 flags:: Build {
84100 release : false ,
85101 no_plugins : false ,
86102 plugins_only : true ,
87103 } ,
88- ) ?;
89-
90- crate :: cargo ( )
91- . and_then ( |cargo| {
92- cmd ! ( sh, "{cargo} run" )
93- . args ( flags. args )
94- . run ( )
95- . context ( "command failure" )
96- } )
97- . context ( "failed to run debug build" )
104+ )
105+ . and_then ( |_| crate :: cargo ( ) )
106+ . and_then ( |cargo| {
107+ cmd ! ( sh, "{cargo} run" )
108+ . args ( & flags. args )
109+ . run ( )
110+ . map_err ( anyhow:: Error :: new)
111+ } )
112+ . with_context ( err_context)
98113}
99114
100115/// Bundle all distributable content to `target/dist`.
101116///
102117/// This includes the optimized zellij executable from the [`install`] pipeline, the man page, the
103118/// `.desktop` file and the application logo.
104119pub fn dist ( sh : & Shell , _flags : flags:: Dist ) -> anyhow:: Result < ( ) > {
120+ let err_context = || format ! ( "failed to run pipeline 'dist'" ) ;
121+
105122 sh. change_dir ( crate :: project_root ( ) ) ;
106123 if sh. path_exists ( "target/dist" ) {
107- sh. remove_path ( "target/dist" )
108- . context ( "Failed to clean up dist directory" ) ?;
124+ sh. remove_path ( "target/dist" ) . with_context ( err_context) ?;
109125 }
110126 sh. create_dir ( "target/dist" )
111- . context ( "Failed to create dist directory" ) ?;
112-
113- install (
114- sh,
115- flags:: Install {
116- destination : crate :: project_root ( ) . join ( "./target/dist/zellij" ) ,
117- } ,
118- )
119- . context ( "Failed to build zellij for distributing" ) ?;
127+ . map_err ( anyhow:: Error :: new)
128+ . and_then ( |_| {
129+ install (
130+ sh,
131+ flags:: Install {
132+ destination : crate :: project_root ( ) . join ( "./target/dist/zellij" ) ,
133+ } ,
134+ )
135+ } )
136+ . with_context ( err_context) ?;
120137
121138 sh. create_dir ( "target/dist/man" )
122- . context ( "Failed to create directory for man pages in dist folder" ) ?;
123- sh. copy_file ( "assets/man/zellij.1" , "target/dist/man/zellij.1" )
124- . context ( "Failed to copy generated manpage to dist folder" ) ?;
125- sh. copy_file ( "assets/zellij.desktop" , "target/dist/zellij.desktop" )
126- . context ( "Failed to copy zellij desktop file to dist folder" ) ?;
127- sh. copy_file ( "assets/logo.png" , "target/dist/logo.png" )
128- . context ( "Failed to copy zellij logo to dist folder" ) ?;
129- Ok ( ( ) )
139+ . and_then ( |_| sh. copy_file ( "assets/man/zellij.1" , "target/dist/man/zellij.1" ) )
140+ . and_then ( |_| sh. copy_file ( "assets/zellij.desktop" , "target/dist/zellij.desktop" ) )
141+ . and_then ( |_| sh. copy_file ( "assets/logo.png" , "target/dist/logo.png" ) )
142+ . with_context ( err_context)
130143}
0 commit comments