Autosplits.

master
Luka Vandervelden 2019-07-04 23:18:54 +02:00
parent 255d644b93
commit b2586be87b
4 changed files with 51 additions and 9 deletions

View File

@ -27,6 +27,16 @@ class Package::Backend::Packaging
end
end
class Package::Backend::Splitter
def initialize(&block : Proc(Recipe, Package))
@callback = block
end
def create_split(recipe : Recipe) : Package
@callback.call recipe
end
end
class Package::Context
property working_directory = "/tmp/package"
property sources_directory = Dir.current
@ -34,6 +44,7 @@ class Package::Context
getter packaging_backends = [] of Backend::Packaging
getter building_backends = [] of Backend::Building
getter splitter_backends = [] of Backend::Splitter
# Well, this will need configuration, auto-detection and conversion,
# but itll be kind of enough for now.
@ -119,6 +130,20 @@ class Package::Context
BuildStatus::Failed
end
end
@splitter_backends << Backend::Splitter.new do |recipe|
Package.new(recipe, true).tap do |split|
split.name = "#{recipe.name}-man"
split.files = ["/usr/share/man", "/package/share/man"]
end
end
@splitter_backends << Backend::Splitter.new do |recipe|
Package.new(recipe, true).tap do |split|
split.name = "#{recipe.name}-dev"
split.files = ["/usr/include", "/package/include"]
end
end
end
def packaging_backend=(name : String)

View File

@ -25,10 +25,13 @@ Context.new().tap do |context|
recipe.description = "The GNU Hello program produces a familiar, friendly greeting."
recipe.dependencies << "gettext"
recipe.packages << Package::Package.new(recipe).tap do |package|
package.name = "#{recipe.name}-man"
package.files = ["/package/share/man"]
end
recipe.auto_split
# Should be automatic now.
#recipe.packages << Package::Package.new(recipe).tap do |package|
# package.name = "#{recipe.name}-man"
# package.files = ["/package/share/man"]
#end
recipe.download
recipe.extract

View File

@ -1,8 +1,9 @@
class Package::Package
getter recipe : Recipe
getter automatic : Bool
def initialize(@recipe)
def initialize(@recipe, @automatic = false)
end
macro inherit(attribute)

View File

@ -134,12 +134,14 @@ class Package::Recipe
next if files.nil? # Should only happen to @packages[0].
# TODO: ↑ add public APIs that ensure it.
Dir.mkdir_p package.fake_root_directory
# FIXME: What do we do if those are not on the filesystem?
files.each do |file|
puts "#{package.fake_root_directory}#{File.dirname file}"
Dir.mkdir_p "#{package.fake_root_directory}#{File.dirname file}"
origin = "#{fake_root_directory}#{file}"
destination ="#{package.fake_root_directory}#{file}"
next unless File.exists? origin
Dir.mkdir_p File.dirname destination
FileUtils.mv(
"#{fake_root_directory}#{file}",
@ -154,11 +156,22 @@ class Package::Recipe
end
end
def auto_split
@context.splitter_backends.each do |backend|
@packages << backend.create_split self
end
end
# TODO:
# - Errors management. Stop at first failure?
# - Splits. This should be done between #build and #package.
def package
# FIXME: if package.automatic and no file, do not build.
@packages.find do |package|
if package.automatic && ! File.exists? package.fake_root_directory
next
end
! @context.package package
end
end