lib/esruby/build.rb in esruby-0.0.10 vs lib/esruby/build.rb in esruby-0.0.11
- old
+ new
@@ -11,37 +11,43 @@
new_build = super
@build = new_build
new_build
end
- def_delegators :@configuration, :root_directory, :build_directory,
+ def_delegators :@configuration, :project_directory, :build_directory,
:build_mode, :output, :mruby_directory, :gems
def initialize(&block)
@configuration = Configuration.new
@configuration.instance_eval(&block)
end
def build
FileUtils.mkdir_p(build_directory)
- load_gems
build_mruby_config
build_mruby
+ load_gems
build_app
end
def gem_directory
ESRuby.gem_directory
end
def load_gems
- @configuration.gems.each do |gem_path|
- load("#{gem_path}/esruby_gem")
+ gem_paths = JSON.parse(File.read(gem_paths_file))
+ gem_paths.each do |gem_path|
+ esruby_spec_path = "#{gem_path}/esruby_gem"
+ load(esruby_spec_path) if File.file?(esruby_spec_path)
end
nil
end
+ def gem_paths_file
+ "#{build_directory}/gem_paths.json"
+ end
+
def prepended_js_sources
js_files = []
Gem::Specification.specifications.each do |specification|
js_files += specification.prepended_js_sources
end
@@ -64,17 +70,16 @@
def build_mruby_config
template = File.read("#{gem_directory}/resources/build_config.eruby")
eruby = Erubis::Eruby.new(template)
config = {}
- config[:prepended_js_sources] = prepended_js_sources
- config[:appended_js_sources] = appended_js_sources
config[:optimization_argument] = optimization_argument
config[:closure_argument] = closure_argument
config[:debug_argument] = debug_argument
config[:build_directory] = build_directory
config[:gems] = gems
+ config[:gem_paths_file] = gem_paths_file
new_output = eruby.result(config)
output_path = "#{build_directory}/build_config.rb"
old_output = File.read(output_path) if File.exists?(output_path)
File.write(output_path, new_output) if (old_output != new_output) # only write if updated
ENV["MRUBY_CONFIG"] = output_path # used by the mruby build process
@@ -112,10 +117,10 @@
RakeFileUtils.sh "rake"
end
end
def build_app
- mrbc = "#{mruby_directory}/bin/mrbc"
+ mrbc = "#{build_directory}/host/bin/mrbc"
js_arguments = prepended_js_sources.map { |path| "--pre-js #{path}" }.join(" ")
js_arguments += " "
js_arguments += appended_js_sources.map { |path| "--post-js #{path}" }.join(" ")
RakeFileUtils.sh "#{mrbc} -B app -o #{build_directory}/app.c #{ruby_sources.join(" ")}"
RakeFileUtils.sh "emcc --bind -I #{mruby_directory}/include #{build_directory}/app.c -o #{build_directory}/app.o #{build_directory}/emscripten/lib/libmruby.a -lm #{js_arguments} #{optimization_argument} #{closure_argument} #{debug_argument}"