Split prop command into separate file (#9514)

This commit is contained in:
Maximilian Downey Twiss
2024-04-03 18:23:27 +11:00
committed by GitHub
parent 8826213d75
commit d13b6dbf9b
7 changed files with 131 additions and 88 deletions

View File

@@ -22,7 +22,9 @@ jobs:
yes | crew remove vim && \
ruby ../tests/prop_test && \
ruby ../tests/buildsystem_test && \
ruby ../tests/commands/* && \
ruby ../tests/commands/const.rb && \
ruby ../tests/commands/help.rb && \
ruby ../tests/commands/prop.rb && \
cd ~ && \
git clone --depth=1 https://github.com/chromebrew/chromebrew.git build_test && \
cd build_test && \

View File

@@ -7,6 +7,7 @@ require 'tmpdir'
require_relative '../commands/const'
require_relative '../commands/help'
require_relative '../commands/list'
require_relative '../commands/prop'
require_relative '../commands/sysinfo'
require_relative '../lib/color'
require_relative '../lib/const'
@@ -294,16 +295,6 @@ def files(pkg_name)
EOT
end
def prop(silent = false)
props = Package.print_boolean_properties
if silent
return props
else
puts props
puts "For more information, type 'crew help prop <property>' where <property> is one of the above properties.".lightblue
end
end
def whatprovides(regex_pat)
matched_list = `grep -R "#{regex_pat}" #{CREW_LIB_PATH}/manifest/#{ARCH}`.lines(chomp: true).flat_map do |result|
filelist, matched_file = result.split(':', 2)
@@ -1859,7 +1850,7 @@ def files_command(args)
end
def help_command(args)
Command.help(args['<command>'], args['<subcommand>'])
Command.help(args['<command>'])
end
def install_command(args)
@@ -1901,8 +1892,8 @@ def postinstall_command(args)
end
end
def prop_command(_)
prop
def prop_command(args)
Command.prop(args['<property>'])
end
def reinstall_command(args)

View File

@@ -1,7 +1,8 @@
require_relative '../lib/const'
require_relative '../lib/package'
class Command
def self.help(command, property)
def self.help(command)
case command
when 'build'
puts <<~EOT
@@ -75,7 +76,11 @@ class Command
The package(s) must be currently installed.
EOT
when 'prop'
help_prop(property)
puts <<~EOT
Explain the purpose of various package boolean properties.
Usage: crew prop <property>
Available properties: #{Package.print_boolean_properties}
EOT
when 'reinstall'
puts <<~EOT
Remove and install package(s).
@@ -166,63 +171,3 @@ class Command
end
end
end
def help_prop(property)
if property
case property
when 'conflicts_ok'
puts "The 'conflicts_ok' property bypasses checks for other package file conflicts."
when 'git_clone_deep'
puts "The 'git_clone_deep' property clones the repository without a depth value."
puts "Applicable only when 'source_url' is a git repository."
when 'git_fetchtags'
puts "The 'git_fetchtags' property gets the repository tags."
puts "Applicable only when 'source_url' is a git repository."
when 'is_fake'
puts "Use the 'is_fake' property for packages that simply depend on other packages."
when 'is_musl'
puts "Use the 'is_musl' property for musl specific packages."
when 'is_static'
puts "Use the 'is_static' property for packages which do not require shared dependencies."
when 'no_compile_needed'
puts "Use the 'no_compile_needed' property for packages that do not require pre-built binaries."
when 'no_compress'
puts "Use the 'no_compress' property for packages that do not need compressed files."
when 'no_env_options'
puts "Use the 'no_env_options' property for packages that do not require"
puts 'environment options or to override the default options.'
when 'no_fhs'
puts "The 'no_fhs' property bypasses FHS3 compliance checks."
when 'no_git_submodules'
puts "Use the 'no_git_submodules' property for repositories without git submodules."
puts "Applicable only when 'source_url' is a git repository."
when 'no_links'
puts "Use the 'no_links' property to bypass checks for duplicate links."
when 'no_patchelf'
puts "Use the 'no_patchelf' property to bypass patchelf execution."
when 'no_shrink'
puts "Use the 'no_shrink' property to bypass upx binary compression."
when 'no_source_build'
puts "Use the 'no_source_build' property to build even if source is unspecified or unavailable."
when 'no_strip'
puts "Use the 'no_strip' property to bypass strip execution."
when 'no_lto'
puts "Use the 'no_lto' property to bypass lto usage."
when 'no_zstd'
puts "Use the 'no_zstd' property for the alternate xz compression algorithm."
when 'patchelf'
puts "Use the 'patchelf' property for patchelf execution."
when 'print_source_bashrc'
puts "Prints 'source ~/.bashrc' message at end of install."
when 'run_tests'
puts "Use the 'run_tests' property to execute make check tests."
else
abort "Invalid property '#{property}'".lightred
end
else
puts <<~EOT
Display all available package boolean properties.
Usage: crew prop
EOT
end
end

67
commands/prop.rb Normal file
View File

@@ -0,0 +1,67 @@
require_relative '../lib/package'
class Command
def self.prop(property)
case property
when 'arch_flags_override'
puts "Use the 'arch_flags_override' property to override architecture specific flags."
when 'conflicts_ok'
puts "The 'conflicts_ok' property bypasses checks for other package file conflicts."
when 'git_clone_deep'
puts "The 'git_clone_deep' property clones the repository without a depth value."
puts "Applicable only when 'source_url' is a git repository."
when 'git_fetchtags'
puts "The 'git_fetchtags' property gets the repository tags."
puts "Applicable only when 'source_url' is a git repository."
when 'gnome'
puts "Use the 'gnome' property to include options for gnome specific packages."
when 'is_fake'
puts "Use the 'is_fake' property for packages that simply depend on other packages."
when 'is_musl'
puts "Use the 'is_musl' property for musl specific packages."
when 'is_static'
puts "Use the 'is_static' property for packages which do not require shared dependencies."
when 'no_compile_needed'
puts "Use the 'no_compile_needed' property for packages that do not require pre-built binaries."
when 'no_compress'
puts "Use the 'no_compress' property for packages that do not need compressed files."
when 'no_env_options'
puts "Use the 'no_env_options' property for packages that do not require"
puts 'environment options or to override the default options.'
when 'no_fhs'
puts "The 'no_fhs' property bypasses FHS3 compliance checks."
when 'no_git_submodules'
puts "Use the 'no_git_submodules' property for repositories without git submodules."
puts "Applicable only when 'source_url' is a git repository."
when 'no_links'
puts "Use the 'no_links' property to bypass checks for duplicate links."
when 'no_lto'
puts "Use the 'no_lto' property to bypass lto usage."
when 'no_patchelf'
puts "Use the 'no_patchelf' property to bypass patchelf execution."
when 'no_shrink'
puts "Use the 'no_shrink' property to bypass upx binary compression."
when 'no_source_build'
puts "Use the 'no_source_build' property to build even if source is unspecified or unavailable."
when 'no_strip'
puts "Use the 'no_strip' property to bypass strip execution."
when 'no_upstream_update'
puts "Use the 'no_upstream_update' property for packages that cannot be updated from an upstream repository."
when 'no_zstd'
puts "Use the 'no_zstd' property for the alternate xz compression algorithm."
when 'patchelf'
puts "Use the 'patchelf' property for patchelf execution."
when 'print_source_bashrc'
puts "Prints 'source ~/.bashrc' message at end of install."
when 'run_tests'
puts "Use the 'run_tests' property to execute make check tests."
else
puts <<~EOT
Explain the purpose of various package boolean properties.
Usage: crew prop <property>
Available properties: #{Package.print_boolean_properties}
EOT
end
end
end

View File

@@ -1,7 +1,7 @@
# lib/const.rb
# Defines common constants used in different parts of crew
CREW_VERSION = '1.46.0'
CREW_VERSION = '1.46.1'
# kernel architecture
KERN_ARCH = `uname -m`.chomp
@@ -338,7 +338,7 @@ CREW_DOCOPT = <<~DOCOPT
Usage:
crew build [options] [-k|--keep] [-v|--verbose] <name> ...
crew check [-V|--version] [-v|--verbose] <name> ...
crew const [options] [-v|--verbose] [<name> ...]
crew const [-v|--verbose] [<name> ...]
crew deps [options] [--deep] [-t|--tree] [-b|--include-build-deps] [--exclude-buildessential] [-v|--verbose] <name> ...
crew download [options] [-s|--source] [-v|--verbose] <name> ...
crew files [options] [-v|--verbose] <name> ...
@@ -346,7 +346,7 @@ CREW_DOCOPT = <<~DOCOPT
crew install [options] [-k|--keep] [-s|--source] [-S|--recursive-build] [-v|--verbose] <name> ...
crew list [options] [-v|--verbose] (available|installed|compatible|incompatible)
crew postinstall [options] [-v|--verbose] <name> ...
crew prop [-v|--verbose]
crew prop [<property>]
crew reinstall [options] [-k|--keep] [-s|--source] [-S|--recursive-build] [-v|--verbose] <name> ...
crew remove [options] [-v|--verbose] <name> ...
crew search [options] [-v|--verbose] [<name> ...]

View File

@@ -1,5 +1,6 @@
require 'minitest/autorun'
require_relative '../../commands/help'
require_relative '../../lib/package'
class HelpCommandTest < Minitest::Test
def test_no_arguments
@@ -8,7 +9,18 @@ class HelpCommandTest < Minitest::Test
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)
Command.help(nil)
end
end
def test_prop_command
expected_output = <<~EOT
Explain the purpose of various package boolean properties.
Usage: crew prop <property>
Available properties: #{Package.print_boolean_properties}
EOT
assert_output expected_output, nil do
Command.help('prop')
end
end
@@ -19,14 +31,7 @@ class HelpCommandTest < Minitest::Test
If no constants are provided, all constants will be displayed.
EOT
assert_output expected_output, nil do
Command.help('const', nil)
end
end
def test_prop_command
expected_output = "Use the 'is_static' property for packages which do not require shared dependencies.\n"
assert_output expected_output, nil do
Command.help('prop', 'is_static')
Command.help('const')
end
end
end

33
tests/commands/prop.rb Normal file
View File

@@ -0,0 +1,33 @@
require 'minitest/autorun'
require_relative '../../commands/prop'
require_relative '../../lib/package'
class PropCommandTest < Minitest::Test
def test_no_arguments
expected_output = <<~EOT
Explain the purpose of various package boolean properties.
Usage: crew prop <property>
Available properties: #{Package.print_boolean_properties}
EOT
assert_output expected_output, nil do
Command.prop(nil)
end
end
def test_no_env_options_property
expected_output = <<~EOT
Use the 'no_env_options' property for packages that do not require
environment options or to override the default options.
EOT
assert_output expected_output, nil do
Command.prop('no_env_options')
end
end
def test_is_static_property
expected_output = "Use the 'is_static' property for packages which do not require shared dependencies.\n"
assert_output expected_output, nil do
Command.prop('is_static')
end
end
end