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/context.cr

90 lines
2.1 KiB
Crystal
Raw Normal View History

2019-07-02 03:50:50 +02:00
2019-07-03 03:35:35 +02:00
class Package::Backend::Packaging
getter name : String
def initialize(@name, &block : Proc(Package, Bool))
@callback = block
end
def package(package : Package)
@callback.call package
end
end
2019-07-02 03:50:50 +02:00
class Package::Context
property working_directory = "/tmp/package"
property sources_directory = Dir.current
property packages_directory = Dir.current
2019-07-03 03:48:31 +02:00
getter packaging_backends = [] of Backend::Packaging
getter building_backends = [] of Backend::Building
2019-07-03 03:35:35 +02:00
2019-07-02 03:50:50 +02:00
def initialize
2019-07-03 03:35:35 +02:00
@packaging_backends << Backend::Packaging.new "pkgutils" do |package|
puts "#{package.fake_root_directory} -> #{packages_directory}/#{package.name}##{package.version}.pkg.tar.xz"
pp! r = run package.fake_root_directory, "tar", ["cJf", "#{packages_directory}/#{package.name}##{package.version}.pkg.tar.xz", "."]
r.exit_status == 0
end
@selected_packaging_backend = @packaging_backends[0]
2019-07-03 03:48:31 +02:00
@building_backends << Backend::Building.new "configure", "autotools" do |context, recipe|
Dir.cd recipe.dirname
unless File.exists? "configure"
next BuildStatus::Pass
end
child = context.run "./configure", ["--prefix=/package"]
if child.exit_status == 0
BuildStatus::Success
else
BuildStatus::Failed
end
end
@building_backends << Backend::Building.new "build", "make" do |context, recipe|
Dir.cd recipe.dirname
unless File.exists? "Makefile"
next BuildStatus::Pass
end
child = context.run "make"
if child.exit_status == 0
BuildStatus::Success
else
BuildStatus::Failed
end
end
2019-07-03 03:35:35 +02:00
end
def packaging_backend=(name : String)
@selected_packaging_backend = @packaging_backends.find(&.name.==(name)).not_nil!
end
def packaging_backend=(backend : Backend::Packaging)
@selected_packaging_backend = backend
2019-07-02 03:50:50 +02:00
end
2019-07-02 19:45:33 +02:00
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
def package(package : Package) : Bool
2019-07-03 03:35:35 +02:00
@selected_packaging_backend.package package
end
2019-07-02 03:50:50 +02:00
end