Module: Webruby
- Defined in:
- lib/webruby/app.rb,
lib/webruby/config.rb,
lib/webruby/utility.rb
Defined Under Namespace
Constant Summary collapse
- COMMON_EXPORTED_FUNCTIONS =
It may appear that mode 0 and mode 1 requires the same set of functions since they both load bytecodes, but due to the fact that mode 0 only loads pre-defined bytecode array, chances are optimizers may perform some tricks to eliminate parts of the source code for mode 0. Hence we still distinguish mode 0 from mode 1 here
['mrb_open', 'mrb_close']
Class Method Summary collapse
- .build_config ⇒ Object
- .build_dir ⇒ Object
- .create_file_if_different(filename) {|f| ... } ⇒ Object
- .entrypoint_file ⇒ Object
- .full_build_config ⇒ Object
- .full_build_dir ⇒ Object
- .gem_js_files ⇒ Object
- .gem_js_flags ⇒ Object
- .gem_test_js_files ⇒ Object
- .gem_test_js_flags ⇒ Object
-
.get_exported_arg(gem_function_file, loading_mode, custom_functions) ⇒ Object
Generate command line option for exported functions, see gen_exported_functions for argument details.
-
.get_exported_functions(gem_function_file, loading_mode, custom_functions) ⇒ Object
Gets a list of all exported functions including following types: * Functions exported by mrbgems * Functions required by loading modes * Functions that are customly added by users.
- .object_files ⇒ Object
- .rb_files ⇒ Object
- .test_object_files ⇒ Object
Class Method Details
.build_config ⇒ Object
30 31 32 |
# File 'lib/webruby/utility.rb', line 30 def build_config "#{build_dir}/mruby_build_config.rb" end |
.build_dir ⇒ Object
22 23 24 |
# File 'lib/webruby/utility.rb', line 22 def build_dir Webruby::App.config.build_dir end |
.create_file_if_different(filename) {|f| ... } ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/webruby/utility.rb', line 5 def create_file_if_different(filename) tmp_filename = "#{filename}.tmp" # TODO: add support for case where block is not given, # maybe using monkey patching on File#close? f = File.open(tmp_filename, 'w') yield f f.close if (!File.exists?(filename)) || (!FileUtils.compare_file(filename, tmp_filename)) puts "Creating new file: #{filename}!" FileUtils.cp(tmp_filename, filename) end FileUtils.rm(tmp_filename) end |
.entrypoint_file ⇒ Object
38 39 40 |
# File 'lib/webruby/utility.rb', line 38 def entrypoint_file Webruby::App.config.entrypoint end |
.full_build_config ⇒ Object
34 35 36 |
# File 'lib/webruby/utility.rb', line 34 def full_build_config File.(build_config) end |
.full_build_dir ⇒ Object
26 27 28 |
# File 'lib/webruby/utility.rb', line 26 def full_build_dir File.(build_dir) end |
.gem_js_files ⇒ Object
60 61 62 |
# File 'lib/webruby/utility.rb', line 60 def gem_js_files ["#{build_dir}/gem_library.js", "#{build_dir}/gem_append.js"] end |
.gem_js_flags ⇒ Object
64 65 66 |
# File 'lib/webruby/utility.rb', line 64 def gem_js_flags "--js-library #{build_dir}/gem_library.js --pre-js #{build_dir}/gem_append.js" end |
.gem_test_js_files ⇒ Object
68 69 70 |
# File 'lib/webruby/utility.rb', line 68 def gem_test_js_files ["#{build_dir}/gem_test_library.js", "#{build_dir}/gem_test_append.js"] end |
.gem_test_js_flags ⇒ Object
72 73 74 |
# File 'lib/webruby/utility.rb', line 72 def gem_test_js_flags "--js-library #{build_dir}/gem_test_library.js --pre-js #{build_dir}/gem_test_append.js" end |
.get_exported_arg(gem_function_file, loading_mode, custom_functions) ⇒ Object
Generate command line option for exported functions, see gen_exported_functions for argument details
141 142 143 144 145 146 |
# File 'lib/webruby/utility.rb', line 141 def get_exported_arg(gem_function_file, loading_mode, custom_functions) func_str = get_exported_functions(gem_function_file, loading_mode, custom_functions) .map{|f| "'_#{f}'"}.join ', ' "-s EXPORTED_FUNCTIONS=\"[#{func_str}]\"" end |
.get_exported_functions(gem_function_file, loading_mode, custom_functions) ⇒ Object
Gets a list of all exported functions including following types:
-
Functions exported by mrbgems
-
Functions required by loading modes
-
Functions that are customly added by users
Attributes
-
gem_function_file
- File name of functions exported by mrbgems, this is
generated by scripts/gen_gems_config.rb
-
loading_mode
- Loading mode -
custom_functions
- Array of custom functions added by user
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/webruby/utility.rb', line 118 def get_exported_functions(gem_function_file, loading_mode, custom_functions) loading_mode = loading_mode.to_i functions = File.readlines(gem_function_file).map {|f| f.strip} functions = functions.concat(custom_functions) functions = functions.concat(COMMON_EXPORTED_FUNCTIONS) functions << 'webruby_internal_setup' # WEBRUBY.run is supported by all loading modes functions << 'webruby_internal_run' # WEBRUBY.run_bytecode functions << 'webruby_internal_run_bytecode' if loading_mode > 0 # WEBRUBY.run_source functions << 'webruby_internal_run_source' if loading_mode > 1 functions.uniq end |
.object_files ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/webruby/utility.rb', line 42 def object_files (Dir.glob("#{full_build_dir}/mruby/emscripten/src/**/*.o") + Dir.glob("#{full_build_dir}/mruby/emscripten/mrblib/**/*.o") + Dir.glob("#{full_build_dir}/mruby/emscripten/mrbgems/**/*.o")) .reject { |f| f.end_with? "gem_test.o" } end |
.rb_files ⇒ Object
56 57 58 |
# File 'lib/webruby/utility.rb', line 56 def rb_files Dir.glob("#{File.dirname(entrypoint_file)}/**") end |
.test_object_files ⇒ Object
51 52 53 54 |
# File 'lib/webruby/utility.rb', line 51 def test_object_files (Dir.glob("#{full_build_dir}/mruby/emscripten/test/**/*.o") + Dir.glob("#{full_build_dir}/mruby/emscripten/mrbgems/**/gem_test.o")) end |