From e1ea9da5072db332084aa12866a06952a1c15851 Mon Sep 17 00:00:00 2001 From: Lukas Oberhuber Date: Tue, 26 Jul 2022 00:00:45 +0100 Subject: [PATCH] Conceptual draft of dsym support for macos --- Library/Homebrew/extend/os/mac/keg.rb | 17 +++++++++++++++++ Library/Homebrew/formula_installer.rb | 15 +++++++++++++++ Library/Homebrew/keg.rb | 4 ++++ Library/Homebrew/shims/super/cc | 6 ++++++ 4 files changed, 42 insertions(+) diff --git a/Library/Homebrew/extend/os/mac/keg.rb b/Library/Homebrew/extend/os/mac/keg.rb index 67abdc6ab3..cfe0b4f648 100644 --- a/Library/Homebrew/extend/os/mac/keg.rb +++ b/Library/Homebrew/extend/os/mac/keg.rb @@ -62,4 +62,21 @@ class Keg #{result.stderr} EOS end + + def dsymutil + binary_executable_or_library_files.each { |file| dsymutil_binary(file) } + end + + def dsymutil_binary(file) + odebug "Extracting symbols #{file}" + + result = system_command("dsymutil", args: [file]) + return if result.success? + + # If it fails again, error out + onoe <<~EOS + Failed to extract symbols from #{file}: + #{result.stderr} + EOS + end end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 03486bb730..611ec46643 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -39,6 +39,7 @@ class FormulaInstaller attr_predicate :installed_as_dependency?, :installed_on_request? attr_predicate :show_summary_heading?, :show_header? attr_predicate :force_bottle?, :ignore_deps?, :only_deps?, :interactive?, :git?, :force?, :overwrite?, :keep_tmp? + attr_predicate :debug_symbols? attr_predicate :verbose?, :debug?, :quiet? def initialize( @@ -71,6 +72,8 @@ class FormulaInstaller @force = force @overwrite = overwrite @keep_tmp = keep_tmp + # Just for this proof of concept + @debug_symbols = keep_tmp @link_keg = !formula.keg_only? || link_keg @show_header = show_header @ignore_deps = ignore_deps @@ -802,6 +805,8 @@ class FormulaInstaller post_install end + dsymutil(keg) if debug_symbols? + # Updates the cache for a particular formula after doing an install CacheStoreDatabase.use(:linkage) do |db| break unless db.created? @@ -1326,4 +1331,14 @@ class FormulaInstaller #{SPDX.license_expression_to_string formula.license}. EOS end + + sig { params(keg: Keg).void } + def dsymutil(keg) + keg.dsymutil + # TODO + # rescue Keg::DsymError => e + rescue RuntimeError => e + ofail "Failed to extract debugging symbols for #{formula.full_name}" + puts e + end end diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index c0ef58fc89..7c7defe7e0 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -483,6 +483,8 @@ class Keg ObserverPathnameExtension.n end + def dsymutil; end + def remove_oldname_opt_record return unless oldname_opt_record return if oldname_opt_record.resolved_path != path @@ -531,6 +533,8 @@ class Keg def codesign_patched_binary(file); end + def dsymutil_binary(file); end + private def resolve_any_conflicts(dst, dry_run: false, verbose: false, overwrite: false) diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 7d68f9fc5f..aed92991f9 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -292,6 +292,7 @@ class Cmd args.concat(optflags) unless runtime_cpu_detection? args.concat(archflags) args << "-std=#{@arg0}" if /c[89]9/.match?(@arg0) + args << "-g" if debug_symbols? args end @@ -399,6 +400,11 @@ class Cmd config.include?("w") end + def debug_symbols? + mac? + # && config.include?("D") + end + def canonical_path(path) path = Pathname.new(path) path = path.realpath if path.exist?