1
1
2
- use std:: fs;
2
+ use std:: fs:: { self , read_dir } ;
3
3
use std:: io:: { Read , Write , Seek } ;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
@@ -13,7 +13,7 @@ use crate::util::cache::CacheBundle;
13
13
use crate :: util:: mod_file:: { ModFileInfo , parse_mod_info} ;
14
14
use crate :: util:: spritesheet;
15
15
use crate :: { cache, project} ;
16
- use crate :: { done, fail , info, warn, fatal} ;
16
+ use crate :: { done, info, warn, fatal} ;
17
17
18
18
#[ derive( Subcommand , Debug ) ]
19
19
#[ clap( rename_all = "kebab-case" ) ]
@@ -29,13 +29,16 @@ pub enum Package {
29
29
/// Location of mod's folder
30
30
root_path : PathBuf ,
31
31
32
- /// Add binary file
32
+ /// Add an external binary file. By default, all known binary files
33
+ /// (.dll, .lib, .dylib, .so) named after the mod ID in the root path
34
+ /// are included
33
35
#[ clap( short, long, num_args( 1 ..) ) ]
34
36
binary : Vec < PathBuf > ,
35
37
36
- /// Location of output file
38
+ /// Location of output file. If not provided, the resulting file is named
39
+ /// {mod.id}.geode and placed at the root path
37
40
#[ clap( short, long) ]
38
- output : PathBuf ,
41
+ output : Option < PathBuf > ,
39
42
40
43
/// Whether to install the generated package after creation
41
44
#[ clap( short, long) ]
@@ -255,35 +258,30 @@ fn create_package(
255
258
config : & mut Config ,
256
259
root_path : & Path ,
257
260
binaries : Vec < PathBuf > ,
258
- mut output : PathBuf ,
261
+ raw_output : Option < PathBuf > ,
259
262
do_install : bool ,
260
263
) {
264
+ // Parse mod.json
265
+ let mod_file_info = parse_mod_info ( root_path) ;
266
+
267
+ let mut output = raw_output. unwrap_or ( root_path. join ( format ! ( "{}.geode" , mod_file_info. id) ) ) ;
268
+
261
269
// If it's a directory, add file path to it
262
270
if output. is_dir ( ) {
263
- output. push ( root_path . file_name ( ) . unwrap ( ) ) ;
271
+ output. push ( & mod_file_info . id ) ;
264
272
output. set_extension ( "geode" ) ;
265
273
warn ! (
266
274
"Specified output is a directory. Creating package at {}" ,
267
275
output. display( )
268
276
) ;
269
277
}
270
278
271
- // Ensure at least one binary
272
- if binaries. is_empty ( ) {
273
- fail ! ( "No binaries added" ) ;
274
- info ! ( "Help: Add a binary with `--binary <bin_path>`" ) ;
275
- return ;
276
- }
277
-
278
279
// Test if possible to create file
279
280
if !output. exists ( ) || output. is_dir ( ) {
280
281
fs:: write ( & output, "" ) . expect ( "Could not create package" ) ;
281
282
fs:: remove_file ( & output) . unwrap ( ) ;
282
283
}
283
284
284
- // Parse mod.json
285
- let mod_file_info = parse_mod_info ( root_path) ;
286
-
287
285
// Setup working directory
288
286
let working_dir = get_working_dir ( & mod_file_info. id ) ;
289
287
@@ -329,7 +327,26 @@ fn create_package(
329
327
}
330
328
}
331
329
332
- // Copy binaries
330
+ let mut binaries_added = false ;
331
+ for file in read_dir ( root_path) . expect ( "Unable to read root directory" ) {
332
+ let Ok ( file) = file else { continue ; } ;
333
+ let path = file. path ( ) ;
334
+ let Some ( name) = path. file_stem ( ) else { continue ; } ;
335
+ let Some ( ext) = path. extension ( ) else { continue ; } ;
336
+ if name. to_string_lossy ( ) == mod_file_info. id
337
+ && matches ! (
338
+ ext. to_string_lossy( ) . as_ref( ) ,
339
+ "ios.dylib" | "dylib" | "dll" | "lib" | "so"
340
+ )
341
+ {
342
+ let binary = name. to_string_lossy ( ) . to_string ( ) + "." + ext. to_string_lossy ( ) . as_ref ( ) ;
343
+ std:: fs:: copy ( path, working_dir. join ( & binary) )
344
+ . expect ( & format ! ( "Unable to copy binary '{}'" , binary) ) ;
345
+ binaries_added = true ;
346
+ }
347
+ }
348
+
349
+ // Copy other binaries
333
350
for binary in & binaries {
334
351
let mut binary_name = binary. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
335
352
if let Some ( ext) = [ ".ios.dylib" , ".dylib" , ".dll" , ".lib" , ".so" ] . iter ( ) . find ( |x| binary_name. contains ( * * x) ) {
@@ -338,6 +355,13 @@ fn create_package(
338
355
339
356
std:: fs:: copy ( binary, working_dir. join ( binary_name) )
340
357
. expect ( & format ! ( "Unable to copy binary at '{}'" , binary. display( ) ) ) ;
358
+ binaries_added = true ;
359
+ }
360
+
361
+ // Ensure at least one binary
362
+ if !binaries_added {
363
+ warn ! ( "No binaries added to the resulting package" ) ;
364
+ info ! ( "Help: Add a binary with `--binary <bin_path>`" ) ;
341
365
}
342
366
343
367
new_cache. save ( & working_dir) ;
0 commit comments