From 255d644b93851da4727ea2019f90dd7a3a01c0ff Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Thu, 4 Jul 2019 07:51:00 +0200 Subject: [PATCH] Splits (sub-packages) support. --- src/context.cr | 2 -- src/main.cr | 5 +++++ src/package.cr | 8 ++++++-- src/recipe.cr | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/context.cr b/src/context.cr index 20c05df..188e15d 100644 --- a/src/context.cr +++ b/src/context.cr @@ -54,8 +54,6 @@ class Package::Context puts "#{package.fake_root_directory} -> #{packages_directory}/#{package.name}-#{package.version}-r#{package.release}.apk" - run package.fake_root_directory, "find", [".."] - puts pkginfo package File.write "#{package.fake_root_directory}/.PKGINFO", pkginfo package diff --git a/src/main.cr b/src/main.cr index 4755e88..636e5ff 100644 --- a/src/main.cr +++ b/src/main.cr @@ -25,6 +25,11 @@ 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.download recipe.extract diff --git a/src/package.cr b/src/package.cr index d765b4a..8a51337 100644 --- a/src/package.cr +++ b/src/package.cr @@ -28,8 +28,12 @@ class Package::Package inherit conflicts : Array(String) inherit provides : Array(String) - # Internals - inherit fake_root_directory : String + # Reference for splits. Recipe#packages[0] should keep this set to `nil`. + property files : Array(String)? + + def fake_root_directory + "#{@recipe.working_directory}/root-#{name}" + end def to_s "" diff --git a/src/recipe.cr b/src/recipe.cr index 642cf8c..a5e29ff 100644 --- a/src/recipe.cr +++ b/src/recipe.cr @@ -68,7 +68,7 @@ class Package::Recipe end def fake_root_directory - "#{working_directory}/root" + @packages[0].fake_root_directory end def dirname @@ -120,9 +120,40 @@ class Package::Recipe ENV["PKG"] = nil + do_splits + success end + private def do_splits + @packages.each do |package| + next if package == @packages[0] + + files = package.files + + 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}" + + FileUtils.mv( + "#{fake_root_directory}#{file}", + "#{package.fake_root_directory}#{file}" + ) + + puts file + @context.run "find", [ + "#{package.fake_root_directory}/#{file}" + ] + end + end + end + # TODO: # - Errors management. Stop at first failure? # - Splits. This should be done between #build and #package.