diff --git a/src/context.cr b/src/context.cr index 935de4d..6a41b6f 100644 --- a/src/context.cr +++ b/src/context.cr @@ -6,5 +6,17 @@ class Package::Context def initialize 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 diff --git a/src/instructions.cr b/src/instructions.cr index cf8b509..524701b 100644 --- a/src/instructions.cr +++ b/src/instructions.cr @@ -8,8 +8,8 @@ class Package::Instructions class BuildDefault getter name : String - getter callback : Proc(Recipe, Status) - def initialize(@name, &block : Proc(Recipe, Status)) + getter callback : Proc(Context, Recipe, Status) + def initialize(@name, &block : Proc(Context, Recipe, Status)) @callback = block end end @@ -20,10 +20,10 @@ class Package::Instructions end # FIXME: def execute - def run(recipe : Recipe) : Instructions::Status + def run(context : Context, 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 + child = context.run recipe.building_directory, "sh", ["-c", self[0]] if child.exit_status == 0 return Instructions::Status::Success @@ -33,7 +33,9 @@ class Package::Instructions end @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 next @@ -59,14 +61,14 @@ class Package::Instructions getter install = Set.new def initialize - @build << BuildDefault.new "autotools" do |recipe| + @build << BuildDefault.new "autotools" do |context, 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) + child = context.run "./configure", ["--prefix=/package"] if child.exit_status == 0 Instructions::Status::Success @@ -75,14 +77,14 @@ class Package::Instructions end end - @build << BuildDefault.new "make" do |recipe| + @build << BuildDefault.new "make" do |context, 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) + child = context.run "make" if child.exit_status == 0 Instructions::Status::Success diff --git a/src/recipe.cr b/src/recipe.cr index 8ccf71c..1233b0e 100644 --- a/src/recipe.cr +++ b/src/recipe.cr @@ -55,7 +55,7 @@ class Package::Recipe def download sources.map do |url| 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 @@ -66,7 +66,7 @@ class Package::Recipe sources.map do |url| 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 @@ -84,11 +84,11 @@ class Package::Recipe ENV["PKG"] = fake_root_directory + # Safety precautions. old_dir = Dir.current instructions.to_a.each do |instruction| - Dir.cd building_directory - if instruction.run(self).failed? + if instruction.run(@context, self).failed? break Instructions::Status::Failed end end @@ -102,7 +102,7 @@ class Package::Recipe def package 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 def clean