Obsolete
/
packaging
Archived
3
0
Fork 0
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

102 lines
2.0 KiB
Crystal
Raw Normal View History

2019-07-02 03:50:50 +02:00
class Package::Instructions
2019-07-02 08:47:11 +02:00
enum Status
Success
Failed
Pass
end
class BuildDefault
getter name : String
2019-07-02 19:45:33 +02:00
getter callback : Proc(Context, Recipe, Status)
def initialize(@name, &block : Proc(Context, Recipe, Status))
2019-07-02 08:47:11 +02:00
@callback = block
end
end
2019-07-02 03:50:50 +02:00
class Set < Array(String)
2019-07-02 08:47:11 +02:00
def initialize(@defaults_if_empty = Array(BuildDefault).new)
super()
end
2019-07-02 03:50:50 +02:00
# FIXME: def execute
2019-07-02 08:47:11 +02:00
2019-07-02 19:45:33 +02:00
def run(context : Context, recipe : Recipe) : Instructions::Status
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
return Instructions::Status::Success
else
return Instructions::Status::Failed
end
end
@defaults_if_empty.each do |default|
2019-07-02 19:45:33 +02:00
Dir.cd recipe.building_directory
rvalue = default.callback.call context, recipe
2019-07-02 08:47:11 +02:00
if rvalue == Status::Pass
next
end
return rvalue
end
Status::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
end
2019-07-02 03:50:50 +02:00
end
getter configure = Set.new
getter build = Set.new
getter install = Set.new
def initialize
2019-07-02 19:45:33 +02:00
@build << BuildDefault.new "autotools" do |context, recipe|
2019-07-02 08:47:11 +02:00
Dir.cd recipe.dirname
unless File.exists? "configure"
next Instructions::Status::Pass
end
2019-07-02 19:45:33 +02:00
child = context.run "./configure", ["--prefix=/package"]
2019-07-02 08:47:11 +02:00
if child.exit_status == 0
Instructions::Status::Success
else
Instructions::Status::Failed
end
end
2019-07-02 19:45:33 +02:00
@build << BuildDefault.new "make" do |context, recipe|
2019-07-02 08:47:11 +02:00
Dir.cd recipe.dirname
unless File.exists? "Makefile"
next Instructions::Status::Pass
end
2019-07-02 19:45:33 +02:00
child = context.run "make"
2019-07-02 08:47:11 +02:00
if child.exit_status == 0
Instructions::Status::Success
else
Instructions::Status::Failed
end
end
2019-07-02 03:50:50 +02:00
end
2019-07-02 08:47:11 +02:00
def to_a
[configure, build, install]
2019-07-02 03:50:50 +02:00
end
end