diff options
| author | KOBAYASHI Shuji <[email protected]> | 2019-08-22 21:40:01 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2019-08-22 21:40:01 +0900 |
| commit | e312842a1866a551c0b73bdf21f52ad94d25152a (patch) | |
| tree | 644e18aa7f3251e0c717012f396a7f015a680274 /lib | |
| parent | 246179518d8e3641dcb026fb24e8b06f9878faa8 (diff) | |
| download | mruby-e312842a1866a551c0b73bdf21f52ad94d25152a.tar.gz mruby-e312842a1866a551c0b73bdf21f52ad94d25152a.zip | |
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.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/mruby/build.rb | 15 | ||||
| -rw-r--r-- | lib/mruby/build/load_gems.rb | 6 | ||||
| -rw-r--r-- | lib/mruby/lockfile.rb | 73 |
3 files changed, 86 insertions, 8 deletions
diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index 98b9b368d..ecc343360 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -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, :locks + attr_reader :libmruby_objs, :gems, :toolchains attr_writer :enable_bintest, :enable_test alias libmruby libmruby_objs @@ -84,11 +84,8 @@ module MRuby @cxx_abi_enabled = false @enable_bintest = false @enable_test = false - @toolchains = [] - - @locks = MRUBY_CONFIG_LOCK['builds'][@name] if MRUBY_CONFIG_LOCK['builds'] - @locks ||= {} @enable_lock = true + @toolchains = [] MRuby.targets[@name] = self end @@ -120,6 +117,10 @@ module MRuby @enable_lock = false end + def lock_enabled? + Lockfile.enabled? && @enable_lock + end + def disable_cxx_exception if @cxx_exception_enabled or @cxx_abi_enabled raise "cxx_exception already enabled" @@ -233,6 +234,10 @@ EOS gem :core => 'mruby-bin-mrbc' end + def locks + Lockfile.build(@name) + end + def mrbcfile return @mrbcfile if @mrbcfile diff --git a/lib/mruby/build/load_gems.rb b/lib/mruby/build/load_gems.rb index 481f91a94..7f2c7202b 100644 --- a/lib/mruby/build/load_gems.rb +++ b/lib/mruby/build/load_gems.rb @@ -83,7 +83,7 @@ module MRuby # by default the 'master' branch is used branch = params[:branch] ? params[:branch] : 'master' - lock = @locks[url] if @enable_lock + lock = locks[url] if lock_enabled? if File.exist?(gemdir) if $pull_gems @@ -112,8 +112,8 @@ module MRuby end end - if @enable_lock - @locks[url] = { + if lock_enabled? + locks[url] = { 'url' => url, 'branch' => git.current_branch(gemdir), 'commit' => git.commit_hash(gemdir), diff --git a/lib/mruby/lockfile.rb b/lib/mruby/lockfile.rb new file mode 100644 index 000000000..ce1442a89 --- /dev/null +++ b/lib/mruby/lockfile.rb @@ -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 |
