105 lines
2.2 KiB
Crystal
105 lines
2.2 KiB
Crystal
require "option_parser"
|
|
require "file_utils"
|
|
require "colorize"
|
|
|
|
require "./context.cr"
|
|
require "./recipe.cr"
|
|
|
|
extend Package
|
|
|
|
context = Context.new()
|
|
context.packaging_backend = "apk"
|
|
context.repositories << "."
|
|
|
|
requested_recipes = [] of String
|
|
download_only = false
|
|
do_not_clean = false
|
|
|
|
used_X = false
|
|
OptionParser.parse! do |parser|
|
|
parser.banner = "Usage: package [options] <port <port <…>>>"
|
|
|
|
parser.on("-X DIR", "--repository DIR", "Sets a ports repository for finding dependencies (default=.).") { |dir|
|
|
unless used_X
|
|
while context.repositories.pop?
|
|
end
|
|
used_X = true
|
|
end
|
|
|
|
context.repositories << dir
|
|
}
|
|
|
|
parser.on("-D", "--download-only", "Only download sources, do not build.") {
|
|
download_only = true
|
|
}
|
|
|
|
parser.on("-k", "--keep-work-dir", "Do not clean after building.") {
|
|
do_not_clean = true
|
|
}
|
|
|
|
parser.on("-h", "--help", "Prints this help message.") {
|
|
puts parser
|
|
exit 0
|
|
}
|
|
|
|
parser.invalid_option do |flag|
|
|
STDERR.puts "ERROR: #{flag} is not a valid option."
|
|
STDERR.puts parser
|
|
exit(1)
|
|
end
|
|
|
|
parser.unknown_args do |arg|
|
|
requested_recipes = arg
|
|
end
|
|
end
|
|
|
|
found_recipes = requested_recipes.map do |name|
|
|
puts context.find_recipe(name)
|
|
context.find_recipe(name) || name
|
|
end
|
|
|
|
invalid_recipes = found_recipes.select &.is_a?(String)
|
|
if invalid_recipes.size > 0
|
|
STDERR.puts "ERROR: some of the requested recipes could not be found:"
|
|
invalid_recipes.each do |name|
|
|
STDERR.puts " - #{name}"
|
|
end
|
|
STDERR.puts " (try using -X?)"
|
|
end
|
|
|
|
recipes = found_recipes.compact_map do |recipe_or_string|
|
|
recipe_or_string unless recipe_or_string.is_a?(String)
|
|
end
|
|
|
|
# FIXME: Now we need to build their respective deptrees and to deduplicate
|
|
# the list of recipes.
|
|
|
|
begin
|
|
latest_build_dir = ""
|
|
recipes.each do |recipe|
|
|
latest_build_dir = recipe.building_directory
|
|
|
|
puts " >> #{recipe.name}".colorize :white
|
|
|
|
recipe.download
|
|
|
|
next if download_only
|
|
|
|
recipe.extract
|
|
|
|
recipe.build
|
|
recipe.package
|
|
|
|
recipe.clean unless do_not_clean
|
|
end
|
|
rescue e : Package::Exception
|
|
STDERR.puts "!! #{e.message}".colorize(:red).bright
|
|
STDERR.puts "!! You may want to inspect the build directory at #{latest_build_dir}"
|
|
exit 1
|
|
rescue e
|
|
STDERR.puts "!! An unexpected error occured:".colorize(:red).bright
|
|
STDERR.puts e
|
|
exit 1
|
|
end
|
|
|