summaryrefslogtreecommitdiff
path: root/build/scripts/slave/recipes/chromium_gn.py
blob: 0bc0dd4c79f967dfc9c3bd7baae8287e7e86ccff (plain)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from recipe_engine.types import freeze

DEPS = [
  'bot_update',
  'chromium',
  'chromium_tests',
  'json',
  'path',
  'platform',
  'properties',
  'python',
  'step',
  'test_utils',
  'tryserver',
  'webrtc',
]


BUILDERS = freeze({
  'tryserver.v8': {
    'builders': {
      'v8_linux_chromium_gn_rel': {
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Release',
          'TARGET_PLATFORM': 'linux',
          'TARGET_BITS': 64,
        },
        'gclient_apply_config': [
          'v8_bleeding_edge_git',
          'chromium_lkcr',
          'show_v8_revision',
        ],
        'root_override': 'src/v8',
        'set_component_rev': {'name': 'src/v8', 'rev_str': '%s'},
      },
      'v8_android_chromium_gn_dbg': {
        'chromium_apply_config': ['gn_minimal_symbols'],
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Debug',
          'TARGET_PLATFORM': 'android',
          'TARGET_ARCH': 'arm',
        },
        'gclient_apply_config': [
          'android',
          'v8_bleeding_edge_git',
          'chromium_lkcr',
          'show_v8_revision',
        ],
        'root_override': 'src/v8',
        'set_component_rev': {'name': 'src/v8', 'rev_str': '%s'},
      },
    },
  },
  'client.v8.fyi': {
    'builders': {
      'V8 Linux GN': {
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Release',
          'TARGET_PLATFORM': 'linux',
          'TARGET_BITS': 64,
        },
        'gclient_apply_config': [
          'v8_bleeding_edge_git',
          'chromium_lkcr',
          'show_v8_revision',
        ],
        'set_component_rev': {'name': 'src/v8', 'rev_str': '%s'},
      },
      'V8 Android GN (dbg)': {
        'chromium_apply_config': ['gn_minimal_symbols'],
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Debug',
          'TARGET_PLATFORM': 'android',
          'TARGET_ARCH': 'arm',
        },
        'gclient_apply_config': [
          'android',
          'v8_bleeding_edge_git',
          'chromium_lkcr',
          'show_v8_revision',
        ],
        'set_component_rev': {'name': 'src/v8', 'rev_str': '%s'},
      },
    },
  },
  'chromium.webrtc.fyi': {
    'builders': {
      'Win GN': {
        'chromium_apply_config': ['gn_minimal_symbols'],
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Release',
          'TARGET_PLATFORM': 'win',
          'TARGET_BITS': 32,
        },
        'gclient_apply_config': ['chromium_webrtc_tot'],
      },
      'Win GN (dbg)': {
        'chromium_apply_config': ['gn_minimal_symbols'],
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Debug',
          'TARGET_PLATFORM': 'win',
          'TARGET_BITS': 32,
        },
        'gclient_apply_config': ['chromium_webrtc_tot'],
      },
      'Mac GN': {
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Release',
          'TARGET_PLATFORM': 'mac',
          'TARGET_BITS': 64,
        },
        'gclient_apply_config': ['chromium_webrtc_tot'],
      },
      'Mac GN (dbg)': {
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Debug',
          'TARGET_PLATFORM': 'mac',
          'TARGET_BITS': 64,
        },
        'gclient_apply_config': ['chromium_webrtc_tot'],
      },
      'Linux GN': {
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Release',
          'TARGET_PLATFORM': 'linux',
          'TARGET_BITS': 64,
        },
        'gclient_apply_config': ['chromium_webrtc_tot'],
      },
      'Linux GN (dbg)': {
        'chromium_apply_config': ['gn_component_build'],
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Debug',
          'TARGET_PLATFORM': 'linux',
          'TARGET_BITS': 64,
        },
        'gclient_apply_config': ['chromium_webrtc_tot'],
      },
      'Android GN': {
        'chromium_apply_config': ['gn_minimal_symbols'],
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Release',
          'TARGET_PLATFORM': 'android',
          'TARGET_ARCH': 'arm',
          'TARGET_BITS': 32,
        },
        'gclient_apply_config': ['android', 'chromium_webrtc_tot'],
      },
      'Android GN (dbg)': {
        'chromium_apply_config': ['gn_minimal_symbols'],
        'chromium_config_kwargs': {
          'BUILD_CONFIG': 'Debug',
          'TARGET_PLATFORM': 'android',
          'TARGET_ARCH': 'arm',
          'TARGET_BITS': 32,
        },
        'gclient_apply_config': ['android', 'chromium_webrtc_tot'],
      },
    },
  },
})

def tests_in_compile_targets(api, compile_targets, tests):
  """Returns the tests in |tests| that have at least one of their compile
  targets in |compile_targets|."""
  result = []
  for test in tests:
    test_compile_targets = test.compile_targets(api)

    # Always return tests that don't require compile. Otherwise we'd never
    # run them.
    if ((set(compile_targets).intersection(set(test_compile_targets))) or
        not test_compile_targets):
      result.append(test)

  return result


def all_compile_targets(api, tests):
  """Returns the compile_targets for all the Tests in |tests|."""
  return sorted(set(x
                    for test in tests
                    for x in test.compile_targets(api)))


def _RunStepsInternal(api):
  mastername = api.properties.get('mastername')
  buildername = api.properties.get('buildername')
  bot_config = BUILDERS[mastername]['builders'][buildername]
  is_android = ('Android' in buildername or 'android' in buildername)
  force_clobber = bot_config.get('force_clobber', False)

  api.chromium.configure_bot(BUILDERS, ['mb'])
  bot_update_step = api.bot_update.ensure_checkout(
      force=True, patch_root=bot_config.get('root_override'))

  # because the 'mb' config is applied, we skip running gyp in the
  # the runhooks step.
  api.chromium.runhooks()

  # TODO(dpranke): Unify this with the logic in the chromium_trybot and
  # chromium recipes so that we can actually run the tests as well
  # and deapply patches and retry as need be.
  test_spec_file = '%s.json' % mastername
  test_spec = api.chromium_tests.read_test_spec(api, test_spec_file)

  tests = list(api.chromium_tests.steps.generate_gtest(
      api, mastername, buildername, test_spec))

  scripts_compile_targets = \
      api.chromium_tests.get_compile_targets_for_scripts().json.output
  tests += list(api.chromium_tests.steps.generate_script(
      api, mastername, buildername, test_spec,
      scripts_compile_targets=scripts_compile_targets))

  additional_compile_targets = test_spec.get(buildername, {}).get(
      'additional_compile_targets',
      ['chrome_public_apk' if is_android else 'all'])

  if api.tryserver.is_tryserver:
    affected_files = api.tryserver.get_files_affected_by_patch()

    test_compile_targets = all_compile_targets(api, tests)

    requires_compile, _, compile_targets = \
        api.chromium_tests.analyze(
            affected_files,
            test_compile_targets,
            test_compile_targets + additional_compile_targets,
            'trybot_analyze_config.json')
    if requires_compile:
      api.chromium.run_mb(mastername, buildername, use_goma=True)
      api.chromium.compile(compile_targets,
                           force_clobber=force_clobber)
    tests = tests_in_compile_targets(api, compile_targets, tests)
  else:
    api.chromium.run_mb(mastername, buildername, use_goma=True)
    api.chromium.compile(all_compile_targets(api, tests) +
                         additional_compile_targets,
                         force_clobber=force_clobber)

  if tests:
    if api.tryserver.is_tryserver:
      api.chromium_tests.run_tests_and_deapply_as_needed(
          mastername, api, tests, bot_update_step)
    else:
      api.chromium_tests.configure_swarming('chromium', precommit=False,
                                            mastername=mastername)
      test_runner = api.chromium_tests.create_test_runner(api, tests)
      with api.chromium_tests.wrap_chromium_tests(mastername, tests):
        test_runner()


def RunSteps(api):
  with api.tryserver.set_failure_hash():
    return _RunStepsInternal(api)


def GenTests(api):
  overrides = {}
  for mastername, master_dict in BUILDERS.items():
    for buildername in master_dict['builders']:

      # The Android bots are currently all only builders and cannot
      # run tests; more importantly, the recipe isn't set up to run
      # tests on Android correctly, and if we specify any tests in
      # the step_data, the recipe will crash :). We will eventually
      # fix this by killing this recipe altogether and moving to the
      # main chromium recipes.
      is_android = ('Android' in buildername or 'android' in buildername)
      gtest_tests = [] if is_android else ['base_unittests']

      overrides.setdefault(mastername, {})
      overrides[mastername][buildername] = (
          api.override_step_data(
              'read test spec',
              api.json.output({
                  buildername: {
                    'gtest_tests': gtest_tests,
                  },
              })))

      if 'tryserver' in mastername:
          overrides[mastername][buildername] += api.override_step_data(
            'analyze',
            api.json.output({
                'status': 'Found dependency',
                'targets': gtest_tests,
                'build_targets': gtest_tests,
            }))

  for test in api.chromium.gen_tests_for_builders(BUILDERS, overrides):
    yield test

  yield (
    api.test('compile_failure') +
    api.platform.name('linux') +
    api.properties.tryserver(
        buildername='v8_linux_chromium_gn_rel',
        mastername='tryserver.v8') +
    api.step_data('compile', retcode=1) +
    overrides['tryserver.v8']['v8_linux_chromium_gn_rel']
  )

  yield (
    api.test('use_v8_patch_on_chromium_gn_trybot') +
    api.platform.name('linux') +
    api.properties.tryserver(
        buildername='v8_linux_chromium_gn_rel',
        mastername='tryserver.v8',
        patch_project='v8') +
    overrides['tryserver.v8']['v8_linux_chromium_gn_rel']
  )

  yield (
    api.test('no_tests_run') +
    api.platform.name('linux') +
    api.properties.tryserver(
        buildername='v8_linux_chromium_gn_rel',
        mastername='tryserver.v8') +
    api.override_step_data(
        'read test spec',
        api.json.output({'linux_chromium_gn_rel': {
           'additional_compile_targets': ['net_unittests'],
           'gtest_tests': ['base_unittests'],
        }})) +
    api.override_step_data(
        'analyze',
        api.json.output({
          'status': 'Found dependency',
          'targets': ['net_unittests'],
          'build_targets': ['net_unittests'],
        }))
  )