mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Refine processing for gem lock file
- Defer YAML library and lock file loading until needed. - Don't write empty parts into lock file. - Extract code to read/write lock file to `MRuby::Lockfile`. - `MRuby::Lockfile.disable` disables the use of lock file.
This commit is contained in:
@@ -8,10 +8,10 @@ MRUBY_BUILD_HOST_IS_OPENBSD = RUBY_PLATFORM.include?('openbsd')
|
|||||||
$LOAD_PATH << File.join(MRUBY_ROOT, "lib")
|
$LOAD_PATH << File.join(MRUBY_ROOT, "lib")
|
||||||
|
|
||||||
# load build systems
|
# load build systems
|
||||||
require 'yaml'
|
|
||||||
require "mruby-core-ext"
|
require "mruby-core-ext"
|
||||||
require "mruby/build"
|
require "mruby/build"
|
||||||
require "mruby/gem"
|
require "mruby/gem"
|
||||||
|
require "mruby/lockfile"
|
||||||
|
|
||||||
# load configuration file
|
# load configuration file
|
||||||
MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
|
MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
|
||||||
@@ -125,25 +125,7 @@ task :all => depfiles do
|
|||||||
MRuby.each_target do
|
MRuby.each_target do
|
||||||
print_build_summary
|
print_build_summary
|
||||||
end
|
end
|
||||||
|
MRuby::Lockfile.write
|
||||||
require 'mruby/source'
|
|
||||||
|
|
||||||
locks_result = {
|
|
||||||
'mruby_version' => {
|
|
||||||
'version' => MRuby::Source::MRUBY_VERSION,
|
|
||||||
'release_no' => MRuby::Source::MRUBY_RELEASE_NO
|
|
||||||
},
|
|
||||||
'builds' => {}
|
|
||||||
}
|
|
||||||
if File.exist? "#{MRUBY_ROOT}/.git"
|
|
||||||
locks_result['mruby_version']['git_commit'] = `git --git-dir '#{MRUBY_ROOT}/.git' --work-tree '#{MRUBY_ROOT}' rev-parse --verify HEAD`.strip
|
|
||||||
end
|
|
||||||
|
|
||||||
MRuby.each_target do
|
|
||||||
locks_result['builds'][name] = locks
|
|
||||||
end
|
|
||||||
|
|
||||||
File.write MRUBY_CONFIG_LOCK_FILE, YAML.dump(locks_result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "run all mruby tests"
|
desc "run all mruby tests"
|
||||||
|
|||||||
+10
-5
@@ -39,7 +39,7 @@ module MRuby
|
|||||||
include Rake::DSL
|
include Rake::DSL
|
||||||
include LoadGems
|
include LoadGems
|
||||||
attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir
|
attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir
|
||||||
attr_reader :libmruby_objs, :gems, :toolchains, :locks
|
attr_reader :libmruby_objs, :gems, :toolchains
|
||||||
attr_writer :enable_bintest, :enable_test
|
attr_writer :enable_bintest, :enable_test
|
||||||
|
|
||||||
alias libmruby libmruby_objs
|
alias libmruby libmruby_objs
|
||||||
@@ -84,11 +84,8 @@ module MRuby
|
|||||||
@cxx_abi_enabled = false
|
@cxx_abi_enabled = false
|
||||||
@enable_bintest = false
|
@enable_bintest = false
|
||||||
@enable_test = false
|
@enable_test = false
|
||||||
@toolchains = []
|
|
||||||
|
|
||||||
@locks = MRUBY_CONFIG_LOCK['builds'][@name] if MRUBY_CONFIG_LOCK['builds']
|
|
||||||
@locks ||= {}
|
|
||||||
@enable_lock = true
|
@enable_lock = true
|
||||||
|
@toolchains = []
|
||||||
|
|
||||||
MRuby.targets[@name] = self
|
MRuby.targets[@name] = self
|
||||||
end
|
end
|
||||||
@@ -120,6 +117,10 @@ module MRuby
|
|||||||
@enable_lock = false
|
@enable_lock = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def lock_enabled?
|
||||||
|
Lockfile.enabled? && @enable_lock
|
||||||
|
end
|
||||||
|
|
||||||
def disable_cxx_exception
|
def disable_cxx_exception
|
||||||
if @cxx_exception_enabled or @cxx_abi_enabled
|
if @cxx_exception_enabled or @cxx_abi_enabled
|
||||||
raise "cxx_exception already enabled"
|
raise "cxx_exception already enabled"
|
||||||
@@ -233,6 +234,10 @@ EOS
|
|||||||
gem :core => 'mruby-bin-mrbc'
|
gem :core => 'mruby-bin-mrbc'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def locks
|
||||||
|
Lockfile.build(@name)
|
||||||
|
end
|
||||||
|
|
||||||
def mrbcfile
|
def mrbcfile
|
||||||
return @mrbcfile if @mrbcfile
|
return @mrbcfile if @mrbcfile
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ module MRuby
|
|||||||
# by default the 'master' branch is used
|
# by default the 'master' branch is used
|
||||||
branch = params[:branch] ? params[:branch] : 'master'
|
branch = params[:branch] ? params[:branch] : 'master'
|
||||||
|
|
||||||
lock = @locks[url] if @enable_lock
|
lock = locks[url] if lock_enabled?
|
||||||
|
|
||||||
if File.exist?(gemdir)
|
if File.exist?(gemdir)
|
||||||
if $pull_gems
|
if $pull_gems
|
||||||
@@ -112,8 +112,8 @@ module MRuby
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @enable_lock
|
if lock_enabled?
|
||||||
@locks[url] = {
|
locks[url] = {
|
||||||
'url' => url,
|
'url' => url,
|
||||||
'branch' => git.current_branch(gemdir),
|
'branch' => git.current_branch(gemdir),
|
||||||
'commit' => git.commit_hash(gemdir),
|
'commit' => git.commit_hash(gemdir),
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
autoload :YAML, 'yaml'
|
||||||
|
|
||||||
|
module MRuby
|
||||||
|
autoload :Source, 'mruby/source'
|
||||||
|
|
||||||
|
class Lockfile
|
||||||
|
class << self
|
||||||
|
def enable
|
||||||
|
@enabled = true
|
||||||
|
end
|
||||||
|
|
||||||
|
def disable
|
||||||
|
@enabled = false
|
||||||
|
end
|
||||||
|
|
||||||
|
def enabled?
|
||||||
|
@enabled
|
||||||
|
end
|
||||||
|
|
||||||
|
def build(target_name)
|
||||||
|
instance.build(target_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def write
|
||||||
|
instance.write if enabled?
|
||||||
|
end
|
||||||
|
|
||||||
|
def instance
|
||||||
|
@instance ||= new("#{MRUBY_CONFIG}.lock")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(filename)
|
||||||
|
@filename = filename
|
||||||
|
end
|
||||||
|
|
||||||
|
def build(target_name)
|
||||||
|
read[target_name] ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def write
|
||||||
|
locks = {"mruby_version" => mruby}
|
||||||
|
locks["builds"] = @builds if @builds
|
||||||
|
File.write(@filename, YAML.dump(locks))
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def read
|
||||||
|
@builds ||= if File.exist?(@filename)
|
||||||
|
YAML.load_file(@filename)["builds"] || {}
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def mruby
|
||||||
|
mruby = {
|
||||||
|
'version' => MRuby::Source::MRUBY_VERSION,
|
||||||
|
'release_no' => MRuby::Source::MRUBY_RELEASE_NO,
|
||||||
|
}
|
||||||
|
|
||||||
|
git_dir = "#{MRUBY_ROOT}/.git"
|
||||||
|
if File.directory?(git_dir)
|
||||||
|
mruby['git_commit'] = `git --git-dir '#{git_dir}' --work-tree '#{MRUBY_ROOT}' rev-parse --verify HEAD`.strip
|
||||||
|
end
|
||||||
|
|
||||||
|
mruby
|
||||||
|
end
|
||||||
|
|
||||||
|
enable
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user