2019-07-02 03:50:50 +02:00
|
|
|
|
2019-07-03 03:48:31 +02:00
|
|
|
enum Package::BuildStatus
|
|
|
|
Success
|
|
|
|
Failed
|
|
|
|
Pass
|
|
|
|
end
|
2019-07-02 08:47:11 +02:00
|
|
|
|
2019-07-03 03:48:31 +02:00
|
|
|
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
|
2019-07-02 08:47:11 +02:00
|
|
|
end
|
2019-07-03 03:48:31 +02:00
|
|
|
end
|
2019-07-02 08:47:11 +02:00
|
|
|
|
2019-07-03 03:48:31 +02:00
|
|
|
class Package::Instructions
|
2019-07-02 03:50:50 +02:00
|
|
|
class Set < Array(String)
|
2019-07-03 03:48:31 +02:00
|
|
|
def initialize(@phase : String)
|
2019-07-02 08:47:11 +02:00
|
|
|
super()
|
|
|
|
end
|
2019-07-02 03:50:50 +02:00
|
|
|
# FIXME: def execute
|
2019-07-02 08:47:11 +02:00
|
|
|
|
2019-07-03 03:48:31 +02:00
|
|
|
def run(context : Context, recipe : Recipe) : BuildStatus
|
2019-07-02 08:47:11 +02:00
|
|
|
if size > 0
|
|
|
|
# FIXME: Maybe do that for [1] and the others, no?
|
2019-07-02 19:45:33 +02:00
|
|
|
child = context.run recipe.building_directory, "sh", ["-c", self[0]]
|
2019-07-02 08:47:11 +02:00
|
|
|
|
|
|
|
if child.exit_status == 0
|
2019-07-03 03:48:31 +02:00
|
|
|
return BuildStatus::Success
|
2019-07-02 08:47:11 +02:00
|
|
|
else
|
2019-07-03 03:48:31 +02:00
|
|
|
return BuildStatus::Failed
|
2019-07-02 08:47:11 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-03 03:48:31 +02:00
|
|
|
context.building_backends.select(&.phase.==(@phase)).each do |backend|
|
2019-07-02 19:45:33 +02:00
|
|
|
Dir.cd recipe.building_directory
|
|
|
|
|
2019-07-03 03:48:31 +02:00
|
|
|
rvalue = backend.build context, recipe
|
2019-07-02 08:47:11 +02:00
|
|
|
|
2019-07-03 03:48:31 +02:00
|
|
|
if rvalue == BuildStatus::Pass
|
2019-07-02 08:47:11 +02:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
return rvalue
|
|
|
|
end
|
|
|
|
|
2019-07-03 03:48:31 +02:00
|
|
|
BuildStatus::Pass
|
2019-07-02 08:47:11 +02:00
|
|
|
rescue e
|
|
|
|
# Possible TODO: print the origin of the exception (backend, user-provided code, other/unknown).
|
|
|
|
STDERR << "Exception caught: " << e.message << "\n"
|
2019-07-03 03:48:31 +02:00
|
|
|
BuildStatus::Failed
|
2019-07-02 08:47:11 +02:00
|
|
|
end
|
2019-07-02 03:50:50 +02:00
|
|
|
end
|
|
|
|
|
2019-07-03 03:48:31 +02:00
|
|
|
# FIXME: Switch to an enum at some point?
|
|
|
|
getter configure = Set.new "configure"
|
|
|
|
getter build = Set.new "build"
|
|
|
|
getter install = Set.new "install"
|
2019-07-02 03:50:50 +02:00
|
|
|
|
2019-07-02 08:47:11 +02:00
|
|
|
def to_a
|
|
|
|
[configure, build, install]
|
2019-07-02 03:50:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|