Archived
3
0

pattern-based auto-split.

This commit is contained in:
Luka Vandervelden 2019-07-23 17:33:38 +02:00
parent d80e1f12b3
commit 06fe475924
3 changed files with 36 additions and 6 deletions

View File

@ -142,6 +142,10 @@ class Package::Context
Package.new(recipe, true).tap do |split|
split.name = "#{recipe.name}-dev"
split.files = ["/usr/include"]
split.file_patterns = [
Regex.new("^/lib/.*\\.a$"),
Regex.new("^/usr/lib/.*\\.a$")
]
end
end
end

View File

@ -31,6 +31,7 @@ class Package::Package
# Reference for splits. Recipe#packages[0] should keep this set to `nil`.
property files : Array(String)?
property file_patterns : Array(Regex)?
def fake_root_directory
"#{@recipe.working_directory}/root-#{name}"

View File

@ -15,6 +15,19 @@ class URI
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
@context : Context
@ -136,17 +149,29 @@ class Package::Recipe
(@packages + auto_splits).each do |package|
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].
# TODO: ↑ add public APIs that ensure it.
files_to_split = [] of String
# FIXME: What do we do if those are not on the filesystem?
files.each do |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