• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6import math
7
8
9DEPS = [
10  'recipe_engine/context',
11  'recipe_engine/json',
12  'recipe_engine/path',
13  'recipe_engine/properties',
14  'recipe_engine/raw_io',
15  'recipe_engine/step',
16]
17
18CF_X86_PHONE_ENG_LUNCH_TARGET = 'cf_x86_phone-eng'
19SDK_LUNCH_TARGET = 'sdk'
20
21LUNCH_TARGET_TO_MMMA_TARGETS = {
22  CF_X86_PHONE_ENG_LUNCH_TARGET: (
23      'frameworks/base/core/jni,frameworks/base/libs/hwui,external/skia'),
24  SDK_LUNCH_TARGET: 'external/skia',
25}
26
27
28def RunSteps(api):
29  buildername = api.properties['buildername']
30  issue = api.properties.get('patch_issue')
31  patchset = api.properties.get('patch_set')
32  if not issue or not patchset:
33    # This bot currently only supports trybot runs because:
34    # Non-trybot runs could fail if the Android tree is red. We mitigate this
35    # for trybot runs by verifying that runs without the patch succeed. We do
36    # not currently have a way to do the same for non-trybot runs.
37    raise Exception('%s can only be run as a trybot.' % buildername)
38
39  if CF_X86_PHONE_ENG_LUNCH_TARGET in buildername:
40    lunch_target = CF_X86_PHONE_ENG_LUNCH_TARGET
41    mmma_targets = LUNCH_TARGET_TO_MMMA_TARGETS[lunch_target]
42  elif SDK_LUNCH_TARGET in buildername:
43    lunch_target = SDK_LUNCH_TARGET
44    mmma_targets = LUNCH_TARGET_TO_MMMA_TARGETS[SDK_LUNCH_TARGET]
45  else:
46    raise Exception('Lunch target in %s is not recognized.' % buildername)
47
48  infrabots_dir = api.path['start_dir'].join('skia', 'infra', 'bots')
49  trigger_wait_ac_script = infrabots_dir.join('android_compile',
50                                              'trigger_wait_ac_task.py')
51
52  # Trigger a compile task on the android compile server and wait for it to
53  # complete.
54  cmd = ['python', trigger_wait_ac_script,
55         '--lunch_target', lunch_target,
56         '--mmma_targets', mmma_targets,
57         '--issue', issue,
58         '--patchset', patchset,
59        ]
60  try:
61    api.step('Trigger and wait for task on android compile server', cmd=cmd)
62  except api.step.StepFailure as e:
63    # Add withpatch and nopatch logs as links (if they exist).
64    gs_file = 'gs://android-compile-tasks/%s-%s-%s.json' % (
65        lunch_target, issue, patchset)
66    step_result = api.step('Get task log links',
67                           ['gsutil', 'cat', gs_file],
68                           stdout=api.json.output())
69    task_json = step_result.stdout
70    if task_json.get('withpatch_log'):
71      api.step.active_result.presentation.links[
72          'withpatch compilation log link'] = task_json['withpatch_log']
73    if task_json.get('nopatch_log'):
74      api.step.active_result.presentation.links[
75          'nopatch compilation log link'] = task_json['nopatch_log']
76    # Add link to force sync of the Android checkout.
77    api.step.active_result.presentation.links['force sync link'] = (
78        'https://skia-android-compile.corp.goog/')
79    raise e
80
81
82def GenTests(api):
83  yield(
84    api.test('android_compile_trybot') +
85    api.properties(
86        buildername='Build-Debian9-Clang-cf_x86_phone-eng-Android_Framework',
87        path_config='kitchen',
88        swarm_out_dir='[SWARM_OUT_DIR]',
89        repository='https://skia.googlesource.com/skia.git',
90        patch_issue=1234,
91        patch_set=1,
92    )
93  )
94
95  yield(
96    api.test('android_compile_sdk_trybot') +
97    api.properties(
98        buildername='Build-Debian9-Clang-host-sdk-Android_Framework',
99        path_config='kitchen',
100        swarm_out_dir='[SWARM_OUT_DIR]',
101        repository='https://skia.googlesource.com/skia.git',
102        patch_issue=1234,
103        patch_set=1,
104    )
105  )
106
107  yield(
108    api.test('android_compile_unrecognized_target') +
109    api.properties(
110        buildername='Build-Debian9-Clang-unrecognized-Android_Framework',
111        path_config='kitchen',
112        swarm_out_dir='[SWARM_OUT_DIR]',
113        repository='https://skia.googlesource.com/skia.git',
114        patch_issue=1234,
115        patch_set=1,
116    ) +
117    api.expect_exception('Exception')
118  )
119
120  yield(
121    api.test('android_compile_trybot_failure') +
122    api.properties(
123        buildername='Build-Debian9-Clang-cf_x86_phone-eng-Android_Framework',
124        path_config='kitchen',
125        swarm_out_dir='[SWARM_OUT_DIR]',
126        repository='https://skia.googlesource.com/skia.git',
127        patch_issue=1234,
128        patch_set=1,
129    ) +
130    api.step_data('Trigger and wait for task on android compile server',
131                  retcode=1) +
132    api.step_data('Get task log links',
133                  stdout=api.raw_io.output(
134                      '{"withpatch_log":"link1", "nopatch_log":"link2"}'))
135  )
136
137  yield(
138    api.test('android_compile_nontrybot') +
139    api.properties(
140        buildername='Build-Debian9-Clang-cf_x86_phone-eng-Android_Framework',
141        path_config='kitchen',
142        swarm_out_dir='[SWARM_OUT_DIR]',
143        repository='https://skia.googlesource.com/skia.git',
144        revision='abc123',
145    ) +
146    api.expect_exception('Exception')
147  )
148