This repository has been archived on 2022-01-17. You can view files and clone it, but cannot push or open issues/pull-requests.
packaging/src/instructions.cr

71 lines
1.5 KiB
Crystal
Raw Normal View History

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-08-16 14:55:25 +02:00
getter phase : String
def initialize(@phase)
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
2019-07-21 15:24:30 +02:00
each do |command|
child = Do.run recipe.building_directory, "sh", ["-x", "-c", command]
2019-07-02 08:47:11 +02:00
2019-07-21 15:24:30 +02:00
if child.exit_status != 0
return BuildStatus::Failed
end
2019-07-02 08:47:11 +02:00
end
2019-07-21 15:24:30 +02:00
return BuildStatus::Success
2019-07-02 08:47:11 +02:00
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