blob: 097232d07f9ab1fd27b5cab0161ac761c044905b [file] [log] [blame]
sakal2e3574d2017-05-09 02:10:57 -07001#!/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.
sakal2e3574d2017-05-09 02:10:57 -07009"""
10This scripts tests creating an Android Studio project using the
11generate_gradle.py script and making a debug build using it.
12
13It expect to be given the webrtc output build directory as the first argument
14all other arguments are optional.
15"""
16
17import argparse
18import logging
19import os
20import shutil
21import subprocess
22import sys
23import tempfile
24
sakal2e3574d2017-05-09 02:10:57 -070025SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
Henrik Kjellandere4f900d2017-09-15 09:23:31 +020026SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir))
Mirko Bonadei8cc66952020-10-30 10:13:45 +010027GENERATE_GRADLE_SCRIPT = os.path.join(
28 SRC_DIR, 'build/android/gradle/generate_gradle.py')
sakal2e3574d2017-05-09 02:10:57 -070029GRADLEW_BIN = os.path.join(SCRIPT_DIR, 'third_party/gradle/gradlew')
30
31
32def _RunCommand(argv, cwd=SRC_DIR, **kwargs):
Mirko Bonadei8cc66952020-10-30 10:13:45 +010033 logging.info('Running %r', argv)
34 subprocess.check_call(argv, cwd=cwd, **kwargs)
sakal2e3574d2017-05-09 02:10:57 -070035
36
37def _ParseArgs():
Mirko Bonadei8cc66952020-10-30 10:13:45 +010038 parser = argparse.ArgumentParser(
39 description='Test generating Android gradle project.')
40 parser.add_argument('build_dir_android',
41 help='The path to the build directory for Android.')
42 parser.add_argument('--project_dir',
43 help='A temporary directory to put the output.')
sakal2e3574d2017-05-09 02:10:57 -070044
Mirko Bonadei8cc66952020-10-30 10:13:45 +010045 args = parser.parse_args()
46 return args
sakal2e3574d2017-05-09 02:10:57 -070047
48
49def main():
Mirko Bonadei8cc66952020-10-30 10:13:45 +010050 logging.basicConfig(level=logging.INFO)
51 args = _ParseArgs()
sakal2e3574d2017-05-09 02:10:57 -070052
Mirko Bonadei8cc66952020-10-30 10:13:45 +010053 project_dir = args.project_dir
54 if not project_dir:
55 project_dir = tempfile.mkdtemp()
sakal2e3574d2017-05-09 02:10:57 -070056
Mirko Bonadei8cc66952020-10-30 10:13:45 +010057 output_dir = os.path.abspath(args.build_dir_android)
58 project_dir = os.path.abspath(project_dir)
sakal2e3574d2017-05-09 02:10:57 -070059
Mirko Bonadei8cc66952020-10-30 10:13:45 +010060 try:
61 env = os.environ.copy()
62 env['PATH'] = os.pathsep.join([
63 os.path.join(SRC_DIR, 'third_party', 'depot_tools'),
64 env.get('PATH', '')
65 ])
66 _RunCommand([
67 GENERATE_GRADLE_SCRIPT, '--output-directory', output_dir,
68 '--target', '//examples:AppRTCMobile', '--project-dir',
69 project_dir, '--use-gradle-process-resources', '--split-projects'
70 ],
71 env=env)
72 _RunCommand([GRADLEW_BIN, 'assembleDebug'], project_dir)
73 finally:
74 # Do not delete temporary directory if user specified it manually.
75 if not args.project_dir:
76 shutil.rmtree(project_dir, True)
sakal2e3574d2017-05-09 02:10:57 -070077
78
79if __name__ == '__main__':
Mirko Bonadei8cc66952020-10-30 10:13:45 +010080 sys.exit(main())