This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[fuchsia] [packaging] Layout debug symbols for Fuchsia #13338
Merged
iskakaushik
merged 7 commits into
flutter:master
from
iskakaushik:debug-symbols-for-fuchsia
Oct 25, 2019
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4047c00
[fuchsia] [packaging] Layout debug symbols for Fuchsia
3409874
Add retry to makedirs
90fff54
use forward_args_from and also rename to "fuchsia_debug_symbols"
230b8bc
add help statements and use os.path.join the copy debug symbols script
cc7fc9f
Add debug logs for "file" command
ab7ca90
use llvm-readelf from Fuchsia toolchain
65e1777
make them hidden again
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| #!/usr/bin/env python | ||
| # | ||
| # Copyright 2013 The Flutter Authors. All rights reserved. | ||
| # Use of this source code is governed by a BSD-style license that can be | ||
| # found in the LICENSE file. | ||
| """ Gather the build_id, prefix_dir, and exec_name given the path to executable | ||
| also copies to the specified destination. | ||
|
|
||
| The structure of debug symbols is as follows: | ||
| .build-id/<prefix>/<exec_name>[.debug] | ||
| """ | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
| import re | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
| import time | ||
|
|
||
|
|
||
| def Touch(fname): | ||
| with open(fname, 'a'): | ||
| os.utime(fname, None) | ||
|
|
||
|
|
||
| def GetBuildIdParts(exec_path, read_elf): | ||
| file_out = subprocess.check_output( | ||
| [read_elf, '--hex-dump=.note.gnu.build-id', exec_path]) | ||
| second_line = file_out.splitlines()[-1].split() | ||
| build_id = second_line[1] + second_line[2] | ||
| return { | ||
| 'build_id': build_id, | ||
| 'prefix_dir': build_id[:2], | ||
| 'exec_name': build_id[2:] | ||
| } | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
|
|
||
| parser.add_argument( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| '--executable-name', | ||
| dest='exec_name', | ||
| action='store', | ||
| required=True, | ||
| help='This is the name of the executable that we wish to layout debug symbols for.' | ||
| ) | ||
| parser.add_argument( | ||
| '--executable-path', | ||
| dest='exec_path', | ||
| action='store', | ||
| required=True, | ||
| help='Path to the executable on the filesystem.') | ||
| parser.add_argument( | ||
| '--destination-base', | ||
| dest='dest', | ||
| action='store', | ||
| required=True, | ||
| help='Path to the base directory where the debug symbols are to be laid out.' | ||
| ) | ||
| parser.add_argument( | ||
| '--stripped', | ||
| dest='stripped', | ||
| action='store_true', | ||
| default=True, | ||
| help='Executable at the specified path is stripped.') | ||
| parser.add_argument( | ||
| '--unstripped', | ||
| dest='stripped', | ||
| action='store_false', | ||
| help='Executable at the specified path is unstripped.') | ||
| parser.add_argument( | ||
| '--read-elf', | ||
| dest='read_elf', | ||
| action='store', | ||
| required=True, | ||
| help='Path to read-elf executable.') | ||
|
|
||
| args = parser.parse_args() | ||
| assert os.path.exists(args.exec_path) | ||
| assert os.path.exists(args.dest) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| assert os.path.exists(args.read_elf) | ||
|
|
||
| parts = GetBuildIdParts(args.exec_path, args.read_elf) | ||
| dbg_prefix_base = os.path.join(args.dest, parts['prefix_dir']) | ||
|
|
||
| success = False | ||
| for _ in range(3): | ||
| try: | ||
| if not os.path.exists(dbg_prefix_base): | ||
| os.makedirs(dbg_prefix_base) | ||
| success = True | ||
| break | ||
| except OSError as error: | ||
| print 'Failed to create dir %s, error: %s. sleeping...' % ( | ||
| dbg_prefix_base, error) | ||
| time.sleep(3) | ||
|
|
||
| if not success: | ||
| print 'Unable to create directory: %s.' % dbg_prefix_base | ||
| return 1 | ||
|
|
||
| dbg_suffix = '' | ||
| if not args.stripped: | ||
| dbg_suffix = '.debug' | ||
| dbg_file_name = '%s%s' % (parts['exec_name'], dbg_suffix) | ||
| dbg_file_path = os.path.join(dbg_prefix_base, dbg_file_name) | ||
|
|
||
| shutil.copyfile(args.exec_path, dbg_file_path) | ||
|
|
||
| # Note this needs to be in sync with debug_symbols.gni | ||
| completion_file = os.path.join(args.dest, '.%s_dbg_success' % args.exec_name) | ||
| Touch(completion_file) | ||
|
|
||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| sys.exit(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Copyright 2013 The Flutter Authors. All rights reserved. | ||
| # Use of this source code is governed by a BSD-style license that can be | ||
| # found in the LICENSE file. | ||
|
|
||
| # The inputs to this template are 'binary_path' and a boolean 'unstripped'. | ||
| # If 'unstripped' is specified, we append '.debug' to the symbols name. | ||
| template("_copy_debug_symbols") { | ||
| assert(defined(invoker.binary_path), "'binary_path' needs to be defined.") | ||
| assert(defined(invoker.unstripped), "'unstripped' needs to be defined.") | ||
|
|
||
| action(target_name) { | ||
| forward_variables_from(invoker, | ||
| [ | ||
| "deps", | ||
| "unstripped", | ||
| "binary_path", | ||
| "testonly", | ||
| ]) | ||
|
|
||
| script = "$flutter_root/tools/fuchsia/copy_debug_symbols.py" | ||
|
|
||
| sources = [ | ||
| binary_path, | ||
| ] | ||
|
|
||
| _dest_base = | ||
| "${root_out_dir}/flutter-debug-symbols-${target_os}-${target_cpu}" | ||
|
|
||
| args = [ | ||
| "--executable-name", | ||
| target_name, | ||
| "--executable-path", | ||
| rebase_path(binary_path), | ||
| "--destination-base", | ||
| rebase_path(_dest_base), | ||
| "--read-elf", | ||
| rebase_path("//fuchsia/toolchain/$host_os/bin/llvm-readelf"), | ||
| ] | ||
|
|
||
| if (unstripped) { | ||
| args += [ "--unstripped" ] | ||
| } | ||
|
|
||
| outputs = [ | ||
| "${_dest_base}/.${target_name}_success", | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| # Takes a binary and generates its debug symbols following | ||
| # the Fuchsia packaging convention. | ||
| template("fuchsia_debug_symbols") { | ||
| assert(defined(invoker.binary), "'binary' needs to be defined.") | ||
|
|
||
| _copy_debug_symbols("_${target_name}_stripped") { | ||
| forward_variables_from(invoker, "*") | ||
| binary_path = rebase_path("${root_out_dir}/$binary") | ||
| unstripped = false | ||
| } | ||
|
|
||
| _copy_debug_symbols("_${target_name}_unstripped") { | ||
| forward_variables_from(invoker, "*") | ||
| binary_path = "${root_out_dir}/exe.unstripped/$binary" | ||
| unstripped = true | ||
| } | ||
|
|
||
| group(target_name) { | ||
| forward_variables_from(invoker, [ "testonly" ]) | ||
| deps = [ | ||
| ":_${target_name}_stripped", | ||
| ":_${target_name}_unstripped", | ||
| ] | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a line about how the build ID directory is structure. That section from the presentation will work great :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done