Grooming, Context#run.
parent
0a565ebb26
commit
ed2a48ca58
|
@ -6,5 +6,17 @@ class Package::Context
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run(chdir, command, args)
|
||||||
|
Process.run command, args, chdir: chdir, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(command, args)
|
||||||
|
run nil, command, args
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(command)
|
||||||
|
run nil, command, nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ class Package::Instructions
|
||||||
|
|
||||||
class BuildDefault
|
class BuildDefault
|
||||||
getter name : String
|
getter name : String
|
||||||
getter callback : Proc(Recipe, Status)
|
getter callback : Proc(Context, Recipe, Status)
|
||||||
def initialize(@name, &block : Proc(Recipe, Status))
|
def initialize(@name, &block : Proc(Context, Recipe, Status))
|
||||||
@callback = block
|
@callback = block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,10 +20,10 @@ class Package::Instructions
|
||||||
end
|
end
|
||||||
# FIXME: def execute
|
# FIXME: def execute
|
||||||
|
|
||||||
def run(recipe : Recipe) : Instructions::Status
|
def run(context : Context, recipe : Recipe) : Instructions::Status
|
||||||
if size > 0
|
if size > 0
|
||||||
# FIXME: Maybe do that for [1] and the others, no?
|
# 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
|
child = context.run recipe.building_directory, "sh", ["-c", self[0]]
|
||||||
|
|
||||||
if child.exit_status == 0
|
if child.exit_status == 0
|
||||||
return Instructions::Status::Success
|
return Instructions::Status::Success
|
||||||
|
@ -33,7 +33,9 @@ class Package::Instructions
|
||||||
end
|
end
|
||||||
|
|
||||||
@defaults_if_empty.each do |default|
|
@defaults_if_empty.each do |default|
|
||||||
rvalue = default.callback.call recipe
|
Dir.cd recipe.building_directory
|
||||||
|
|
||||||
|
rvalue = default.callback.call context, recipe
|
||||||
|
|
||||||
if rvalue == Status::Pass
|
if rvalue == Status::Pass
|
||||||
next
|
next
|
||||||
|
@ -59,14 +61,14 @@ class Package::Instructions
|
||||||
getter install = Set.new
|
getter install = Set.new
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@build << BuildDefault.new "autotools" do |recipe|
|
@build << BuildDefault.new "autotools" do |context, recipe|
|
||||||
Dir.cd recipe.dirname
|
Dir.cd recipe.dirname
|
||||||
|
|
||||||
unless File.exists? "configure"
|
unless File.exists? "configure"
|
||||||
next Instructions::Status::Pass
|
next Instructions::Status::Pass
|
||||||
end
|
end
|
||||||
|
|
||||||
child = Process.run("./configure", ["--prefix=/package"], output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
|
child = context.run "./configure", ["--prefix=/package"]
|
||||||
|
|
||||||
if child.exit_status == 0
|
if child.exit_status == 0
|
||||||
Instructions::Status::Success
|
Instructions::Status::Success
|
||||||
|
@ -75,14 +77,14 @@ class Package::Instructions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@build << BuildDefault.new "make" do |recipe|
|
@build << BuildDefault.new "make" do |context, recipe|
|
||||||
Dir.cd recipe.dirname
|
Dir.cd recipe.dirname
|
||||||
|
|
||||||
unless File.exists? "Makefile"
|
unless File.exists? "Makefile"
|
||||||
next Instructions::Status::Pass
|
next Instructions::Status::Pass
|
||||||
end
|
end
|
||||||
|
|
||||||
child = Process.run("make", output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
|
child = context.run "make"
|
||||||
|
|
||||||
if child.exit_status == 0
|
if child.exit_status == 0
|
||||||
Instructions::Status::Success
|
Instructions::Status::Success
|
||||||
|
|
|
@ -55,7 +55,7 @@ class Package::Recipe
|
||||||
def download
|
def download
|
||||||
sources.map do |url|
|
sources.map do |url|
|
||||||
unless File.exists? url.basename
|
unless File.exists? url.basename
|
||||||
Process.run "wget", [ url.to_s, "-O", @context.sources_directory + "/" + url.basename ], output: Process::Redirect::Inherit, error: Process::Redirect::Inherit
|
@context.run @context.sources_directory, "wget", [ url.to_s, "-O", url.basename ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -66,7 +66,7 @@ class Package::Recipe
|
||||||
sources.map do |url|
|
sources.map do |url|
|
||||||
basename = url.basename
|
basename = url.basename
|
||||||
|
|
||||||
Process.run "tar", [ "xvf", @context.sources_directory + "/" + url.basename ], output: Process::Redirect::Inherit, error: Process::Redirect::Inherit, chdir: building_directory
|
@context.run building_directory, "tar", [ "xvf", @context.sources_directory + "/" + url.basename ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,11 +84,11 @@ class Package::Recipe
|
||||||
|
|
||||||
ENV["PKG"] = fake_root_directory
|
ENV["PKG"] = fake_root_directory
|
||||||
|
|
||||||
|
# Safety precautions.
|
||||||
old_dir = Dir.current
|
old_dir = Dir.current
|
||||||
|
|
||||||
instructions.to_a.each do |instruction|
|
instructions.to_a.each do |instruction|
|
||||||
Dir.cd building_directory
|
if instruction.run(@context, self).failed?
|
||||||
if instruction.run(self).failed?
|
|
||||||
break Instructions::Status::Failed
|
break Instructions::Status::Failed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -102,7 +102,7 @@ class Package::Recipe
|
||||||
|
|
||||||
def package
|
def package
|
||||||
puts "#{fake_root_directory} -> #{@context.packages_directory}/#{name}##{version}.pkg.tar.xz"
|
puts "#{fake_root_directory} -> #{@context.packages_directory}/#{name}##{version}.pkg.tar.xz"
|
||||||
pp! Process.run "tar", ["cJf", "#{@context.packages_directory}/#{name}##{version}.pkg.tar.xz", "."], output: Process::Redirect::Inherit, error: Process::Redirect::Inherit, chdir: fake_root_directory
|
pp! @context.run fake_root_directory, "tar", ["cJf", "#{@context.packages_directory}/#{name}##{version}.pkg.tar.xz", "."]
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean
|
def clean
|
||||||
|
|
Reference in New Issue