4 gembox = File.expand_path("#{gemboxfile}.gembox", "#{MRUBY_ROOT}/mrbgems")
5 fail "Can't find gembox '#{gembox}'" unless File.exist?(gembox)
10 instance_eval File.read(gembox)
15 def gem(gemdir, &block)
16 caller_dir = File.expand_path(File.dirname(/^(.*?):\d/.match(caller.first).to_a[1]))
19 gemdir = load_special_path_gem(gemdir)
20 elsif GemBox.path && gemdir.is_a?(String)
21 gemdir = File.expand_path(gemdir, File.dirname(GemBox.path))
23 gemdir = File.expand_path(gemdir, caller_dir)
26 gemrake = File.join(gemdir, "mrbgem.rake")
28 fail "Can't find #{gemrake}" unless File.exist?(gemrake)
31 return nil unless Gem.current
33 Gem.current.dir = gemdir
34 Gem.current.build = self.is_a?(MRuby::Build) ? self : MRuby::Build.current
35 Gem.current.build_config_initializer = block
38 cxx_srcs = ['src', 'test', 'tools'].map do |subdir|
39 Dir.glob("#{Gem.current.dir}/#{subdir}/*.{cpp,cxx,cc}")
41 enable_cxx_exception unless cxx_srcs.empty?
46 def load_special_path_gem(params)
48 params[:git] = "https://github.com/#{params[:github]}.git"
49 elsif params[:bitbucket]
50 if params[:method] == "ssh"
51 params[:git] = "git@bitbucket.org:#{params[:bitbucket]}.git"
53 params[:git] = "https://bitbucket.org/#{params[:bitbucket]}.git"
56 mgem_list_dir = "#{gem_clone_dir}/mgem-list"
57 mgem_list_url = 'https://github.com/mruby/mgem-list.git'
58 if File.exist? mgem_list_dir
59 git.run_pull mgem_list_dir, mgem_list_url if $pull_gems
61 FileUtils.mkdir_p mgem_list_dir
62 git.run_clone mgem_list_dir, mgem_list_url, "--depth 1"
67 conf_path = "#{mgem_list_dir}/#{params[:mgem]}.gem"
68 conf_path = "#{mgem_list_dir}/mruby-#{params[:mgem]}.gem" unless File.exist? conf_path
69 fail "mgem not found: #{params[:mgem]}" unless File.exist? conf_path
70 conf = YAML.load File.read conf_path
72 fail "unknown mgem protocol: #{conf['protocol']}" if conf['protocol'] != 'git'
73 params[:git] = conf['repository']
74 params[:branch] = conf['branch'] if conf['branch']
78 gemdir = "#{root}/mrbgems/#{params[:core]}"
81 gemdir = "#{gem_clone_dir}/#{url.match(/([-\w]+)(\.[-\w]+|)$/).to_a[1]}"
83 # by default the 'master' branch is used
84 branch = params[:branch] ? params[:branch] : 'master'
86 if File.exist?(gemdir)
88 git.run_pull gemdir, url
93 options = [params[:options]] || []
94 options << "--recursive"
95 options << "--branch \"#{branch}\""
96 options << "--depth 1" unless params[:checksum_hash]
97 FileUtils.mkdir_p "#{gem_clone_dir}"
98 git.run_clone gemdir, url, options
101 if params[:checksum_hash]
102 # Jump to the specified commit
103 git.run_checkout gemdir, params[:checksum_hash]
105 # Jump to the top of the branch
106 git.run_checkout gemdir, branch if $pull_gems
109 gemdir << "/#{params[:path]}" if params[:path]
112 gemdir = Pathname.new(params[:path]).absolute? ? params[:path] : "#{root}/#{params[:path]}"
114 fail "unknown gem option #{params}"