Archived
3
0

Temporary UI, error detection.

This commit is contained in:
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,11 +5,13 @@ require "./recipe.cr"
extend Package extend Package
# FIXME: recipe.clean? context autoclean? # FIXME: recipe.clean? context autoclean?
Context.new().tap do |context| context = Context.new()
context.packaging_backend = "apk" context.packaging_backend = "apk"
# FIXME: context.new_recipe? context.recipe? recipes = [] of Package::Recipe
Recipe.new(context, "hello", "2.10").tap do |recipe|
# 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.sources << "https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz"
# This is a voluntary mix of automatic and manual build # This is a voluntary mix of automatic and manual build
@ -32,14 +34,42 @@ Context.new().tap do |context|
# package.name = "#{recipe.name}-man" # package.name = "#{recipe.name}-man"
# package.files = ["/package/share/man"] # package.files = ["/package/share/man"]
#end #end
end
recipe.download if ARGV.size == 0 || ARGV[0]? == "-h"
recipe.extract pp recipes.map &.name
exit 0
end
raise "oh no, build failed" unless recipe.build selected_recipes = ARGV.map do |name|
recipe.package recipes.find(&.name.==(name)) || name
end
recipe.clean 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
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}" @dirname || "#{name}-#{version}"
end end
def download def download : Bool
sources.map do |url| sources
.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 ] @context.run @context.sources_directory, "wget", [ url.to_s, "-O", url.basename ]
end end
end end
.map(&.success?)
.reduce(true) { |a, b| a && b }
end end
def extract def extract : Bool
Dir.mkdir_p building_directory Dir.mkdir_p building_directory
sources.map do |url| sources
.map do |url|
basename = url.basename basename = url.basename
@context.run building_directory, "tar", [ "xvf", @context.sources_directory + "/" + url.basename ] @context.run building_directory, "tar", [ "xvf", @context.sources_directory + "/" + url.basename ]
end end
.map(&.success?)
.reduce true { |a, b| a && b }
end end
# TODO: # TODO:
@ -100,7 +106,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 def build : Bool
success = true success = true
Dir.mkdir_p fake_root_directory Dir.mkdir_p fake_root_directory
@ -165,15 +171,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 def package : Bool
# FIXME: if package.automatic and no file, do not build. # This tries to build them all and stops at the first failure
@packages.find do |package| # (failures are currently reported by Context#package)
@packages
.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 ! @context.package package
end end
.== nil
end end
def clean def clean