sakal | 2e3574d | 2017-05-09 02:10:57 -0700 | [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__)) |
| 28 | SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, |
| 29 | os.pardir)) |
| 30 | GENERATE_GRADLE_SCRIPT = os.path.join(SRC_DIR, |
| 31 | 'build/android/gradle/generate_gradle.py') |
| 32 | GRADLEW_BIN = os.path.join(SCRIPT_DIR, 'third_party/gradle/gradlew') |
| 33 | |
| 34 | |
| 35 | def _RunCommand(argv, cwd=SRC_DIR, **kwargs): |
| 36 | logging.info('Running %r', argv) |
| 37 | subprocess.check_call(argv, cwd=cwd, **kwargs) |
| 38 | |
| 39 | |
| 40 | def _ParseArgs(): |
| 41 | parser = argparse.ArgumentParser( |
| 42 | description='Test generating Android gradle project.') |
| 43 | parser.add_argument('build_dir_android', |
| 44 | help='The path to the build directory for Android.') |
| 45 | parser.add_argument('--project_dir', |
| 46 | help='A temporary directory to put the output.') |
| 47 | |
| 48 | args = parser.parse_args() |
| 49 | return args |
| 50 | |
| 51 | |
| 52 | def main(): |
| 53 | logging.basicConfig(level=logging.INFO) |
| 54 | args = _ParseArgs() |
| 55 | |
| 56 | project_dir = args.project_dir |
| 57 | if not project_dir: |
| 58 | project_dir = tempfile.mkdtemp() |
| 59 | |
| 60 | output_dir = os.path.abspath(args.build_dir_android) |
| 61 | project_dir = os.path.abspath(project_dir) |
| 62 | |
| 63 | try: |
| 64 | _RunCommand([GENERATE_GRADLE_SCRIPT, '--output-directory', output_dir, |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 65 | '--target', '//examples:AppRTCMobile', |
sakal | 2e3574d | 2017-05-09 02:10:57 -0700 | [diff] [blame] | 66 | '--project-dir', project_dir, |
sakal | 42f1d6e | 2017-08-11 01:03:13 -0700 | [diff] [blame] | 67 | '--use-gradle-process-resources', '--split-projects', '--canary']) |
sakal | 2e3574d | 2017-05-09 02:10:57 -0700 | [diff] [blame] | 68 | _RunCommand([GRADLEW_BIN, 'assembleDebug'], project_dir) |
| 69 | finally: |
sakal | 27ce02e | 2017-05-11 03:36:21 -0700 | [diff] [blame] | 70 | # Do not delete temporary directory if user specified it manually. |
| 71 | if not args.project_dir: |
| 72 | shutil.rmtree(project_dir, True) |
sakal | 2e3574d | 2017-05-09 02:10:57 -0700 | [diff] [blame] | 73 | |
| 74 | |
| 75 | if __name__ == '__main__': |
| 76 | sys.exit(main()) |