Skip to content

Commit 874bec2

Browse files
committed
Implement :checksum_hash mrbgem option.
This allows to use a mgem with a specific checksum hash. The following modification were necessary to implement this function: - add run_checkout build command to use 'git checkout' - skip shallow copy in case checksum_hash is used - make 'master' the default branch if branch isn't defined
1 parent 44cc51f commit 874bec2

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

build_config.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# g.cc.flags << '-g' # append cflags in this gem
1717
# end
1818
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
19-
# conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master'
19+
# conf.gem :github => 'masuidrive/mrbgems-example', :checksum_hash => '76518e8aecd131d047378448ac8055fa29d974a9'
2020
# conf.gem :git => '[email protected]:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v'
2121

2222
# include the default GEMs

tasks/mruby_build_commands.rake

+11-2
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,15 @@ module MRuby
228228

229229
class Command::Git < Command
230230
attr_accessor :flags
231-
attr_accessor :clone_options, :pull_options
231+
attr_accessor :clone_options, :pull_options, :checkout_options
232232

233233
def initialize(build)
234234
super
235235
@command = 'git'
236-
@flags = %w[--depth 1]
236+
@flags = %w[]
237237
@clone_options = "clone %{flags} %{url} %{dir}"
238238
@pull_options = "pull"
239+
@checkout_options = "checkout %{checksum_hash}"
239240
end
240241

241242
def run_clone(dir, url, _flags = [])
@@ -250,6 +251,14 @@ module MRuby
250251
_run pull_options
251252
Dir.chdir root
252253
end
254+
255+
def run_checkout(dir, checksum_hash)
256+
root = Dir.pwd
257+
Dir.chdir dir
258+
_pp "GIT CHECKOUT", checksum_hash
259+
_run checkout_options, { :checksum_hash => checksum_hash }
260+
Dir.chdir root
261+
end
253262
end
254263

255264
class Command::Mrbc < Command

tasks/mruby_build_gem.rake

+13-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ module MRuby
5959
url = params[:git]
6060
gemdir = "#{gem_clone_dir}/#{url.match(/([-\w]+)(\.[-\w]+|)$/).to_a[1]}"
6161

62+
# by default the 'master' branch is used
63+
branch = params[:branch] ? params[:branch] : 'master'
64+
6265
if File.exist?(gemdir)
6366
if $pull_gems
6467
git.run_pull gemdir, url
@@ -67,10 +70,19 @@ module MRuby
6770
end
6871
else
6972
options = [params[:options]] || []
70-
options << "--branch \"#{params[:branch]}\"" if params[:branch]
73+
options << "--branch \"#{branch}\""
74+
options << "--depth 1" unless params[:checksum_hash]
7175
FileUtils.mkdir_p "#{gem_clone_dir}"
7276
git.run_clone gemdir, url, options
7377
end
78+
79+
if params[:checksum_hash]
80+
# Jump to the specified commit
81+
git.run_checkout gemdir, params[:checksum_hash]
82+
else
83+
# Jump to the top of the branch
84+
git.run_checkout gemdir, branch
85+
end
7486
else
7587
fail "unknown gem option #{params}"
7688
end

0 commit comments

Comments
 (0)