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

100 lines
2.1 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
getter callback : Proc(Recipe, Status)
def initialize(@name, &block : Proc(Recipe, Status))
@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
def run(recipe : Recipe) : Instructions::Status
if size > 0
# FIXME: Maybe do that for [1] and the others, no?
child = Process.run "sh", ["-c", self[0]], output: Process::Redirect::Inherit, error: Process::Redirect::Inherit
if child.exit_status == 0
return Instructions::Status::Success
else
return Instructions::Status::Failed
end
end
@defaults_if_empty.each do |default|
rvalue = default.callback.call recipe
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 08:47:11 +02:00
@build << BuildDefault.new "autotools" do |recipe|
Dir.cd recipe.dirname
unless File.exists? "configure"
next Instructions::Status::Pass
end
child = Process.run("./configure", ["--prefix=/package"], output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
if child.exit_status == 0
Instructions::Status::Success
else
Instructions::Status::Failed
end
end
@build << BuildDefault.new "make" do |recipe|
Dir.cd recipe.dirname
unless File.exists? "Makefile"
next Instructions::Status::Pass
end
child = Process.run("make", output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
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