From 6fccf0ccc7debb37b5dd1a46ed1daaf624cefef4 Mon Sep 17 00:00:00 2001 From: "chromebrew-actions[bot]" <220035932+chromebrew-actions[bot]@users.noreply.github.com> Date: Sun, 17 Aug 2025 15:07:47 -0500 Subject: [PATCH] Let tool/version.rb update source hashes too. (#12525) * Let tool/version.rb update source hashes too. Signed-off-by: Satadru Pramanik * Suggested changes Signed-off-by: Satadru Pramanik --------- Signed-off-by: Satadru Pramanik Co-authored-by: Satadru Pramanik --- lib/const.rb | 2 +- lib/package.rb | 5 +++-- tools/version.rb | 42 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/const.rb b/lib/const.rb index ecedf1f0d..c67606a25 100644 --- a/lib/const.rb +++ b/lib/const.rb @@ -4,7 +4,7 @@ require 'etc' require 'open3' OLD_CREW_VERSION ||= defined?(CREW_VERSION) ? CREW_VERSION : '1.0' -CREW_VERSION ||= '1.64.10' unless defined?(CREW_VERSION) && CREW_VERSION == OLD_CREW_VERSION +CREW_VERSION ||= '1.65.0' unless defined?(CREW_VERSION) && CREW_VERSION == OLD_CREW_VERSION # Kernel architecture. KERN_ARCH ||= Etc.uname[:machine] diff --git a/lib/package.rb b/lib/package.rb index e73c26921..e11f7fb11 100644 --- a/lib/package.rb +++ b/lib/package.rb @@ -92,7 +92,8 @@ class Package end end - def self.load_package(pkg_file) + def self.load_package(pkg_file, reload = nil) + reload = !reload.nil? # self.load_package: load a package under 'Package' class scope # pkg_name = File.basename(pkg_file, '.rb') @@ -104,7 +105,7 @@ class Package # If this package has been removed, it won't be found in either directory, so set it back to what it was before to get a nicer error. pkg_file = "#{CREW_PACKAGES_PATH}/#{pkg_name}.rb" if pkg_file.nil? - class_eval(File.read(pkg_file, encoding: Encoding::UTF_8), pkg_file) unless const_defined?("Package::#{class_name}") + class_eval(File.read(pkg_file, encoding: Encoding::UTF_8), pkg_file) unless const_defined?("Package::#{class_name}") && !reload pkg_obj = const_get(class_name) pkg_obj.name = pkg_name diff --git a/tools/version.rb b/tools/version.rb index 377f5f2c1..c4616787d 100755 --- a/tools/version.rb +++ b/tools/version.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -# version.rb version 2.0 (for Chromebrew) +# version.rb version 2.1 (for Chromebrew) OPTIONS = %w[-h --help -j --json -u --update-package-files -v --verbose] @@ -197,11 +197,7 @@ if filelist.length.positive? else "version alias: #{`grep '^ version' #{filename} | awk '{print $2}'`.chomp}" end - elsif @pkg.source_url.is_a?(Hash) - # source_url hashes are not - # automatically updatable. - 'source_url hash' - elsif @pkg.source_url.include?('SKIP') + elsif @pkg.source_url.is_a?(Hash) || @pkg.source_url.include?('SKIP') 'Yes' # If there is a git_hashtag, we can # check to see if 'version' is on @@ -276,6 +272,40 @@ if filelist.length.positive? if file.sub!(PackageUtils.get_clean_version(@pkg.version), upstream_version.chomp).nil? versions_updated[@pkg.name.to_sym] = false else + # Version update succeeded. Now check for a sha256 update. + old_hash = {} + new_hash = {} + # Handle source_url whether hash or not. + if !@pkg.source_sha256.nil? && @pkg.source_sha256.is_a?(Hash) && @pkg.source_sha256&.key?(ARCH.to_sym) + # Get old hashes + (@pkg.source_url.keys.map &:to_s).each do |arch| + puts "old source_url: #{@pkg.source_url[arch.to_sym]}" if VERBOSE + old_hash[arch] = @pkg.source_sha256[arch.to_sym] + puts "old hash: #{old_hash[arch]}" if VERBOSE + end + File.write(filename, file) + # Now get new hashes + @pkg = Package.load_package(filename, true) + (@pkg.source_url.keys.map &:to_s).each do |arch| + puts "new source_url: #{@pkg.source_url[arch.to_sym]}" if VERBOSE + new_hash[arch] = `curl -Ls #{@pkg.source_url[arch.to_sym]} | sha256sum - | awk '{print $1}'`.chomp + puts "new hash: #{new_hash[arch]}" if VERBOSE + file.sub!(old_hash[arch], new_hash[arch]) + end + elsif !@pkg.source_sha256.nil? && !@pkg.source_sha256.is_a?(Hash) + arch = :all + # Get old hashes + old_hash[arch] = @pkg.source_sha256 + puts "old source_url: #{@pkg.source_url}" if VERBOSE + puts "old hash: #{old_hash[arch]}" if VERBOSE + File.write(filename, file) + # Now get new hashes + @pkg = Package.load_package(filename, true) + puts "new source_url: #{@pkg.source_url}" if VERBOSE + new_hash[arch] = `curl -Ls #{@pkg.source_url} | sha256sum - | awk '{print $1}'`.chomp + puts "new hash: #{new_hash[arch]}" if VERBOSE + file.sub!(old_hash[arch], new_hash[arch]) + end File.write(filename, file) versions_updated[@pkg.name.to_sym] = true end