From 06fe475924e2d895db719d9f3ea05ffe860d067c Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Tue, 23 Jul 2019 17:33:38 +0200 Subject: [PATCH] pattern-based auto-split. --- src/context.cr | 4 ++++ src/package.cr | 1 + src/recipe.cr | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/context.cr b/src/context.cr index 2ea0bc2..1fded7d 100644 --- a/src/context.cr +++ b/src/context.cr @@ -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 diff --git a/src/package.cr b/src/package.cr index 263578b..dceb678 100644 --- a/src/package.cr +++ b/src/package.cr @@ -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}" diff --git a/src/recipe.cr b/src/recipe.cr index 7f10363..26e1c25 100644 --- a/src/recipe.cr +++ b/src/recipe.cr @@ -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