sakal | 2e3574d | 2017-05-09 09:10:57 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | # |
| 4 | # Use of this source code is governed by a BSD-style license |
| 5 | # that can be found in the LICENSE file in the root of the source |
| 6 | # tree. An additional intellectual property rights grant can be found |
| 7 | # in the file PATENTS. All contributing project authors may |
| 8 | # be found in the AUTHORS file in the root of the source tree. |
| 9 | |
| 10 | """ |
| 11 | This scripts tests creating an Android Studio project using the |
| 12 | generate_gradle.py script and making a debug build using it. |
| 13 | |
| 14 | It expect to be given the webrtc output build directory as the first argument |
| 15 | all other arguments are optional. |
| 16 | """ |
| 17 | |
| 18 | import argparse |
| 19 | import logging |
| 20 | import os |
| 21 | import shutil |
| 22 | import subprocess |
| 23 | import sys |
| 24 | import tempfile |
| 25 | |
| 26 | |
| 27 | SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
Henrik Kjellander | e4f900d | 2017-09-15 07:23:31 | [diff] [blame] | 28 | SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir)) |
sakal | 2e3574d | 2017-05-09 09:10:57 | [diff] [blame] | 29 | GENERATE_GRADLE_SCRIPT = os.path.join(SRC_DIR, |
| 30 | 'build/android/gradle/generate_gradle.py') |
| 31 | GRADLEW_BIN = os.path.join(SCRIPT_DIR, 'third_party/gradle/gradlew') |
| 32 | |
| 33 | |
| 34 | def _RunCommand(argv, cwd=SRC_DIR, **kwargs): |
| 35 | logging.info('Running %r', argv) |
| 36 | subprocess.check_call(argv, cwd=cwd, **kwargs) |
| 37 | |
| 38 | |
| 39 | def _ParseArgs(): |
| 40 | parser = argparse.ArgumentParser( |
| 41 | description='Test generating Android gradle project.') |
| 42 | parser.add_argument('build_dir_android', |
| 43 | help='The path to the build directory for Android.') |
| 44 | parser.add_argument('--project_dir', |
| 45 | help='A temporary directory to put the output.') |
| 46 | |
| 47 | args = parser.parse_args() |
| 48 | return args |
| 49 | |
| 50 | |
| 51 | def main(): |
| 52 | logging.basicConfig(level=logging.INFO) |
| 53 | args = _ParseArgs() |
| 54 | |
| 55 | project_dir = args.project_dir |
| 56 | if not project_dir: |
| 57 | project_dir = tempfile.mkdtemp() |
| 58 | |
| 59 | output_dir = os.path.abspath(args.build_dir_android) |
| 60 | project_dir = os.path.abspath(project_dir) |
| 61 | |
| 62 | try: |
Henrik Kjellander | ec57e05 | 2017-10-17 19:36:01 | [diff] [blame] | 63 | env = os.environ.copy() |
| 64 | env['PATH'] = os.pathsep.join([ |
| 65 | os.path.join(SRC_DIR, 'third_party', 'depot_tools'), env.get('PATH', '') |
| 66 | ]) |
sakal | 2e3574d | 2017-05-09 09:10:57 | [diff] [blame] | 67 | _RunCommand([GENERATE_GRADLE_SCRIPT, '--output-directory', output_dir, |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 68 | '--target', '//examples:AppRTCMobile', |
sakal | 2e3574d | 2017-05-09 09:10:57 | [diff] [blame] | 69 | '--project-dir', project_dir, |
Edward Lemur | 82752c4 | 2017-11-08 18:08:54 | [diff] [blame] | 70 | '--use-gradle-process-resources', '--split-projects'], |
Henrik Kjellander | ec57e05 | 2017-10-17 19:36:01 | [diff] [blame] | 71 | env=env) |
sakal | 2e3574d | 2017-05-09 09:10:57 | [diff] [blame] | 72 | _RunCommand([GRADLEW_BIN, 'assembleDebug'], project_dir) |
| 73 | finally: |
sakal | 27ce02e | 2017-05-11 10:36:21 | [diff] [blame] | 74 | # Do not delete temporary directory if user specified it manually. |
| 75 | if not args.project_dir: |
| 76 | shutil.rmtree(project_dir, True) |
sakal | 2e3574d | 2017-05-09 09:10:57 | [diff] [blame] | 77 | |
| 78 | |
| 79 | if __name__ == '__main__': |
| 80 | sys.exit(main()) |