Added support for multiple input dirs
This commit is contained in:
parent
f73f1d4360
commit
8c85dc5c13
@ -80,12 +80,15 @@ fn patch_runner(arch: &str, exec_name: &str) -> io::Result<Vec<u8>> {
|
|||||||
Ok(buf)
|
Ok(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_tgz(dir: &Path, out: &Path) -> io::Result<()> {
|
fn create_tgz(dirs: &Vec<&Path>, out: &Path) -> io::Result<()> {
|
||||||
let f = fs::File::create(out)?;
|
let f = fs::File::create(out)?;
|
||||||
let gz = GzEncoder::new(f, Compression::best());
|
let gz = GzEncoder::new(f, Compression::best());
|
||||||
let mut tar = tar::Builder::new(gz);
|
let mut tar = tar::Builder::new(gz);
|
||||||
tar.follow_symlinks(false);
|
tar.follow_symlinks(false);
|
||||||
tar.append_dir_all(".", dir)?;
|
for dir in dirs.iter() {
|
||||||
|
println!("Compressing input directory {:?}...", dir);
|
||||||
|
tar.append_dir_all(".", dir)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +119,14 @@ fn create_app(runner_buf: &Vec<u8>, tgz_path: &Path, out: &Path) -> io::Result<(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_path(path_str: &str) -> &Path {
|
||||||
|
let path = Path::new(path_str);
|
||||||
|
if fs::metadata(path).is_err() {
|
||||||
|
bail!("Cannot access specified input directory {:?}", path);
|
||||||
|
}
|
||||||
|
return &path;
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<Error>> {
|
fn main() -> Result<(), Box<Error>> {
|
||||||
let args = App::new(APP_NAME)
|
let args = App::new(APP_NAME)
|
||||||
.settings(&[AppSettings::ArgRequiredElseHelp, AppSettings::ColoredHelp])
|
.settings(&[AppSettings::ArgRequiredElseHelp, AppSettings::ColoredHelp])
|
||||||
@ -134,10 +145,12 @@ fn main() -> Result<(), Box<Error>> {
|
|||||||
.short("i")
|
.short("i")
|
||||||
.long("input_dir")
|
.long("input_dir")
|
||||||
.value_name("input_dir")
|
.value_name("input_dir")
|
||||||
.help("Sets the input directory containing the application and dependencies")
|
.help("Sets the input directories for packing. Might provide multiple directories, but the first must contain the executed application")
|
||||||
.display_order(2)
|
.display_order(2)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(true))
|
.required(true)
|
||||||
|
.multiple(true)
|
||||||
|
.min_values(1))
|
||||||
.arg(Arg::with_name("exec")
|
.arg(Arg::with_name("exec")
|
||||||
.short("e")
|
.short("e")
|
||||||
.long("exec")
|
.long("exec")
|
||||||
@ -161,17 +174,17 @@ fn main() -> Result<(), Box<Error>> {
|
|||||||
bail!("Unknown architecture specified: {}, supported: {:?}", arch, RUNNER_BY_ARCH.keys());
|
bail!("Unknown architecture specified: {}, supported: {:?}", arch, RUNNER_BY_ARCH.keys());
|
||||||
}
|
}
|
||||||
|
|
||||||
let input_dir = Path::new(args.value_of("input_dir").unwrap());
|
let input_dirs: Vec<&Path> = args.values_of("input_dir")
|
||||||
if fs::metadata(input_dir).is_err() {
|
.unwrap()
|
||||||
bail!("Cannot access specified input directory {:?}", input_dir);
|
.map(make_path)
|
||||||
}
|
.collect();
|
||||||
|
|
||||||
let exec_name = args.value_of("exec").unwrap();
|
let exec_name = args.value_of("exec").unwrap();
|
||||||
if exec_name.len() >= RUNNER_MAGIC.len() {
|
if exec_name.len() >= RUNNER_MAGIC.len() {
|
||||||
bail!("Executable name is too long, please consider using a shorter name");
|
bail!("Executable name is too long, please consider using a shorter name");
|
||||||
}
|
}
|
||||||
|
|
||||||
let exec_path = Path::new(input_dir).join(exec_name);
|
let exec_path = Path::new(input_dirs[0]).join(exec_name);
|
||||||
match fs::metadata(&exec_path) {
|
match fs::metadata(&exec_path) {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
bail!("Cannot find file {:?}", exec_path);
|
bail!("Cannot find file {:?}", exec_path);
|
||||||
@ -185,10 +198,11 @@ fn main() -> Result<(), Box<Error>> {
|
|||||||
|
|
||||||
let runner_buf = patch_runner(&arch, &exec_name)?;
|
let runner_buf = patch_runner(&arch, &exec_name)?;
|
||||||
|
|
||||||
println!("Compressing input directory {:?}...", input_dir);
|
|
||||||
let tmp_dir = TempDir::new(APP_NAME)?;
|
let tmp_dir = TempDir::new(APP_NAME)?;
|
||||||
let tgz_path = tmp_dir.path().join("input.tgz");
|
let tgz_path = tmp_dir.path().join("input.tgz");
|
||||||
create_tgz(&input_dir, &tgz_path)?;
|
|
||||||
|
create_tgz(&input_dirs, &tgz_path)?;
|
||||||
|
|
||||||
|
|
||||||
let exec_name = Path::new(args.value_of("output").unwrap());
|
let exec_name = Path::new(args.value_of("output").unwrap());
|
||||||
println!("Creating self-contained application binary {:?}...", exec_name);
|
println!("Creating self-contained application binary {:?}...", exec_name);
|
||||||
|
Loading…
Reference in New Issue
Block a user