Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # |
| 3 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """Script to patch Android repo with diffs that are needed by the suite. |
| 7 | |
| 8 | Run this script before running the suite. |
| 9 | """ |
| 10 | from __future__ import print_function |
| 11 | |
| 12 | import config |
| 13 | import os |
| 14 | import subprocess |
| 15 | |
| 16 | # The patches to be added to the android repo. |
| 17 | # An error may occur if it is already patched, or meets some error. |
| 18 | # FIXME: Needs to be FIXED in the future. |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 19 | def try_patch_autotest(): |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 20 | # Patch autotest, which includes all the testcases on device, |
| 21 | # setting device, and running the benchmarks |
| 22 | autotest_dir = os.path.join(config.android_home, config.autotest_dir) |
| 23 | autotest_patch = os.path.join( |
| 24 | os.path.dirname(os.path.realpath(__file__)), 'autotest.diff') |
| 25 | dex2oat_dir = os.path.join(autotest_dir, |
| 26 | 'server/site_tests/android_Dex2oat') |
| 27 | panorama_dir = os.path.join(autotest_dir, |
| 28 | 'server/site_tests/android_Panorama') |
| 29 | # FIXME: A quick hack, need to handle errors and check whether has been |
| 30 | # applied in the future. |
| 31 | try: |
| 32 | subprocess.check_call(['git', '-C', autotest_dir, |
| 33 | 'apply', autotest_patch]) |
| 34 | subprocess.check_call(['cp', '-rf', 'dex2oat_input', dex2oat_dir]) |
| 35 | subprocess.check_call(['cp', '-rf', 'panorama_input', panorama_dir]) |
| 36 | print('Autotest patched successfully!') |
| 37 | except subprocess.CalledProcessError: |
| 38 | print('Autotest patch not applied, error or already patched.') |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 39 | |
| 40 | |
| 41 | def try_patch_panorama(): |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 42 | panorama_dir = os.path.join(config.android_home, |
| 43 | config.bench_dict['Panorama']) |
| 44 | panorama_patch = os.path.join( |
| 45 | os.path.dirname(os.path.realpath(__file__)), 'panorama.diff') |
| 46 | # FIXME: A quick hack, need to handle errors and check whether has been |
| 47 | # applied in the future. |
| 48 | try: |
| 49 | subprocess.check_call(['mkdir', '-p', panorama_dir]) |
| 50 | subprocess.check_call(['git', '-C', panorama_dir, |
| 51 | 'apply', panorama_patch]) |
| 52 | print('Panorama patched successfully!') |
| 53 | except subprocess.CalledProcessError: |
| 54 | print('Panorama patch not applied, error or already patched.') |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 55 | |
| 56 | |
| 57 | def try_patch_synthmark(): |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 58 | synthmark_dir = '/tmp/devrel/tools/synthmark' |
| 59 | # FIXME: A quick hack, need to handle errors and check whether has been |
| 60 | # applied in the future. |
| 61 | try: |
| 62 | subprocess.check_call([ |
| 63 | 'bash', '-c', 'cd /tmp && ' |
| 64 | 'rm -rf devrel && ' |
| 65 | 'mkdir devrel && ' |
| 66 | 'cd devrel && ' |
| 67 | 'repo init -u sso://devrel/manifest && ' |
| 68 | 'repo sync tools/synthmark' |
| 69 | ]) |
| 70 | synthmark_patch = os.path.join( |
| 71 | os.path.dirname(os.path.realpath(__file__)), 'synthmark.diff') |
| 72 | subprocess.check_call(['git', '-C', synthmark_dir, |
| 73 | 'apply', synthmark_patch]) |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 74 | |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 75 | subprocess.check_call(['mv', '-f', synthmark_dir, config.android_home]) |
| 76 | subprocess.check_call(['rm', '-rf', '/tmp/devrel']) |
| 77 | print('Synthmark patched successfully!') |
| 78 | except subprocess.CalledProcessError: |
| 79 | print('Synthmark patch not applied, error or already patched.') |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 80 | |
| 81 | |
| 82 | def main(): |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 83 | try_patch_panorama() |
| 84 | try_patch_autotest() |
| 85 | try_patch_synthmark() |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 86 | |
| 87 | if __name__ == '__main__': |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 88 | main() |