Commit 8f75ae33 authored by Kevin Perkins's avatar Kevin Perkins Committed by GitHub

Eliminate nested searching to speed up `crew search` (#4944)

* Eliminate nested searching to speed up `crew search`

* Bump CREW_VERSION
parent 9dd483a9
...@@ -91,8 +91,14 @@ end ...@@ -91,8 +91,14 @@ end
@device[key] = @device[key].to_sym rescue @device[key] @device[key] = @device[key].to_sym rescue @device[key]
end end
def print_package(pkgName, extra = false) def print_package(pkgPath, extra = false)
search pkgName, true pkgName = File.basename pkgPath, '.rb'
set_package pkgName, pkgPath
print_current_package extra
end
def print_current_package (extra = false)
pkgName = @pkg.name
status = '' status = ''
status = 'installed' if @device[:installed_packages].any? do |elem| elem[:name] == pkgName end status = 'installed' if @device[:installed_packages].any? do |elem| elem[:name] == pkgName end
status = 'incompatible' unless @device[:compatible_packages].any? do |elem| elem[:name] == pkgName end status = 'incompatible' unless @device[:compatible_packages].any? do |elem| elem[:name] == pkgName end
...@@ -113,18 +119,17 @@ def print_package(pkgName, extra = false) ...@@ -113,18 +119,17 @@ def print_package(pkgName, extra = false)
puts "" puts ""
end end
def set_package (pkgName, silent = false) def set_package (pkgName, pkgPath)
require CREW_LIB_PATH + 'packages/' + pkgName require pkgPath
@pkg = Object.const_get(pkgName.capitalize) @pkg = Object.const_get(pkgName.capitalize)
@pkg.build_from_source = true if @opt_recursive @pkg.build_from_source = true if @opt_recursive
@pkg.name = pkgName @pkg.name = pkgName
print_package(pkgName, true) unless silent
end end
def list_packages def list_packages
Find.find (CREW_LIB_PATH + 'packages') do |filename| Find.find (CREW_LIB_PATH + 'packages') do |filename|
if File.extname(filename) == '.rb' if File.extname(filename) == '.rb'
print_package File.basename filename, '.rb' print_package filename
end end
end end
end end
...@@ -138,7 +143,7 @@ def list_available ...@@ -138,7 +143,7 @@ def list_available
end end
if @notInstalled and File.extname(filename) == '.rb' if @notInstalled and File.extname(filename) == '.rb'
pkgName = File.basename filename, '.rb' pkgName = File.basename filename, '.rb'
set_package pkgName, true set_package pkgName, filename
if @pkg.compatibility.include? 'all' or @pkg.compatibility.include? ARCH if @pkg.compatibility.include? 'all' or @pkg.compatibility.include? ARCH
puts pkgName puts pkgName
else else
...@@ -158,7 +163,7 @@ def list_compatible(compat = true) ...@@ -158,7 +163,7 @@ def list_compatible(compat = true)
Find.find (CREW_LIB_PATH + 'packages') do |filename| Find.find (CREW_LIB_PATH + 'packages') do |filename|
if File.extname(filename) == '.rb' if File.extname(filename) == '.rb'
pkgName = File.basename filename, '.rb' pkgName = File.basename filename, '.rb'
set_package pkgName, true set_package pkgName, filename
if compat if compat
if @pkg.compatibility.include? 'all' or @pkg.compatibility.include? ARCH if @pkg.compatibility.include? 'all' or @pkg.compatibility.include? ARCH
if File.exist? CREW_CONFIG_PATH + 'meta/' + pkgName + '.filelist' if File.exist? CREW_CONFIG_PATH + 'meta/' + pkgName + '.filelist'
...@@ -181,7 +186,7 @@ def generate_compatible ...@@ -181,7 +186,7 @@ def generate_compatible
Find.find (CREW_LIB_PATH + 'packages') do |filename| Find.find (CREW_LIB_PATH + 'packages') do |filename|
if File.extname(filename) == '.rb' if File.extname(filename) == '.rb'
pkgName = File.basename filename, '.rb' pkgName = File.basename filename, '.rb'
set_package pkgName, true set_package pkgName, filename
if @pkg.compatibility.include? 'all' or @pkg.compatibility.include? ARCH if @pkg.compatibility.include? 'all' or @pkg.compatibility.include? ARCH
#add to compatible packages #add to compatible packages
@device[:compatible_packages].push(name: @pkg.name) @device[:compatible_packages].push(name: @pkg.name)
...@@ -196,29 +201,29 @@ end ...@@ -196,29 +201,29 @@ end
def search (pkgName, silent = false) def search (pkgName, silent = false)
Find.find (CREW_LIB_PATH + 'packages') do |filename| Find.find (CREW_LIB_PATH + 'packages') do |filename|
return set_package(pkgName, silent) if filename == CREW_LIB_PATH + 'packages/' + pkgName + '.rb' return set_package(pkgName, filename) if filename == CREW_LIB_PATH + 'packages/' + pkgName + '.rb'
end end
abort "Package #{pkgName} not found. :(".lightred unless silent abort "Package #{pkgName} not found. :(".lightred unless silent
end end
def regexp_search(pkgName) def regexp_search(pkgPat)
re = Regexp.new(pkgPat, true)
results = Dir["#{CREW_LIB_PATH}packages/*.rb"].sort \ results = Dir["#{CREW_LIB_PATH}packages/*.rb"].sort \
.select { |f| File.basename(f, '.rb') =~ Regexp.new(pkgName, true) } \ .select { |f| File.basename(f, '.rb') =~ re } \
.collect { |f| File.basename(f, '.rb') } \
.each { |f| print_package(f, @opt_verbose) } .each { |f| print_package(f, @opt_verbose) }
if results.empty? if results.empty?
Find.find ("#{CREW_LIB_PATH}packages/") do |packageName| Find.find ("#{CREW_LIB_PATH}packages/") do |packagePath|
if File.file? packageName if File.file? packagePath and File.extname(packagePath) == '.rb'
package = File.basename packageName, '.rb' packageName = File.basename packagePath, '.rb'
search package, true set_package packageName, packagePath
if ( @pkg.description =~ /#{pkgName}/i ) if ( @pkg.description =~ /#{pkgPat}/i )
print_package(package, @opt_verbose) print_current_package @opt_verbose
results.push(package) results.push(packageName)
end end
end end
end end
end end
abort "Package #{pkgName} not found. :(".lightred unless results.length > 0 abort "Package #{pkgPat} not found. :(".lightred unless results.length > 0
end end
def help (pkgName) def help (pkgName)
...@@ -464,6 +469,7 @@ def upgrade ...@@ -464,6 +469,7 @@ def upgrade
puts "Updating packages..." puts "Updating packages..."
toBeUpdated.each do |package| toBeUpdated.each do |package|
search package search package
print_current_package
puts "Updating " + @pkg.name + "..." if @opt_verbose puts "Updating " + @pkg.name + "..." if @opt_verbose
@pkg.in_upgrade = true @pkg.in_upgrade = true
resolve_dependencies_and_install resolve_dependencies_and_install
...@@ -796,6 +802,7 @@ def resolve_dependencies ...@@ -796,6 +802,7 @@ def resolve_dependencies
if proceed if proceed
@dependencies.each do |dep| @dependencies.each do |dep|
search dep search dep
print_current_package
install install
end end
end end
...@@ -974,7 +981,7 @@ def remove (pkgName) ...@@ -974,7 +981,7 @@ def remove (pkgName)
file.write JSON.pretty_generate(out) file.write JSON.pretty_generate(out)
end end
set_package pkgName, true search pkgName, true
@pkg.remove @pkg.remove
puts "#{pkgName.capitalize} removed!".lightgreen puts "#{pkgName.capitalize} removed!".lightgreen
...@@ -984,6 +991,7 @@ def build_command (args) ...@@ -984,6 +991,7 @@ def build_command (args)
args["<name>"].each do |name| args["<name>"].each do |name|
@pkgName = name @pkgName = name
search @pkgName search @pkgName
print_current_package
resolve_dependencies_and_build resolve_dependencies_and_build
end end
end end
...@@ -992,6 +1000,7 @@ def download_command (args) ...@@ -992,6 +1000,7 @@ def download_command (args)
args["<name>"].each do |name| args["<name>"].each do |name|
@pkgName = name @pkgName = name
search @pkgName search @pkgName
print_current_package
download download
end end
end end
...@@ -1010,6 +1019,7 @@ def files_command (args) ...@@ -1010,6 +1019,7 @@ def files_command (args)
args["<name>"].each do |name| args["<name>"].each do |name|
@pkgName = name @pkgName = name
search @pkgName search @pkgName
print_current_package
files name files name
end end
end end
...@@ -1027,6 +1037,7 @@ def install_command (args) ...@@ -1027,6 +1037,7 @@ def install_command (args)
args["<name>"].each do |name| args["<name>"].each do |name|
@pkgName = name @pkgName = name
search @pkgName search @pkgName
print_current_package
@pkg.build_from_source = true if @opt_src or @opt_recursive @pkg.build_from_source = true if @opt_src or @opt_recursive
resolve_dependencies_and_install resolve_dependencies_and_install
end end
...@@ -1046,7 +1057,7 @@ end ...@@ -1046,7 +1057,7 @@ end
def postinstall_command (args) def postinstall_command (args)
args["<name>"].each do |name| args["<name>"].each do |name|
set_package name, true search name, true
if @device[:installed_packages].any? do |elem| elem[:name] == name end if @device[:installed_packages].any? do |elem| elem[:name] == name end
@pkg.postinstall @pkg.postinstall
else else
...@@ -1059,6 +1070,7 @@ def reinstall_command (args) ...@@ -1059,6 +1070,7 @@ def reinstall_command (args)
args["<name>"].each do |name| args["<name>"].each do |name|
@pkgName = name @pkgName = name
search @pkgName search @pkgName
print_current_package
@pkg.build_from_source = true if @opt_src or @opt_recursive @pkg.build_from_source = true if @opt_src or @opt_recursive
if @pkgName if @pkgName
@pkg.in_upgrade = true @pkg.in_upgrade = true
...@@ -1090,6 +1102,7 @@ def upgrade_command (args) ...@@ -1090,6 +1102,7 @@ def upgrade_command (args)
args["<name>"].each do |name| args["<name>"].each do |name|
@pkgName = name @pkgName = name
search @pkgName search @pkgName
print_current_package
@pkg.build_from_source = true if @opt_src @pkg.build_from_source = true if @opt_src
upgrade upgrade
end.empty? and begin end.empty? and begin
......
# Defines common constants used in different parts of crew # Defines common constants used in different parts of crew
CREW_VERSION = '1.5.5' CREW_VERSION = '1.5.6'
ARCH_ACTUAL = `uname -m`.strip ARCH_ACTUAL = `uname -m`.strip
# This helps with virtualized builds on aarch64 machines # This helps with virtualized builds on aarch64 machines
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment