Files
KOBAYASHI Shuji 81c2108819 Revert MRUBY_TARGET mechanism; ref #5096
* In explanation of mruby, the expression `build_config.rb` is frequently
  used including official documents, so I think that it will not make sense
  if the file is no longer used.
* The `MRUBY_TARGET` mechanism seems to have little improvement, so I don't
  think it should be changed to avoid unnecessary confusion.
* `MRUBY_TARGET` and `MRuby.targets` represent somewhat different things,
  so using the same term "target" is a bit confusing.

The mechanism that can be written short when using a file under
`build_config` (renamed from `target`) directory remains
(`build_config/${MRUBY_CONFIG}.rb` is used if the path specified
in `MRUBY_CONFIG` doesn't exist).
2020-10-19 15:03:22 +09:00

82 lines
1.5 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" => 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 shellquote(s)
if ENV['OS'] == 'Windows_NT'
"\"#{s}\""
else
"'#{s}'"
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 #{shellquote(git_dir)} --work-tree #{shellquote(MRUBY_ROOT)} rev-parse --verify HEAD`.strip
end
mruby
end
enable
end
end