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)
17 gemdir = load_special_path_gem(gemdir)
18 elsif GemBox.path && gemdir.is_a?(String)
19 gemdir = File.expand_path(gemdir, File.dirname(GemBox.path))
21 caller_dir = File.expand_path(File.dirname(caller(1,1)[0][/^(.*?):\d/,1]))
22 gemdir = File.expand_path(gemdir, caller_dir)
25 gemrake = File.join(gemdir, "mrbgem.rake")
27 fail "Can't find #{gemrake}" unless File.exist?(gemrake)
30 return nil unless Gem.current
32 Gem.current.dir = gemdir
33 Gem.current.build = self.is_a?(MRuby::Build) ? self : MRuby::Build.current
34 Gem.current.build_config_initializer = block
37 cxx_srcs = ['src', 'test', 'tools'].map do |subdir|
38 Dir.glob("#{Gem.current.dir}/#{subdir}/*.{cpp,cxx,cc}")
40 enable_cxx_exception unless cxx_srcs.empty?
45 def load_special_path_gem(params)
47 params[:git] = "https://github.com/#{params[:github]}.git"
48 elsif params[:bitbucket]
49 if params[:method] == "ssh"
50 params[:git] = "git@bitbucket.org:#{params[:bitbucket]}.git"
52 params[:git] = "https://bitbucket.org/#{params[:bitbucket]}.git"
55 mgem_list_dir = "#{gem_clone_dir}/mgem-list"
56 mgem_list_url = 'https://github.com/mruby/mgem-list.git'
57 if File.exist? mgem_list_dir
58 git.run_pull mgem_list_dir, mgem_list_url if $pull_gems
61 git.run_clone mgem_list_dir, mgem_list_url, "--depth 1"
66 conf_path = "#{mgem_list_dir}/#{params[:mgem]}.gem"
67 conf_path = "#{mgem_list_dir}/mruby-#{params[:mgem]}.gem" unless File.exist? conf_path
68 fail "mgem not found: #{params[:mgem]}" unless File.exist? conf_path
69 conf = YAML.load File.read conf_path
71 fail "unknown mgem protocol: #{conf['protocol']}" if conf['protocol'] != 'git'
72 params[:git] = conf['repository']
73 params[:branch] = conf['branch'] if conf['branch']
77 gemdir = "#{root}/mrbgems/#{params[:core]}"
80 gemdir = "#{gem_clone_dir}/#{url.match(/([-\w]+)(\.[-\w]+|)$/).to_a[1]}"
82 # by default the 'master' branch is used
83 branch = params[:branch] ? params[:branch] : 'master'
85 lock = locks[url] if lock_enabled?
87 if File.exist?(gemdir)
89 # Jump to the top of the branch
90 git.run_checkout gemdir, branch
91 git.run_pull gemdir, url
92 elsif params[:checksum_hash]
93 git.run_checkout_detach gemdir, params[:checksum_hash]
95 git.run_checkout_detach gemdir, lock['commit']
98 options = [params[:options]] || []
99 options << "--recursive"
100 options << "--branch \"#{branch}\""
101 options << "--depth 1" unless params[:checksum_hash]
102 mkdir_p "#{gem_clone_dir}"
103 git.run_clone gemdir, url, options
105 # Jump to the specified commit
106 if params[:checksum_hash]
107 git.run_checkout_detach gemdir, params[:checksum_hash]
109 git.run_checkout_detach gemdir, lock['commit']
114 @gem_dir_to_repo_url[gemdir] = url unless params[:path]
117 'branch' => git.current_branch(gemdir),
118 'commit' => git.commit_hash(gemdir),
122 gemdir << "/#{params[:path]}" if params[:path]
125 gemdir = Pathname.new(params[:path]).absolute? ? params[:path] : "#{root}/#{params[:path]}"
127 fail "unknown gem option #{params}"