PoC automatic building.
This commit is contained in:
parent
928559f71f
commit
0a565ebb26
@ -1,7 +1,57 @@
|
|||||||
|
|
||||||
class Package::Instructions
|
class Package::Instructions
|
||||||
|
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
|
||||||
|
|
||||||
class Set < Array(String)
|
class Set < Array(String)
|
||||||
|
def initialize(@defaults_if_empty = Array(BuildDefault).new)
|
||||||
|
super()
|
||||||
|
end
|
||||||
# FIXME: def execute
|
# FIXME: def execute
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
getter configure = Set.new
|
getter configure = Set.new
|
||||||
@ -9,10 +59,41 @@ class Package::Instructions
|
|||||||
getter install = Set.new
|
getter install = Set.new
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
def map(&block : Proc(String, Nil))
|
def to_a
|
||||||
(configure + build + install).map &block
|
[configure, build, install]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -13,11 +13,11 @@ Context.new().tap do |context|
|
|||||||
recipe.download
|
recipe.download
|
||||||
recipe.extract
|
recipe.extract
|
||||||
|
|
||||||
recipe.instructions.configure << "cd hello-#{recipe.version} && ./configure"
|
#recipe.instructions.configure << "cd hello-#{recipe.version} && ./configure"
|
||||||
recipe.instructions.build << "cd hello-#{recipe.version} && make"
|
#recipe.instructions.build << "cd hello-#{recipe.version} && make"
|
||||||
recipe.instructions.install << "cd hello-#{recipe.version} && make DESTDIR='${PKG}' install"
|
recipe.instructions.install << "cd hello-#{recipe.version} && make DESTDIR='${PKG}' install"
|
||||||
|
|
||||||
recipe.build
|
raise "oh no, build failed" unless recipe.build
|
||||||
recipe.package
|
recipe.package
|
||||||
|
|
||||||
recipe.clean
|
recipe.clean
|
||||||
|
@ -20,6 +20,7 @@ class Package::Recipe
|
|||||||
|
|
||||||
getter name : String
|
getter name : String
|
||||||
getter version : String
|
getter version : String
|
||||||
|
getter dirname : String?
|
||||||
|
|
||||||
getter sources : Sources
|
getter sources : Sources
|
||||||
getter packages : Array(Package)
|
getter packages : Array(Package)
|
||||||
@ -47,6 +48,10 @@ class Package::Recipe
|
|||||||
"#{working_directory}/root"
|
"#{working_directory}/root"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dirname
|
||||||
|
@dirname || "#{name}-#{version}"
|
||||||
|
end
|
||||||
|
|
||||||
def download
|
def download
|
||||||
sources.map do |url|
|
sources.map do |url|
|
||||||
unless File.exists? url.basename
|
unless File.exists? url.basename
|
||||||
@ -73,15 +78,26 @@ class Package::Recipe
|
|||||||
# goes somehow wrong.
|
# goes somehow wrong.
|
||||||
# - Make things thread-safe. (those ENV[]= calls are definitely not)
|
# - Make things thread-safe. (those ENV[]= calls are definitely not)
|
||||||
def build
|
def build
|
||||||
|
success = true
|
||||||
|
|
||||||
Dir.mkdir_p fake_root_directory
|
Dir.mkdir_p fake_root_directory
|
||||||
|
|
||||||
ENV["PKG"] = fake_root_directory
|
ENV["PKG"] = fake_root_directory
|
||||||
|
|
||||||
instructions.map do |script|
|
old_dir = Dir.current
|
||||||
pp! Process.run "sh", ["-c", script], output: Process::Redirect::Inherit, error: Process::Redirect::Inherit, chdir: building_directory
|
|
||||||
|
instructions.to_a.each do |instruction|
|
||||||
|
Dir.cd building_directory
|
||||||
|
if instruction.run(self).failed?
|
||||||
|
break Instructions::Status::Failed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Dir.cd old_dir
|
||||||
|
|
||||||
ENV["PKG"] = nil
|
ENV["PKG"] = nil
|
||||||
|
|
||||||
|
success
|
||||||
end
|
end
|
||||||
|
|
||||||
def package
|
def package
|
||||||
|
Reference in New Issue
Block a user