lib/packages: Move multithread make logic to buildsystems/autotools (#12080)

* lib/packages: Move multithread make logic to buildsystems/autotools

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Make rubocop happy

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

---------

Signed-off-by: SupeChicken666 <me@supechicken666.dev>
This commit is contained in:
SupeChicken666
2025-06-20 15:47:35 +08:00
committed by GitHub
parent e13478dc44
commit 10f08ee3d8
3 changed files with 14 additions and 42 deletions

View File

@@ -4,6 +4,7 @@ require_relative '../require_gem'
require_relative '../report_buildsystem_methods'
class Autotools < Package
boolean_property :autotools_make_j1
property :autotools_configure_options, :autotools_pre_configure_options, :autotools_build_extras, :autotools_install_extras
def self.build
@@ -26,7 +27,14 @@ class Autotools < Package
system 'filefix', exception: false unless @no_filefix
system "#{@autotools_pre_configure_options} ./configure #{CREW_CONFIGURE_OPTIONS} #{@autotools_configure_options}"
end
system 'make'
# Add "-j#" argument to "make" at compile-time, if necessary.
if @autotools_make_j1
system 'make', '-j1'
else
system 'make', '-j', CREW_NPROC
end
@autotools_build_extras&.call
end

View File

@@ -228,7 +228,7 @@ class Package
# check if there have any non-space char (pkg_names) between starting point ([line_i][char_i]) and endpoint vertically ([next_arrow_line_offset][char_i])
# (used to determine if the starting point and endpoint are in same branch, use pipe char to connect them if true)
next_arrow_line_offset = tree_view.lines[line_i..].index { |l| l[char_i] == '└' }
have_line_with_non_empty_char = tree_view.lines[line_i + 1..line_i + next_arrow_line_offset.to_i - 1].any? { |l| l[char_i].nil? or l[char_i] =~ /\S/ }
have_line_with_non_empty_char = tree_view.lines[line_i + (1..line_i) + next_arrow_line_offset.to_i - 1].any? { |l| l[char_i].nil? || l[char_i] =~ /\S/ }
line[char_i] = '│' if next_arrow_line_offset && (line[char_i] == ' ') && !have_line_with_non_empty_char
end
@@ -338,14 +338,6 @@ class Package
# Replace CREW_ARCH_FLAGS if @arch_flags_override is true.
crew_env_options_hash.transform_values! { |v| v.gsub(CREW_ARCH_FLAGS, CREW_ARCH_FLAGS_OVERRIDE) } if arch_flags_override
# Add "-j#" argument to "make" at compile-time, if necessary.
# Order of precedence to assign the number of threads:
# 1. The value of '-j#' from the package make argument
# 2. The value of ENV["CREW_NPROC"]
# 3. The value of `nproc`.strip
# See lib/const.rb for more details.
# Add exception option to opt_args.
opt_args.merge!(exception: true) unless opt_args.key?(:exception)
@@ -362,40 +354,10 @@ class Package
env['LD_PRELOAD'] = File.join(CREW_LIB_PREFIX, 'crew-preload.so') if File.exist?("#{CREW_LIB_PREFIX}/crew-preload.so")
# After removing the env hash, all remaining args must be command args.
cmd_args = args
make_threads = CREW_NPROC
modded_make_cmd = false
# Append -j placeholder to `make` commands only if '-j#' does not exist.
unless cmd_args.grep(/-j[[:space:]]?[0-9]+/).any?
if cmd_args.size == 1
# Involve a shell if the command is passed in one single string.
cmd_args = ['bash', '-c', cmd_args[0].sub(/^(make)\b/, '\\1 <<<CREW_NPROC>>>')]
modded_make_cmd = true
elsif cmd_args[0] == 'make'
cmd_args.insert(1, '<<<CREW_NPROC>>>')
modded_make_cmd = true
end
end
begin
if modded_make_cmd
# Replace placeholder with '-j#' arg and execute the actual command.
Kernel.system(env, *cmd_args.map { |arg| arg.sub('<<<CREW_NPROC>>>', "-j#{make_threads}") }, **opt_args)
else
Kernel.system(env, *cmd_args, **opt_args)
end
Kernel.system(env, *args, **opt_args)
rescue RuntimeError => e
if modded_make_cmd && make_threads != 1
# Retry with single thread if command is `make` and is modified by crew.
warn "Command \"#{cmd_args.map { |arg| arg.sub('<<<CREW_NPROC>>>', "-j#{make_threads}") }.join(' ')}\" failed, retrying with \"-j1\"...".yellow
make_threads = 1
retry
else
# Exit with error.
raise e
end
rescue StandardError => e
# Print failed line number and error message.
puts "#{e.backtrace[1]}: #{e.message}".orange
raise InstallError, "`#{env.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')} #{cmd_args.join(' ')}` exited with #{$CHILD_STATUS.exitstatus}".lightred

View File

@@ -1,6 +1,8 @@
module ReportBuildsystemMethods
def print_buildsystem_methods
method_list = methods.grep(/#{superclass.to_s.downcase}_/).delete_if { |i| send(i).blank? }
boolean_list = available_boolean_properties
method_list = methods.reject(&->(m) { boolean_list.include?(m.to_s.delete_suffix('?').to_sym) }).grep(/#{superclass.to_s.downcase}_/).delete_if { |i| send(i).blank? }
unless method_list.empty?
require_gem 'method_source'
method_blocks = []