未验证 提交 bc70eb6c 编写于 作者: D Darren Chan 提交者: GitHub

[build] Speed up incremental & no-op builds. (#26815)

Per gn documentation, the output timestamp can remain the same if all outputs remain the same, resulting in large time savings since dependent targets don't need to be rebuilt.
See: https://gn.googlesource.com/gn/+/HEAD/docs/reference.md#target-declarations-action_declare-a-target-that-runs-a-script-a-single-time-outputs

Currently, `copy_debug_symbols.py` updates timestamps unconditionally, resulting in slower incremental and no-op builds.
We change its current behavior to not update the timestamps if the debug symbols will not change.

Local testing indicates around a `20s` improvement for no-op and incremental builds:
 - Control: http://go/paste/4800062489100288
 - Experiment: http://go/paste/5727928869453824

See https://fxbug.dev/79001.

CC: @naudzghebre 
上级 dea585f5
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
import argparse import argparse
import errno import errno
import hashlib
import json import json
import os import os
import re import re
...@@ -21,6 +22,18 @@ import sys ...@@ -21,6 +22,18 @@ import sys
import time import time
def HashFile(filepath):
"""Calculates the hash of a file without reading it all in memory at once."""
digest = hashlib.sha1()
with open(filepath, 'rb') as f:
while True:
chunk = f.read(1024*1024)
if not chunk:
break
digest.update(chunk)
return digest.hexdigest()
def Touch(fname): def Touch(fname):
with open(fname, 'a'): with open(fname, 'a'):
os.utime(fname, None) os.utime(fname, None)
...@@ -111,9 +124,14 @@ def main(): ...@@ -111,9 +124,14 @@ def main():
dbg_file_name = '%s%s' % (parts['exec_name'], dbg_suffix) dbg_file_name = '%s%s' % (parts['exec_name'], dbg_suffix)
dbg_file_path = os.path.join(dbg_prefix_base, dbg_file_name) dbg_file_path = os.path.join(dbg_prefix_base, dbg_file_name)
# If the debug file hasn't changed, don't rewrite the debug and completion
# file, speeding up incremental builds.
if os.path.exists(dbg_file_path) and HashFile(args.exec_path) == HashFile(dbg_file_path):
return 0
shutil.copyfile(args.exec_path, dbg_file_path) shutil.copyfile(args.exec_path, dbg_file_path)
# Note this needs to be in sync with debug_symbols.gni # Note this needs to be in sync with fuchsia_debug_symbols.gni
completion_file = os.path.join(args.dest, '.%s_dbg_success' % args.exec_name) completion_file = os.path.join(args.dest, '.%s_dbg_success' % args.exec_name)
Touch(completion_file) Touch(completion_file)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册