Grooming.
parent
fa92519f4d
commit
e6645e4f3d
|
@ -16,7 +16,8 @@ class Package::Context
|
||||||
property sources_directory = Dir.current
|
property sources_directory = Dir.current
|
||||||
property packages_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
|
def initialize
|
||||||
@packaging_backends << Backend::Packaging.new "pkgutils" do |package|
|
@packaging_backends << Backend::Packaging.new "pkgutils" do |package|
|
||||||
|
@ -27,6 +28,38 @@ class Package::Context
|
||||||
end
|
end
|
||||||
|
|
||||||
@selected_packaging_backend = @packaging_backends[0]
|
@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
|
end
|
||||||
|
|
||||||
def packaging_backend=(name : String)
|
def packaging_backend=(name : String)
|
||||||
|
|
|
@ -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
|
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)
|
class Set < Array(String)
|
||||||
def initialize(@defaults_if_empty = Array(BuildDefault).new)
|
def initialize(@phase : String)
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
# FIXME: def execute
|
# FIXME: def execute
|
||||||
|
|
||||||
def run(context : Context, recipe : Recipe) : Instructions::Status
|
def run(context : Context, recipe : Recipe) : BuildStatus
|
||||||
if size > 0
|
if size > 0
|
||||||
# FIXME: Maybe do that for [1] and the others, no?
|
# FIXME: Maybe do that for [1] and the others, no?
|
||||||
child = context.run recipe.building_directory, "sh", ["-c", self[0]]
|
child = context.run recipe.building_directory, "sh", ["-c", self[0]]
|
||||||
|
|
||||||
if child.exit_status == 0
|
if child.exit_status == 0
|
||||||
return Instructions::Status::Success
|
return BuildStatus::Success
|
||||||
else
|
else
|
||||||
return Instructions::Status::Failed
|
return BuildStatus::Failed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@defaults_if_empty.each do |default|
|
context.building_backends.select(&.phase.==(@phase)).each do |backend|
|
||||||
Dir.cd recipe.building_directory
|
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
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
return rvalue
|
return rvalue
|
||||||
end
|
end
|
||||||
|
|
||||||
Status::Pass
|
BuildStatus::Pass
|
||||||
rescue e
|
rescue e
|
||||||
# Possible TODO: print the origin of the exception (backend, user-provided code, other/unknown).
|
# Possible TODO: print the origin of the exception (backend, user-provided code, other/unknown).
|
||||||
STDERR << "Exception caught: " << e.message << "\n"
|
STDERR << "Exception caught: " << e.message << "\n"
|
||||||
Status::Failed
|
BuildStatus::Failed
|
||||||
end
|
|
||||||
|
|
||||||
def <<(other : BuildDefault)
|
|
||||||
@defaults_if_empty << other
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
getter configure = Set.new
|
# FIXME: Switch to an enum at some point?
|
||||||
getter build = Set.new
|
getter configure = Set.new "configure"
|
||||||
getter install = Set.new
|
getter build = Set.new "build"
|
||||||
|
getter install = Set.new "install"
|
||||||
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
|
|
||||||
|
|
||||||
def to_a
|
def to_a
|
||||||
[configure, build, install]
|
[configure, build, install]
|
||||||
|
|
|
@ -94,7 +94,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?
|
||||||
break Instructions::Status::Failed
|
break BuildStatus::Failed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Reference in New Issue