diff options
| author | take-cheeze <[email protected]> | 2018-12-06 11:47:17 +0900 |
|---|---|---|
| committer | take-cheeze <[email protected]> | 2018-12-06 11:47:17 +0900 |
| commit | b6850f88a1de68599e48e2c08b996d96eed5ea33 (patch) | |
| tree | 6ab66ba29d404f403fa6964671e1ec08640a2cb9 /lib | |
| parent | e6bad6766a8ddc00c23b1c0204b047dfbf8e3041 (diff) | |
| download | mruby-b6850f88a1de68599e48e2c08b996d96eed5ea33.tar.gz mruby-b6850f88a1de68599e48e2c08b996d96eed5ea33.zip | |
Support lock file for git.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/mruby/build.rb | 12 | ||||
| -rw-r--r-- | lib/mruby/build/command.rb | 30 | ||||
| -rw-r--r-- | lib/mruby/build/load_gems.rb | 30 |
3 files changed, 51 insertions, 21 deletions
diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index e2d9fc41e..ae17d372c 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -45,7 +45,7 @@ module MRuby include Rake::DSL include LoadGems attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir - attr_reader :libmruby_objs, :gems, :toolchains + attr_reader :libmruby_objs, :gems, :toolchains, :locks attr_writer :enable_bintest, :enable_test alias libmruby libmruby_objs @@ -70,7 +70,7 @@ module MRuby @file_separator = '/' @build_dir = "#{build_dir}/#{@name}" - @gem_clone_dir = "#{build_dir}/mrbgems" + @gem_clone_dir = "#{@build_dir}/repos" @cc = Command::Compiler.new(self, %w(.c)) @cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp)) @objc = Command::Compiler.new(self, %w(.m)) @@ -92,6 +92,10 @@ module MRuby @enable_test = false @toolchains = [] + @locks = MRUBY_CONFIG_LOCK['builds'][@name] if MRUBY_CONFIG_LOCK['builds'] + @locks ||= {} + @enable_lock = true + MRuby.targets[@name] = self end @@ -118,6 +122,10 @@ module MRuby @enable_debug = true end + def disable_lock + @enable_lock = false + end + def disable_cxx_exception if @cxx_exception_enabled or @cxx_abi_enabled raise "cxx_exception already enabled" diff --git a/lib/mruby/build/command.rb b/lib/mruby/build/command.rb index 694b4a24c..e3dc0d78c 100644 --- a/lib/mruby/build/command.rb +++ b/lib/mruby/build/command.rb @@ -243,15 +243,16 @@ module MRuby class Command::Git < Command attr_accessor :flags - attr_accessor :clone_options, :pull_options, :checkout_options + attr_accessor :clone_options, :pull_options, :checkout_options, :reset_options def initialize(build) super @command = 'git' @flags = %w[] @clone_options = "clone %{flags} %{url} %{dir}" - @pull_options = "pull" - @checkout_options = "checkout %{checksum_hash}" + @pull_options = "--git-dir '%{repo_dir}/.git' --work-tree '%{repo_dir}' pull" + @checkout_options = "--git-dir '%{repo_dir}/.git' --work-tree '%{repo_dir}' checkout %{checksum_hash}" + @reset_options = "--git-dir '%{repo_dir}/.git' --work-tree '%{repo_dir}' reset %{checksum_hash}" end def run_clone(dir, url, _flags = []) @@ -260,19 +261,26 @@ module MRuby end def run_pull(dir, url) - root = Dir.pwd - Dir.chdir dir _pp "GIT PULL", url, dir.relative_path - _run pull_options - Dir.chdir root + _run pull_options, { :repo_dir => dir } end def run_checkout(dir, checksum_hash) - root = Dir.pwd - Dir.chdir dir _pp "GIT CHECKOUT", checksum_hash - _run checkout_options, { :checksum_hash => checksum_hash } - Dir.chdir root + _run checkout_options, { :checksum_hash => checksum_hash, :repo_dir => dir } + end + + def run_reset_hard(dir, checksum_hash) + _pp "GIT RESET", checksum_hash + _run reset_options, { :checksum_hash => checksum_hash, :repo_dir => dir } + end + + def commit_hash(dir) + `#{@command} --git-dir '#{dir}/.git' --work-tree '#{dir}' rev-parse --verify HEAD`.strip + end + + def current_branch(dir) + `#{@command} --git-dir '#{dir}/.git' --work-tree '#{dir}' rev-parse --abbrev-ref HEAD`.strip end end diff --git a/lib/mruby/build/load_gems.rb b/lib/mruby/build/load_gems.rb index 723be6ffc..481f91a94 100644 --- a/lib/mruby/build/load_gems.rb +++ b/lib/mruby/build/load_gems.rb @@ -83,11 +83,18 @@ module MRuby # by default the 'master' branch is used branch = params[:branch] ? params[:branch] : 'master' + lock = @locks[url] if @enable_lock + if File.exist?(gemdir) if $pull_gems git.run_pull gemdir, url - else - gemdir + # Jump to the top of the branch + git.run_checkout(gemdir, branch) + git.run_reset_hard gemdir, "origin/#{branch}" + elsif params[:checksum_hash] + git.run_reset_hard(gemdir, params[:checksum_hash]) + elsif lock + git.run_reset_hard(gemdir, lock['commit']) end else options = [params[:options]] || [] @@ -96,14 +103,21 @@ module MRuby options << "--depth 1" unless params[:checksum_hash] FileUtils.mkdir_p "#{gem_clone_dir}" git.run_clone gemdir, url, options - end - if params[:checksum_hash] # Jump to the specified commit - git.run_checkout gemdir, params[:checksum_hash] - else - # Jump to the top of the branch - git.run_checkout gemdir, branch if $pull_gems + if params[:checksum_hash] + git.run_reset_hard gemdir, params[:checksum_hash] + elsif lock + git.run_reset_hard gemdir, lock['commit'] + end + end + + if @enable_lock + @locks[url] = { + 'url' => url, + 'branch' => git.current_branch(gemdir), + 'commit' => git.commit_hash(gemdir), + } end gemdir << "/#{params[:path]}" if params[:path] |
