From 54be99b433a5949024b13a15135e03ca714a965e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Thu, 23 Jul 2015 17:51:15 -0400 Subject: [PATCH] contrib/jwrapper: add an option to search for existing wrappers in custom libs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- contrib/jwrapper/src/jwrapper.nit | 2 +- contrib/jwrapper/src/model.nit | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/contrib/jwrapper/src/jwrapper.nit b/contrib/jwrapper/src/jwrapper.nit index ca3fd7f..60a6ca3 100644 --- a/contrib/jwrapper/src/jwrapper.nit +++ b/contrib/jwrapper/src/jwrapper.nit @@ -44,7 +44,7 @@ var opt_output = new OptionString("Output file", "-o") var opt_regex = new OptionString("Regex pattern to filter classes in Jar archives", "-r") var opt_help = new OptionBool("Show this help message", "-h", "--help") -opts.add_option(opt_output, opt_unknown, opt_extern_class_prefix, opt_regex, opt_verbose, opt_help) +opts.add_option(opt_output, opt_unknown, opt_extern_class_prefix, opt_libs, opt_regex, opt_verbose, opt_help) opts.parse args if opts.errors.not_empty or opts.rest.is_empty or opt_help.value then diff --git a/contrib/jwrapper/src/model.nit b/contrib/jwrapper/src/model.nit index 7c49790..0f406b0 100644 --- a/contrib/jwrapper/src/model.nit +++ b/contrib/jwrapper/src/model.nit @@ -263,19 +263,26 @@ redef class Sys var map = new DefaultMap[String, nullable NitType](null) var modules = new HashMap[String, NitModule] - var nit_dir = "NIT_DIR".environ - if nit_dir.is_empty then - # Simple heuristic to find the Nit lib - var dir = sys.program_name.dirname / "../../../" - nit_dir = dir.simplify_path - if not nit_dir.file_exists then return map + var lib_paths = opt_libs.value + if lib_paths == null then lib_paths = new Array[String] + + if lib_paths.has("auto") then + lib_paths.remove "auto" + var nit_dir = "NIT_DIR".environ + if nit_dir.is_empty then + # Simple heuristic to find the Nit lib + var dir = sys.program_name.dirname / "../../../lib/" + dir = dir.simplify_path + if dir.file_exists then lib_paths.add dir.simplify_path + end end + if lib_paths.is_empty then return map + # Use grep to find all extern classes implemented in Java var grep_regex = "extern class [a-zA-Z0-9]\\\+[ ]\\\+in[ ]\\\+\"Java\"" - var grep_args = ["-r", grep_regex, - nit_dir/"lib/android/", - nit_dir/"lib/java/"] + var grep_args = ["-r", "--with-filename", grep_regex] + grep_args.add_all lib_paths var grep = new ProcessReader("grep", grep_args...) var lines = grep.read_lines @@ -312,6 +319,9 @@ redef class Sys # Prefix used to name extern classes, if `null` use the full namespace var extern_class_prefix: nullable String is lazy do return opt_extern_class_prefix.value + + # Libraries to search for existing wrappers + var opt_libs = new OptionArray("Paths to libraries with wrappers of Java classes ('auto' to use the full Nit lib)", "-i") end redef class Text -- 1.7.9.5