mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
e312842a18
- 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.
74 lines
1.3 KiB
Ruby
74 lines
1.3 KiB
Ruby
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
|