This repository has been archived on 2022-01-17. You can view files and clone it, but cannot push or open issues/pull-requests.
packaging/src/backends/apk.cr

73 lines
2.0 KiB
Crystal
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require "../backends.cr"
class ApkBackend < Package::Backend::Packaging
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}`
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