Skip to content

Commit

Permalink
Format all of ANGLE's python code.
Browse files Browse the repository at this point in the history
BUG=angleproject:3421

Change-Id: I1d7282ac513c046de5d8ed87f7789290780d30a6
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1595440
Reviewed-by: Jamie Madill <[email protected]>
Commit-Queue: Geoff Lang <[email protected]>
  • Loading branch information
vonture authored and Commit Bot committed May 6, 2019
1 parent 8ba78da commit d7d4239
Show file tree
Hide file tree
Showing 41 changed files with 1,363 additions and 1,134 deletions.
3 changes: 2 additions & 1 deletion .style.yapf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[style]
based_on_style = chromium
column_limit = 99
column_limit = 99
indent_width = 4
111 changes: 51 additions & 60 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2019 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Top-level presubmit script for code generation.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
Expand All @@ -10,101 +9,93 @@

from subprocess import call


# Fragment of a regular expression that matches C++ and Objective-C++ implementation files.
_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'


# Fragment of a regular expression that matches C++ and Objective-C++ header files.
_HEADER_EXTENSIONS = r'\.(h|hpp|hxx)$'


def _CheckCodeGeneration(input_api, output_api):

class Msg(output_api.PresubmitError):
"""Specialized error message"""
def __init__(self, message):
super(output_api.PresubmitError, self).__init__(message,
long_text='Please ensure your ANGLE repositiory is synced to tip-of-tree\n'
'and you have an up-to-date checkout of all ANGLE dependencies.\n'
'If you are using ANGLE inside Chromium you may need to bootstrap ANGLE \n'
'and run gclient sync. See the DevSetup documentation for details.\n')
"""Specialized error message"""

def __init__(self, message):
super(output_api.PresubmitError, self).__init__(
message,
long_text='Please ensure your ANGLE repositiory is synced to tip-of-tree\n'
'and you have an up-to-date checkout of all ANGLE dependencies.\n'
'If you are using ANGLE inside Chromium you may need to bootstrap ANGLE \n'
'and run gclient sync. See the DevSetup documentation for details.\n')

code_gen_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
'scripts/run_code_generation.py')
cmd_name = 'run_code_generation'
cmd = [input_api.python_executable, code_gen_path, '--verify-no-dirty']
test_cmd = input_api.Command(
name=cmd_name,
cmd=cmd,
kwargs={},
message=Msg)
test_cmd = input_api.Command(name=cmd_name, cmd=cmd, kwargs={}, message=Msg)
if input_api.verbose:
print('Running ' + cmd_name)
return input_api.RunTests([test_cmd])


# Taken directly from Chromium's PRESUBMIT.py
def _CheckNewHeaderWithoutGnChange(input_api, output_api):
"""Checks that newly added header files have corresponding GN changes.
"""Checks that newly added header files have corresponding GN changes.
Note that this is only a heuristic. To be precise, run script:
build/check_gn_headers.py.
"""

def headers(f):
return input_api.FilterSourceFile(
f, white_list=(r'.+%s' % _HEADER_EXTENSIONS, ))

new_headers = []
for f in input_api.AffectedSourceFiles(headers):
if f.Action() != 'A':
continue
new_headers.append(f.LocalPath())

def gn_files(f):
return input_api.FilterSourceFile(f, white_list=(r'.+\.gn', ))

all_gn_changed_contents = ''
for f in input_api.AffectedSourceFiles(gn_files):
for _, line in f.ChangedContents():
all_gn_changed_contents += line

problems = []
for header in new_headers:
basename = input_api.os_path.basename(header)
if basename not in all_gn_changed_contents:
problems.append(header)

if problems:
return [output_api.PresubmitPromptWarning(
'Missing GN changes for new header files', items=sorted(problems),
long_text='Please double check whether newly added header files need '
'corresponding changes in gn or gni files.\nThis checking is only a '
'heuristic. Run build/check_gn_headers.py to be precise.\n'
'Read https://crbug.com/661774 for more info.')]
return []
def headers(f):
return input_api.FilterSourceFile(f, white_list=(r'.+%s' % _HEADER_EXTENSIONS,))

new_headers = []
for f in input_api.AffectedSourceFiles(headers):
if f.Action() != 'A':
continue
new_headers.append(f.LocalPath())

def gn_files(f):
return input_api.FilterSourceFile(f, white_list=(r'.+\.gn',))

all_gn_changed_contents = ''
for f in input_api.AffectedSourceFiles(gn_files):
for _, line in f.ChangedContents():
all_gn_changed_contents += line

problems = []
for header in new_headers:
basename = input_api.os_path.basename(header)
if basename not in all_gn_changed_contents:
problems.append(header)

if problems:
return [
output_api.PresubmitPromptWarning(
'Missing GN changes for new header files',
items=sorted(problems),
long_text='Please double check whether newly added header files need '
'corresponding changes in gn or gni files.\nThis checking is only a '
'heuristic. Run build/check_gn_headers.py to be precise.\n'
'Read https://crbug.com/661774 for more info.')
]
return []


def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CheckCodeGeneration(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasBugField(
input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasDescription(
input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasBugField(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasDescription(input_api, output_api))
results.extend(_CheckNewHeaderWithoutGnChange(input_api, output_api))
results.extend(
input_api.canned_checks.CheckPatchFormatted(input_api, output_api))
results.extend(input_api.canned_checks.CheckPatchFormatted(input_api, output_api))
return results


def CheckChangeOnCommit(input_api, output_api):
results = []
results.extend(_CheckCodeGeneration(input_api, output_api))
results.extend(
input_api.canned_checks.CheckPatchFormatted(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasBugField(
input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasDescription(
input_api, output_api))
results.extend(input_api.canned_checks.CheckPatchFormatted(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasBugField(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasDescription(input_api, output_api))
return results
204 changes: 95 additions & 109 deletions android/compress_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,115 +14,101 @@


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--objcopy',
required=True,
help='The objcopy binary to run',
metavar='PATH')
parser.add_argument(
'--nm', required=True, help='The nm binary to run', metavar='PATH')
parser.add_argument(
'--sofile',
required=True,
help='Shared object file produced by linking command',
metavar='FILE')
parser.add_argument(
'--output',
required=True,
help='Final output shared object file',
metavar='FILE')
parser.add_argument(
'--unstrippedsofile',
required=True,
help='Unstripped shared object file produced by linking command',
metavar='FILE')
args = parser.parse_args()

copy_cmd = ["cp", args.sofile, args.output]
result = subprocess.call(copy_cmd)

objcopy_cmd = [args.objcopy]
objcopy_cmd.append('--only-keep-debug')
objcopy_cmd.append(args.unstrippedsofile)
objcopy_cmd.append(args.output + '.debug')
result = subprocess.call(objcopy_cmd)

nm_cmd = subprocess.Popen(
[args.nm, args.unstrippedsofile, '--format=posix', '--defined-only'],
stdout=subprocess.PIPE)

awk_cmd = subprocess.Popen(['awk', '{ print $1}'],
stdin=nm_cmd.stdout,
stdout=subprocess.PIPE)

dynsym_out = open(args.output + '.dynsyms', 'w')
sort_cmd = subprocess.Popen(['sort'], stdin=awk_cmd.stdout, stdout=dynsym_out)
dynsym_out.close()

nm_cmd = subprocess.Popen(
[args.nm, args.unstrippedsofile, '--format=posix', '--defined-only'],
stdout=subprocess.PIPE)

awk_cmd = subprocess.Popen(
['awk', '{ if ($2 == "T" || $2 == "t" ||' + ' $2 == "D") print $1 }'],
stdin=nm_cmd.stdout,
stdout=subprocess.PIPE)

funcsyms_out = open(args.output + '.funcsyms', 'w')
sort_cmd = subprocess.Popen(['sort'],
stdin=awk_cmd.stdout,
stdout=funcsyms_out)
funcsyms_out.close()

keep_symbols = open(args.output + '.keep_symbols', 'w')
sort_cmd = subprocess.Popen(
['comm', '-13', args.output + '.dynsyms', args.output + '.funcsyms'],
stdin=awk_cmd.stdout,
stdout=keep_symbols)

# Ensure that the keep_symbols file is not empty.
keep_symbols.write("\n")
keep_symbols.close()

objcopy_cmd = [
args.objcopy, '--rename-section', '.debug_frame=saved_debug_frame',
args.output + '.debug', args.output + ".mini_debuginfo"
]
subprocess.check_call(objcopy_cmd)

objcopy_cmd = [
args.objcopy, '-S', '--remove-section', '.gdb_index', '--remove-section',
'.comment', '--keep-symbols=' + args.output + '.keep_symbols',
args.output + '.mini_debuginfo'
]
subprocess.check_call(objcopy_cmd)

objcopy_cmd = [
args.objcopy, '--rename-section', '.saved_debug_frame=.debug_frame',
args.output + ".mini_debuginfo"
]
subprocess.check_call(objcopy_cmd)

xz_cmd = ['xz', args.output + '.mini_debuginfo']
subprocess.check_call(xz_cmd)

objcopy_cmd = [
args.objcopy, '--add-section',
'.gnu_debugdata=' + args.output + '.mini_debuginfo.xz', args.output
]
subprocess.check_call(objcopy_cmd)

# Clean out scratch files
rm_cmd = [
'rm', '-f', args.output + '.dynsyms', args.output + '.funcsyms',
args.output + '.keep_symbols', args.output + '.debug',
args.output + '.mini_debuginfo', args.output + '.mini_debuginfo.xz'
]
result = subprocess.call(rm_cmd)

return result
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--objcopy', required=True, help='The objcopy binary to run', metavar='PATH')
parser.add_argument('--nm', required=True, help='The nm binary to run', metavar='PATH')
parser.add_argument(
'--sofile',
required=True,
help='Shared object file produced by linking command',
metavar='FILE')
parser.add_argument(
'--output', required=True, help='Final output shared object file', metavar='FILE')
parser.add_argument(
'--unstrippedsofile',
required=True,
help='Unstripped shared object file produced by linking command',
metavar='FILE')
args = parser.parse_args()

copy_cmd = ["cp", args.sofile, args.output]
result = subprocess.call(copy_cmd)

objcopy_cmd = [args.objcopy]
objcopy_cmd.append('--only-keep-debug')
objcopy_cmd.append(args.unstrippedsofile)
objcopy_cmd.append(args.output + '.debug')
result = subprocess.call(objcopy_cmd)

nm_cmd = subprocess.Popen([args.nm, args.unstrippedsofile, '--format=posix', '--defined-only'],
stdout=subprocess.PIPE)

awk_cmd = subprocess.Popen(['awk', '{ print $1}'], stdin=nm_cmd.stdout, stdout=subprocess.PIPE)

dynsym_out = open(args.output + '.dynsyms', 'w')
sort_cmd = subprocess.Popen(['sort'], stdin=awk_cmd.stdout, stdout=dynsym_out)
dynsym_out.close()

nm_cmd = subprocess.Popen([args.nm, args.unstrippedsofile, '--format=posix', '--defined-only'],
stdout=subprocess.PIPE)

awk_cmd = subprocess.Popen(
['awk', '{ if ($2 == "T" || $2 == "t" ||' + ' $2 == "D") print $1 }'],
stdin=nm_cmd.stdout,
stdout=subprocess.PIPE)

funcsyms_out = open(args.output + '.funcsyms', 'w')
sort_cmd = subprocess.Popen(['sort'], stdin=awk_cmd.stdout, stdout=funcsyms_out)
funcsyms_out.close()

keep_symbols = open(args.output + '.keep_symbols', 'w')
sort_cmd = subprocess.Popen(
['comm', '-13', args.output + '.dynsyms', args.output + '.funcsyms'],
stdin=awk_cmd.stdout,
stdout=keep_symbols)

# Ensure that the keep_symbols file is not empty.
keep_symbols.write("\n")
keep_symbols.close()

objcopy_cmd = [
args.objcopy, '--rename-section', '.debug_frame=saved_debug_frame', args.output + '.debug',
args.output + ".mini_debuginfo"
]
subprocess.check_call(objcopy_cmd)

objcopy_cmd = [
args.objcopy, '-S', '--remove-section', '.gdb_index', '--remove-section', '.comment',
'--keep-symbols=' + args.output + '.keep_symbols', args.output + '.mini_debuginfo'
]
subprocess.check_call(objcopy_cmd)

objcopy_cmd = [
args.objcopy, '--rename-section', '.saved_debug_frame=.debug_frame',
args.output + ".mini_debuginfo"
]
subprocess.check_call(objcopy_cmd)

xz_cmd = ['xz', args.output + '.mini_debuginfo']
subprocess.check_call(xz_cmd)

objcopy_cmd = [
args.objcopy, '--add-section', '.gnu_debugdata=' + args.output + '.mini_debuginfo.xz',
args.output
]
subprocess.check_call(objcopy_cmd)

# Clean out scratch files
rm_cmd = [
'rm', '-f', args.output + '.dynsyms', args.output + '.funcsyms',
args.output + '.keep_symbols', args.output + '.debug', args.output + '.mini_debuginfo',
args.output + '.mini_debuginfo.xz'
]
result = subprocess.call(rm_cmd)

return result


if __name__ == "__main__":
sys.exit(main())
sys.exit(main())
12 changes: 6 additions & 6 deletions scripts/bmp_to_nv12.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
# convert to YUV 4:4:4
converted_pixels = bytearray(pixels)
for i in range(0, width * height):
R, = struct.unpack("B", pixels[i*3+2])
G, = struct.unpack("B", pixels[i*3+1])
B, = struct.unpack("B", pixels[i*3])
converted_pixels[i*3] = ((66*R + 129*G + 25*B + 128) >> 8) + 16
converted_pixels[i*3+1] = ((-38*R - 74*G + 112*B + 128) >> 8) + 128
converted_pixels[i*3+2] = ((112*R - 94*G - 18*B + 128) >> 8) + 128
R, = struct.unpack("B", pixels[i * 3 + 2])
G, = struct.unpack("B", pixels[i * 3 + 1])
B, = struct.unpack("B", pixels[i * 3])
converted_pixels[i * 3] = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16
converted_pixels[i * 3 + 1] = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128
converted_pixels[i * 3 + 2] = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128

# downsample to packed UV buffer
uv_buffer = bytearray(width * height / 2)
Expand Down
Loading

0 comments on commit d7d4239

Please sign in to comment.