Class: MRuby::Gem::Specification
- Extended by:
- Forwardable
- Includes:
- Rake::DSL
- Defined in:
- ext/enterprise_script_service/mruby/lib/mruby/gem.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#bins ⇒ Object
Returns the value of attribute bins.
-
#build ⇒ Object
(also: #mruby)
Returns the value of attribute build.
-
#build_config_initializer ⇒ Object
Returns the value of attribute build_config_initializer.
-
#conflicts ⇒ Object
readonly
Returns the value of attribute conflicts.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#description ⇒ Object
Returns the value of attribute description.
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#export_include_paths ⇒ Object
Returns the value of attribute export_include_paths.
-
#generate_functions ⇒ Object
readonly
Returns the value of attribute generate_functions.
-
#homepage ⇒ Object
Returns the value of attribute homepage.
-
#licenses ⇒ Object
Returns the value of attribute licenses.
-
#mrblib_dir ⇒ Object
Returns the value of attribute mrblib_dir.
-
#name ⇒ Object
Returns the value of attribute name.
-
#objs ⇒ Object
Returns the value of attribute objs.
-
#objs_dir ⇒ Object
Returns the value of attribute objs_dir.
-
#rbfiles ⇒ Object
Returns the value of attribute rbfiles.
-
#requirements ⇒ Object
Returns the value of attribute requirements.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#test_args ⇒ Object
Returns the value of attribute test_args.
-
#test_objs ⇒ Object
Returns the value of attribute test_objs.
-
#test_preload ⇒ Object
Returns the value of attribute test_preload.
-
#test_rbfiles ⇒ Object
Returns the value of attribute test_rbfiles.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #add_conflict(name, *req) ⇒ Object
- #add_dependency(name, *requirements) ⇒ Object
- #add_test_dependency(*args) ⇒ Object
- #build_dir ⇒ Object
- #compilers ⇒ Object
- #custom_test_init? ⇒ Boolean
- #define_gem_init_builder ⇒ Object
- #for_windows? ⇒ Boolean
- #funcname ⇒ Object
- #generate_gem_init(fname) ⇒ Object
-
#initialize(name, &block) ⇒ Specification
constructor
A new instance of Specification.
-
#print_gem_comment(f) ⇒ Object
generate_gem_init.
- #print_gem_init_header(f) ⇒ Object
- #print_gem_test_header(f) ⇒ Object
- #search_package(name, version_query = nil) ⇒ Object
- #setup ⇒ Object
- #setup_compilers ⇒ Object
- #test_dependencies ⇒ Object
- #test_rbireps ⇒ Object
- #version_ok?(req_versions) ⇒ Boolean
Constructor Details
#initialize(name, &block) ⇒ Specification
Returns a new instance of Specification.
44 45 46 47 48 49 50 51 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 44 def initialize(name, &block) @name = name @initializer = block @version = "0.0.0" @mrblib_dir = "mrblib" @objs_dir = "src" MRuby::Gem.current = self end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
25 26 27 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 25 def end |
#bins ⇒ Object
Returns the value of attribute bins.
33 34 35 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 33 def bins @bins end |
#build ⇒ Object Also known as: mruby
Returns the value of attribute build.
17 18 19 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 17 def build @build end |
#build_config_initializer ⇒ Object
Returns the value of attribute build_config_initializer.
19 20 21 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 19 def build_config_initializer @build_config_initializer end |
#conflicts ⇒ Object (readonly)
Returns the value of attribute conflicts.
36 37 38 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 36 def conflicts @conflicts end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
36 37 38 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 36 def dependencies @dependencies end |
#description ⇒ Object
Returns the value of attribute description.
23 24 25 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 23 def description @description end |
#dir ⇒ Object
Returns the value of attribute dir.
17 18 19 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 17 def dir @dir end |
#export_include_paths ⇒ Object
Returns the value of attribute export_include_paths.
38 39 40 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 38 def export_include_paths @export_include_paths end |
#generate_functions ⇒ Object (readonly)
Returns the value of attribute generate_functions.
40 41 42 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 40 def generate_functions @generate_functions end |
#homepage ⇒ Object
Returns the value of attribute homepage.
24 25 26 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 24 def homepage @homepage end |
#licenses ⇒ Object
Returns the value of attribute licenses.
25 26 27 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 25 def licenses @licenses end |
#mrblib_dir ⇒ Object
Returns the value of attribute mrblib_dir.
20 21 22 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 20 def mrblib_dir @mrblib_dir end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 17 def name @name end |
#objs ⇒ Object
Returns the value of attribute objs.
29 30 31 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 29 def objs @objs end |
#objs_dir ⇒ Object
Returns the value of attribute objs_dir.
20 21 22 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 20 def objs_dir @objs_dir end |
#rbfiles ⇒ Object
Returns the value of attribute rbfiles.
29 30 31 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 29 def rbfiles @rbfiles end |
#requirements ⇒ Object
Returns the value of attribute requirements.
35 36 37 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 35 def requirements @requirements end |
#summary ⇒ Object
Returns the value of attribute summary.
23 24 25 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 23 def summary @summary end |
#test_args ⇒ Object
Returns the value of attribute test_args.
30 31 32 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 30 def test_args @test_args end |
#test_objs ⇒ Object
Returns the value of attribute test_objs.
30 31 32 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 30 def test_objs @test_objs end |
#test_preload ⇒ Object
Returns the value of attribute test_preload.
31 32 33 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 31 def test_preload @test_preload end |
#test_rbfiles ⇒ Object
Returns the value of attribute test_rbfiles.
30 31 32 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 30 def test_rbfiles @test_rbfiles end |
#version ⇒ Object
Returns the value of attribute version.
22 23 24 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 22 def version @version end |
Instance Method Details
#add_conflict(name, *req) ⇒ Object
129 130 131 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 129 def add_conflict(name, *req) @conflicts << {:gem => name, :requirements => req.empty? ? nil : req} end |
#add_dependency(name, *requirements) ⇒ Object
118 119 120 121 122 123 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 118 def add_dependency(name, *requirements) default_gem = requirements.last.kind_of?(Hash) ? requirements.pop : nil requirements = ['>= 0.0.0'] if requirements.empty? requirements.flatten! @dependencies << {:gem => name, :requirements => requirements, :default => default_gem} end |
#add_test_dependency(*args) ⇒ Object
125 126 127 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 125 def add_test_dependency(*args) add_dependency(*args) if build.test_enabled? || build.bintest_enabled? end |
#build_dir ⇒ Object
133 134 135 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 133 def build_dir "#{build.build_dir}/mrbgems/#{name}" end |
#compilers ⇒ Object
160 161 162 163 164 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 160 def compilers MRuby::Build::COMPILERS.map do |c| instance_variable_get("@#{c}") end end |
#custom_test_init? ⇒ Boolean
233 234 235 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 233 def custom_test_init? @custom_test_init end |
#define_gem_init_builder ⇒ Object
166 167 168 169 170 171 172 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 166 def define_gem_init_builder file objfile("#{build_dir}/gem_init") => [ "#{build_dir}/gem_init.c", File.join(dir, "mrbgem.rake") ] file "#{build_dir}/gem_init.c" => [build.mrbcfile, __FILE__] + [rbfiles].flatten do |t| mkdir_p build_dir generate_gem_init("#{build_dir}/gem_init.c") end end |
#for_windows? ⇒ Boolean
109 110 111 112 113 114 115 116 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 109 def for_windows? if build.kind_of?(MRuby::CrossBuild) return %w(x86_64-w64-mingw32 i686-w64-mingw32).include?(build.host_target) elsif build.kind_of?(MRuby::Build) return ('A'..'Z').to_a.any? { |vol| Dir.exist?("#{vol}:") } end return false end |
#funcname ⇒ Object
156 157 158 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 156 def funcname @funcname ||= @name.gsub('-', '_') end |
#generate_gem_init(fname) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 174 def generate_gem_init(fname) open(fname, 'w') do |f| print_gem_init_header f build.mrbc.run f, rbfiles, "gem_mrblib_irep_#{funcname}" unless rbfiles.empty? f.puts %Q[void mrb_#{funcname}_gem_init(mrb_state *mrb);] f.puts %Q[void mrb_#{funcname}_gem_final(mrb_state *mrb);] f.puts %Q[] f.puts %Q[void GENERATED_TMP_mrb_#{funcname}_gem_init(mrb_state *mrb) {] f.puts %Q[ int ai = mrb_gc_arena_save(mrb);] f.puts %Q[ mrb_#{funcname}_gem_init(mrb);] if objs != [objfile("#{build_dir}/gem_init")] unless rbfiles.empty? f.puts %Q[ mrb_load_irep(mrb, gem_mrblib_irep_#{funcname});] f.puts %Q[ if (mrb->exc) {] f.puts %Q[ mrb_print_error(mrb);] f.puts %Q[ mrb_close(mrb);] f.puts %Q[ exit(EXIT_FAILURE);] f.puts %Q[ }] end f.puts %Q[ mrb_gc_arena_restore(mrb, ai);] f.puts %Q[}] f.puts %Q[] f.puts %Q[void GENERATED_TMP_mrb_#{funcname}_gem_final(mrb_state *mrb) {] f.puts %Q[ mrb_#{funcname}_gem_final(mrb);] if objs != [objfile("#{build_dir}/gem_init")] f.puts %Q[}] end end |
#print_gem_comment(f) ⇒ Object
generate_gem_init
201 202 203 204 205 206 207 208 209 210 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 201 def print_gem_comment(f) f.puts %Q[/*] f.puts %Q[ * This file is loading the irep] f.puts %Q[ * Ruby GEM code.] f.puts %Q[ *] f.puts %Q[ * IMPORTANT:] f.puts %Q[ * This file was generated!] f.puts %Q[ * All manual changes will get lost.] f.puts %Q[ */] end |
#print_gem_init_header(f) ⇒ Object
212 213 214 215 216 217 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 212 def print_gem_init_header(f) print_gem_comment(f) f.puts %Q[#include <stdlib.h>] unless rbfiles.empty? f.puts %Q[#include <mruby.h>] f.puts %Q[#include <mruby/irep.h>] unless rbfiles.empty? end |
#print_gem_test_header(f) ⇒ Object
219 220 221 222 223 224 225 226 227 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 219 def print_gem_test_header(f) print_gem_comment(f) f.puts %Q[#include <stdio.h>] f.puts %Q[#include <stdlib.h>] f.puts %Q[#include <mruby.h>] f.puts %Q[#include <mruby/irep.h>] f.puts %Q[#include <mruby/variable.h>] f.puts %Q[#include <mruby/hash.h>] unless test_args.empty? end |
#search_package(name, version_query = nil) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 141 def search_package(name, version_query=nil) package_query = name package_query += " #{version_query}" if version_query _pp "PKG-CONFIG", package_query escaped_package_query = Shellwords.escape(package_query) if system("pkg-config --exists #{escaped_package_query}") cc.flags += [`pkg-config --cflags #{escaped_package_query}`.strip] cxx.flags += [`pkg-config --cflags #{escaped_package_query}`.strip] linker.flags_before_libraries += [`pkg-config --libs #{escaped_package_query}`.strip] true else false end end |
#setup ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 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 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 53 def setup return if defined?(@linker) # return if already set up MRuby::Gem.current = self MRuby::Build::COMMANDS.each do |command| instance_variable_set("@#{command}", @build.send(command).clone) end @linker = LinkerConfig.new([], [], [], [], []) @rbfiles = Dir.glob("#{@dir}/#{@mrblib_dir}/**/*.rb").sort @objs = Dir.glob("#{@dir}/#{@objs_dir}/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f| objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X")) end @test_rbfiles = Dir.glob("#{dir}/test/**/*.rb").sort @test_objs = Dir.glob("#{dir}/test/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f| objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X")) end @custom_test_init = !@test_objs.empty? @test_preload = nil # 'test/assert.rb' @test_args = {} @bins = [] @requirements = [] @dependencies, @conflicts = [], [] @export_include_paths = [] @export_include_paths << "#{dir}/include" if File.directory? "#{dir}/include" instance_eval(&@initializer) @generate_functions = !(@rbfiles.empty? && @objs.empty?) @objs << objfile("#{build_dir}/gem_init") if @generate_functions if !name || !licenses || ! fail "#{name || dir} required to set name, license(s) and author(s)" end build.libmruby_objs << @objs instance_eval(&@build_config_initializer) if @build_config_initializer repo_url = build.gem_dir_to_repo_url[dir] build.locks[repo_url]['version'] = version if repo_url end |
#setup_compilers ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 99 def setup_compilers compilers.each do |compiler| compiler.define_rules build_dir, "#{dir}" compiler.defines << %Q[MRBGEM_#{funcname.upcase}_VERSION=#{version}] compiler.include_paths << "#{dir}/include" if File.directory? "#{dir}/include" end define_gem_init_builder if @generate_functions end |
#test_dependencies ⇒ Object
229 230 231 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 229 def test_dependencies [@name] end |
#test_rbireps ⇒ Object
137 138 139 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 137 def test_rbireps "#{build_dir}/gem_test.c" end |
#version_ok?(req_versions) ⇒ Boolean
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 237 def version_ok?(req_versions) req_versions.map do |req| cmp, ver = req.split cmp_result = Version.new(version) <=> Version.new(ver) case cmp when '=' then cmp_result == 0 when '!=' then cmp_result != 0 when '>' then cmp_result == 1 when '<' then cmp_result == -1 when '>=' then cmp_result >= 0 when '<=' then cmp_result <= 0 when '~>' Version.new(version).twiddle_wakka_ok?(Version.new(ver)) else fail "Comparison not possible with '#{cmp}'" end end.all? end |