Archived
3
0

backend#install packages

This commit is contained in:
Philippe Pittoli 2021-02-28 20:56:51 +01:00
parent a4c53f2b8c
commit 20376a36ed
6 changed files with 76 additions and 50 deletions

View File

@ -6,6 +6,12 @@ abstract class Package::Backend::Packaging
end end
abstract def package(context : Context, package : Package) : Bool abstract def package(context : Context, package : Package) : Bool
def self.install(packages : Array(String))
raise "'install' unimplemented for this backend, yet"
end
def install(packages : Array(String))
self.install packages
end
end end
class Package::Backend::Splitter class Package::Backend::Splitter

View File

@ -1,13 +1,37 @@
require "../backends.cr" require "../backends.cr"
# FIXME: Where should this go? We cant just leave it here. :( class ApkBackend < Package::Backend::Packaging
def pkginfo(package) def initialize
@name = "apk"
end
def package(context : Package::Context, package : Package::Package) : Bool
# FIXME: This needs to have access to architecture (from Context?)
# to work properly.
old_cwd = Dir.current
File.write "#{package.fake_root_directory}/.PKGINFO", ApkBackend.pkginfo package
# Create data.tar.gz here.
package_target = "#{context.packages_directory}/#{context.architecture}/#{package.name}-#{package.version}-r#{package.release}.apk"
Dir.mkdir_p File.dirname package_target
# FIXME: This shouldnt have to be in users PATH. libexec?
r = context.run package.fake_root_directory, "#{OWN_LIBEXEC_DIR}/assemble-apk.sh", [
package_target
]
r.exit_status == 0
end
# This generated file content is specific to the Apk package manager.
def self.pkginfo(package)
du = `du -sk #{package.fake_root_directory}` du = `du -sk #{package.fake_root_directory}`
size = du.sub(/[ \t].*/, "").to_i * 1024 size = du.sub(/[ \t].*/, "").to_i * 1024
lines = [] of String lines = [] of String
lines << "# Generated by `package`." lines << "# Generated by `packaging`."
lines << "pkgname = #{package.name}" lines << "pkgname = #{package.name}"
lines << "pkgver = #{package.version}-r#{package.release}" lines << "pkgver = #{package.version}-r#{package.release}"
lines << "url = #{package.url || ""} " lines << "url = #{package.url || ""} "
@ -29,30 +53,20 @@ def pkginfo(package)
end end
lines.join("\n") + "\n" lines.join("\n") + "\n"
end
class ApkBackend < Package::Backend::Packaging
def initialize
@name = "apk"
end end
def package(context : Package::Context, package : Package::Package) : Bool # Install programs.
# FIXME: This needs to have access to architecture (from Context?) def self.install(packages : Array(String))
# to work properly. opts = ["add"] + (ENV["APK_FLAGS"]? || "-i").split(/[ \t]+/) + packages
old_cwd = Dir.current puts "+ apk #{opts.join " "}"
r = Process.run "apk", opts,
File.write "#{package.fake_root_directory}/.PKGINFO", pkginfo package output: Process::Redirect::Inherit,
input: Process::Redirect::Inherit,
# Create data.tar.gz here. error: Process::Redirect::Inherit
package_target = "#{context.packages_directory}/#{context.architecture}/#{package.name}-#{package.version}-r#{package.release}.apk" if r.exit_status != 0
Dir.mkdir_p File.dirname package_target STDERR.puts "!! Running apk failed!"
exit 8
# FIXME: This shouldnt have to be in users PATH. libexec? end
r = context.run package.fake_root_directory, "#{OWN_LIBEXEC_DIR}/assemble-apk.sh", [
package_target
]
r.exit_status == 0
end end
end end

View File

@ -18,7 +18,7 @@ class BaguetteBackend < Package::Backend::Packaging
control_spec_file_path = "#{tmpdir}/control.spec" control_spec_file_path = "#{tmpdir}/control.spec"
manifest_file_path = "#{tmpdir}/manifest" manifest_file_path = "#{tmpdir}/manifest"
package_filename = "#{context.packages_directory}/#{package.name}-#{package.version}-#{package.release}.baguette" package_target = "#{context.packages_directory}/#{package.name}-#{package.version}-#{package.release}.baguette"
context.detail "Archiving package content" context.detail "Archiving package content"
context.run fake_root, "tar", ["cvf", data_archive_path, "."] context.run fake_root, "tar", ["cvf", data_archive_path, "."]
@ -33,9 +33,9 @@ class BaguetteBackend < Package::Backend::Packaging
context.detail "Generating manifest" context.detail "Generating manifest"
generate_manifest context, package, manifest_file_path generate_manifest context, package, manifest_file_path
context.detail "Assembling '#{package_filename}'" context.detail "Assembling '#{package_target}'"
r = context.run tmpdir, "tar", [ r = context.run tmpdir, "tar", [
"cf", package_filename, "cf", package_target,
# WARNING: relative paths are necessary. # WARNING: relative paths are necessary.
"control.spec", "manifest", "data.tar.zst" "control.spec", "manifest", "data.tar.zst"
] ]
@ -93,5 +93,10 @@ class BaguetteBackend < Package::Backend::Packaging
ensure ensure
Dir.cd old_pwd.not_nil! Dir.cd old_pwd.not_nil!
end end
def self.install(packages : Array(String))
# TODO: install packages through package-install
raise "call to package-install not implemented, yet"
end
end end

View File

@ -153,6 +153,11 @@ class Package::Context
end end
end end
# Splitters = creating new packages:
# keep prefixes
# split names (man, src, ...)
# split files
@splitter_backends << Backend::Splitter.new do |recipe| @splitter_backends << Backend::Splitter.new do |recipe|
Package.new(recipe, true).tap do |split| Package.new(recipe, true).tap do |split|
prefixes = (@prefixes + [recipe.prefix]).uniq prefixes = (@prefixes + [recipe.prefix]).uniq
@ -331,5 +336,9 @@ class Package::Context
end end
end end
end end
def install(packages : Array(String))
@selected_packaging_backend.install packages
end
end end

View File

@ -158,17 +158,9 @@ begin
end end
if dependencies.size > 0 && ! skip_build_dependencies && !download_only if dependencies.size > 0 && ! skip_build_dependencies && !download_only
# FIXME: Well probably want to have backends other than apk at some point. # TODO: change this. We want other backends.
opts = ["add"] + (ENV["APK_FLAGS"]? || "-i").split(/[ \t]+/) + dependencies # TODO: write something in Context
puts "+ apk #{opts.join " "}" context.install dependencies
r = Process.run "apk", opts,
output: Process::Redirect::Inherit,
input: Process::Redirect::Inherit,
error: Process::Redirect::Inherit
if r.exit_status != 0
STDERR.puts "!! Running apk failed!"
exit 8
end
end end
recipes.each do |recipe| recipes.each do |recipe|

View File

@ -23,8 +23,8 @@ class Package::Package
when "description" when "description"
@description = value.as_s_or_ls @description = value.as_s_or_ls
when "dependencies" when "dependencies"
# Remember, no build-dep versus run-dep for # Remember, no build-dep versus run-dep for packages!
# packages! Build-deps are recipe-only! # Build-deps are recipe-only!
@dependencies = value.as_a_or_s @dependencies = value.as_a_or_s
when "conflicts" when "conflicts"
@conflicts = value.as_a_or_s @conflicts = value.as_a_or_s
@ -77,8 +77,8 @@ class Package::Package
@fake_root_directory || "#{recipe.working_directory}/root-#{name}" @fake_root_directory || "#{recipe.working_directory}/root-#{name}"
end end
def to_s def to_s(io : IO)
"<Package: #{name}-#{version}>" io << "<Package: #{name}-#{version}>"
end end
end end