This application was a prequel to `package.mk`. Conserved for historical value, and Crystal code example.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

152 lines
3.0 KiB

require "spec"
require "./src/context.cr"
require "./src/recipe.cr"
extend Package
# FIXME: recipe.clean? context autoclean?
context = Context.new()
context.packaging_backend = "apk"
recipes = [] of Package::Recipe
class SpecParser
def get_string?(id) : String?
entry = self.assignments[id]?
unless entry.is_a? StringContainer
nil
else
entry.value
end
end
def get_string(id) : String
entry = self.assignments[id]?
unless entry.is_a? StringContainer
raise Exception.new "`#{id}` was expected to be a string, but was a #{entry.class}."
end
entry.value
end
def get_long_string?(id) : String?
entry = self.assignments[id]?
unless entry.is_a? LongStringContainer
nil
else
entry.value
end
end
def get_string_any?(id) : String?
get_string?(id) || get_long_string?(id)
end
def get_list?(id) : Array(String)?
entry = assignments[id]?
case entry
when SpecParser::ArrayContainer
entry.value
when SpecParser::StringContainer
entry.value.split(",")
when Nil
return nil
else
raise Exception.new "`#{id}` was expected to be a list (string), but was a `#{entry.class}`"
end
end
end
class Package::Recipe
def initialize(@context, specs : SpecParser)
pp! specs
@name = specs.get_string "name"
@version = specs.get_string "version"
@release = specs.get_string?("release").try(&.to_i) || 1
@url = specs.get_string? "url"
@description = specs.get_string_any? "description"
@packager = specs.get_string? "packager"
@maintainer = specs.get_string? "packager"
specs.get_string_any?("configure").try do |script|
@instructions.configure << script
end
specs.get_string_any?("build").try do |script|
@instructions.build << script
end
specs.get_string_any?("install").try do |script|
@instructions.install << script
end
specs.get_list?("dependencies").try &.each do |atom|
@dependencies << atom
end
specs.get_list?("conflicts").try &.each do |atom|
@conflicts << atom
end
specs.get_list?("provides").try &.each do |atom|
@provides << atom
end
specs.get_list?("sources").try &.each do |source|
@sources << source
end
specs.get_list?("options").try &.each do |option|
match = option.match /\(.*\) *= *\(.*\)/
unless match
puts "WARNING: misformed option: #{option}"
next
end
name, value = match
puts "OPTION: #{name} -> #{value}"
@options[name] = value
end
end
end
class Package::Context
def read_recipe(filename : String)
specs = SpecParser.parse filename
if specs.nil?
raise ::Exception.new "file could not be parsed"
end
Recipe.new self, specs
end
end
pp! context.read_recipe "test.spec"
if ARGV.size == 0 || ARGV[0]? == "-h"
pp recipes.map &.name
exit 0
end
recipes.each do |recipe|
pp recipe
raise "oh no, download failed" unless recipe.download
raise "oh no, extraction failed" unless recipe.extract
raise "oh no, build failed" unless recipe.build
raise "oh no, packaging failed" unless recipe.package
recipe.clean
end