Class: Mundler::MRuby
- Inherits:
-
Object
- Object
- Mundler::MRuby
- Defined in:
- lib/mundler/mruby.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #clone_repository ⇒ Object
- #compile(build_config) ⇒ Object
- #delete_repository ⇒ Object
- #exec(args) ⇒ Object
-
#initialize(config) ⇒ MRuby
constructor
A new instance of MRuby.
- #print_summary ⇒ Object
Constructor Details
#initialize(config) ⇒ MRuby
Returns a new instance of MRuby.
3 4 5 6 7 8 9 |
# File 'lib/mundler/mruby.rb', line 3 def initialize(config) @config = config @path = File.join(ENV["HOME"], ".mundler", config.hex) # Protect just incase, as we're doing an rm_rf raise "Something went wrong" if config.hex.length == 0 end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/mundler/mruby.rb', line 11 def path @path end |
Instance Method Details
#clone_repository ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mundler/mruby.rb', line 17 def clone_repository success_indicator = File.join(@path, ".mundler_cloned_successfully") return if File.file?(success_indicator) mruby_url = @config.mruby[:url] version = ( @config.mruby[:tag] || @config.mruby[:branch] || @config.mruby[:version] ) FileUtils.rm_rf(@path) FileUtils.mkdir_p(@path) FileUtils.cd(@path) git_clone = Proc.new do system( { # The {mundler gem path}/cached_git directory contains a binary called # `git` that will run instead of normal git, making a cache of a # clone. "PATH" => ([cached_git_dir] + ENV["PATH"].split(":")).join(":") }, "git clone #{mruby_url} . >/dev/null 2>&1" ) || error_out("Failed to clone mruby: #{mruby_url}") end if defined?(Bundler) && Bundler.respond_to?(:with_unbundled_env) Bundler.with_unbundled_env(&git_clone) elsif defined?(Bundler) Bundler.with_clean_env(&git_clone) else git_clone.call end if version system("git reset --hard #{version} >/dev/null 2>&1") || error_out("Failed to set version to #{version}") end FileUtils.touch(success_indicator) end |
#compile(build_config) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/mundler/mruby.rb', line 70 def compile(build_config) logfile = Tempfile.new(['mundler_build', '.log']) success_indicator = File.join(@path, ".mundler_built_successfully") if File.file?(success_indicator) return end FileUtils.cd(@path) cleaned = false covered = [] output_thread = Thread.new do loop do if cleaned Dir.glob(File.join(Dir.pwd, "build", "*", "*", "*")).each do |file| pathname = Pathname.new(file) directory = pathname.directory? ? pathname.to_s : Pathname.new(file).dirname.to_s next if covered.include?(directory) covered << directory print "\e[32m.\e[0m" end end sleep(0.3) end end clean = Proc.new do rake = `which rake`.chomp system( { "MRUBY_CONFIG" => build_config, # The {mundler gem path}/cached_git directory contains a binary called # `git` that will run instead of normal git, making a cache of a # clone. "PATH" => ([cached_git_dir] + ENV["PATH"].split(":")).join(":") }, "#{rake} clean >#{logfile.path} 2>&1 && #{rake} deep_clean >#{logfile.path} 2>&1" ) || begin $stderr.print "\e[31mF\e[0m" $stderr.puts "\n\n" $stderr.puts File.read(logfile) raise Mundler::CompilationError end cleaned = true end compile = Proc.new do rake = `which rake`.chomp system( { "MRUBY_CONFIG" => build_config, # The {mundler gem path}/cached_git directory contains a binary called # `git` that will run instead of normal git, making a cache of a # clone. "PATH" => ([cached_git_dir] + ENV["PATH"].split(":")).join(":") }, "#{rake} >#{logfile.path} 2>&1" ) || begin $stderr.print "\e[31mF\e[0m" $stderr.puts "\n\n" $stderr.puts File.read(logfile) raise Mundler::CompilationError end end if defined?(Bundler) && Bundler.respond_to?(:with_unbundled_env) Bundler.with_unbundled_env(&clean) Bundler.with_unbundled_env(&compile) elsif defined?(Bundler) Bundler.with_clean_env(&clean) Bundler.with_clean_env(&compile) else clean.call compile.call end output_thread.kill FileUtils.touch(success_indicator) ensure logfile.close logfile.delete end |
#delete_repository ⇒ Object
13 14 15 |
# File 'lib/mundler/mruby.rb', line 13 def delete_repository FileUtils.rm_rf(@path) end |
#exec(args) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/mundler/mruby.rb', line 60 def exec(args) raise NotInstalledError unless installed? bin_dir = File.join(@path, "bin") path = bin_dir + ":" + ENV['PATH'] Process.spawn({ "PATH" => path }, *args) Process.wait exit($?.exitstatus) if $?.exitstatus end |
#print_summary ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/mundler/mruby.rb', line 157 def print_summary FileUtils.cd(@path) puts "Libraries:" Dir.glob(File.join(Dir.pwd, "**", "*.a")).each { |a| puts "* " + a.split("build/").last } binaries = Dir.glob(File.join(Dir.pwd, "build", "host", "bin", "*")) if binaries.count > 0 puts "" puts "Binaries:" binaries.each { |a| puts "* " + a.split("/").last } end end |