Verbosity control.
Multiple -v or -q flags can be provided to alter verbosity more. No log file with full-verbosity is currently stored, but that’s a planned feature.
This commit is contained in:
parent
a6b32e3420
commit
24ff4358d3
@ -1,3 +1,5 @@
|
|||||||
|
require "colorize"
|
||||||
|
|
||||||
require "specfileparser"
|
require "specfileparser"
|
||||||
|
|
||||||
require "./exception.cr"
|
require "./exception.cr"
|
||||||
@ -76,6 +78,8 @@ class Package::Context
|
|||||||
property prefixes = ["/usr", "/", "/usr/weirdos"]
|
property prefixes = ["/usr", "/", "/usr/weirdos"]
|
||||||
property environment = {} of String => String
|
property environment = {} of String => String
|
||||||
|
|
||||||
|
property verbosity = 0
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@packaging_backends << Backend::Packaging.new "pkgutils" do |context, package|
|
@packaging_backends << Backend::Packaging.new "pkgutils" do |context, package|
|
||||||
puts "#{package.fake_root_directory} -> #{packages_directory}/#{package.name}##{package.version}-#{package.release}.pkg.tar.xz"
|
puts "#{package.fake_root_directory} -> #{packages_directory}/#{package.name}##{package.version}-#{package.release}.pkg.tar.xz"
|
||||||
@ -89,12 +93,8 @@ class Package::Context
|
|||||||
# to work properly.
|
# to work properly.
|
||||||
old_cwd = Dir.current
|
old_cwd = Dir.current
|
||||||
|
|
||||||
puts "#{package.fake_root_directory} -> #{packages_directory}/#{package.name}-#{package.version}-r#{package.release}.apk"
|
|
||||||
|
|
||||||
puts pkginfo package
|
|
||||||
File.write "#{package.fake_root_directory}/.PKGINFO", pkginfo package
|
File.write "#{package.fake_root_directory}/.PKGINFO", pkginfo package
|
||||||
|
|
||||||
|
|
||||||
# Create data.tar.gz here.
|
# Create data.tar.gz here.
|
||||||
package_target = "#{packages_directory}/#{context.architecture}/#{package.name}-#{package.version}-r#{package.release}.apk"
|
package_target = "#{packages_directory}/#{context.architecture}/#{package.name}-#{package.version}-r#{package.release}.apk"
|
||||||
Dir.mkdir_p File.dirname package_target
|
Dir.mkdir_p File.dirname package_target
|
||||||
@ -219,7 +219,13 @@ class Package::Context
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run(chdir, command, args)
|
def run(chdir, command, args)
|
||||||
Process.run command, args, chdir: chdir, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit, env: @environment
|
output = Process::Redirect::Inherit
|
||||||
|
|
||||||
|
if @verbosity < -1
|
||||||
|
output = Process::Redirect::Close
|
||||||
|
end
|
||||||
|
|
||||||
|
Process.run command, args, chdir: chdir, output: output, error: output, env: @environment
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(command, args)
|
def run(command, args)
|
||||||
@ -241,6 +247,21 @@ class Package::Context
|
|||||||
{child, output}
|
{child, output}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Output functions.
|
||||||
|
def title(s)
|
||||||
|
return if @verbosity < -3
|
||||||
|
puts ">> ".colorize(:green).mode(:bright).to_s +
|
||||||
|
s.colorize(:white).mode(:bright).to_s
|
||||||
|
end
|
||||||
|
def info(s)
|
||||||
|
return if @verbosity < -2
|
||||||
|
puts ":: ".colorize(:green).to_s + s.colorize(:white).to_s
|
||||||
|
end
|
||||||
|
def detail(s)
|
||||||
|
return if @verbosity < -1
|
||||||
|
puts ("+ " + s).colorize(:cyan)
|
||||||
|
end
|
||||||
|
|
||||||
def package(package : Package) : Bool
|
def package(package : Package) : Bool
|
||||||
@selected_packaging_backend.package self, package
|
@selected_packaging_backend.package self, package
|
||||||
end
|
end
|
||||||
@ -268,7 +289,6 @@ class Package::Context
|
|||||||
specs = SpecFileParser.parse(filename).not_nil!
|
specs = SpecFileParser.parse(filename).not_nil!
|
||||||
|
|
||||||
specs.assignments.each do |key, value|
|
specs.assignments.each do |key, value|
|
||||||
puts key, value
|
|
||||||
case key
|
case key
|
||||||
when "packages-directory"
|
when "packages-directory"
|
||||||
@packages_directory = value.as_s
|
@packages_directory = value.as_s
|
||||||
|
11
src/main.cr
11
src/main.cr
@ -60,6 +60,14 @@ OptionParser.parse! do |parser|
|
|||||||
watch_only = true
|
watch_only = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parser.on("-v", "--verbose", "Runs more verbosely.") {
|
||||||
|
context.verbosity += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
parser.on("-q", "--quiet", "Runs more quietely.") {
|
||||||
|
context.verbosity -= 1
|
||||||
|
}
|
||||||
|
|
||||||
parser.invalid_option do |flag|
|
parser.invalid_option do |flag|
|
||||||
STDERR.puts "ERROR: #{flag} is not a valid option."
|
STDERR.puts "ERROR: #{flag} is not a valid option."
|
||||||
STDERR.puts parser
|
STDERR.puts parser
|
||||||
@ -79,7 +87,6 @@ elsif configuration_file_requested
|
|||||||
end
|
end
|
||||||
|
|
||||||
found_recipes = requested_recipes.map do |name|
|
found_recipes = requested_recipes.map do |name|
|
||||||
puts context.find_recipe(name)
|
|
||||||
context.find_recipe(name) || name
|
context.find_recipe(name) || name
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -142,7 +149,7 @@ begin
|
|||||||
recipes.each do |recipe|
|
recipes.each do |recipe|
|
||||||
latest_build_dir = recipe.building_directory
|
latest_build_dir = recipe.building_directory
|
||||||
|
|
||||||
puts " >> #{recipe.name}".colorize :white
|
context.title recipe.name
|
||||||
|
|
||||||
recipe.download
|
recipe.download
|
||||||
|
|
||||||
|
@ -217,6 +217,8 @@ class Package::Recipe
|
|||||||
filename = @context.sources_directory + "/" + url.filename
|
filename = @context.sources_directory + "/" + url.filename
|
||||||
|
|
||||||
unless File.exists? filename
|
unless File.exists? filename
|
||||||
|
@context.info "Downloading '#{url.filename}'"
|
||||||
|
|
||||||
status = @context.run @context.sources_directory, "wget", [ url.to_s, "-O", filename ]
|
status = @context.run @context.sources_directory, "wget", [ url.to_s, "-O", filename ]
|
||||||
|
|
||||||
raise DownloadError.new self, url unless status.success?
|
raise DownloadError.new self, url unless status.success?
|
||||||
@ -231,7 +233,8 @@ class Package::Recipe
|
|||||||
basename = url.filename
|
basename = url.filename
|
||||||
|
|
||||||
if basename.match /\.(tar\.(gz|xz|bz2|lzma)|tgz)$/
|
if basename.match /\.(tar\.(gz|xz|bz2|lzma)|tgz)$/
|
||||||
puts ":: Extracting '#{url.filename}'"
|
@context.info "Extracting '#{url.filename}'"
|
||||||
|
|
||||||
status = @context.run(
|
status = @context.run(
|
||||||
building_directory,
|
building_directory,
|
||||||
"bsdtar", [
|
"bsdtar", [
|
||||||
@ -272,6 +275,8 @@ class Package::Recipe
|
|||||||
old_dir = Dir.current
|
old_dir = Dir.current
|
||||||
|
|
||||||
instructions.to_a.each do |instruction|
|
instructions.to_a.each do |instruction|
|
||||||
|
@context.info "Building ('#{instruction.phase}' phase)"
|
||||||
|
|
||||||
if instruction.run(@context, self).failed?
|
if instruction.run(@context, self).failed?
|
||||||
raise BuildError.new self, "Building (#{instruction.phase} phase) failed."
|
raise BuildError.new self, "Building (#{instruction.phase} phase) failed."
|
||||||
break
|
break
|
||||||
@ -292,6 +297,8 @@ class Package::Recipe
|
|||||||
end
|
end
|
||||||
|
|
||||||
private def do_strip
|
private def do_strip
|
||||||
|
@context.info "Stripping binaries"
|
||||||
|
|
||||||
@context.prefixes.each do |prefix|
|
@context.prefixes.each do |prefix|
|
||||||
directory = "#{fake_root_directory}/#{prefix}/lib"
|
directory = "#{fake_root_directory}/#{prefix}/lib"
|
||||||
|
|
||||||
@ -303,7 +310,8 @@ class Package::Recipe
|
|||||||
file_output = `file #{path}`
|
file_output = `file #{path}`
|
||||||
|
|
||||||
if file_output.match /not stripped/
|
if file_output.match /not stripped/
|
||||||
puts "STRIPPING #{path}"
|
@context.detail "stripping #{path}"
|
||||||
|
|
||||||
Process.run "strip", [path]
|
Process.run "strip", [path]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -332,22 +340,23 @@ class Package::Recipe
|
|||||||
files_to_split << file if file_patterns.any? &.match file
|
files_to_split << file if file_patterns.any? &.match file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if files_to_split.size > 0
|
||||||
|
@context.info "Splitting '#{package.name}'"
|
||||||
|
end
|
||||||
|
|
||||||
# FIXME: What do we do if those are not on the filesystem?
|
# FIXME: What do we do if those are not on the filesystem?
|
||||||
files_to_split.each do |file|
|
files_to_split.each do |file|
|
||||||
origin = "#{fake_root_directory}#{file}"
|
origin = "#{fake_root_directory}#{file}"
|
||||||
destination ="#{package.fake_root_directory}#{file}"
|
destination ="#{package.fake_root_directory}#{file}"
|
||||||
|
|
||||||
|
@context.detail "Moving '#{file}' to split"
|
||||||
|
|
||||||
Dir.mkdir_p File.dirname destination
|
Dir.mkdir_p File.dirname destination
|
||||||
|
|
||||||
FileUtils.mv(
|
FileUtils.mv(
|
||||||
"#{fake_root_directory}#{file}",
|
"#{fake_root_directory}#{file}",
|
||||||
"#{package.fake_root_directory}#{file}"
|
"#{package.fake_root_directory}#{file}"
|
||||||
)
|
)
|
||||||
|
|
||||||
puts file
|
|
||||||
@context.run "find", [
|
|
||||||
"#{package.fake_root_directory}/#{file}"
|
|
||||||
]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -369,6 +378,8 @@ class Package::Recipe
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@context.info "Assempling '#{package.name}'"
|
||||||
|
|
||||||
unless @context.package package
|
unless @context.package package
|
||||||
raise PackagingError.new self, package
|
raise PackagingError.new self, package
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user