Improved error reporting a bit.
This commit is contained in:
parent
ef774194dc
commit
6fb2715267
@ -1,3 +1,4 @@
|
|||||||
|
require "./exception.cr"
|
||||||
|
|
||||||
require "./config.cr"
|
require "./config.cr"
|
||||||
|
|
||||||
|
32
src/exception.cr
Normal file
32
src/exception.cr
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
class Package::Exception < Exception
|
||||||
|
getter recipe : Recipe
|
||||||
|
def initialize(@recipe, message : String)
|
||||||
|
super message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Package::DownloadError < Package::Exception
|
||||||
|
getter url : URI
|
||||||
|
def initialize(recipe : Recipe, @url)
|
||||||
|
super recipe, "Downloading one of the sources failed."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Package::ExtractionError < Package::Exception
|
||||||
|
getter url : URI
|
||||||
|
def initialize(recipe : Recipe, @url)
|
||||||
|
super recipe, "Extracting one of the sources failed."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Package::BuildError < Package::Exception
|
||||||
|
end
|
||||||
|
|
||||||
|
class Package::PackagingError < Package::Exception
|
||||||
|
getter package : Package
|
||||||
|
def initialize(recipe : Recipe, @package)
|
||||||
|
super recipe, "Assembling a package failed."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -19,7 +19,8 @@ end
|
|||||||
|
|
||||||
class Package::Instructions
|
class Package::Instructions
|
||||||
class Set < Array(String)
|
class Set < Array(String)
|
||||||
def initialize(@phase : String)
|
getter phase : String
|
||||||
|
def initialize(@phase)
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
# FIXME: def execute
|
# FIXME: def execute
|
||||||
|
27
src/main.cr
27
src/main.cr
@ -74,20 +74,31 @@ end
|
|||||||
# FIXME: Now we need to build their respective deptrees and to deduplicate
|
# FIXME: Now we need to build their respective deptrees and to deduplicate
|
||||||
# the list of recipes.
|
# the list of recipes.
|
||||||
|
|
||||||
recipes.each do |recipe|
|
begin
|
||||||
|
latest_build_dir = ""
|
||||||
|
recipes.each do |recipe|
|
||||||
|
latest_build_dir = recipe.building_directory
|
||||||
|
|
||||||
puts " >> #{recipe.name}".colorize :white
|
puts " >> #{recipe.name}".colorize :white
|
||||||
|
|
||||||
raise "oh no, download failed" unless recipe.download
|
recipe.download
|
||||||
|
|
||||||
if download_only
|
next if download_only
|
||||||
exit 0
|
|
||||||
end
|
|
||||||
|
|
||||||
raise "oh no, extraction failed" unless recipe.extract
|
recipe.extract
|
||||||
|
|
||||||
raise "oh no, build failed" unless recipe.build
|
recipe.build
|
||||||
raise "oh no, packaging failed" unless recipe.package
|
recipe.package
|
||||||
|
|
||||||
recipe.clean unless do_not_clean
|
recipe.clean unless do_not_clean
|
||||||
|
end
|
||||||
|
rescue e : Package::Exception
|
||||||
|
STDERR.puts "!! #{e.message}".colorize(:red).bright
|
||||||
|
STDERR.puts "!! You may want to inspect the build directory at #{latest_build_dir}"
|
||||||
|
exit 1
|
||||||
|
rescue e
|
||||||
|
STDERR.puts "!! An unexpected error occured:".colorize(:red).bright
|
||||||
|
STDERR.puts e
|
||||||
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
require "uuid"
|
require "uuid"
|
||||||
require "uri"
|
require "uri"
|
||||||
require "file_utils"
|
require "file_utils"
|
||||||
@ -9,6 +8,7 @@ require "./context.cr"
|
|||||||
require "./package.cr"
|
require "./package.cr"
|
||||||
require "./instructions.cr"
|
require "./instructions.cr"
|
||||||
require "./sources.cr"
|
require "./sources.cr"
|
||||||
|
require "./exception.cr"
|
||||||
|
|
||||||
# 🤔
|
# 🤔
|
||||||
class URI
|
class URI
|
||||||
@ -184,28 +184,32 @@ class Package::Recipe
|
|||||||
@dirname || "#{name}-#{version}"
|
@dirname || "#{name}-#{version}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def download : Bool
|
def download
|
||||||
sources
|
sources.each do |url|
|
||||||
.compact_map do |url|
|
|
||||||
unless File.exists? url.basename
|
unless File.exists? url.basename
|
||||||
@context.run @context.sources_directory, "wget", [ url.to_s, "-O", url.basename ]
|
status = @context.run @context.sources_directory, "wget", [ url.to_s, "-O", url.basename ]
|
||||||
|
|
||||||
|
raise DownloadError.new self, url unless status.success?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
.map(&.success?)
|
|
||||||
.reduce(true) { |a, b| a && b }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract : Bool
|
def extract
|
||||||
Dir.mkdir_p building_directory
|
Dir.mkdir_p building_directory
|
||||||
|
|
||||||
sources
|
sources.each do |url|
|
||||||
.map do |url|
|
|
||||||
basename = url.basename
|
basename = url.basename
|
||||||
|
|
||||||
@context.run building_directory, "bsdtar", [ "xvf", @context.sources_directory + "/" + url.basename ]
|
status = @context.run(
|
||||||
|
building_directory,
|
||||||
|
"bsdtar", [
|
||||||
|
"xvf",
|
||||||
|
@context.sources_directory + "/" + url.basename
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
raise ExtractionError.new self, url unless status.success?
|
||||||
end
|
end
|
||||||
.map(&.success?)
|
|
||||||
.reduce true { |a, b| a && b }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
@ -215,9 +219,7 @@ class Package::Recipe
|
|||||||
# - Be careful about return values, flee from everything if something
|
# - Be careful about return values, flee from everything if something
|
||||||
# goes somehow wrong.
|
# goes somehow wrong.
|
||||||
# - Make things thread-safe. (those ENV[]= calls are definitely not)
|
# - Make things thread-safe. (those ENV[]= calls are definitely not)
|
||||||
def build : Bool
|
def build
|
||||||
success = true
|
|
||||||
|
|
||||||
Dir.mkdir_p fake_root_directory
|
Dir.mkdir_p fake_root_directory
|
||||||
|
|
||||||
ENV["PKG"] = fake_root_directory
|
ENV["PKG"] = fake_root_directory
|
||||||
@ -227,7 +229,7 @@ class Package::Recipe
|
|||||||
|
|
||||||
instructions.to_a.each do |instruction|
|
instructions.to_a.each do |instruction|
|
||||||
if instruction.run(@context, self).failed?
|
if instruction.run(@context, self).failed?
|
||||||
success = false
|
raise BuildError.new self, "Building (#{instruction.phase} phase) failed."
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -236,11 +238,11 @@ class Package::Recipe
|
|||||||
|
|
||||||
ENV["PKG"] = nil
|
ENV["PKG"] = nil
|
||||||
|
|
||||||
success = false if Dir.children(fake_root_directory).size == 0
|
if Dir.children(fake_root_directory).size == 0
|
||||||
|
raise BuildError.new self, "No file was installed in the fake root."
|
||||||
|
end
|
||||||
|
|
||||||
do_splits if success
|
do_splits
|
||||||
|
|
||||||
success
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private def do_splits
|
private def do_splits
|
||||||
@ -295,18 +297,18 @@ class Package::Recipe
|
|||||||
# TODO:
|
# TODO:
|
||||||
# - Errors management. Stop at first failure?
|
# - Errors management. Stop at first failure?
|
||||||
# - Splits. This should be done between #build and #package.
|
# - Splits. This should be done between #build and #package.
|
||||||
def package : Bool
|
def package
|
||||||
# This tries to build them all and stops at the first failure
|
# This tries to build them all and stops at the first failure
|
||||||
# (failures are currently reported by Context#package)
|
# (failures are currently reported by Context#package)
|
||||||
(@packages + auto_splits)
|
(@packages + auto_splits).each do |package|
|
||||||
.find do |package|
|
|
||||||
if package.automatic && ! File.exists? package.fake_root_directory
|
if package.automatic && ! File.exists? package.fake_root_directory
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
! @context.package package
|
unless @context.package package
|
||||||
|
raise PackagingError.new self, package
|
||||||
|
end
|
||||||
end
|
end
|
||||||
.== nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean
|
def clean
|
||||||
|
Reference in New Issue
Block a user