79 lines
2.1 KiB
Crystal
79 lines
2.1 KiB
Crystal
|
|
# Instructions for src-split, [pre-](configure|build|install) and post-install
|
|
# Simple array of strings with a name.
|
|
#
|
|
# Methods:
|
|
# - run(context, recipe) : BuildStatus
|
|
# execute each instruction
|
|
# instructions are provided by the recipe or by a backend if not specified
|
|
|
|
class Package::Instructions
|
|
class Set < Array(String)
|
|
getter phase : String
|
|
def initialize(@phase)
|
|
super()
|
|
end
|
|
# FIXME: def execute
|
|
|
|
def run(context : Context, recipe : Recipe) : BuildStatus
|
|
# Does the recipe provided instructions for this phase?
|
|
if size > 0
|
|
each do |command|
|
|
child = Do.run recipe.building_directory, "sh", ["-x", "-c", command]
|
|
|
|
if child.exit_status != 0
|
|
return BuildStatus::Failed
|
|
end
|
|
end
|
|
|
|
return BuildStatus::Success
|
|
end
|
|
|
|
last_backend = "not-known"
|
|
# In case the recipe didn't provide instructions: checking backends.
|
|
context.building_backends.select(&.phase.==(@phase)).each do |backend|
|
|
last_backend = backend.name
|
|
Baguette::Log.info "Doing phase '#{@phase}' :: '" +
|
|
backend.name.colorize(:light_magenta).to_s +
|
|
"'"
|
|
Do.cd recipe.building_directory
|
|
|
|
rvalue = backend.build context, recipe
|
|
|
|
if rvalue == BuildStatus::Pass
|
|
next
|
|
end
|
|
|
|
return rvalue
|
|
end
|
|
|
|
BuildStatus::Pass
|
|
rescue e
|
|
# Possible TODO: print the origin of the exception (backend, user-provided code, other/unknown).
|
|
Baguette::Log.error "Exception during phase '#{@phase}', backend '#{last_backend}'"
|
|
Baguette::Log.error "Exception caught: #{e.message}"
|
|
BuildStatus::Failed
|
|
end
|
|
end
|
|
|
|
# FIXME: Switch to an enum at some point?
|
|
getter src_split = Set.new "src-split"
|
|
getter configure = Set.new "configure"
|
|
getter pre_configure = Set.new "pre-configure"
|
|
getter build = Set.new "build"
|
|
getter pre_build = Set.new "pre-build"
|
|
getter install = Set.new "install"
|
|
getter pre_install = Set.new "pre-install"
|
|
getter post_install = Set.new "post-install"
|
|
|
|
def to_a
|
|
[
|
|
src_split,
|
|
pre_configure, configure,
|
|
pre_build, build,
|
|
pre_install, install, post_install
|
|
]
|
|
end
|
|
end
|
|
|