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 "./exception.cr"
|
||||
@ -76,6 +78,8 @@ class Package::Context
|
||||
property prefixes = ["/usr", "/", "/usr/weirdos"]
|
||||
property environment = {} of String => String
|
||||
|
||||
property verbosity = 0
|
||||
|
||||
def initialize
|
||||
@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"
|
||||
@ -89,12 +93,8 @@ class Package::Context
|
||||
# to work properly.
|
||||
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
|
||||
|
||||
|
||||
# Create data.tar.gz here.
|
||||
package_target = "#{packages_directory}/#{context.architecture}/#{package.name}-#{package.version}-r#{package.release}.apk"
|
||||
Dir.mkdir_p File.dirname package_target
|
||||
@ -219,7 +219,13 @@ class Package::Context
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def run(command, args)
|
||||
@ -241,6 +247,21 @@ class Package::Context
|
||||
{child, output}
|
||||
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
|
||||
@selected_packaging_backend.package self, package
|
||||
end
|
||||
@ -268,7 +289,6 @@ class Package::Context
|
||||
specs = SpecFileParser.parse(filename).not_nil!
|
||||
|
||||
specs.assignments.each do |key, value|
|
||||
puts key, value
|
||||
case key
|
||||
when "packages-directory"
|
||||
@packages_directory = value.as_s
|
||||
|
11
src/main.cr
11
src/main.cr
@ -60,6 +60,14 @@ OptionParser.parse! do |parser|
|
||||
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|
|
||||
STDERR.puts "ERROR: #{flag} is not a valid option."
|
||||
STDERR.puts parser
|
||||
@ -79,7 +87,6 @@ elsif configuration_file_requested
|
||||
end
|
||||
|
||||
found_recipes = requested_recipes.map do |name|
|
||||
puts context.find_recipe(name)
|
||||
context.find_recipe(name) || name
|
||||
end
|
||||
|
||||
@ -142,7 +149,7 @@ begin
|
||||
recipes.each do |recipe|
|
||||
latest_build_dir = recipe.building_directory
|
||||
|
||||
puts " >> #{recipe.name}".colorize :white
|
||||
context.title recipe.name
|
||||
|
||||
recipe.download
|
||||
|
||||
|
@ -217,6 +217,8 @@ class Package::Recipe
|
||||
filename = @context.sources_directory + "/" + url.filename
|
||||
|
||||
unless File.exists? filename
|
||||
@context.info "Downloading '#{url.filename}'"
|
||||
|
||||
status = @context.run @context.sources_directory, "wget", [ url.to_s, "-O", filename ]
|
||||
|
||||
raise DownloadError.new self, url unless status.success?
|
||||
@ -231,7 +233,8 @@ class Package::Recipe
|
||||
basename = url.filename
|
||||
|
||||
if basename.match /\.(tar\.(gz|xz|bz2|lzma)|tgz)$/
|
||||
puts ":: Extracting '#{url.filename}'"
|
||||
@context.info "Extracting '#{url.filename}'"
|
||||
|
||||
status = @context.run(
|
||||
building_directory,
|
||||
"bsdtar", [
|
||||
@ -272,6 +275,8 @@ class Package::Recipe
|
||||
old_dir = Dir.current
|
||||
|
||||
instructions.to_a.each do |instruction|
|
||||
@context.info "Building ('#{instruction.phase}' phase)"
|
||||
|
||||
if instruction.run(@context, self).failed?
|
||||
raise BuildError.new self, "Building (#{instruction.phase} phase) failed."
|
||||
break
|
||||
@ -292,6 +297,8 @@ class Package::Recipe
|
||||
end
|
||||
|
||||
private def do_strip
|
||||
@context.info "Stripping binaries"
|
||||
|
||||
@context.prefixes.each do |prefix|
|
||||
directory = "#{fake_root_directory}/#{prefix}/lib"
|
||||
|
||||
@ -303,7 +310,8 @@ class Package::Recipe
|
||||
file_output = `file #{path}`
|
||||
|
||||
if file_output.match /not stripped/
|
||||
puts "STRIPPING #{path}"
|
||||
@context.detail "stripping #{path}"
|
||||
|
||||
Process.run "strip", [path]
|
||||
end
|
||||
end
|
||||
@ -332,22 +340,23 @@ class Package::Recipe
|
||||
files_to_split << file if file_patterns.any? &.match file
|
||||
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?
|
||||
files_to_split.each do |file|
|
||||
origin = "#{fake_root_directory}#{file}"
|
||||
destination ="#{package.fake_root_directory}#{file}"
|
||||
|
||||
@context.detail "Moving '#{file}' to split"
|
||||
|
||||
Dir.mkdir_p File.dirname destination
|
||||
|
||||
FileUtils.mv(
|
||||
"#{fake_root_directory}#{file}",
|
||||
"#{package.fake_root_directory}#{file}"
|
||||
)
|
||||
|
||||
puts file
|
||||
@context.run "find", [
|
||||
"#{package.fake_root_directory}/#{file}"
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -369,6 +378,8 @@ class Package::Recipe
|
||||
next
|
||||
end
|
||||
|
||||
@context.info "Assempling '#{package.name}'"
|
||||
|
||||
unless @context.package package
|
||||
raise PackagingError.new self, package
|
||||
end
|
||||
|
Reference in New Issue
Block a user