pattern-based auto-split.
This commit is contained in:
parent
d80e1f12b3
commit
06fe475924
@ -142,6 +142,10 @@ class Package::Context
|
|||||||
Package.new(recipe, true).tap do |split|
|
Package.new(recipe, true).tap do |split|
|
||||||
split.name = "#{recipe.name}-dev"
|
split.name = "#{recipe.name}-dev"
|
||||||
split.files = ["/usr/include"]
|
split.files = ["/usr/include"]
|
||||||
|
split.file_patterns = [
|
||||||
|
Regex.new("^/lib/.*\\.a$"),
|
||||||
|
Regex.new("^/usr/lib/.*\\.a$")
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -31,6 +31,7 @@ class Package::Package
|
|||||||
|
|
||||||
# Reference for splits. Recipe#packages[0] should keep this set to `nil`.
|
# Reference for splits. Recipe#packages[0] should keep this set to `nil`.
|
||||||
property files : Array(String)?
|
property files : Array(String)?
|
||||||
|
property file_patterns : Array(Regex)?
|
||||||
|
|
||||||
def fake_root_directory
|
def fake_root_directory
|
||||||
"#{@recipe.working_directory}/root-#{name}"
|
"#{@recipe.working_directory}/root-#{name}"
|
||||||
|
@ -15,6 +15,19 @@ class URI
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module FileUtils
|
||||||
|
def self.find(directory, &block : Proc(String, Nil))
|
||||||
|
Dir.each_child directory do |child|
|
||||||
|
child_path = directory + "/" + child
|
||||||
|
yield child_path
|
||||||
|
|
||||||
|
if File.directory? child_path
|
||||||
|
self.find child_path, &block
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class Package::Recipe
|
class Package::Recipe
|
||||||
@context : Context
|
@context : Context
|
||||||
|
|
||||||
@ -136,17 +149,29 @@ class Package::Recipe
|
|||||||
(@packages + auto_splits).each do |package|
|
(@packages + auto_splits).each do |package|
|
||||||
next if package == @packages[0]
|
next if package == @packages[0]
|
||||||
|
|
||||||
files = package.files
|
files = package.files || [] of String
|
||||||
|
file_patterns = package.file_patterns || [] of Regex
|
||||||
|
|
||||||
next if files.nil? # Should only happen to @packages[0].
|
files_to_split = [] of String
|
||||||
# TODO: ↑ add public APIs that ensure it.
|
|
||||||
|
|
||||||
# FIXME: What do we do if those are not on the filesystem?
|
|
||||||
files.each do |file|
|
files.each do |file|
|
||||||
origin = "#{fake_root_directory}#{file}"
|
origin = "#{fake_root_directory}#{file}"
|
||||||
destination ="#{package.fake_root_directory}#{file}"
|
|
||||||
|
|
||||||
next unless File.exists? origin
|
if File.exists? origin
|
||||||
|
files_to_split << file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
FileUtils.find fake_root_directory do |file|
|
||||||
|
file = file[fake_root_directory.size..file.size]
|
||||||
|
pp! file
|
||||||
|
files_to_split << file if file_patterns.any? &.match file
|
||||||
|
end
|
||||||
|
|
||||||
|
# FIXME: What do we do if those are not on the filesystem?
|
||||||
|
files_to_split.each do |file|
|
||||||
|
origin = "#{fake_root_directory}#{file}"
|
||||||
|
destination ="#{package.fake_root_directory}#{file}"
|
||||||
|
|
||||||
Dir.mkdir_p File.dirname destination
|
Dir.mkdir_p File.dirname destination
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user