Skip to content

Commit 17a621d

Browse files
committed
make geode package new auto-detect binaries and auto-name the output
1 parent c2e4e97 commit 17a621d

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "geode"
3-
version = "2.2.4"
3+
version = "2.3.0"
44
authors = ["HJfod <[email protected]>", "Camila314 <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"

src/package.rs

+42-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
use std::fs;
2+
use std::fs::{self, read_dir};
33
use std::io::{Read, Write, Seek};
44
use std::path::{Path, PathBuf};
55

@@ -13,7 +13,7 @@ use crate::util::cache::CacheBundle;
1313
use crate::util::mod_file::{ModFileInfo, parse_mod_info};
1414
use crate::util::spritesheet;
1515
use crate::{cache, project};
16-
use crate::{done, fail, info, warn, fatal};
16+
use crate::{done, info, warn, fatal};
1717

1818
#[derive(Subcommand, Debug)]
1919
#[clap(rename_all = "kebab-case")]
@@ -29,13 +29,16 @@ pub enum Package {
2929
/// Location of mod's folder
3030
root_path: PathBuf,
3131

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
3335
#[clap(short, long, num_args(1..))]
3436
binary: Vec<PathBuf>,
3537

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
3740
#[clap(short, long)]
38-
output: PathBuf,
41+
output: Option<PathBuf>,
3942

4043
/// Whether to install the generated package after creation
4144
#[clap(short, long)]
@@ -255,35 +258,30 @@ fn create_package(
255258
config: &mut Config,
256259
root_path: &Path,
257260
binaries: Vec<PathBuf>,
258-
mut output: PathBuf,
261+
raw_output: Option<PathBuf>,
259262
do_install: bool,
260263
) {
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+
261269
// If it's a directory, add file path to it
262270
if output.is_dir() {
263-
output.push(root_path.file_name().unwrap());
271+
output.push(&mod_file_info.id);
264272
output.set_extension("geode");
265273
warn!(
266274
"Specified output is a directory. Creating package at {}",
267275
output.display()
268276
);
269277
}
270278

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-
278279
// Test if possible to create file
279280
if !output.exists() || output.is_dir() {
280281
fs::write(&output, "").expect("Could not create package");
281282
fs::remove_file(&output).unwrap();
282283
}
283284

284-
// Parse mod.json
285-
let mod_file_info = parse_mod_info(root_path);
286-
287285
// Setup working directory
288286
let working_dir = get_working_dir(&mod_file_info.id);
289287

@@ -329,7 +327,26 @@ fn create_package(
329327
}
330328
}
331329

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
333350
for binary in &binaries {
334351
let mut binary_name = binary.file_name().unwrap().to_str().unwrap().to_string();
335352
if let Some(ext) = [".ios.dylib", ".dylib", ".dll", ".lib", ".so"].iter().find(|x| binary_name.contains(**x)) {
@@ -338,6 +355,13 @@ fn create_package(
338355

339356
std::fs::copy(binary, working_dir.join(binary_name))
340357
.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>`");
341365
}
342366

343367
new_cache.save(&working_dir);

0 commit comments

Comments
 (0)