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