forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalise gen_snapshots.py to strip_bitcode.py (flutter#36496)
The gen_snapshots.py tool is used to copy an input gen_snapshot to an output path with an architecture-specific suffix. For example, to copy gen_snapshot to gen_snapshot_arm64. Bitcode segments, if any, are stripped. This moves the input/output filename hardcoding into the BUILD.gn file and generalises the logic to simply copy an input binary to an output path with bitcode segments stripped. Since the tool is no longer gen_snapshot specific, we rename it from gen_snapshots.py to strip_bitcode.py. This also renames the generalised `macos_gen_snapshots` rule to `strip_bitcode`. Since we're working on removing bitcode support from the engine, this script will eventually serve no purpose other than to copy the input binary to an output path, at which point this script, and the associated `strip_bitcode` template in `//flutter/sky/tools/macos_tools.gni` can be removed. Along with the TODO, renaming the script and the rule help ensure we'll spot this and remove it when bitcode support is removed from the engine. Finally, this fixes a dependency issue in the target //flutter/lib/snapshot:create_macos_gen_snapshots. Previously, it dependended on ":generate_snapshot_bin", but in fact, the only file it touches is gen_snapshot. This was built transitively as part of the ":generate_snapshot_bin" target, but is now depended on directly. This is pre-factoring for merging the iOS and macOS gen_snapshot creation build rules in `flutter/lib/snapshot/BUILD.gn`. Issue: flutter/flutter#103386 Issue: flutter/flutter#101138 Issue: flutter/flutter#107884
- Loading branch information
Showing
5 changed files
with
101 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,41 @@ | ||
# 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. | ||
|
||
import("//flutter/common/config.gni") | ||
|
||
# Copies an input macOS binary to the specified output path. Bitcode segments, | ||
# if any, are stripped. | ||
# | ||
# Example: | ||
# | ||
# strip_bitcode( | ||
# input = "$root_build_dir/gen_snapshot" | ||
# output = "$root_build_dir/gen_snapshot_arm64" | ||
# deps = [ ":gen_snapshot" ] | ||
# ) | ||
# | ||
# TODO(cbracken): https://github.com/flutter/flutter/issues/107884 | ||
# When we stop building with bitcode enabled, this template and the | ||
# strip_bitcode.py script can be deleted and users can call copy() instead. | ||
template("strip_bitcode") { | ||
assert(defined(invoker.input), "The input to strip_bitcode must be defined") | ||
assert(defined(invoker.output), "The output to strip_bitcode most be defined") | ||
action(target_name) { | ||
forward_variables_from(invoker, | ||
[ | ||
"deps", | ||
"metadata", | ||
"visibility", | ||
]) | ||
script = "//flutter/sky/tools/strip_bitcode.py" | ||
args = [ | ||
"--input", | ||
rebase_path(invoker.input), | ||
"--output", | ||
rebase_path(invoker.output), | ||
] | ||
inputs = [ invoker.input ] | ||
outputs = [ invoker.output ] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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,44 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# 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. | ||
|
||
import argparse | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description='Copies an input macOS binary to the specified output path. ' | ||
'Bitcode segments, if any, are stripped.' | ||
) | ||
parser.add_argument( | ||
'--input', | ||
type=str, | ||
required=True, | ||
help='path of input binary to be read' | ||
) | ||
parser.add_argument( | ||
'--output', | ||
type=str, | ||
required=True, | ||
help='path of output binary to be written' | ||
) | ||
args = parser.parse_args() | ||
|
||
# Verify input binary exists. | ||
if not os.path.isfile(args.input): | ||
print('Cannot find input binary at %s' % args.input) | ||
sys.exit(1) | ||
|
||
# Copy input path to output path. Strip bitcode segments, if any. | ||
subprocess.check_call([ | ||
'xcrun', 'bitcode_strip', '-r', args.input, '-o', args.output | ||
]) | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |