lib/autoproj/cli/show.rb in autoproj-2.0.0.rc37 vs lib/autoproj/cli/show.rb in autoproj-2.0.0.rc38
- old
+ new
@@ -2,63 +2,150 @@
require 'autoproj/cli/inspection_tool'
module Autoproj
module CLI
class Show < InspectionTool
- def run(user_selection, options = Hash.new)
- options = Kernel.validate_options options,
- mainline: false, env: false
-
- initialize_and_load(mainline: options.delete(:mainline))
+ def run(user_selection, short: false, recursive: false, mainline: false, env: false)
+ initialize_and_load(mainline: mainline)
default_packages = ws.manifest.default_packages
- source_packages, osdep_packages, * =
- finalize_setup(user_selection,
- recursive: false,
- ignore_non_imported_packages: true)
+ # Filter out selections that match package set names
+ package_set_names, user_selection = user_selection.partition do |name|
+ ws.manifest.find_package_set(name)
+ end
- if source_packages.empty? && osdep_packages.empty?
- Autoproj.error "no packages or OS packages match #{user_selection.join(" ")}"
+ if !user_selection.empty? || package_set_names.empty?
+ source_packages, osdep_packages, * =
+ finalize_setup(user_selection, recursive: recursive, non_imported_packages: :return)
+ else
+ source_packages, osdep_packages = Array.new, Array.new
+ end
+
+ if package_set_names.empty? && source_packages.empty? && osdep_packages.empty?
+ Autoproj.error "no package set, packages or OS packages match #{user_selection.join(" ")}"
return
+ elsif !source_packages.empty? || !osdep_packages.empty?
+ load_all_available_package_manifests
+ revdeps = ws.manifest.compute_revdeps
end
- load_all_available_package_manifests
- revdeps = ws.manifest.compute_revdeps
- source_packages.each do |pkg_name|
- display_source_package(pkg_name, default_packages, revdeps, env: options[:env])
+ package_set_names = package_set_names.sort
+ source_packages = source_packages.sort
+ osdep_packages = osdep_packages.sort
+
+ if short
+ package_set_names.each do |name|
+ puts "pkg_set #{name}"
+ end
+ source_packages.each do |name|
+ puts "pkg #{name}"
+ end
+ osdep_packages.each do |name|
+ puts "osdep #{name}"
+ end
+ else
+ package_set_names.each do |pkg_set_name|
+ display_package_set(pkg_set_name)
+ end
+ source_packages.each do |pkg_name|
+ display_source_package(pkg_name, default_packages, revdeps, env: env)
+ end
+ osdep_packages.each do |pkg_name|
+ display_osdep_package(pkg_name, default_packages, revdeps)
+ end
end
- osdep_packages.each do |pkg_name|
- display_osdep_package(pkg_name, default_packages, revdeps)
+ end
+
+ def display_package_set(name, package_per_line: 8)
+ puts Autoproj.color("package set #{name}", :bold)
+ pkg_set = ws.manifest.find_package_set(name)
+ if !File.directory?(pkg_set.raw_local_dir)
+ puts Autobuild.color(" this package set is not checked out", :magenta)
end
+ if overrides_key = pkg_set.vcs.overrides_key
+ puts " overrides key: pkg_set:#{overrides_key}"
+ end
+ if pkg_set.raw_local_dir != pkg_set.user_local_dir
+ puts " checkout dir: #{pkg_set.raw_local_dir}"
+ puts " symlinked to: #{pkg_set.user_local_dir}"
+ else
+ puts " path: #{pkg_set.raw_local_dir}"
+ end
+
+ puts " version control information:"
+ display_vcs(pkg_set.vcs)
+
+ metapackage = ws.manifest.find_metapackage(name)
+ size = metapackage.size
+ if size == 0
+ puts " does not have any packages"
+ else
+ puts " refers to #{metapackage.size} package#{'s' if metapackage.size > 1}"
+ end
+ names = metapackage.each_package.map(&:name).sort
+ package_lines = names.each_slice(package_per_line).map do |*line_names|
+ line_names.join(", ")
+ end
+ puts " " + package_lines.join(",\n ")
+
end
def display_source_package(pkg_name, default_packages, revdeps, options = Hash.new)
puts Autoproj.color("source package #{pkg_name}", :bold)
pkg = ws.manifest.find_autobuild_package(pkg_name)
if !File.directory?(pkg.srcdir)
puts Autobuild.color(" this package is not checked out yet, the dependency information will probably be incomplete", :magenta)
end
puts " source definition"
ws.manifest.load_package_manifest(pkg_name)
- vcs = ws.manifest.find_package(pkg_name).vcs
+ vcs = ws.manifest.find_package_definition(pkg_name).vcs
+ display_vcs(vcs)
+ display_common_information(pkg_name, default_packages, revdeps)
+
+ puts " directly depends on: #{pkg.dependencies.sort.join(", ")}"
+ puts " optionally depends on: #{pkg.optional_dependencies.sort.join(", ")}"
+ puts " dependencies on OS packages: #{pkg.os_packages.sort.join(", ")}"
+ if options[:env]
+ puts " environment"
+ pkg.resolved_env.sort_by(&:first).each do |name, v|
+ values = v.split(File::PATH_SEPARATOR)
+ if values.size == 1
+ puts " #{name}: #{values.first}"
+ else
+ puts " #{name}:"
+ values.each do |single_v|
+ puts " #{single_v}"
+ end
+ end
+ end
+ end
+ end
+
+ def display_vcs(vcs)
fragments = []
- if !vcs
+ if vcs.none?
fragments << ["has no VCS definition", []]
- elsif vcs.raw
+ else
first = true
fragments << [nil, vcs_to_array(vcs)]
- vcs.raw.each do |pkg_set, vcs_info|
- pkg_set = if pkg_set then pkg_set.name
- end
+ vcs.raw.each do |entry|
+ entry_name =
+ if entry.package_set && entry.file
+ "#{entry.package_set.name} (#{entry.file})"
+ elsif entry.package_set
+ "#{entry.package_set.name}"
+ elsif entry.file
+ "#{entry.file}"
+ end
title = if first
- "first match: in #{pkg_set}"
- else "overriden in #{pkg_set}"
+ "first match: in #{entry_name}"
+ else "overriden in #{entry_name}"
end
first = false
- fragments << [title, vcs_to_array(vcs_info)]
+ fragments << [title, vcs_to_array(entry.vcs)]
end
end
fragments.each do |title, elements|
if title
puts " #{title}"
@@ -69,30 +156,10 @@
elements.each do |key, value|
puts " #{key}: #{value}"
end
end
end
-
- display_common_information(pkg_name, default_packages, revdeps)
-
- puts " directly depends on: #{pkg.dependencies.sort.join(", ")}"
- puts " optionally depends on: #{pkg.optional_dependencies.sort.join(", ")}"
- puts " dependencies on OS packages: #{pkg.os_packages.sort.join(", ")}"
- if options[:env]
- puts " environment"
- pkg.resolved_env.sort_by(&:first).each do |name, v|
- values = v.split(File::PATH_SEPARATOR)
- if values.size == 1
- puts " #{name}: #{values.first}"
- else
- puts " #{name}:"
- values.each do |single_v|
- puts " #{single_v}"
- end
- end
- end
- end
end
def display_osdep_package(pkg_name, default_packages, revdeps)
puts Autoproj.color("the osdep '#{pkg_name}'", :bold)
ws.os_package_resolver.resolve_os_packages([pkg_name]).each do |manager_name, packages|
@@ -158,11 +225,13 @@
if from == to
return [[from]]
end
all_paths = Array.new
- ws.manifest.resolve_package_set(from).each do |pkg_name|
+ ws.manifest.resolve_package_name(from).each do |pkg_type, pkg_name|
+ next if pkg_type != :package
+
path = if pkg_name == from then []
else [pkg_name]
end
pkg = ws.manifest.find_autobuild_package(pkg_name)
@@ -199,18 +268,18 @@
options = vcs.options
type = vcs.type
url = vcs.url
end
- value = []
+ fields = []
if type
- value << ['type', type]
+ fields << ['type', type]
end
if url
- value << ['url', url]
+ fields << ['url', url]
end
- value = value.concat(options.to_a.sort_by { |k, _| k.to_s })
- value.map do |key, value|
+ fields = fields.concat(options.to_a.sort_by { |k, _| k.to_s })
+ fields.map do |key, value|
if value.respond_to?(:to_str) && File.file?(value) && value =~ /^\//
value = Pathname.new(value).relative_path_from(Pathname.new(Autoproj.root_dir))
end
[key, value]
end