File: cr_cronet.py

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (158 lines) | stat: -rwxr-xr-x 5,450 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
cr_cronet.py - cr - like helper tool for cronet developers
"""

import argparse
import sys
import os
import shlex
from datetime import datetime

REPOSITORY_ROOT = os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir))

sys.path.insert(0, REPOSITORY_ROOT)
from components.cronet.tools.utils import run, android_gn_gen, build  # pylint: disable=wrong-import-position


def install(out_dir):
  cmd = ['build/android/adb_install_apk.py']
  # Propagate PATH to avoid issues with missing tools http://crbug/1217979
  env = {
      'BUILDTYPE': out_dir[4:],
      'PATH': os.environ.get('PATH', ''),
      'HOME': os.environ.get('HOME', '')
  }
  return run(cmd + ['CronetTestInstrumentation.apk'], env=env)


def test(out_dir, extra_options):
  # Ideally we would fetch this path from somewhere. Though, that's not trivial
  # and very unlikely to change. This being "best effort test code", it should
  # be fine just to hardcode it.
  remote_netlog_dir = '/data/data/org.chromium.net.tests/app_cronet_test/NetLog'
  run(['adb', 'shell', 'rm', '-rf', remote_netlog_dir])
  run([out_dir + '/bin/run_cronet_test_instrumentation_apk'] + extra_options)
  local_netlog_dir = out_dir + '/netlogs_for-' + datetime.now().strftime(
      "%y_%m_%d-%H_%M_%S")
  return run(['adb', 'pull', remote_netlog_dir, local_netlog_dir])


def unittest(out_dir, extra_options):
  return run([out_dir + '/bin/run_cronet_unittests_android'] + extra_options)


def debug(extra_options):
  return run([
      'build/android/adb_gdb', '--start', '--activity=.CronetTestActivity',
      '--program-name=CronetTest', '--package-name=org.chromium.net'
  ] + extra_options)


def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('command',
                      choices=[
                          'gn', 'sync', 'build', 'install', 'proguard', 'test',
                          'build-test', 'unit', 'build-unit', 'stack', 'debug',
                          'build-debug'
                      ])
  parser.add_argument('-d',
                      '--out_dir',
                      action='store',
                      help='name of the build directory')
  parser.add_argument('-x',
                      '--x86',
                      action='store_true',
                      help='build for Intel x86 architecture')
  parser.add_argument('--x64',
                      action='store_true',
                      help='build for Intel x86_64 architecture')
  parser.add_argument('--arm',
                      action='store_true',
                      help='build for arm architecture')
  parser.add_argument('-R',
                      '--riscv64',
                      action='store_true',
                      help='build for riscv64 architecture')
  parser.add_argument('-r',
                      '--release',
                      action='store_true',
                      help='use release configuration')
  parser.add_argument('-a',
                      '--asan',
                      action='store_true',
                      help='use address sanitizer')

  options, extra_options = parser.parse_known_args()
  print("Options:", options)
  print("Extra options:", extra_options)

  test_target = 'cronet_test_instrumentation_apk'
  unit_target = 'cronet_unittests_android'
  if options.x86:
    target_cpu = 'x86'
    out_dir_suffix = '-x86'
  elif options.x64:
    target_cpu = 'x64'
    out_dir_suffix = '-x64'
  elif options.riscv64:
    target_cpu = 'riscv64'
    out_dir_suffix = '-riscv64'
  elif options.arm:
    target_cpu = 'arm'
    out_dir_suffix = '-arm'
  else:
    target_cpu = 'arm64'
    out_dir_suffix = '-arm64'

  if options.asan:
    # ASAN on Android requires one-time setup described here:
    # https://www.chromium.org/developers/testing/addresssanitizer
    out_dir_suffix += '-asan'

  if options.out_dir:
    out_dir = options.out_dir
  else:
    if options.release:
      out_dir = 'out/Release' + out_dir_suffix
    else:
      out_dir = 'out/Debug' + out_dir_suffix

  if (options.command == 'gn'):
    return android_gn_gen(options.release, target_cpu, out_dir)
  if (options.command == 'sync'):
    return run(['git', 'pull', '--rebase']) or run(['gclient', 'sync'])
  if (options.command == 'build'):
    return build(out_dir, test_target, extra_options)
  if (options.command == 'install'):
    return install(out_dir)
  if (options.command == 'proguard'):
    return build(out_dir, 'cronet_sample_proguard_apk')
  if (options.command == 'test'):
    return install(out_dir) or test(out_dir, extra_options)
  if (options.command == 'build-test'):
    return build(out_dir, test_target) or install(out_dir) or \
        test(out_dir, extra_options)
  if (options.command == 'stack'):
    return stack(out_dir)
  if (options.command == 'debug'):
    return install(out_dir) or debug(extra_options)
  if (options.command == 'build-debug'):
    return build(out_dir, test_target) or install(out_dir) or \
        debug(extra_options)
  if (options.command == 'unit'):
    return unittest(out_dir, extra_options)
  if (options.command == 'build-unit'):
    return build(out_dir, unit_target) or unittest(out_dir, extra_options)

  parser.print_help()
  return 1


if __name__ == '__main__':
  sys.exit(main())