Merge pull request #1084 from David-OConnor/master

Added an --out-name param to the CLI, to allow custom output file names
This commit is contained in:
Alex Crichton 2018-12-04 23:16:36 -05:00 committed by GitHub
commit 7768328fc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -27,6 +27,7 @@ mod wasm_utils;
pub struct Bindgen { pub struct Bindgen {
input: Input, input: Input,
out_name: Option<String>,
nodejs: bool, nodejs: bool,
nodejs_experimental_modules: bool, nodejs_experimental_modules: bool,
browser: bool, browser: bool,
@ -56,6 +57,7 @@ impl Bindgen {
pub fn new() -> Bindgen { pub fn new() -> Bindgen {
Bindgen { Bindgen {
input: Input::None, input: Input::None,
out_name: None,
nodejs: false, nodejs: false,
nodejs_experimental_modules: false, nodejs_experimental_modules: false,
browser: false, browser: false,
@ -77,6 +79,11 @@ impl Bindgen {
self self
} }
pub fn out_name(&mut self, name: &str) -> &mut Bindgen {
self.out_name = Some(name.to_string());
self
}
/// Explicitly specify the already parsed input module. /// Explicitly specify the already parsed input module.
pub fn input_module(&mut self, name: &str, module: Module) -> &mut Bindgen { pub fn input_module(&mut self, name: &str, module: Module) -> &mut Bindgen {
let name = name.to_string(); let name = name.to_string();
@ -155,7 +162,10 @@ impl Bindgen {
.with_context(|_| format!("failed to read `{}`", path.display()))?; .with_context(|_| format!("failed to read `{}`", path.display()))?;
let module = parity_wasm::deserialize_buffer::<Module>(&contents) let module = parity_wasm::deserialize_buffer::<Module>(&contents)
.context("failed to parse input file as wasm")?; .context("failed to parse input file as wasm")?;
let stem = path.file_stem().unwrap().to_str().unwrap(); let stem = match &self.out_name {
Some(name) => &name,
None => path.file_stem().unwrap().to_str().unwrap(),
};
(module, stem) (module, stem)
} }
}; };

View File

@ -29,6 +29,7 @@ Usage:
Options: Options:
-h --help Show this screen. -h --help Show this screen.
--out-dir DIR Output directory --out-dir DIR Output directory
--out-name VAR Set a custom output filename (Without extension. Defaults to crate name)
--nodejs Generate output that only works in node.js --nodejs Generate output that only works in node.js
--browser Generate output that only works in a browser --browser Generate output that only works in a browser
--no-modules Generate output that only works in a browser (without modules) --no-modules Generate output that only works in a browser (without modules)
@ -50,6 +51,7 @@ struct Args {
flag_typescript: bool, flag_typescript: bool,
flag_no_typescript: bool, flag_no_typescript: bool,
flag_out_dir: Option<PathBuf>, flag_out_dir: Option<PathBuf>,
flag_out_name: Option<String>,
flag_debug: bool, flag_debug: bool,
flag_version: bool, flag_version: bool,
flag_no_demangle: bool, flag_no_demangle: bool,
@ -101,6 +103,9 @@ fn rmain(args: &Args) -> Result<(), Error> {
if let Some(ref name) = args.flag_no_modules_global { if let Some(ref name) = args.flag_no_modules_global {
b.no_modules_global(name); b.no_modules_global(name);
} }
if let Some(ref name) = args.flag_out_name {
b.out_name(name);
}
let out_dir = match args.flag_out_dir { let out_dir = match args.flag_out_dir {
Some(ref p) => p, Some(ref p) => p,