Temporary UI, error detection.

master
Luka Vandervelden 2019-07-20 13:30:09 +02:00
parent b2586be87b
commit 132b3751ce
2 changed files with 85 additions and 46 deletions

View File

@ -5,41 +5,71 @@ require "./recipe.cr"
extend Package
# FIXME: recipe.clean? context autoclean?
Context.new().tap do |context|
context.packaging_backend = "apk"
context = Context.new()
context.packaging_backend = "apk"
# FIXME: context.new_recipe? context.recipe?
Recipe.new(context, "hello", "2.10").tap do |recipe|
recipe.sources << "https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz"
recipes = [] of Package::Recipe
# This is a voluntary mix of automatic and manual build
# instructions.
# Also, installing in /package makes testing with a real-life
# package manager trivial and reduces the damage done in case
# of… containment failure. ]:->
recipe.instructions.configure << "cd hello-#{recipe.version} && ./configure --prefix=/package"
#recipe.instructions.build << "cd hello-#{recipe.version} && make"
#recipe.instructions.install << "cd hello-#{recipe.version} && make DESTDIR='${PKG}' install"
# FIXME: context.new_recipe? context.recipe?
recipes << Recipe.new(context, "hello", "2.10").tap do |recipe|
recipe.sources << "https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz"
recipe.url = "https://www.gnu.org/software/hello/"
recipe.description = "The GNU Hello program produces a familiar, friendly greeting."
recipe.dependencies << "gettext"
# This is a voluntary mix of automatic and manual build
# instructions.
# Also, installing in /package makes testing with a real-life
# package manager trivial and reduces the damage done in case
# of… containment failure. ]:->
recipe.instructions.configure << "cd hello-#{recipe.version} && ./configure --prefix=/package"
#recipe.instructions.build << "cd hello-#{recipe.version} && make"
#recipe.instructions.install << "cd hello-#{recipe.version} && make DESTDIR='${PKG}' install"
recipe.auto_split
recipe.url = "https://www.gnu.org/software/hello/"
recipe.description = "The GNU Hello program produces a familiar, friendly greeting."
recipe.dependencies << "gettext"
# Should be automatic now.
#recipe.packages << Package::Package.new(recipe).tap do |package|
# package.name = "#{recipe.name}-man"
# package.files = ["/package/share/man"]
#end
recipe.auto_split
recipe.download
recipe.extract
# Should be automatic now.
#recipe.packages << Package::Package.new(recipe).tap do |package|
# package.name = "#{recipe.name}-man"
# package.files = ["/package/share/man"]
#end
end
raise "oh no, build failed" unless recipe.build
recipe.package
if ARGV.size == 0 || ARGV[0]? == "-h"
pp recipes.map &.name
exit 0
end
recipe.clean
selected_recipes = ARGV.map do |name|
recipes.find(&.name.==(name)) || name
end
if selected_recipes.any? &.is_a?(String)
puts "At least one of the requested recipes is not known."
selected_recipes.select! &.is_a?(String)
pp! selected_recipes
end
# Getting rid of Strings.
selected_recipes = selected_recipes.compact_map do |recipe|
if recipe.is_a? String
nil
else
recipe
end
end
selected_recipes.each do |recipe|
pp recipe
raise "oh no, download failed" unless recipe.download
raise "oh no, extraction failed" unless recipe.extract
raise "oh no, build failed" unless recipe.build
raise "oh no, packaging failed" unless recipe.package
recipe.clean
end

View File

@ -75,22 +75,28 @@ class Package::Recipe
@dirname || "#{name}-#{version}"
end
def download
sources.map do |url|
unless File.exists? url.basename
@context.run @context.sources_directory, "wget", [ url.to_s, "-O", url.basename ]
def download : Bool
sources
.compact_map do |url|
unless File.exists? url.basename
@context.run @context.sources_directory, "wget", [ url.to_s, "-O", url.basename ]
end
end
end
.map(&.success?)
.reduce(true) { |a, b| a && b }
end
def extract
def extract : Bool
Dir.mkdir_p building_directory
sources.map do |url|
basename = url.basename
sources
.map do |url|
basename = url.basename
@context.run building_directory, "tar", [ "xvf", @context.sources_directory + "/" + url.basename ]
end
@context.run building_directory, "tar", [ "xvf", @context.sources_directory + "/" + url.basename ]
end
.map(&.success?)
.reduce true { |a, b| a && b }
end
# TODO:
@ -100,7 +106,7 @@ class Package::Recipe
# - Be careful about return values, flee from everything if something
# goes somehow wrong.
# - Make things thread-safe. (those ENV[]= calls are definitely not)
def build
def build : Bool
success = true
Dir.mkdir_p fake_root_directory
@ -165,15 +171,18 @@ class Package::Recipe
# TODO:
# - Errors management. Stop at first failure?
# - Splits. This should be done between #build and #package.
def package
# FIXME: if package.automatic and no file, do not build.
@packages.find do |package|
if package.automatic && ! File.exists? package.fake_root_directory
next
end
def package : Bool
# This tries to build them all and stops at the first failure
# (failures are currently reported by Context#package)
@packages
.find do |package|
if package.automatic && ! File.exists? package.fake_root_directory
next
end
! @context.package package
end
! @context.package package
end
.== nil
end
def clean