Format all Python scripts
Some Python scripts weren't formatted - particularly scripts with just
the shebang and not the .py suffix. Run:
git ls-tree --full-tree --name-only -r HEAD | xargs grep -l '#!.*python' | xargs yapf -i chromium
to format them.
Change-Id: I68eae3e10496de558b184e9e16aaa1ba12b240e2
diff --git a/tools/build_all_configs.py b/tools/build_all_configs.py
index 95fe044..25e031c 100755
--- a/tools/build_all_configs.py
+++ b/tools/build_all_configs.py
@@ -58,8 +58,8 @@
'linux_msan': ('is_clang=true', 'is_debug=false', 'is_msan=true'),
'linux_tsan': ('is_clang=true', 'is_debug=false', 'is_tsan=true'),
'linux_ubsan': ('is_clang=true', 'is_debug=false', 'is_ubsan=true'),
- 'linux_fuzzer': ('is_clang=true', 'is_debug=false', 'is_fuzzer=true',
- 'is_asan=true'),
+ 'linux_fuzzer':
+ ('is_clang=true', 'is_debug=false', 'is_fuzzer=true', 'is_asan=true'),
}
LINUX_ARCHS = ('arm64',)
@@ -111,8 +111,8 @@
gn = os.path.join(ROOT_DIR, 'tools', 'gn')
for config_name, gn_args in iteritems(configs):
- print('\n\033[32mBuilding %-20s[%s]\033[0m' % (config_name,
- ','.join(gn_args)))
+ print('\n\033[32mBuilding %-20s[%s]\033[0m' %
+ (config_name, ','.join(gn_args)))
out_dir = os.path.join(ROOT_DIR, 'out', config_name)
if not os.path.isdir(out_dir):
os.mkdir(out_dir)
diff --git a/tools/check_proto_comments b/tools/check_proto_comments
index 05159ed..244f26e 100755
--- a/tools/check_proto_comments
+++ b/tools/check_proto_comments
@@ -25,6 +25,7 @@
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
def main():
errors = 0
# Don't want to check protos/third_party:
@@ -48,9 +49,8 @@
continue
rel_path = os.path.relpath(fpath, ROOT_DIR)
- sys.stderr.write(
- ('Proto file %s has inline comment, please move to ' +
- 'the previous line:\t%s') % (rel_path, line))
+ sys.stderr.write(('Proto file %s has inline comment, please move to ' +
+ 'the previous line:\t%s') % (rel_path, line))
errors += 1
return 0 if errors == 0 else 1
diff --git a/tools/compat.py b/tools/compat.py
index 44b0c02..42fdf68 100644
--- a/tools/compat.py
+++ b/tools/compat.py
@@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
try:
from shlex import quote
except ImportError:
@@ -34,6 +33,7 @@
except NameError:
basestring = str
+
def itervalues(o):
try:
return o.itervalues()
diff --git a/tools/extract_linux_syscall_tables b/tools/extract_linux_syscall_tables
index 0f2d2a6..e7c5b2d 100755
--- a/tools/extract_linux_syscall_tables
+++ b/tools/extract_linux_syscall_tables
@@ -3,7 +3,7 @@
import re
import sys
-from urllib.request import urlopen
+from urllib.request import urlopen
syscalls = {}
@@ -69,4 +69,4 @@
if __name__ == '__main__':
- sys.exit(Main())
\ No newline at end of file
+ sys.exit(Main())
diff --git a/tools/gen_amalgamated b/tools/gen_amalgamated
index c1cb2bc..0da3e42 100755
--- a/tools/gen_amalgamated
+++ b/tools/gen_amalgamated
@@ -344,8 +344,8 @@
if not rel_path in allowed_files:
return
with open(full_path) as f:
- self.source.append(
- '// %s begin header: %s' % (tool_name, normalize_path(full_path)))
+ self.source.append('// %s begin header: %s' %
+ (tool_name, normalize_path(full_path)))
self.source.extend(
self._process_source_includes(include_dirs, allowed_files, f))
return
@@ -364,13 +364,13 @@
if not os.path.exists(full_path):
raise Error('Source file %s not found' % source_name)
with open(full_path) as f:
- self.source.append(
- '// %s begin source: %s' % (tool_name, normalize_path(full_path)))
+ self.source.append('// %s begin source: %s' %
+ (tool_name, normalize_path(full_path)))
try:
self.source.extend(
self._patch_source(
- source_name, self._process_source_includes(
- include_dirs, deps, f)))
+ source_name,
+ self._process_source_includes(include_dirs, deps, f)))
except Error as e:
raise Error('Failed adding source %s: %s' % (source_name, e.message))
@@ -382,8 +382,8 @@
full_path = os.path.join(gn_utils.repo_root(), include_dir, header_name)
if os.path.exists(full_path):
with open(full_path) as f:
- self.header.append(
- '// %s begin header: %s' % (tool_name, normalize_path(full_path)))
+ self.header.append('// %s begin header: %s' %
+ (tool_name, normalize_path(full_path)))
self.header.extend(self._process_header_includes(include_dirs, f))
return
if self._compute_deps_only:
@@ -402,8 +402,8 @@
return
raise Error('Header file %s not found' % header_name)
with open(full_path) as f:
- self.header.append(
- '// %s begin header: %s' % (tool_name, normalize_path(full_path)))
+ self.header.append('// %s begin header: %s' %
+ (tool_name, normalize_path(full_path)))
try:
self.header.extend(self._process_header_includes(include_dirs, f))
except Error as e:
@@ -522,8 +522,8 @@
Example build command:
%s
-""" % (header_file, source_file, ' '.join(self.cflags), ' '.join(self.ldflags),
- ' '.join(self.libs), ' '.join(build_cmd))
+""" % (header_file, source_file, ' '.join(self.cflags), ' '.join(
+ self.ldflags), ' '.join(self.libs), ' '.join(build_cmd))
def get_build_command(self, output_prefix):
"""Returns an example command line for building the output source."""
@@ -531,9 +531,8 @@
library = self._get_nice_path(output_prefix, 'lib%s.so')
if sys.platform.startswith('linux'):
- llvm_script = os.path.join(gn_utils.repo_root(), 'gn',
- 'standalone', 'toolchain',
- 'linux_find_llvm.py')
+ llvm_script = os.path.join(gn_utils.repo_root(), 'gn', 'standalone',
+ 'toolchain', 'linux_find_llvm.py')
cxx = subprocess.check_output([llvm_script]).splitlines()[2].decode()
else:
cxx = 'clang++'
@@ -585,7 +584,7 @@
# to avoid emitting a stale version information in the remote case of somebody
# running gen_amalgamated incrementally after having moved to another commit.
changelog_path = os.path.join(project_root, 'CHANGELOG')
- assert(os.path.exists(changelog_path))
+ assert (os.path.exists(changelog_path))
subprocess.check_call(['touch', '-c', changelog_path])
output = args.output
diff --git a/tools/gen_binary_descriptors b/tools/gen_binary_descriptors
index dbbf8c7..952e809 100755
--- a/tools/gen_binary_descriptors
+++ b/tools/gen_binary_descriptors
@@ -26,8 +26,7 @@
SOURCE_TARGET = [
('protos/perfetto/trace_processor/trace_processor.proto',
- 'python/perfetto/trace_processor/trace_processor.descriptor'
- ),
+ 'python/perfetto/trace_processor/trace_processor.descriptor'),
('protos/perfetto/metrics/metrics.proto',
'python/perfetto/trace_processor/metrics.descriptor'),
]
diff --git a/tools/gen_ui_imports b/tools/gen_ui_imports
index 2a5f5b4..b644dfe 100755
--- a/tools/gen_ui_imports
+++ b/tools/gen_ui_imports
@@ -12,7 +12,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
"""Generates TypeScript files that import all subdirectories and
registers them with plugin registry. If you have three modules:
- core/
@@ -44,10 +43,12 @@
UI_SRC_DIR = os.path.join(ROOT_DIR, 'ui', 'src')
PLUGINS_PATH = os.path.join(UI_SRC_DIR, 'common', 'plugins')
+
def to_camel_case(s):
first, *rest = s.split('_')
return first + ''.join(x.title() for x in rest)
+
def gen_imports(input_dir, output_path):
paths = [os.path.join(input_dir, p) for p in os.listdir(input_dir)]
paths = [p for p in paths if os.path.isdir(p)]
@@ -57,7 +58,7 @@
rel_plugins_path = os.path.relpath(PLUGINS_PATH, output_dir)
imports = []
- registrations = []
+ registrations = []
for path in paths:
rel_path = os.path.relpath(path, output_dir)
snake_name = os.path.basename(path)
@@ -75,9 +76,10 @@
f.write(expected)
return True
+
def main():
- parser = argparse.ArgumentParser(description=__doc__,
- formatter_class=argparse.RawDescriptionHelpFormatter)
+ parser = argparse.ArgumentParser(
+ description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('INPUT')
parser.add_argument('--out', required=True)
args = parser.parse_args()
@@ -99,5 +101,6 @@
success = gen_imports(input_dir, output_path)
return 0 if success else 1
+
if __name__ == '__main__':
exit(main())
diff --git a/tools/install-build-deps b/tools/install-build-deps
index 3f1fca2..bb58d88 100755
--- a/tools/install-build-deps
+++ b/tools/install-build-deps
@@ -337,7 +337,6 @@
'https://storage.googleapis.com/chromium-nodejs/16.13.0/ab9544e24e752d3d17f335fb7b2055062e582d11',
'3b5ca150a55f3aadfa18f3a10a4495aaf9653614ba3e460647170fef5287ec4f',
'linux', 'x64'),
-
Dependency(
'buildtools/mac/emsdk.tgz',
'https://storage.googleapis.com/perfetto/emscripten-2.0.12-mac.tgz',
diff --git a/tools/java_heap_dump b/tools/java_heap_dump
index a0e69220..c35c111 100755
--- a/tools/java_heap_dump
+++ b/tools/java_heap_dump
@@ -63,7 +63,7 @@
"""
UUID = str(uuid.uuid4())[-6:]
-PROFILE_PATH = '/data/misc/perfetto-traces/java-profile-' + UUID
+PROFILE_PATH = '/data/misc/perfetto-traces/java-profile-' + UUID
PERFETTO_CMD = ('CFG=\'{cfg}\'; echo ${{CFG}} | '
'perfetto --txt -c - -o ' + PROFILE_PATH + ' -d')
@@ -72,17 +72,20 @@
'S': 31,
}
+
def release_or_newer(release):
- sdk = int(subprocess.check_output(
- ['adb', 'shell', 'getprop', 'ro.system.build.version.sdk']
- ).decode('utf-8').strip())
+ sdk = int(
+ subprocess.check_output(
+ ['adb', 'shell', 'getprop',
+ 'ro.system.build.version.sdk']).decode('utf-8').strip())
if sdk >= SDK[release]:
return True
codename = subprocess.check_output(
- ['adb', 'shell', 'getprop', 'ro.build.version.codename']
- ).decode('utf-8').strip()
+ ['adb', 'shell', 'getprop',
+ 'ro.build.version.codename']).decode('utf-8').strip()
return codename == release
+
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument(
@@ -192,8 +195,8 @@
print(cfg)
return 0
- user = subprocess.check_output(
- ['adb', 'shell', 'whoami']).strip().decode('utf8')
+ user = subprocess.check_output(['adb', 'shell',
+ 'whoami']).strip().decode('utf8')
perfetto_pid = subprocess.check_output(
['adb', 'exec-out',
PERFETTO_CMD.format(cfg=cfg, user=user)]).strip().decode('utf8')
@@ -212,11 +215,9 @@
['adb', 'shell', '[ -d /proc/{} ]'.format(perfetto_pid)]) == 0
time.sleep(1)
- subprocess.check_call(
- ['adb', 'pull', PROFILE_PATH, output_file], stdout=NULL)
+ subprocess.check_call(['adb', 'pull', PROFILE_PATH, output_file], stdout=NULL)
- subprocess.check_call(
- ['adb', 'shell', 'rm', PROFILE_PATH], stdout=NULL)
+ subprocess.check_call(['adb', 'shell', 'rm', PROFILE_PATH], stdout=NULL)
print("Wrote profile to {}".format(output_file))
print("This can be viewed using https://ui.perfetto.dev.")
diff --git a/tools/package-prebuilts-for-github-release b/tools/package-prebuilts-for-github-release
index d7a9414..4c638f5 100755
--- a/tools/package-prebuilts-for-github-release
+++ b/tools/package-prebuilts-for-github-release
@@ -12,7 +12,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
"""Pulls LUCI-generated binaries and generates .zip files for GitHub releases.
Usage: ./tools/package_prebuilts_for_github_release v20.0
@@ -51,5 +50,6 @@
print('')
print('%d zip files saved in %s (%s)' % (len(zips), tmpdir, ','.join(zips)))
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/tools/roll-prebuilts b/tools/roll-prebuilts
index 6df208c..50ef65d 100755
--- a/tools/roll-prebuilts
+++ b/tools/roll-prebuilts
@@ -39,8 +39,15 @@
TOOLS_DIR = os.path.join(ROOT_DIR, 'tools')
UNIX_ARCHS = [
- 'mac-amd64', 'mac-arm64', 'linux-amd64', 'linux-arm', 'linux-arm64',
- 'android-arm', 'android-arm64', 'android-x86', 'android-x64',
+ 'mac-amd64',
+ 'mac-arm64',
+ 'linux-amd64',
+ 'linux-arm',
+ 'linux-arm64',
+ 'android-arm',
+ 'android-arm64',
+ 'android-x86',
+ 'android-x64',
]
ALL_ARCHS = UNIX_ARCHS + ['windows-amd64']
diff --git a/tools/run_test_like_ci b/tools/run_test_like_ci
index 1df5fff..7137747 100755
--- a/tools/run_test_like_ci
+++ b/tools/run_test_like_ci
@@ -110,12 +110,11 @@
print('')
print('About to build %r locally with %r' % (args.image, args.runner))
decision(confirm=args.confirm)
- check_call(('make', '-C', os.path.join(REPO_ROOT, 'infra',
- 'ci'),
+ check_call(('make', '-C', os.path.join(REPO_ROOT, 'infra', 'ci'),
'BUILDER=%s' % args.runner, 'build-sandbox'))
bundle_path = '/tmp/perfetto-ci.bundle'
- check_call(['git', '-C', REPO_ROOT, 'bundle', 'create', bundle_path, 'HEAD' ])
+ check_call(['git', '-C', REPO_ROOT, 'bundle', 'create', bundle_path, 'HEAD'])
os.chmod(bundle_path, 0o664)
env = {
'PERFETTO_TEST_GIT_REF': bundle_path,
diff --git a/tools/serialize_test_trace.py b/tools/serialize_test_trace.py
index 5bb9080..49cdc68 100755
--- a/tools/serialize_test_trace.py
+++ b/tools/serialize_test_trace.py
@@ -27,9 +27,7 @@
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
- '--out',
- type=str,
- help='out directory to search for trace descriptor')
+ '--out', type=str, help='out directory to search for trace descriptor')
parser.add_argument(
'--descriptor', type=str, help='path to the trace descriptor')
parser.add_argument('trace_path', type=str, help='path of trace to serialize')
diff --git a/tools/size-report b/tools/size-report
index ef0a4a3..51dd746 100755
--- a/tools/size-report
+++ b/tools/size-report
@@ -34,6 +34,7 @@
BLOATY_PATH = os.path.join(ROOT_DIR, 'buildtools', 'bloaty', 'bloaty')
GN_PATH = os.path.join(ROOT_DIR, 'tools', 'gn')
+
def GetGnArgValueOrNone(arg):
if 'current' in arg:
return eval(arg['current']['value'])
diff --git a/tools/symbolize-ui-crash b/tools/symbolize-ui-crash
index 77ea74c..8da6bf3 100755
--- a/tools/symbolize-ui-crash
+++ b/tools/symbolize-ui-crash
@@ -41,9 +41,9 @@
print('Run `pip3 install sourcemap` and try again')
sys.exit(1)
-
GERRIT_BASE_URL = 'https://android.googlesource.com/platform/external/perfetto/'
+
def fetch_url_cached(url):
normalized = re.sub('[^a-zA-Z0-9-._]', '_', url)
local_file = os.path.join(tempfile.gettempdir(), normalized)
diff --git a/tools/test_data b/tools/test_data
index 7b12baa..1a71f72 100755
--- a/tools/test_data
+++ b/tools/test_data
@@ -58,7 +58,7 @@
if fname.endswith('.swp'):
continue # Temporary files left around if CTRL-C-ing while downloading.
if fname == "OWNERS":
- continue # OWNERS file should not be uploaded.
+ continue # OWNERS file should not be uploaded.
fpath = os.path.join(root, fname)
if not os.path.isfile(fpath) or fname.startswith('.'):
continue