Autosplits.
This commit is contained in:
parent
255d644b93
commit
b2586be87b
@ -27,6 +27,16 @@ class Package::Backend::Packaging
|
|||||||
end
|
end
|
||||||
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
|
class Package::Context
|
||||||
property working_directory = "/tmp/package"
|
property working_directory = "/tmp/package"
|
||||||
property sources_directory = Dir.current
|
property sources_directory = Dir.current
|
||||||
@ -34,6 +44,7 @@ class Package::Context
|
|||||||
|
|
||||||
getter packaging_backends = [] of Backend::Packaging
|
getter packaging_backends = [] of Backend::Packaging
|
||||||
getter building_backends = [] of Backend::Building
|
getter building_backends = [] of Backend::Building
|
||||||
|
getter splitter_backends = [] of Backend::Splitter
|
||||||
|
|
||||||
# Well, this will need configuration, auto-detection and conversion,
|
# Well, this will need configuration, auto-detection and conversion,
|
||||||
# but it’ll be kind of enough for now.
|
# but it’ll be kind of enough for now.
|
||||||
@ -119,6 +130,20 @@ class Package::Context
|
|||||||
BuildStatus::Failed
|
BuildStatus::Failed
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
def packaging_backend=(name : String)
|
def packaging_backend=(name : String)
|
||||||
|
11
src/main.cr
11
src/main.cr
@ -25,10 +25,13 @@ Context.new().tap do |context|
|
|||||||
recipe.description = "The GNU Hello program produces a familiar, friendly greeting."
|
recipe.description = "The GNU Hello program produces a familiar, friendly greeting."
|
||||||
recipe.dependencies << "gettext"
|
recipe.dependencies << "gettext"
|
||||||
|
|
||||||
recipe.packages << Package::Package.new(recipe).tap do |package|
|
recipe.auto_split
|
||||||
package.name = "#{recipe.name}-man"
|
|
||||||
package.files = ["/package/share/man"]
|
# Should be automatic now.
|
||||||
end
|
#recipe.packages << Package::Package.new(recipe).tap do |package|
|
||||||
|
# package.name = "#{recipe.name}-man"
|
||||||
|
# package.files = ["/package/share/man"]
|
||||||
|
#end
|
||||||
|
|
||||||
recipe.download
|
recipe.download
|
||||||
recipe.extract
|
recipe.extract
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
|
||||||
class Package::Package
|
class Package::Package
|
||||||
getter recipe : Recipe
|
getter recipe : Recipe
|
||||||
|
getter automatic : Bool
|
||||||
|
|
||||||
def initialize(@recipe)
|
def initialize(@recipe, @automatic = false)
|
||||||
end
|
end
|
||||||
|
|
||||||
macro inherit(attribute)
|
macro inherit(attribute)
|
||||||
|
@ -134,12 +134,14 @@ class Package::Recipe
|
|||||||
next if files.nil? # Should only happen to @packages[0].
|
next if files.nil? # Should only happen to @packages[0].
|
||||||
# TODO: ↑ add public APIs that ensure it.
|
# 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?
|
# FIXME: What do we do if those are not on the filesystem?
|
||||||
files.each do |file|
|
files.each do |file|
|
||||||
puts "#{package.fake_root_directory}#{File.dirname file}"
|
origin = "#{fake_root_directory}#{file}"
|
||||||
Dir.mkdir_p "#{package.fake_root_directory}#{File.dirname file}"
|
destination ="#{package.fake_root_directory}#{file}"
|
||||||
|
|
||||||
|
next unless File.exists? origin
|
||||||
|
|
||||||
|
Dir.mkdir_p File.dirname destination
|
||||||
|
|
||||||
FileUtils.mv(
|
FileUtils.mv(
|
||||||
"#{fake_root_directory}#{file}",
|
"#{fake_root_directory}#{file}",
|
||||||
@ -154,11 +156,22 @@ class Package::Recipe
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def auto_split
|
||||||
|
@context.splitter_backends.each do |backend|
|
||||||
|
@packages << backend.create_split self
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# - Errors management. Stop at first failure?
|
# - Errors management. Stop at first failure?
|
||||||
# - Splits. This should be done between #build and #package.
|
# - Splits. This should be done between #build and #package.
|
||||||
def package
|
def package
|
||||||
|
# FIXME: if package.automatic and no file, do not build.
|
||||||
@packages.find do |package|
|
@packages.find do |package|
|
||||||
|
if package.automatic && ! File.exists? package.fake_root_directory
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
! @context.package package
|
! @context.package package
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user