Add check command (#9501)

This commit is contained in:
Ed Reel
2024-03-20 07:46:01 -05:00
committed by GitHub
parent 3522e1130c
commit 7c17beeee7
48 changed files with 325 additions and 60 deletions

View File

@@ -80,6 +80,7 @@ Where available commands are:
| Command | Description |
|:------------:|:------------|
| build | build package(s) from source and store the archive and checksum in the current working directory |
| check | check packages(s) |
| const | display constant(s) |
| deps | display dependencies of package(s) |
| download | download package(s) to CREW_BREW_DIR (/usr/local/tmp/crew by default), but don't install |

View File

@@ -43,6 +43,7 @@ DOC = <<~DOCOPT
Usage:
crew build [options] [-k|--keep] <name> ...
crew check [-V|--version] [-v|--verbose] <name> ...
crew const [options] [<name> ...]
crew deps [options] [--deep] [-t|--tree] [-b|--include-build-deps] [--exclude-buildessential] <name> ...
crew download [options] [-s|--source] <name> ...
@@ -54,7 +55,7 @@ DOC = <<~DOCOPT
crew prop
crew reinstall [options] [-k|--keep] [-s|--source] [-S|--recursive-build] <name> ...
crew remove [options] <name> ...
crew search [options] [<name> ...]
crew search [options] [-v|--verbose] [<name> ...]
crew sysinfo [options]
crew test [<name> ...]
crew update [options] [<compatible>]
@@ -102,15 +103,19 @@ rescue Docopt::Exit => e
exit 0
end
unless %w[-h --help].include?(ARGV[0])
puts "Could not understand \"crew #{ARGV.join(' ')}\".".lightred
# Looking for similar commands
unless @cmds.include?(ARGV[0])
similar = @cmds.select { |word| edit_distance(ARGV[0], word) < 4 }
unless similar.empty?
abort <<~EOT
Did you mean?
#{similar.join("\n ")}
EOT
if DOC.include?("crew #{ARGV[0]} ")
puts 'Missing or invalid argument(s).'.lightred
else
puts "Could not understand \"crew #{ARGV.join(' ')}\".".lightred
# Looking for similar commands
unless @cmds.include?(ARGV[0])
similar = @cmds.select { |word| edit_distance(ARGV[0], word) < 4 }
unless similar.empty?
abort <<~EOT
Did you mean?
#{similar.join("\n ")}
EOT
end
end
end
end
@@ -126,6 +131,7 @@ String.use_color = args['--color'] || !args['--no-color']
@opt_verbose = args['--verbose']
@opt_source = args['--source']
@opt_recursive = args['--recursive-build']
@opt_version = args['--version']
# Verbose options
@fileutils_verbose = @opt_verbose
@@ -1860,6 +1866,21 @@ def build_command(args)
puts "Builds are located in #{CREW_LOCAL_BUILD_DIR}.".yellow
end
def check_command(args)
args['<name>'].each do |name|
search name
if @opt_version
Dir.chdir CREW_PACKAGES_PATH do
system "../tools/version.rb #{name} #{@short_verbose}"
end
else
Dir.chdir CREW_PACKAGES_PATH do
system "../tests/prop_test #{name}"
end
end
end
end
def const_command(args)
args['<name>'].each do |name|
Command.const(name)

View File

@@ -12,6 +12,13 @@ class Command
If `-k` or `--keep` is present, the `CREW_BREW_DIR` (#{CREW_BREW_DIR}) directory will remain.
If `-v` or `--verbose` is present, extra information will be displayed.
EOT
when 'check'
puts <<~EOT
Check package(s) for syntax errors and upstream updates.
Usage: crew check [-V|--version] [-v|--verbose] <package1> [<package2> ...]
If `-V` or `--version` is present, it will search for an upstream update.
If `-v` or `--verbose` is present, up to date packages will be displayed.
EOT
when 'const'
puts <<~EOT
Display constant(s).
@@ -154,7 +161,7 @@ class Command
else
puts <<~EOT
Usage: crew help <command>
Available commands: build, const, deps, download, files, help, install, list, postinstall, prop, reinstall, remove, search, sysinfo, update, upgrade, upload, whatprovides, license, version
Available commands: build, check, const, deps, download, files, help, install, license, list, postinstall, prop, reinstall, remove, search, sysinfo, test, update, upgrade, upload, version, whatprovides
EOT
end
end

View File

@@ -1,7 +1,7 @@
# lib/const.rb
# Defines common constants used in different parts of crew
CREW_VERSION = '1.45.3'
CREW_VERSION = '1.45.4'
# kernel architecture
KERN_ARCH = `uname -m`.chomp

View File

@@ -10,9 +10,8 @@ class Package
:git_branch, :git_hashtag, :min_glibc
boolean_property :arch_flags_override, :conflicts_ok, :git_clone_deep, :git_fetchtags, :gnome, :is_fake, :is_musl, :is_static,
:no_compile_needed, :no_compress, :no_env_options, :no_fhs, :no_git_submodules,
:no_links, :no_lto, :no_patchelf, :no_shrink, :no_source_build, :no_strip, :no_zstd, :patchelf,
:print_source_bashrc, :run_tests
:no_compile_needed, :no_compress, :no_env_options, :no_fhs, :no_git_submodules, :no_links, :no_lto, :no_patchelf,
:no_shrink, :no_source_build, :no_strip, :no_upstream_update, :no_zstd, :patchelf, :print_source_bashrc, :run_tests
create_placeholder :preflight, # Function for checks to see if install should occur.
:patch, # Function to perform patch operations prior to build from source.

View File

@@ -24,6 +24,7 @@ class Atkmm16 < Meson
depends_on 'libsigcplusplus' # R
gnome
no_upstream_update
meson_options '-Dbuild-documentation=false'
end

View File

@@ -17,6 +17,8 @@ class Autoconf213 < Package
x86_64: '98f744a5a7ae84583997e57ec03dcc6ce1f962b6316bd6d4c54a6c3ebaad5a36'
})
no_upstream_update
def self.build
system "env #{CREW_ENV_OPTIONS} \
./configure #{CREW_OPTIONS} \

View File

@@ -8,10 +8,11 @@ class Broadway < Package
compatibility 'x86_64 aarch64 armv7l'
source_url 'SKIP'
no_compile_needed
depends_on 'gtk3'
no_compile_needed
no_upstream_update
def self.build
@broadwayenv = <<~BROADWAYENVEOF
GDK_BACKEND=broadway

View File

@@ -24,6 +24,8 @@ class Cairomm_1_0 < Meson
depends_on 'libxrender' => :build
depends_on 'libxxf86vm' => :build
no_upstream_update
meson_options '-Dbuild-documentation=false \
-Dbuild-examples=false'
end

View File

@@ -24,6 +24,8 @@ class Cairomm_1_16 < Meson
depends_on 'libxrender' => :build
depends_on 'libxxf86vm' => :build
no_upstream_update
meson_options '-Dbuild-documentation=false \
-Dbuild-examples=false'
end

View File

@@ -3,38 +3,38 @@ require 'package'
class Clear_cache < Package
description 'Script to remove system cache files'
homepage 'https://github.com/chromebrew/chromebrew/wiki/FAQ'
version '1.0'
version '1.1'
license 'GPL-3+'
compatibility 'all'
source_url 'SKIP'
no_upstream_update
def self.build
system "cat << 'EOF' > clear-cache
#!/bin/bash
cd \$HOME
SPACE_BEFORE=\$(du -s | cut -f1)
SPACE_BEFORE_HUMAN=\$(du -hs | cut -f1)
DIRS=\".cache Cache Application_Cache Code_Cache GCache GPUCache Service_Worker\"
for D in \$DIRS; do
DIR=\$(echo \$D | sed \'s,_, ,\')
[ -d \"\$DIR\" ] && rm -rf \"\$DIR\"
done
SPACE_AFTER=\$(du -s | cut -f1)
SPACE_AFTER_HUMAN=\$(du -hs | cut -f1)
SPACE_RECOVERED=\$((\$SPACE_BEFORE-\$SPACE_AFTER))
echo \"Space used before: \$SPACE_BEFORE_HUMAN\"
echo \"Space used after: \$SPACE_AFTER_HUMAN\"
echo \"Space recovered: \${SPACE_RECOVERED}KB\"
EOF"
File.write 'clear-cache', <<~EOF
#!/bin/bash
cd $HOME
SPACE_BEFORE=$(du -s | cut -f1)
SPACE_BEFORE_HUMAN=$(du -hs | cut -f1)
DIRS=".cache Cache Application_Cache Code_Cache GCache GPUCache Service_Worker"
for D in $DIRS; do
DIR=$(echo $D | sed 's,_, ,')
[ -d "$DIR" ] && rm -rf "$DIR"
done
SPACE_AFTER=$(du -s | cut -f1)
SPACE_AFTER_HUMAN=$(du -hs | cut -f1)
SPACE_RECOVERED=$(($SPACE_BEFORE-$SPACE_AFTER))
echo "Space used before: $SPACE_BEFORE_HUMAN"
echo "Space used after: $SPACE_AFTER_HUMAN"
echo "Space recovered: ${SPACE_RECOVERED}KB"
EOF
end
def self.install
system "install -Dm755 clear-cache #{CREW_DEST_PREFIX}/bin/clear-cache"
FileUtils.install 'clear-cache', "#{CREW_DEST_PREFIX}/bin/clear-cache", mode: 0o755
end
def self.postinstall
puts
puts "Type 'clear-cache' to remove system cache files.".lightblue
puts
ExitMessage.add "\nType 'clear-cache' to remove system cache files.\n".lightblue
end
end

View File

@@ -22,6 +22,8 @@ class Docbook_xml412 < Package
depends_on 'libxml2'
depends_on 'xmlcatmgr'
no_upstream_update
def self.install
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"
system "cp -dr docbook.cat *.dtd ent/ *.mod #{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"

View File

@@ -22,6 +22,8 @@ class Docbook_xml42 < Package
depends_on 'libxml2'
depends_on 'xmlcatmgr'
no_upstream_update
def self.install
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"
system "cp -dr docbook.cat *.dtd ent/ *.mod #{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"

View File

@@ -22,6 +22,8 @@ class Docbook_xml43 < Package
depends_on 'libxml2'
depends_on 'xmlcatmgr'
no_upstream_update
def self.install
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"
system "cp -dr docbook.cat *.dtd ent/ *.mod #{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"

View File

@@ -22,6 +22,8 @@ class Docbook_xml44 < Package
depends_on 'xmlcatmgr'
depends_on 'libxml2'
no_upstream_update
def self.install
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"
system "cp -dr docbook.cat *.dtd ent/ *.mod #{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"

View File

@@ -22,6 +22,8 @@ class Docbook_xml45 < Package
depends_on 'xmlcatmgr'
depends_on 'libxml2'
no_upstream_update
def self.install
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"
system "cp -dr docbook.cat *.dtd ent/ *.mod #{CREW_DEST_PREFIX}/share/xml/docbook/xml-dtd-#{@_ver}"

View File

@@ -22,6 +22,8 @@ class Docbook_xml50 < Package
depends_on 'libxml2'
depends_on 'xmlcatmgr'
no_upstream_update
def self.install
system "xmlcatalog --noout --create docbook-#{@_ver}.xml"
# DTD

View File

@@ -22,6 +22,8 @@ class Docbook_xml51 < Package
depends_on 'libxml2'
depends_on 'xmlcatmgr'
no_upstream_update
def self.install
system "xmlcatalog --noout --create docbook-#{@_ver}.xml"

View File

@@ -22,6 +22,8 @@ class Docbook_xsl_nons < Package
depends_on 'libxml2'
depends_on 'xmlcatmgr'
no_upstream_update
def self.patch
downloader 'https://github.com/archlinux/svntogit-packages/raw/packages/docbook-xsl/trunk/765567_non-recursive_string_subst.patch',
'193ec26dcb37bdf12037ed4ea98d68bd550500c8e96b719685d76d7096c3f9b3'

View File

@@ -13,8 +13,9 @@ class Glibc_build223 < Package
depends_on 'texinfo' => :build
depends_on 'hashpipe' => :build
no_env_options
conflicts_ok
no_env_options
no_upstream_update
@libc_version = LIBC_VERSION
version '2.23-6'

View File

@@ -13,8 +13,9 @@ class Glibc_build227 < Package
depends_on 'texinfo' => :build
depends_on 'hashpipe' => :build
no_env_options
conflicts_ok
no_env_options
no_upstream_update
@libc_version = LIBC_VERSION
version '2.27-1'

View File

@@ -13,8 +13,9 @@ class Glibc_build232 < Package
depends_on 'texinfo' => :build
depends_on 'hashpipe' => :build
no_env_options
conflicts_ok
no_env_options
no_upstream_update
@libc_version = LIBC_VERSION
version '2.32-3'

View File

@@ -13,8 +13,9 @@ class Glibc_build233 < Package
depends_on 'texinfo' => :build
depends_on 'hashpipe' => :build
no_env_options
conflicts_ok
no_env_options
no_upstream_update
@libc_version = LIBC_VERSION
version '2.33-3'

View File

@@ -13,8 +13,9 @@ class Glibc_build235 < Package
depends_on 'texinfo' => :build
depends_on 'hashpipe' => :build
no_env_options
conflicts_ok
no_env_options
no_upstream_update
@libc_version = LIBC_VERSION
version '2.35-1'

View File

@@ -19,6 +19,8 @@ class Glibc_dev235 < Package
depends_on 'glibc_build235' => :build
depends_on 'glibc_lib235' # R
no_upstream_update
def self.preflight
abort 'Glibc_lib requires glibc = 2.35.' unless Gem::Version.new(LIBC_VERSION.to_s) == Gem::Version.new('2.35')
end

View File

@@ -19,6 +19,7 @@ class Glibc_lib235 < Package
depends_on 'glibc_build235' => :build
conflicts_ok
no_upstream_update
def self.preflight
abort 'Glibc_lib requires glibc = 2.35.' unless Gem::Version.new(LIBC_VERSION.to_s) == Gem::Version.new('2.35')

View File

@@ -23,6 +23,7 @@ class Glibmm_2_4 < Meson
depends_on 'mm_common' => :build
gnome
no_upstream_update
meson_options '-Dbuild-documentation=false'
end

View File

@@ -24,6 +24,7 @@ class Glibmm_2_68 < Meson
depends_on 'mm_common' => :build
gnome
no_upstream_update
meson_options '-Dbuild-documentation=false'
end

View File

@@ -48,6 +48,7 @@ class Gtk2 < Package
depends_on 'sommelier' unless ARCH == 'i686' # L
gnome
no_upstream_update
def self.build
system "#{CREW_ENV_OPTIONS} \

View File

@@ -69,6 +69,7 @@ class Gtk3 < Meson
gnome
no_fhs
no_upstream_update
def self.patch
# Use locally build subprojects

View File

@@ -21,6 +21,7 @@ class Gtkmm2 < Autotools
depends_on 'pangomm'
gnome
no_upstream_update
def self.patch
# fix the documents directory name

View File

@@ -28,6 +28,7 @@ class Gtkmm3 < Meson
depends_on 'pangomm_1_4' # R
gnome
no_upstream_update
meson_options '--default-library=both \
-Dbuild-documentation=false \

View File

@@ -32,6 +32,7 @@ class Gtkmm4 < Meson
depends_on 'vulkan_headers' => :build
gnome
no_upstream_update
meson_options '-Dbuild-documentation=false'
end

View File

@@ -39,6 +39,7 @@ class Gtksourceview_3 < Autotools
depends_on 'zlibpkg' # R
gnome
no_upstream_update
configure_options '--enable-glade-catalog --enable-gtk-doc --disable-gtk-doc-html'
end

View File

@@ -37,6 +37,7 @@ class Gtksourceview_4 < Meson
depends_on 'zlibpkg' # R
gnome
no_upstream_update
def self.patch
system "sed -i 's/-fstack-protector-strong/-flto=auto/g' meson.build"

View File

@@ -37,6 +37,7 @@ class Gtksourceview_5 < Meson
depends_on 'pcre2' # R
gnome
no_upstream_update
def self.patch
system "sed -i 's/-fstack-protector-strong/-flto=auto/g' meson.build"

View File

@@ -36,6 +36,8 @@ class Imagemagick6 < Autotools
depends_on 'zstd'
depends_on 'sommelier'
no_upstream_update
def self.preinstall
imver = `stream -version 2> /dev/null | head -1 | cut -d' ' -f3`.chomp
abort "ImageMagick version #{imver} already installed.".lightgreen unless imver.to_s == ''

View File

@@ -65,6 +65,8 @@ class Imagemagick7 < Autotools
depends_on 'zlibpkg' # R
depends_on 'zstd' # R
no_upstream_update
def self.preinstall
imver = `stream -version 2> /dev/null | head -1 | cut -d' ' -f3`.chomp
abort "ImageMagick version #{imver} already installed.".lightgreen unless imver.to_s == ''

View File

@@ -30,6 +30,8 @@ class Js102 < Package
depends_on 'rust' => :build
depends_on 'zlibpkg' # R
no_upstream_update
@rust_default_host = case ARCH
when 'aarch64', 'armv7l'
'armv7-unknown-linux-gnueabihf'

View File

@@ -34,6 +34,8 @@ class Js115 < Package
depends_on 'rust' => :build
depends_on 'zlibpkg' # R
no_upstream_update
@rust_default_host = case ARCH
when 'aarch64', 'armv7l'
'armv7-unknown-linux-gnueabihf'

View File

@@ -22,6 +22,8 @@ class Js78 < Package
depends_on 'llvm16_dev' => :build
depends_on 'nspr'
no_upstream_update
@rust_default_host = case ARCH
when 'aarch64', 'armv7l'
'armv7-unknown-linux-gnueabihf'

View File

@@ -22,6 +22,8 @@ class Js91 < Package
depends_on 'llvm16_dev' => :build
depends_on 'nspr'
no_upstream_update
@rust_default_host = case ARCH
when 'aarch64', 'armv7l'
'armv7-unknown-linux-gnueabihf'

View File

@@ -20,6 +20,8 @@ class Libsigcplusplus < Package
depends_on 'gcc_lib' # R
depends_on 'glibc' # R
no_upstream_update
def self.build
system "meson setup #{CREW_MESON_OPTIONS} \
-Dbuild-deprecated-api=true \

View File

@@ -20,6 +20,8 @@ class Libsigcplusplus3 < Package
depends_on 'gcc_lib' # R
depends_on 'glibc' # R
no_upstream_update
def self.build
system "meson setup #{CREW_MESON_OPTIONS} \
-Dbuild-examples=false \

View File

@@ -9,6 +9,7 @@ class Linter < Package
source_url 'SKIP'
no_compile_needed
no_upstream_update
depends_on 'py3_codespell'
depends_on 'ruby_mdl'

View File

@@ -5,7 +5,7 @@ class HelpCommandTest < Minitest::Test
def test_no_arguments
expected_output = <<~EOT
Usage: crew help <command>
Available commands: build, const, deps, download, files, help, install, list, postinstall, prop, reinstall, remove, search, sysinfo, update, upgrade, upload, whatprovides, license, version
Available commands: build, check, const, deps, download, files, help, install, license, list, postinstall, prop, reinstall, remove, search, sysinfo, test, update, upgrade, upload, version, whatprovides
EOT
assert_output expected_output, nil do
Command.help(nil, nil)

View File

@@ -7,22 +7,49 @@ require_relative '../lib/package'
# Add >LOCAL< lib to LOAD_PATH so that packages can be loaded
$LOAD_PATH.unshift File.join(CREW_LIB_PATH, 'lib')
tofail = 0
Dir.glob('../packages/*.rb').each do |filename|
pkg = Package.load_package(filename)
name = File.basename(filename, '.rb').gsub('_', '-')
puts "#{name} is missing a description." if pkg.description.to_s.empty?
puts "#{name} is missing a homepage." if pkg.homepage.to_s.empty?
puts "#{name} is missing a version." if pkg.version.to_s.empty?
puts "#{name} is missing a license." if pkg.license.to_s.empty?
puts "#{name} is missing a compatibility property." if pkg.compatibility.to_s.empty?
tofail += 1 if pkg.description.to_s.empty? || pkg.homepage.to_s.empty? || pkg.version.to_s.empty? || pkg.license.to_s.empty? || pkg.compatibility.to_s.empty?
def check_properties(name)
puts "Checking #{name} package ...".yellow
puts "#{name} is missing a description.".lightred if @pkg.description.to_s.empty?
puts "#{name} is missing a homepage.".lightred if @pkg.homepage.to_s.empty?
puts "#{name} is missing a version.".lightred if @pkg.version.to_s.empty?
puts "#{name} is missing a license.".lightred if @pkg.license.to_s.empty?
puts "#{name} is missing a compatibility.".lightred if @pkg.compatibility.to_s.empty?
if @pkg.description.to_s.empty? || @pkg.homepage.to_s.empty? || @pkg.version.to_s.empty? || @pkg.license.to_s.empty? || @pkg.compatibility.to_s.empty?
puts "Property tests for #{name} failed.".lightred
@tofail += 1
else
puts "Property tests for #{name} passed.".lightgreen
end
end
if tofail.positive?
puts "\n#{tofail} failing packages."
exit(1) if tofail.positive?
@tofail = 0
warn_level = $VERBOSE
$VERBOSE = nil
if ARGV[0]
ARGV.each do |arg|
next if %w[-V --version].include?(arg)
if File.file? "../packages/#{arg}.rb"
@pkg = Package.load_package("../packages/#{arg}.rb")
check_properties(arg)
else
puts "Package #{arg} not found.".lightred
end
end
else
puts "\nAll property tests successful.".lightgreen
Dir['../packages/*.rb'].each do |filename|
@pkg = Package.load_package(filename)
name = File.basename(filename, '.rb').gsub('_', '-')
check_properties(name)
end
if @tofail.positive?
puts "\n#{@tofail} packages failed property tests.".lightred
exit(1)
else
puts "\nAll packages passed property tests.".lightgreen
end
end
$VERBOSE = warn_level

151
tools/version.rb Executable file
View File

@@ -0,0 +1,151 @@
#!/usr/bin/env ruby
if ARGV.include?('-h') || ARGV.include?('--help')
abort "Usage: ./version.rb [<package>] [-h, --help, -v, --verbose]
Example: ./version.rb abcde -v
The <package> can contain '*': ./version.rb xorg_*
If <package> is omitted, all packages will be checked."
end
require 'json'
require 'net/http'
# Add >LOCAL< lib to LOAD_PATH
$LOAD_PATH.unshift '../lib'
require_relative '../lib/color'
require_relative '../lib/package'
def get_version(name, homepage)
anitya_id = get_anitya_id(name, homepage)
# If we weren't able to get an Anitya ID, return early here to save time and headaches
return '' if anitya_id.nil?
# Get the latest version of the package
json = JSON.parse(Net::HTTP.get(URI("https://release-monitoring.org/api/v2/versions/?project_id=#{anitya_id}")))
return '' if json['latest_version'].nil?
return json['latest_version'].chomp
end
def get_anitya_id(name, homepage)
# Find out how many packages Anitya has with the provided name.
json = JSON.parse(Net::HTTP.get(URI("https://release-monitoring.org/api/v2/projects/?name=#{name}")))
number_of_packages = json['total_items']
if number_of_packages == 1 # We assume we have the right package, take the ID and move on.
return json['items'][0]['id']
elsif number_of_packages.zero? # Anitya either doesn't have this package, or has it under a different name.
# If it has it under a different name, check if it has the name used by Chromebrew.
json2 = JSON.parse(Net::HTTP.get(URI("https://release-monitoring.org/api/v2/packages/?name=#{name}")))
return if (json2['total_items']).zero?
(0..json2['total_items'] - 1).each do |i|
next unless json2['items'][i]['distribution'] == 'Chromebrew'
return get_anitya_id(json2['items'][i]['project'], homepage) if json2['items'][i]['name'] == name
end
else # Anitya has more than one package with this exact name.
candidates = []
# First, we remove any candidates which are provided by language package managers, such as pip.
# This is because Chromebrew does not repackage them (#7713), so they won't be what we're looking for.
(0..number_of_packages - 1).each do |i|
# If a package is not provided by a language package manager, the ecosystem will be set to the homepage.
# https://release-monitoring.org/static/docs/api.html#get--api-v2-projects-
candidates.append(i) if json['items'][i]['ecosystem'] == json['items'][i]['homepage']
end
if candidates.length == 1 # If there's only one candidate left, we're done.
return json['items'][candidates[0]]['id']
elsif candidates.empty? # The package we're looking for is provided by a language package manager.
# We probably shouldn't be providing this package.
return
else # There are still multiple candidates left.
# This is where things get a little uncertain.
# We check if the homepage Anitya has matches ours, but this really only works for Github projects.
# For other projects, there's a lot more opinion involved in choosing the exact homepage.
# Nevertheless, its our best shot at this point.
candidates.each do |candidate|
# We assume there is only one candidate with the same name and homepage as their crew counterpart.
# Even if there are multiple candidates with the same name and homepage, its probably fine to treat them as identical.
# If it isn't fine to treat them as identical, something has gone horribly wrong.
return json['items'][candidate]['id'] if homepage == json['items'][candidate]['homepage']
end
# If we're still here, that means none of the candidates had the same homepage as their crew counterpart.
# Not much we can do at this point to find the version, and its better to be cautious to avoid getting the wrong candidate.
return
end
end
end
# Check for valid semantic version.
def valid_semantic_version?(version)
valid = (version =~ /^[0-9a-zA-Z\.\-]*$/)
return valid
end
filelist = []
verbose = ARGV.include?('-v') || ARGV.include?('--verbose')
if ARGV.length.positive? && !(ARGV.length == 1 && verbose)
ARGV.each do |arg|
next unless arg =~ /^[0-9a-zA-Z\_\*]+$/
if arg.include?('*')
Dir["../packages/#{arg}.rb"].each do |filename|
filelist.push filename
end
else
filename = "../packages/#{arg}.rb"
filelist.push filename if File.exist?(filename)
end
end
else
Dir['../packages/*.rb'].each do |filename|
filelist.push filename
end
end
if filelist.length.positive?
puts "#{'Package'.ljust(35)}#{'Status'.ljust(20)}#{'Current'.ljust(20)}Upstream"
puts "#{'-------'.ljust(35)}#{'------'.ljust(20)}#{'-------'.ljust(20)}--------"
filelist.each do |filename|
pkg = Package.load_package(filename)
# Instead of typing out the name of every python package, we just use a regex here
if pkg.name.match?(/py3\S+/)
puts pkg.name.ljust(35) + 'noupdate'.lightred if verbose
next
end
# Package is fake
if pkg.is_fake?
puts pkg.name.ljust(35) + 'fake'.lightred if verbose
next
end
# No upstream update available
if pkg.no_upstream_update?
puts pkg.name.ljust(35) + 'noupdate'.lightred if verbose
next
end
# Some packages don't work with this yet, so gracefully exit now rather than throwing false positives
upstream_version = get_version(pkg.name.tr('_', '-'), pkg.homepage)
if upstream_version.nil?
puts pkg.name.ljust(35) + 'notfound'.lightred if verbose
next
end
status = if upstream_version == pkg.version
'uptodate'.ljust(20).lightgreen
elsif upstream_version.empty? || pkg.version.empty?
'notfound'.ljust(20).lightred
elsif valid_semantic_version?(upstream_version) && valid_semantic_version?(pkg.version)
if Gem::Version.correct?(upstream_version) && Gem::Version.correct?(pkg.version)
if Gem::Version.new(upstream_version) > Gem::Version.new(pkg.version)
'outdated'.ljust(20).yellow
else
'mismatch'.ljust(20).orange
end
else
'notvalid'.ljust(20).lightred
end
else
'notvalid'.ljust(20).lightred
end
puts pkg.name.ljust(35) + status + pkg.version.ljust(20) + upstream_version unless !verbose && status == 'uptodate'.ljust(20).lightgreen
end
end