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,41 +5,71 @@ 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|
recipe.sources << "https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz"
# This is a voluntary mix of automatic and manual build # FIXME: context.new_recipe? context.recipe?
# instructions. recipes << Recipe.new(context, "hello", "2.10").tap do |recipe|
# Also, installing in /package makes testing with a real-life recipe.sources << "https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz"
# 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.url = "https://www.gnu.org/software/hello/" # This is a voluntary mix of automatic and manual build
recipe.description = "The GNU Hello program produces a familiar, friendly greeting." # instructions.
recipe.dependencies << "gettext" # 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.auto_split
#recipe.packages << Package::Package.new(recipe).tap do |package|
# package.name = "#{recipe.name}-man"
# package.files = ["/package/share/man"]
#end
recipe.download # Should be automatic now.
recipe.extract #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 if ARGV.size == 0 || ARGV[0]? == "-h"
recipe.package 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
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
unless File.exists? url.basename .compact_map do |url|
@context.run @context.sources_directory, "wget", [ url.to_s, "-O", url.basename ] unless File.exists? 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
basename = url.basename .map do |url|
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)
if package.automatic && ! File.exists? package.fake_root_directory @packages
next .find do |package|
end if package.automatic && ! File.exists? package.fake_root_directory
next
end
! @context.package package ! @context.package package
end end
.== nil
end end
def clean def clean