Upstream version 9.37.195.0
[platform/framework/web/crosswalk.git] / src / build / android / pylib / constants.py
1 # Copyright (c) 2012 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 """Defines a set of constants shared by test runners and other scripts."""
6 # pylint: disable=W0212
7
8 import collections
9 import logging
10 import os
11 import subprocess
12
13
14 DIR_SOURCE_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),
15                                                os.pardir, os.pardir, os.pardir))
16 ISOLATE_DEPS_DIR = os.path.join(DIR_SOURCE_ROOT, 'isolate_deps_dir')
17
18 CHROME_SHELL_HOST_DRIVEN_DIR = os.path.join(
19     DIR_SOURCE_ROOT, 'chrome', 'android')
20
21
22 PackageInfo = collections.namedtuple('PackageInfo',
23     ['package', 'activity', 'cmdline_file', 'devtools_socket',
24      'test_package'])
25
26 PACKAGE_INFO = {
27     'chrome': PackageInfo(
28         'com.google.android.apps.chrome',
29         'com.google.android.apps.chrome.Main',
30         '/data/local/chrome-command-line',
31         'chrome_devtools_remote',
32         'com.google.android.apps.chrome.tests'),
33     'chrome_beta': PackageInfo(
34         'com.chrome.beta',
35         'com.google.android.apps.chrome.Main',
36         '/data/local/chrome-command-line',
37         'chrome_devtools_remote',
38         None),
39     'chrome_stable': PackageInfo(
40         'com.android.chrome',
41         'com.google.android.apps.chrome.Main',
42         '/data/local/chrome-command-line',
43         'chrome_devtools_remote',
44         None),
45     'chrome_dev': PackageInfo(
46         'com.google.android.apps.chrome_dev',
47         'com.google.android.apps.chrome.Main',
48         '/data/local/chrome-command-line',
49         'chrome_devtools_remote',
50         None),
51     'chrome_canary': PackageInfo(
52         'com.chrome.canary',
53         'com.google.android.apps.chrome.Main',
54         '/data/local/chrome-command-line',
55         'chrome_devtools_remote',
56         None),
57     'legacy_browser': PackageInfo(
58         'com.google.android.browser',
59         'com.android.browser.BrowserActivity',
60         None,
61         None,
62         None),
63     'content_shell': PackageInfo(
64         'org.chromium.content_shell_apk',
65         'org.chromium.content_shell_apk.ContentShellActivity',
66         '/data/local/tmp/content-shell-command-line',
67         None,
68         'org.chromium.content_shell_apk.tests'),
69     'chrome_shell': PackageInfo(
70         'org.chromium.chrome.shell',
71         'org.chromium.chrome.shell.ChromeShellActivity',
72         '/data/local/tmp/chrome-shell-command-line',
73         'chrome_shell_devtools_remote',
74         'org.chromium.chrome.shell.tests'),
75     'android_webview_shell': PackageInfo(
76         'org.chromium.android_webview.shell',
77         'org.chromium.android_webview.shell.AwShellActivity',
78         None,
79         None,
80         'org.chromium.android_webview.test'),
81     'gtest': PackageInfo(
82         'org.chromium.native_test',
83         'org.chromium.native_test.ChromeNativeTestActivity',
84         '/data/local/tmp/chrome-native-tests-command-line',
85         None,
86         None),
87     'content_browsertests': PackageInfo(
88         'org.chromium.content_browsertests_apk',
89         'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity',
90         '/data/local/tmp/content-browser-tests-command-line',
91         None,
92         None),
93     'chromedriver_webview_shell': PackageInfo(
94         'org.chromium.chromedriver_webview_shell',
95         'org.chromium.chromedriver_webview_shell.Main',
96         None,
97         None,
98         None),
99 }
100
101
102 # Ports arrangement for various test servers used in Chrome for Android.
103 # Lighttpd server will attempt to use 9000 as default port, if unavailable it
104 # will find a free port from 8001 - 8999.
105 LIGHTTPD_DEFAULT_PORT = 9000
106 LIGHTTPD_RANDOM_PORT_FIRST = 8001
107 LIGHTTPD_RANDOM_PORT_LAST = 8999
108 TEST_SYNC_SERVER_PORT = 9031
109 TEST_SEARCH_BY_IMAGE_SERVER_PORT = 9041
110
111 # The net test server is started from port 10201.
112 # TODO(pliard): http://crbug.com/239014. Remove this dirty workaround once
113 # http://crbug.com/239014 is fixed properly.
114 TEST_SERVER_PORT_FIRST = 10201
115 TEST_SERVER_PORT_LAST = 30000
116 # A file to record next valid port of test server.
117 TEST_SERVER_PORT_FILE = '/tmp/test_server_port'
118 TEST_SERVER_PORT_LOCKFILE = '/tmp/test_server_port.lock'
119
120 TEST_EXECUTABLE_DIR = '/data/local/tmp'
121 # Directories for common java libraries for SDK build.
122 # These constants are defined in build/android/ant/common.xml
123 SDK_BUILD_JAVALIB_DIR = 'lib.java'
124 SDK_BUILD_TEST_JAVALIB_DIR = 'test.lib.java'
125 SDK_BUILD_APKS_DIR = 'apks'
126
127 ADB_KEYS_FILE = '/data/misc/adb/adb_keys'
128
129 PERF_OUTPUT_DIR = os.path.join(DIR_SOURCE_ROOT, 'out', 'step_results')
130 # The directory on the device where perf test output gets saved to.
131 DEVICE_PERF_OUTPUT_DIR = (
132     '/data/data/' + PACKAGE_INFO['chrome'].package + '/files')
133
134 SCREENSHOTS_DIR = os.path.join(DIR_SOURCE_ROOT, 'out_screenshots')
135
136 ANDROID_SDK_VERSION = 20
137 ANDROID_SDK_BUILD_TOOLS_VERSION = '20.0.0'
138 ANDROID_SDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
139                                 'third_party/android_tools/sdk')
140 ANDROID_SDK_TOOLS = os.path.join(ANDROID_SDK_ROOT,
141                                  'build-tools', ANDROID_SDK_BUILD_TOOLS_VERSION)
142 ANDROID_NDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
143                                 'third_party/android_tools/ndk')
144
145 EMULATOR_SDK_ROOT = os.environ.get('ANDROID_EMULATOR_SDK_ROOT',
146                                    os.path.join(DIR_SOURCE_ROOT,
147                                                 'android_emulator_sdk'))
148
149 BAD_DEVICES_JSON = os.path.join(DIR_SOURCE_ROOT,
150                                 os.environ.get('CHROMIUM_OUT_DIR', 'out'),
151                                 'bad_devices.json')
152
153 UPSTREAM_FLAKINESS_SERVER = 'test-results.appspot.com'
154
155 DEVICE_LOCAL_PROPERTIES_PATH = '/data/local.prop'
156
157 def GetBuildType():
158   try:
159     return os.environ['BUILDTYPE']
160   except KeyError:
161     raise Exception('The BUILDTYPE environment variable has not been set')
162
163
164 def SetBuildType(build_type):
165   os.environ['BUILDTYPE'] = build_type
166
167
168 def GetOutDirectory(build_type=None):
169   """Returns the out directory where the output binaries are built.
170
171   Args:
172     build_type: Build type, generally 'Debug' or 'Release'. Defaults to the
173       globally set build type environment variable BUILDTYPE.
174   """
175   return os.path.abspath(os.path.join(
176       DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'),
177       GetBuildType() if build_type is None else build_type))
178
179
180 def _Memoize(func):
181   def Wrapper():
182     try:
183       return func._result
184     except AttributeError:
185       func._result = func()
186       return func._result
187   return Wrapper
188
189
190 @_Memoize
191 def GetAdbPath():
192   if os.environ.get('ANDROID_SDK_ROOT'):
193     return 'adb'
194   # If envsetup.sh hasn't been sourced and there's no adb in the path,
195   # set it here.
196   try:
197     with file(os.devnull, 'w') as devnull:
198       subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull)
199     return 'adb'
200   except OSError:
201     logging.debug('No adb found in $PATH, fallback to checked in binary.')
202     return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb')
203
204
205 # Exit codes
206 ERROR_EXIT_CODE = 1
207 WARNING_EXIT_CODE = 88