mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-10 07:57:59 -05:00
crew: Add autoremove command (#6273)
* Update package.rb * Update README.md * Bump minor version Co-authored-by: Cassandra Watergate <55339220+saltedcoffii@users.noreply.github.com>
This commit is contained in:
@@ -73,6 +73,7 @@ Where available commands are:
|
||||
|
||||
| Command | Description |
|
||||
|:---|:---|
|
||||
| autoremove | remove unused dependencies installed by removed packages |
|
||||
| build | build package(s) from source and store the archive and checksum in the current working directory |
|
||||
| const | display constant(s) |
|
||||
| deps | display dependencies of package(s) |
|
||||
|
||||
203
bin/crew
203
bin/crew
@@ -19,6 +19,7 @@ DOC = <<DOCOPT
|
||||
Chromebrew - Package manager for Chrome OS http://skycocker.github.io/chromebrew/
|
||||
|
||||
Usage:
|
||||
crew autoremove [options]
|
||||
crew build [options] [-k|--keep] <name> ...
|
||||
crew const [options] [<name> ...]
|
||||
crew deps [options] <name> ...
|
||||
@@ -65,7 +66,7 @@ CREW_LICENSE = <<~LICENSESTRING
|
||||
LICENSESTRING
|
||||
|
||||
# All available crew commands.
|
||||
@cmds = ["build", "const", "deps", "download", "files", "help", "install", "list", "postinstall", "reinstall", "remove", "search", "update", "upgrade", "whatprovides"]
|
||||
@cmds = ["autoremove", "build", "const", "deps", "download", "files", "help", "install", "list", "postinstall", "reinstall", "remove", "search", "update", "upgrade", "whatprovides"]
|
||||
|
||||
# Parse arguments using docopt
|
||||
require_relative '../lib/docopt'
|
||||
@@ -307,85 +308,118 @@ end
|
||||
|
||||
def help(pkgName)
|
||||
case pkgName
|
||||
when "autoremove"
|
||||
puts <<~EOT
|
||||
Remove unused dependencies installed by removed packages
|
||||
Usage: crew autoremove
|
||||
EOT
|
||||
when "build"
|
||||
puts "Build package(s)."
|
||||
puts "Usage: crew build [-k|--keep] [-v|--verbose] <package1> [<package2> ...]"
|
||||
puts "Build package(s) from source and place the archive and checksum in the current working directory."
|
||||
puts "If `-k` or `--keep` is present, the `CREW_BREW_DIR` (#{CREW_BREW_DIR}) directory will remain."
|
||||
puts "If `-v` or `--verbose` is present, extra information will be displayed."
|
||||
puts <<~EOT
|
||||
Build package(s).
|
||||
Usage: crew build [-k|--keep] [-v|--verbose] <package1> [<package2> ...]
|
||||
Build package(s) from source and place the archive and checksum in the current working directory.
|
||||
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 "const"
|
||||
puts "Display constant(s)."
|
||||
puts "Usage: crew const [<const1> <const2> ...]"
|
||||
puts "If no constants are provided, all constants will be displayed."
|
||||
puts <<~EOT
|
||||
Display constant(s).
|
||||
Usage: crew const [<const1> <const2> ...]
|
||||
If no constants are provided, all constants will be displayed.
|
||||
EOT
|
||||
when "deps"
|
||||
puts "Display dependencies of package(s)."
|
||||
puts "Usage: crew deps <package1> [<package2> ...]"
|
||||
puts <<~EOT
|
||||
Display dependencies of package(s).
|
||||
Usage: crew deps <package1> [<package2> ...]
|
||||
EOT
|
||||
when "download"
|
||||
puts "Download package(s)."
|
||||
puts "Usage: crew download [-v|--verbose] <package1> [<package2> ...]"
|
||||
puts "Download package(s) to `CREW_BREW_DIR` (#{CREW_BREW_DIR}), but don't install."
|
||||
puts "If `-v` or `--verbose` is present, extra information will be displayed."
|
||||
puts <<~EOT
|
||||
Download package(s).
|
||||
Usage: crew download [-v|--verbose] <package1> [<package2> ...]
|
||||
Download package(s) to `CREW_BREW_DIR` (#{CREW_BREW_DIR}), but don't install.
|
||||
If `-v` or `--verbose` is present, extra information will be displayed.
|
||||
EOT
|
||||
when "files"
|
||||
puts "Display installed files of package(s)."
|
||||
puts "Usage: crew files <package1> [<package2> ...]"
|
||||
puts "The package(s) must be currently installed."
|
||||
puts <<~EOT
|
||||
Display installed files of package(s).
|
||||
Usage: crew files <package1> [<package2> ...]
|
||||
The package(s) must be currently installed.
|
||||
EOT
|
||||
when "install"
|
||||
puts "Install package(s)."
|
||||
puts "Usage: crew install [-k|--keep] [-s|--build-from-source] [-S|--recursive-build] [-v|--verbose] <package1> [<package2> ...]"
|
||||
puts "The package(s) must have a valid name. Use `crew search <pattern>` to search for packages to install."
|
||||
puts "If `-k` or `--keep` is present, the `CREW_BREW_DIR` (#{CREW_BREW_DIR}) directory will remain."
|
||||
puts "If `-s` or `--build-from-source` is present, the package(s) will be compiled instead of installed via binary."
|
||||
puts "If `-S` or `--recursive-build` is present, the package(s), including all dependencies, will be compiled instead of installed via binary."
|
||||
puts "If `-v` or `--verbose` is present, extra information will be displayed."
|
||||
puts <<~EOT
|
||||
Install package(s).
|
||||
Usage: crew install [-k|--keep] [-s|--build-from-source] [-S|--recursive-build] [-v|--verbose] <package1> [<package2> ...]
|
||||
The package(s) must have a valid name. Use `crew search <pattern>` to search for packages to install.
|
||||
If `-k` or `--keep` is present, the `CREW_BREW_DIR` (#{CREW_BREW_DIR}) directory will remain.
|
||||
If `-s` or `--build-from-source` is present, the package(s) will be compiled instead of installed via binary.
|
||||
If `-S` or `--recursive-build` is present, the package(s), including all dependencies, will be compiled instead of installed via binary.
|
||||
If `-v` or `--verbose` is present, extra information will be displayed.
|
||||
EOT
|
||||
when "list"
|
||||
puts "List packages"
|
||||
puts "Usage: crew list [-v|--verbose] available|installed|compatible|incompatible"
|
||||
puts <<~EOT
|
||||
List packages
|
||||
Usage: crew list [-v|--verbose] available|installed|compatible|incompatible
|
||||
EOT
|
||||
when "postinstall"
|
||||
puts "Display postinstall messages of package(s)."
|
||||
puts "Usage: crew postinstall <package1> [<package2> ...]"
|
||||
puts "The package(s) must be currently installed."
|
||||
puts <<~EOT
|
||||
Display postinstall messages of package(s).
|
||||
Usage: crew postinstall <package1> [<package2> ...]
|
||||
The package(s) must be currently installed.
|
||||
EOT
|
||||
when "reinstall"
|
||||
puts "Remove and install package(s)."
|
||||
puts "Usage: crew reinstall [-k|--keep] [-s|--build-from-source] [-S|--recursive-build] [-v|--verbose] <package1> [<package2> ...]"
|
||||
puts "If `-k` or `--keep` is present, the `CREW_BREW_DIR` (#{CREW_BREW_DIR}) directory will remain."
|
||||
puts "If `-s` or `--build-from-source` is present, the package(s) will be compiled instead of installed via binary."
|
||||
puts "If `-S` or `--recursive-build` is present, the package(s), including all dependencies, will be compiled instead of installed via binary."
|
||||
puts "If `-v` or `--verbose` is present, extra information will be displayed."
|
||||
puts <<~EOT
|
||||
Remove and install package(s).
|
||||
Usage: crew reinstall [-k|--keep] [-s|--build-from-source] [-S|--recursive-build] [-v|--verbose] <package1> [<package2> ...]
|
||||
If `-k` or `--keep` is present, the `CREW_BREW_DIR` (#{CREW_BREW_DIR}) directory will remain.
|
||||
If `-s` or `--build-from-source` is present, the package(s) will be compiled instead of installed via binary.
|
||||
If `-S` or `--recursive-build` is present, the package(s), including all dependencies, will be compiled instead of installed via binary.
|
||||
If `-v` or `--verbose` is present, extra information will be displayed.
|
||||
EOT
|
||||
when "remove"
|
||||
puts "Remove package(s)."
|
||||
puts "Usage: crew remove [-v|--verbose] <package1> [<package2> ...]"
|
||||
puts "The package(s) must be currently installed."
|
||||
puts "If `-v` or `--verbose` is present, extra information will be displayed."
|
||||
puts <<~EOT
|
||||
Remove package(s).
|
||||
Usage: crew remove [-v|--verbose] <package1> [<package2> ...]
|
||||
The package(s) must be currently installed.
|
||||
If `-v` or `--verbose` is present, extra information will be displayed.
|
||||
EOT
|
||||
when "search"
|
||||
puts "Look for package(s)."
|
||||
puts "Usage: crew search [-v|--verbose] [<pattern> ...]"
|
||||
puts "If <pattern> is omitted, all packages will be returned."
|
||||
puts "If the package color is " + "green".lightgreen + ", it means the package is installed."
|
||||
puts "If the package color is " + "red".lightred + ", it means the architecture is not supported."
|
||||
puts "The <pattern> string can also contain regular expressions."
|
||||
puts "If `-v` or `--verbose` is present, homepage, version and license will be displayed."
|
||||
puts "Examples:"
|
||||
puts " crew search ^lib".lightblue + " will display all packages that start with `lib`."
|
||||
puts " crew search audio".lightblue + " will display all packages with `audio` in the name."
|
||||
puts " crew search | grep -i audio".lightblue + " will display all packages with `audio` in the name or description."
|
||||
puts " crew search git -v".lightblue + " will display packages with `git` in the name along with homepage, version and license."
|
||||
puts <<~EOT
|
||||
Look for package(s).
|
||||
Usage: crew search [-v|--verbose] [<pattern> ...]
|
||||
If <pattern> is omitted, all packages will be returned.
|
||||
If the package color is " + "green".lightgreen + ", it means the package is installed.
|
||||
If the package color is " + "red".lightred + ", it means the architecture is not supported.
|
||||
The <pattern> string can also contain regular expressions.
|
||||
If `-v` or `--verbose` is present, homepage, version and license will be displayed.
|
||||
Examples:
|
||||
crew search ^lib".lightblue + " will display all packages that start with `lib`.
|
||||
crew search audio".lightblue + " will display all packages with `audio` in the name.
|
||||
crew search | grep -i audio".lightblue + " will display all packages with `audio` in the name or description.
|
||||
crew search git -v".lightblue + " will display packages with `git` in the name along with homepage, version and license.
|
||||
EOT
|
||||
when "update"
|
||||
puts "Update crew."
|
||||
puts "Usage: crew update"
|
||||
puts "This only updates crew itself. Use `crew upgrade` to update packages."
|
||||
puts "Usage: crew update compatible"
|
||||
puts "This updates the crew package compatibility list."
|
||||
puts <<~EOT
|
||||
Update crew.
|
||||
Usage: crew update
|
||||
This only updates crew itself. Use `crew upgrade` to update packages.
|
||||
Usage: crew update compatible
|
||||
This updates the crew package compatibility list.
|
||||
EOT
|
||||
when "upgrade"
|
||||
puts "Update package(s)."
|
||||
puts "Usage: crew upgrade [-v|--verbose] [-s|--build-from-source] <package1> [<package2> ...]"
|
||||
puts "If package(s) are omitted, all packages will be updated. Otherwise, specific package(s) will be updated."
|
||||
puts "Use `crew update` to update crew itself."
|
||||
puts "If `-s` or `--build-from-source` is present, the package(s) will be compiled instead of upgraded via binary."
|
||||
puts "If `-v` or `--verbose` is present, extra information will be displayed."
|
||||
puts <<~EOT
|
||||
Update package(s).
|
||||
Usage: crew upgrade [-v|--verbose] [-s|--build-from-source] <package1> [<package2> ...]
|
||||
If package(s) are omitted, all packages will be updated. Otherwise, specific package(s) will be updated.
|
||||
Use `crew update` to update crew itself.
|
||||
If `-s` or `--build-from-source` is present, the package(s) will be compiled instead of upgraded via binary.
|
||||
If `-v` or `--verbose` is present, extra information will be displayed.
|
||||
EOT
|
||||
when "whatprovides"
|
||||
puts "Determine which package(s) contains file(s)."
|
||||
puts "Usage: crew whatprovides <pattern> ..."
|
||||
puts "The <pattern> is a search string which can contain regular expressions."
|
||||
puts <<~EOT
|
||||
Determine which package(s) contains file(s).
|
||||
Usage: crew whatprovides <pattern> ...
|
||||
The <pattern> is a search string which can contain regular expressions.
|
||||
EOT
|
||||
else
|
||||
puts "Available commands: #{@cmds.join(', ')}"
|
||||
end
|
||||
@@ -1198,6 +1232,7 @@ def resolve_dependencies
|
||||
@dependencies.each do |dep|
|
||||
search dep
|
||||
print_current_package
|
||||
@pkg.is_dep = true
|
||||
install
|
||||
end
|
||||
if @resolve_dependencies_and_install == 1 or @resolve_dependencies_and_build == 1
|
||||
@@ -1257,7 +1292,7 @@ def install
|
||||
end
|
||||
|
||||
#add to installed packages
|
||||
@device[:installed_packages].push(name: @pkg.name, version: @pkg.version)
|
||||
@device[:installed_packages].push(name: @pkg.name, version: @pkg.version, is_dep: @pkg.is_dep)
|
||||
File.open(CREW_CONFIG_PATH + 'device.json', 'w') do |file|
|
||||
output = JSON.parse @device.to_json
|
||||
file.write JSON.pretty_generate(output)
|
||||
@@ -1400,6 +1435,40 @@ def remove(pkgName)
|
||||
puts "#{pkgName.capitalize} removed!".lightgreen
|
||||
end
|
||||
|
||||
def autoremove_command(args)
|
||||
deps_of_installed_pkgs = @device[:installed_packages].map do |pkg|
|
||||
# ignore deleted/non-exist package recipes
|
||||
next unless File.exist?("#{CREW_PACKAGES_PATH}/#{pkg[:name]}.rb")
|
||||
set_package pkg[:name], "#{CREW_PACKAGES_PATH}/#{pkg[:name]}.rb"
|
||||
next @pkg.dependencies
|
||||
end.flatten
|
||||
|
||||
remove_pkg = @device[:installed_packages].select do |pkg|
|
||||
pkg[:is_dep] and !deps_of_installed_pkgs.include?(pkg[:name])
|
||||
end.map {|pkg| pkg[:name] }
|
||||
|
||||
return if remove_pkg.empty?
|
||||
|
||||
puts 'The following packages also need to be REMOVED: '
|
||||
remove_pkg.each do |pkg|
|
||||
print pkg + ' '
|
||||
end
|
||||
print "\n" + 'Do you agree? [Y/n] '
|
||||
|
||||
response = STDIN.getc
|
||||
case response
|
||||
when 'n'
|
||||
abort 'No changes made.'
|
||||
when "\n", "y", "Y"
|
||||
puts 'Proceeding...'
|
||||
else
|
||||
puts "I don't understand `#{response}`. :(".lightred
|
||||
abort 'No changes made.'
|
||||
end
|
||||
|
||||
remove_pkg.each {|pkg| remove(pkg) }
|
||||
end
|
||||
|
||||
def build_command(args)
|
||||
args["<name>"].each do |name|
|
||||
@pkgName = name
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Defines common constants used in different parts of crew
|
||||
|
||||
CREW_VERSION = '1.18.2'
|
||||
CREW_VERSION = '1.19.0'
|
||||
|
||||
ARCH_ACTUAL = `uname -m`.chomp
|
||||
# This helps with virtualized builds on aarch64 machines
|
||||
|
||||
@@ -5,7 +5,7 @@ class Package
|
||||
|
||||
class << self
|
||||
attr_reader :is_fake
|
||||
attr_accessor :name, :in_build, :build_from_source
|
||||
attr_accessor :name, :is_dep, :in_build, :build_from_source
|
||||
attr_accessor :in_upgrade
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user