Grooming.

master
Luka Vandervelden 2019-07-03 03:48:31 +02:00
parent fa92519f4d
commit e6645e4f3d
3 changed files with 66 additions and 66 deletions

View File

@ -16,7 +16,8 @@ class Package::Context
property sources_directory = Dir.current
property packages_directory = Dir.current
@packaging_backends = [] of Backend::Packaging
getter packaging_backends = [] of Backend::Packaging
getter building_backends = [] of Backend::Building
def initialize
@packaging_backends << Backend::Packaging.new "pkgutils" do |package|
@ -27,6 +28,38 @@ class Package::Context
end
@selected_packaging_backend = @packaging_backends[0]
@building_backends << Backend::Building.new "configure", "autotools" do |context, recipe|
Dir.cd recipe.dirname
unless File.exists? "configure"
next BuildStatus::Pass
end
child = context.run "./configure", ["--prefix=/package"]
if child.exit_status == 0
BuildStatus::Success
else
BuildStatus::Failed
end
end
@building_backends << Backend::Building.new "build", "make" do |context, recipe|
Dir.cd recipe.dirname
unless File.exists? "Makefile"
next BuildStatus::Pass
end
child = context.run "make"
if child.exit_status == 0
BuildStatus::Success
else
BuildStatus::Failed
end
end
end
def packaging_backend=(name : String)

View File

@ -1,98 +1,65 @@
enum Package::BuildStatus
Success
Failed
Pass
end
class Package::Backend::Building
getter phase : String
getter name : String
getter callback : Proc(Context, Recipe, BuildStatus)
def initialize(@phase, @name, &block : Proc(Context, Recipe, BuildStatus))
@callback = block
end
def build(context : Context, recipe : Recipe)
@callback.call context, recipe
end
end
class Package::Instructions
enum Status
Success
Failed
Pass
end
class BuildDefault
getter name : String
getter callback : Proc(Context, Recipe, Status)
def initialize(@name, &block : Proc(Context, Recipe, Status))
@callback = block
end
end
class Set < Array(String)
def initialize(@defaults_if_empty = Array(BuildDefault).new)
def initialize(@phase : String)
super()
end
# FIXME: def execute
def run(context : Context, recipe : Recipe) : Instructions::Status
def run(context : Context, recipe : Recipe) : BuildStatus
if size > 0
# FIXME: Maybe do that for [1] and the others, no?
child = context.run recipe.building_directory, "sh", ["-c", self[0]]
if child.exit_status == 0
return Instructions::Status::Success
return BuildStatus::Success
else
return Instructions::Status::Failed
return BuildStatus::Failed
end
end
@defaults_if_empty.each do |default|
context.building_backends.select(&.phase.==(@phase)).each do |backend|
Dir.cd recipe.building_directory
rvalue = default.callback.call context, recipe
rvalue = backend.build context, recipe
if rvalue == Status::Pass
if rvalue == BuildStatus::Pass
next
end
return rvalue
end
Status::Pass
BuildStatus::Pass
rescue e
# Possible TODO: print the origin of the exception (backend, user-provided code, other/unknown).
STDERR << "Exception caught: " << e.message << "\n"
Status::Failed
end
def <<(other : BuildDefault)
@defaults_if_empty << other
BuildStatus::Failed
end
end
getter configure = Set.new
getter build = Set.new
getter install = Set.new
def initialize
@build << BuildDefault.new "autotools" do |context, recipe|
Dir.cd recipe.dirname
unless File.exists? "configure"
next Instructions::Status::Pass
end
child = context.run "./configure", ["--prefix=/package"]
if child.exit_status == 0
Instructions::Status::Success
else
Instructions::Status::Failed
end
end
@build << BuildDefault.new "make" do |context, recipe|
Dir.cd recipe.dirname
unless File.exists? "Makefile"
next Instructions::Status::Pass
end
child = context.run "make"
if child.exit_status == 0
Instructions::Status::Success
else
Instructions::Status::Failed
end
end
end
# FIXME: Switch to an enum at some point?
getter configure = Set.new "configure"
getter build = Set.new "build"
getter install = Set.new "install"
def to_a
[configure, build, install]

View File

@ -94,7 +94,7 @@ class Package::Recipe
instructions.to_a.each do |instruction|
if instruction.run(@context, self).failed?
break Instructions::Status::Failed
break BuildStatus::Failed
end
end