`backend`#install packages

master
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
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
class Package::Backend::Splitter

View File

@ -1,36 +1,5 @@
require "../backends.cr"
# FIXME: Where should this go? We cant just leave it here. :(
def pkginfo(package)
du = `du -sk #{package.fake_root_directory}`
size = du.sub(/[ \t].*/, "").to_i * 1024
lines = [] of String
lines << "# Generated by `package`."
lines << "pkgname = #{package.name}"
lines << "pkgver = #{package.version}-r#{package.release}"
lines << "url = #{package.url || ""} "
lines << "size = #{size}"
lines << "origin = #{package.recipe.name}"
lines << "buildtype = host" # Thisll need to be imported from Context.
lines << "builddate = #{Time.utc.to_unix}"
package.dependencies.each do |atom|
lines << "depend = #{atom.to_s}"
end
package.provides.each do |atom|
lines << "provides = #{atom.to_s}"
end
package.conflicts.each do |atom|
lines << "conflicts = #{atom.to_s}"
end
lines.join("\n") + "\n"
end
class ApkBackend < Package::Backend::Packaging
def initialize
@name = "apk"
@ -41,7 +10,7 @@ class ApkBackend < Package::Backend::Packaging
# to work properly.
old_cwd = Dir.current
File.write "#{package.fake_root_directory}/.PKGINFO", pkginfo package
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"
@ -54,5 +23,50 @@ class ApkBackend < Package::Backend::Packaging
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}`
size = du.sub(/[ \t].*/, "").to_i * 1024
lines = [] of String
lines << "# Generated by `packaging`."
lines << "pkgname = #{package.name}"
lines << "pkgver = #{package.version}-r#{package.release}"
lines << "url = #{package.url || ""} "
lines << "size = #{size}"
lines << "origin = #{package.recipe.name}"
lines << "buildtype = host" # Thisll need to be imported from Context.
lines << "builddate = #{Time.utc.to_unix}"
package.dependencies.each do |atom|
lines << "depend = #{atom.to_s}"
end
package.provides.each do |atom|
lines << "provides = #{atom.to_s}"
end
package.conflicts.each do |atom|
lines << "conflicts = #{atom.to_s}"
end
lines.join("\n") + "\n"
end
# Install programs.
def self.install(packages : Array(String))
opts = ["add"] + (ENV["APK_FLAGS"]? || "-i").split(/[ \t]+/) + packages
puts "+ apk #{opts.join " "}"
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

View File

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

View File

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

View File

@ -158,17 +158,9 @@ begin
end
if dependencies.size > 0 && ! skip_build_dependencies && !download_only
# FIXME: Well probably want to have backends other than apk at some point.
opts = ["add"] + (ENV["APK_FLAGS"]? || "-i").split(/[ \t]+/) + dependencies
puts "+ apk #{opts.join " "}"
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
# TODO: change this. We want other backends.
# TODO: write something in Context
context.install dependencies
end
recipes.each do |recipe|

View File

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