Archived
3
0
This repository has been archived on 2022-01-17. You can view files and clone it, but cannot push or open issues or pull requests.
packaging/src/package.cr
Luka Vandervelden e6fb4d6c3d Splits can be defined in recipes.
This is done using `%split split-name` sections. `files` and
`file-patterns` are both array attributes that can be provided to set
what paths or files should go in them. Other variables can be overriden
as well from that %split section.
2019-08-22 19:16:08 +02:00

83 lines
1.9 KiB
Crystal

require "specfileparser"
class Package::Package
getter recipe : Recipe
getter automatic : Bool
def initialize(@recipe, @automatic = false, @fake_root_directory = nil)
end
def initialize(@recipe, section : SpecFileParser::Section)
@automatic = false
@name = section.options[0]
section.content.each do |name, value|
case name
when "version"
@version = value.as_s
when "release"
@release = value.as_s.to_i
when "url"
@url = value.as_s
when "description"
@description = value.as_s_or_ls
when "dependencies"
# 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
when "provides"
@provides = value.as_a_or_s
when "files"
@files = value.as_a_or_s
when "file-patterns"
@file_patterns = value.as_a_or_s.map { |x| Regex.new x }
end
end
end
macro inherit(attribute)
@{{attribute.var.id}} : {{attribute.type.id}}?
def {{attribute.var.id}} : {{attribute.type.id}}
@{{attribute.var.id}} || @recipe.{{attribute.var.id}}
end
def {{attribute.var.id}}=(new_value : {{attribute.type.id}})
@{{attribute.var.id}} = new_value
end
end
inherit name : String
inherit version : String
inherit release : Int32
inherit url : String?
inherit description : String
setter dependencies : Array(String)?
inherit conflicts : Array(String)
inherit provides : Array(String)
# Reference for splits. Recipe#packages[0] should keep this set to `nil`.
property files : Array(String)?
property file_patterns : Array(Regex)?
@fake_root_directory : String?
def dependencies
@dependencies || @recipe.run_dependencies
end
def fake_root_directory
@fake_root_directory || "#{recipe.working_directory}/root-#{name}"
end
def to_s
"<Package: #{name}-#{version}>"
end
end