niti FFI: cmd line option to change the nit_compile dir and default to /tmp/
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 4 Mar 2016 19:19:05 +0000 (14:19 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sat, 5 Mar 2016 02:20:59 +0000 (21:20 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/interpreter/dynamic_loading_ffi/on_demand_compiler.nit

index 85deec6..a52d7eb 100644 (file)
@@ -20,6 +20,15 @@ import c_tools
 import nitni
 import ffi
 import naive_interpreter
+import debugger_socket # To linearize `ToolContext::init`
+
+redef class ToolContext
+
+       # --compile-dir
+       var opt_compile_dir = new OptionString("Directory used to generate temporary files", "--compile-dir")
+
+       init do option_context.add_option opt_compile_dir
+end
 
 redef class AMethPropdef
        # Does this method definition use the FFI and is it supported by the interpreter?
@@ -46,9 +55,15 @@ end
 
 redef class NaiveInterpreter
        # Where to store generated C and extracted code
-       #
-       # TODO make customizable and delete when execution completes
-       private var compile_dir = "nit_compile"
+       private var compile_dir: String is lazy do
+               # Prioritize the user supplied directory
+               var opt = modelbuilder.toolcontext.opt_compile_dir.value
+               if opt != null then return opt
+               return "/tmp/niti_ffi_{process_id}"
+       end
+
+       # Identifier for this process, unique between running interpreters
+       private fun process_id: Int `{ return getpid(); `}
 
        # Path of the compiled foreign code library
        #