build-cores, logs

master
Karchnu 2021-02-22 17:14:00 +01:00
parent 72aceb035d
commit a4c53f2b8c
2 changed files with 44 additions and 11 deletions

View File

@ -18,7 +18,7 @@ def pkginfo(package)
lines = [] of String
lines << "# Generated by `package`."
lines << "# Generated by `packaging`."
lines << "pkgname = #{package.name}"
lines << "pkgver = #{package.version}-r#{package.release}"
lines << "url = #{package.url || ""} "
@ -62,11 +62,17 @@ class Package::Context
# = where to search for binaries and libraries for the build
property prefixes = ["/usr", "/", "/usr/baguette"]
# By default, building a package only uses one core
property build_cores = 1
# list of environment variables we want to have when building
property environment = {} of String => String
property verbosity = 0
property recipe : Recipe? = nil
def initialize
@packaging_backends << ApkBackend.new
@packaging_backends << BaguetteBackend.new
@ -101,7 +107,8 @@ class Package::Context
options = [
"-DCMAKE_INSTALL_PREFIX='#{recipe.prefix}'",
"-DCMAKE_BUILD_TYPE=Release #{recipe.options["cmake"]}"
"-DCMAKE_BUILD_TYPE=Release #{recipe.options["cmake"]}",
"-- -j#{context.build_cores}"
]
child = context.sh "cmake . #{options.join " "}"
@ -120,7 +127,7 @@ class Package::Context
next BuildStatus::Pass
end
child = context.sh "make #{recipe.options["make"]? || ""}"
child = context.sh "make -j#{context.build_cores} #{recipe.options["make"]? || ""}"
if child.exit_status == 0
BuildStatus::Success
@ -188,9 +195,27 @@ class Package::Context
if @verbosity < -1
output = Process::Redirect::Close
else
# log sub-commands outputs
logfile_path = "#{@working_directory}/#{@recipe.not_nil!.working_uuid}.log"
output = File.open logfile_path, "a"
STDOUT.puts "logging command #{command} #{args}"
STDOUT.puts "in " + logfile_path.colorize(:blue).mode(:bright).to_s
output.puts ""
output.puts ""
output.puts "logging command $ #{command}"
output.puts " parameters $ #{args}"
end
Process.run command, args, chdir: chdir, output: output, error: output, env: @environment
c = Process.run command, args, chdir: chdir, output: output, error: output, env: @environment
case output
when File
output.close
end
c
end
def run(command, args)
@ -235,7 +260,8 @@ class Package::Context
end
def read_recipe(filename : String)
Recipe.new self, filename
@recipe = Recipe.new self, filename
@recipe.not_nil!
end
def find_recipe(name : String) : Recipe?
@ -267,6 +293,10 @@ class Package::Context
when "prefixes"
# Prefixes during the build process.
@prefixes = value.as_a_or_s
when "build-cores"
# NB of cores used to compile applications.
@build_cores = value.as_s.to_i
when "environment"
# Environment variables during the build process.
value.as_a_or_s.each do |entry|
@ -280,7 +310,11 @@ class Package::Context
key, value = match
@environment[key] = value
if @verbosity > 0
STDOUT.puts "environment: #{key} => #{value}"
end
end
when "package-manager"
# Targeted package manager (default: package, for BaguetteOS).
begin

View File

@ -49,8 +49,8 @@ class Package::Recipe
property description : String?
# Informations not specific to individual packages.
getter sources : Sources
getter packages : Array(Package)
getter sources = Sources.new
getter packages = Array(Package).new
property packager : String?
property maintainer : String?
@ -68,16 +68,13 @@ class Package::Recipe
getter instructions = Instructions.new
getter options = Hash(String, String).new
getter sources = Sources.new
getter packages = Array(Package).new
getter watch_script : String?
@prefix : String?
property recipe_directory = "."
@working_uuid : UUID = UUID.random
getter working_uuid : UUID = UUID.random
def initialize(@context, @name, @version)
end
@ -152,6 +149,7 @@ class Package::Recipe
value.as_a_or_s.each do |atom|
@provides << atom
end
when "options"
value.as_a_or_s.each do |option|
match = option.split(':').map(
@ -309,6 +307,7 @@ class Package::Recipe
do_splits
end
# TODO: do not search within source files.
private def do_strip
@context.info "Stripping binaries"