71 lines
1.5 KiB
Crystal
71 lines
1.5 KiB
Crystal
|
|
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 Set < Array(String)
|
|
getter phase : String
|
|
def initialize(@phase)
|
|
super()
|
|
end
|
|
# FIXME: def execute
|
|
|
|
def run(context : Context, recipe : Recipe) : BuildStatus
|
|
if size > 0
|
|
each do |command|
|
|
child = context.run recipe.building_directory, "sh", ["-x", "-c", command]
|
|
|
|
if child.exit_status != 0
|
|
return BuildStatus::Failed
|
|
end
|
|
end
|
|
|
|
return BuildStatus::Success
|
|
end
|
|
|
|
context.building_backends.select(&.phase.==(@phase)).each do |backend|
|
|
Dir.cd recipe.building_directory
|
|
|
|
rvalue = backend.build context, recipe
|
|
|
|
if rvalue == BuildStatus::Pass
|
|
next
|
|
end
|
|
|
|
return rvalue
|
|
end
|
|
|
|
BuildStatus::Pass
|
|
rescue e
|
|
# Possible TODO: print the origin of the exception (backend, user-provided code, other/unknown).
|
|
STDERR << "Exception caught: " << e.message << "\n"
|
|
BuildStatus::Failed
|
|
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]
|
|
end
|
|
end
|
|
|