Unverified Commit 90bffaa2 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4180 from take-cheeze/lock_file

Support lock file for git.
parents 4c8e6daa b6850f88
......@@ -8,12 +8,19 @@ MRUBY_BUILD_HOST_IS_OPENBSD = RUBY_PLATFORM.include?('openbsd')
$LOAD_PATH << File.join(MRUBY_ROOT, "lib")
# load build systems
require 'yaml'
require "mruby-core-ext"
require "mruby/build"
require "mruby/gem"
# load configuration file
MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
MRUBY_CONFIG_LOCK_FILE = "#{MRUBY_CONFIG}.lock"
MRUBY_CONFIG_LOCK = if File.exist? MRUBY_CONFIG_LOCK_FILE
YAML.load File.read MRUBY_CONFIG_LOCK_FILE
else
{}
end
load MRUBY_CONFIG
# load basic rules
......@@ -118,6 +125,13 @@ task :all => depfiles do
MRuby.each_target do
print_build_summary
end
locks_result = { 'builds' => {} }
MRuby.each_target do
locks_result['builds'][name] = locks
end
File.write MRUBY_CONFIG_LOCK_FILE, YAML.dump(locks_result)
end
desc "run all mruby tests"
......
......@@ -39,7 +39,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
......@@ -64,7 +64,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))
......@@ -86,6 +86,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
......@@ -112,6 +116,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"
......
......@@ -270,15 +270,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 = [])
......@@ -287,19 +288,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
......
......@@ -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]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment