From 61dfdcb3e3d208ba6baa4f96933f031ee42a2882 Mon Sep 17 00:00:00 2001 From: Max Downey Twiss Date: Thu, 30 Oct 2025 02:46:24 +1100 Subject: [PATCH] Add `conflicts_with` property and use it for `coreutils`, `tealdeer` and `tldr` (#13252) * Add PackageUtils.compatible? tests for min_glibc and max_glibc * Add conflicts_with property and use it for coreutils, tealdeer and tldr --- lib/const.rb | 2 +- lib/package.rb | 8 ++--- lib/package_utils.rb | 3 +- packages/coreutils.rb | 10 +------ packages/tealdeer.rb | 10 +------ packages/tldr.rb | 10 +------ tests/lib/package_utils.rb | 60 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 68 insertions(+), 35 deletions(-) diff --git a/lib/const.rb b/lib/const.rb index 67e33e8c2..c25b25361 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.67.11' unless defined?(CREW_VERSION) && CREW_VERSION == OLD_CREW_VERSION +CREW_VERSION ||= '1.67.12' 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 9470948f3..a25f4d55e 100644 --- a/lib/package.rb +++ b/lib/package.rb @@ -71,7 +71,8 @@ class Package :git_branch, :git_hashtag, :max_glibc, - :min_glibc + :min_glibc, + :conflicts_with create_placeholder :preflight, # Function for checks to see if install should occur. :patch, # Function to perform patch operations prior to build from source. @@ -134,11 +135,6 @@ class Package end end - def self.installed(pkg) - # Returns true if the package is installed, false otherwise. - return File.file? "#{CREW_META_PATH}/#{pkg}.filelist" - end - def self.load_package(pkg_file, reload = nil) reload = !reload.nil? # self.load_package: load a package under 'Package' class scope diff --git a/lib/package_utils.rb b/lib/package_utils.rb index 2104d5c76..c17eb4671 100644 --- a/lib/package_utils.rb +++ b/lib/package_utils.rb @@ -11,7 +11,7 @@ class PackageUtils end def self.compatible?(pkg) - return (pkg.compatibility.casecmp?('all') || pkg.compatibility.include?(ARCH)) && (pkg.min_glibc.nil? || (pkg.min_glibc <= LIBC_VERSION)) && (pkg.max_glibc.nil? || (pkg.max_glibc >= LIBC_VERSION)) + return (pkg.compatibility.casecmp?('all') || pkg.compatibility.include?(ARCH)) && (pkg.min_glibc.nil? || (pkg.min_glibc <= LIBC_VERSION)) && (pkg.max_glibc.nil? || (pkg.max_glibc >= LIBC_VERSION)) && !installed?(pkg.conflicts_with) end def self.incompatible_reason(pkg) @@ -19,6 +19,7 @@ class PackageUtils reason.push "#{pkg.name.capitalize} is not compatible with #{ARCH}." if !pkg.compatibility.casecmp?('all') && !pkg.compatibility.include?(ARCH) reason.push "ChromeOS is currently running glibc #{LIBC_VERSION}, but the minimum version for #{pkg.name} is #{pkg.min_glibc}." if !pkg.min_glibc.nil? && (pkg.min_glibc >= LIBC_VERSION) reason.push "ChromeOS is currently running glibc #{LIBC_VERSION}, but the maximum version for #{pkg.name} is #{pkg.min_glibc}." if !pkg.max_glibc.nil? && (pkg.max_glibc.to_s <= LIBC_VERSION) + reason.push "#{pkg.name.capitalize} conflicts with #{pkg.conflicts_with.capitalize}, which is currently installed." if installed?(pkg.conflicts_with) return reason end diff --git a/packages/coreutils.rb b/packages/coreutils.rb index 344f9d169..aa5cf0265 100644 --- a/packages/coreutils.rb +++ b/packages/coreutils.rb @@ -24,15 +24,7 @@ class Coreutils < Autotools depends_on 'libcap' # R depends_on 'openssl' # R - def self.preflight - %w[uutils_coreutils].each do |cutils| - next unless File.exist? "#{CREW_PREFIX}/etc/crew/meta/#{cutils}.filelist" - - puts "#{cutils} is installed and conflicts with this version.".orange - puts 'To install this version, execute the following:'.lightblue - abort "crew remove #{cutils} && crew install coreutils".lightblue - end - end + conflicts_with 'uutils_coreutils' def self.prebuild File.write 'arch', <<~EOF diff --git a/packages/tealdeer.rb b/packages/tealdeer.rb index c2f4a0be5..9c1c1a51a 100644 --- a/packages/tealdeer.rb +++ b/packages/tealdeer.rb @@ -21,13 +21,5 @@ class Tealdeer < RUST depends_on 'glibc' # R depends_on 'rust' => :build - def self.preflight - if Package.installed('tldr') - abort <<~EOM.orange - - tldr is installed. To install this package, execute: - crew remove tldr && crew install tealdeer - EOM - end - end + conflicts_with 'tldr' end diff --git a/packages/tldr.rb b/packages/tldr.rb index 3955ec7c5..7063ad021 100644 --- a/packages/tldr.rb +++ b/packages/tldr.rb @@ -11,15 +11,7 @@ class Tldr < Package no_compile_needed - def self.preflight - if Package.installed('tealdeer') - abort <<~EOM.orange - - tealdeer is installed. To install this package, execute: - crew remove tealdeer && crew install tldr - EOM - end - end + conflicts_with 'tealdeer' def self.patch # Fix /usr/local/bin/tldr: 97: /usr/local/bin/tldr: cannot create /dev/stderr: Permission denied diff --git a/tests/lib/package_utils.rb b/tests/lib/package_utils.rb index 20794bfe0..23a89a455 100644 --- a/tests/lib/package_utils.rb +++ b/tests/lib/package_utils.rb @@ -50,6 +50,66 @@ class PackageUtilsTest < Minitest::Test refute(PackageUtils.compatible?(pkg)) end + def test_compatible_min_glibc + # A package with a minimum glibc smaller than the current libc version is compatible. + pkg = Class.new(Package) + pkg.instance_eval do + compatibility 'all' + min_glibc (LIBC_VERSION.to_f - 0.10).to_s + end + assert(PackageUtils.compatible?(pkg)) + end + + def test_not_compatible_min_glibc + # A package with a minimum glibc greater than the current libc version is not compatible. + pkg = Class.new(Package) + pkg.instance_eval do + compatibility 'all' + min_glibc (LIBC_VERSION.to_f + 0.01).to_s + end + refute(PackageUtils.compatible?(pkg)) + end + + def test_compatible_max_glibc + # A package with a maximum glibc greater than the current libc version is compatible. + pkg = Class.new(Package) + pkg.instance_eval do + compatibility 'all' + max_glibc (LIBC_VERSION.to_f + 0.10).to_s + end + assert(PackageUtils.compatible?(pkg)) + end + + def test_not_compatible_max_glibc + # A package with a maximum glibc smaller than the current libc version is not compatible. + pkg = Class.new(Package) + pkg.instance_eval do + compatibility 'all' + max_glibc (LIBC_VERSION.to_f - 0.01).to_s + end + refute(PackageUtils.compatible?(pkg)) + end + + def test_compatible_conflicts_with + # A package that conflicts with a package that is not installed is compatible. + pkg = Class.new(Package) + pkg.instance_eval do + compatibility 'all' + conflicts_with '99notinstalled' + end + assert(PackageUtils.compatible?(pkg)) + end + + def test_not_compatible_conflicts_with + # A package that conflicts with a package that is not installed is compatible. + pkg = Class.new(Package) + pkg.instance_eval do + compatibility 'all' + conflicts_with 'ruby' + end + refute(PackageUtils.compatible?(pkg)) + end + def test_get_binary_url_old_hash pkg = Class.new(Package) pkg.name = 'hello_world_chromebrew'