From d900701ec4c1bd414e0972fd522dbb390780ad4e Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 20 Sep 2019 15:11:07 +0900 Subject: [PATCH] Automate bottle update --- utils/formula.rb | 32 ++++++++++++++++++++++++++++++++ utils/replace_bottle_sha256.rb | 20 ++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 utils/formula.rb create mode 100644 utils/replace_bottle_sha256.rb diff --git a/utils/formula.rb b/utils/formula.rb new file mode 100644 index 0000000..752790f --- /dev/null +++ b/utils/formula.rb @@ -0,0 +1,32 @@ +class Formula + class << self + def bottle(&block) + @bottle ||= Bottle.new + @bottle.instance_eval(&block) + end + + def method_missing(method, *args); end + + def to_hash + { + 'bottle': @bottle.to_hash + } + end + end + class Bottle + def sha256(hash) + @sha256 ||= {} + hash.each do |k, v| + @sha256[v] = k + end + end + + def method_missing(method, *args); end + + def to_hash + { + 'sha256': @sha256 + } + end + end +end diff --git a/utils/replace_bottle_sha256.rb b/utils/replace_bottle_sha256.rb new file mode 100644 index 0000000..acba195 --- /dev/null +++ b/utils/replace_bottle_sha256.rb @@ -0,0 +1,20 @@ +require_relative "formula.rb" + +formula_path = Dir.pwd + "/" + ARGV[0] +new_sha256 = ARGV[1] +os_version = ARGV[2] + +require_relative formula_path + +formulae = [] +ObjectSpace.each_object(Formula.singleton_class) do |klass| + next if klass == Formula + formulae.push(klass) +end + +formula = formulae[0] +old_sha256 = formula.to_hash[:bottle][:sha256][os_version.to_sym] + +formula_content = File.read(formula_path) +formula_content.gsub!(old_sha256, new_sha256) +File.write(formula_path, formula_content)