From 10f08ee3d8d057692a3e5962a372843a955d85c9 Mon Sep 17 00:00:00 2001 From: SupeChicken666 Date: Fri, 20 Jun 2025 15:47:35 +0800 Subject: [PATCH] lib/packages: Move multithread make logic to buildsystems/autotools (#12080) * lib/packages: Move multithread make logic to buildsystems/autotools Signed-off-by: SupeChicken666 * Make rubocop happy Signed-off-by: SupeChicken666 --------- Signed-off-by: SupeChicken666 --- lib/buildsystems/autotools.rb | 10 +++++++- lib/package.rb | 42 ++----------------------------- lib/report_buildsystem_methods.rb | 4 ++- 3 files changed, 14 insertions(+), 42 deletions(-) diff --git a/lib/buildsystems/autotools.rb b/lib/buildsystems/autotools.rb index 13154e63c..730e6ba1a 100644 --- a/lib/buildsystems/autotools.rb +++ b/lib/buildsystems/autotools.rb @@ -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 diff --git a/lib/package.rb b/lib/package.rb index 770ffd043..ee49d7b9f 100644 --- a/lib/package.rb +++ b/lib/package.rb @@ -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 <<>>')] - modded_make_cmd = true - elsif cmd_args[0] == 'make' - cmd_args.insert(1, '<<>>') - 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('<<>>', "-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('<<>>', "-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 diff --git a/lib/report_buildsystem_methods.rb b/lib/report_buildsystem_methods.rb index b654b0a2f..2e3ae68f3 100644 --- a/lib/report_buildsystem_methods.rb +++ b/lib/report_buildsystem_methods.rb @@ -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 = []