Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / android_webview / buildbot / deps_whitelist.py
1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 #
6 """Logic to generate lists of DEPS used by various parts of
7 the android_webview continuous integration (buildbot) infrastructure.
8
9 Note: The root Chromium project (which is not explicitly listed here)
10 has a couple of third_party libraries checked in directly into it. This means
11 that the list of third parties present in this file is not a comprehensive
12 list of third party android_webview dependencies.
13 """
14
15 import argparse
16 import json
17 import logging
18 import os
19 import sys
20
21
22 class DepsWhitelist(object):
23   def __init__(self):
24     # If a new DEPS entry is needed for the AOSP bot to compile please add it
25     # here first.
26     # This is a staging area for deps that are accepted by the android_webview
27     # team and are in the process of having the required branches being created
28     # in the Android tree.
29     self._compile_but_not_snapshot_dependencies = [
30     ]
31
32     # Dependencies that need to be merged into the Android tree.
33     self._snapshot_into_android_dependencies = [
34       'sdch/open-vcdiff',
35       'testing/gtest',
36       'third_party/WebKit',
37       'third_party/angle',
38       'third_party/brotli/src',
39       ('third_party/eyesfree/src/android/java/src/com/googlecode/eyesfree/'
40        'braille'),
41       'third_party/freetype',
42       'third_party/icu',
43       'third_party/leveldatabase/src',
44       'third_party/libjingle/source/talk',
45       'third_party/libphonenumber/src/phonenumbers',
46       'third_party/libphonenumber/src/resources',
47       'third_party/libsrtp',
48       'third_party/libvpx',
49       'third_party/libyuv',
50       'third_party/mesa/src',
51       'third_party/openssl',
52       'third_party/opus/src',
53       'third_party/ots',
54       'third_party/sfntly/cpp/src',
55       'third_party/skia/gyp',
56       'third_party/skia/include',
57       'third_party/skia/src',
58       'third_party/smhasher/src',
59       'third_party/webrtc',
60       'third_party/yasm/source/patched-yasm',
61       'tools/grit',
62       'tools/gyp',
63       'v8',
64     ]
65
66     # Dependencies required to build android_webview.
67     self._compile_dependencies = (self._snapshot_into_android_dependencies +
68                                   self._compile_but_not_snapshot_dependencies)
69
70     # Dependencies required to run android_webview tests but not required to
71     # compile.
72     self._test_data_dependencies = [
73       'chrome/test/data/perf/third_party/octane',
74     ]
75
76   @staticmethod
77   def _read_deps_file(deps_file_path):
78     class FileImplStub(object):
79       """Stub for the File syntax."""
80       def __init__(self, file_location):
81         pass
82
83       @staticmethod
84       def GetPath():
85         return ''
86
87       @staticmethod
88       def GetFilename():
89         return ''
90
91       @staticmethod
92       def GetRevision():
93         return None
94
95     def from_stub(__, _=None):
96       """Stub for the From syntax."""
97       return ''
98
99     class VarImpl(object):
100       def __init__(self, custom_vars, local_scope):
101         self._custom_vars = custom_vars
102         self._local_scope = local_scope
103
104       def Lookup(self, var_name):
105         """Implements the Var syntax."""
106         if var_name in self._custom_vars:
107           return self._custom_vars[var_name]
108         elif var_name in self._local_scope.get("vars", {}):
109           return self._local_scope["vars"][var_name]
110         raise Exception("Var is not defined: %s" % var_name)
111
112     local_scope = {}
113     var = VarImpl({}, local_scope)
114     global_scope = {
115         'File': FileImplStub,
116         'From': from_stub,
117         'Var': var.Lookup,
118         'deps_os': {},
119     }
120     execfile(deps_file_path, global_scope, local_scope)
121     deps = local_scope.get('deps', {})
122     deps_os = local_scope.get('deps_os', {})
123     for os_specific_deps in deps_os.itervalues():
124       deps.update(os_specific_deps)
125     return deps.keys()
126
127   def _make_gclient_blacklist(self, deps_file_path, whitelisted_deps):
128     """Calculates the list of deps that need to be excluded from the deps_file
129     so that the only deps left are the one in the whitelist."""
130     all_deps = self._read_deps_file(deps_file_path)
131     # The list of deps read from the DEPS file are prefixed with the source
132     # tree root, which is 'src' for Chromium.
133     def prepend_root(path):
134       return os.path.join('src', path)
135     whitelisted_deps = map(prepend_root, whitelisted_deps)
136     deps_blacklist = set(all_deps).difference(set(whitelisted_deps))
137     return dict(map(lambda(x): (x, None), deps_blacklist))
138
139   def get_deps_for_android_build(self, deps_file_path):
140     """This is used to calculate the custom_deps list for the Android bot.
141     """
142     if not deps_file_path:
143       raise Exception('You need to specify a DEPS file path.')
144     return self._make_gclient_blacklist(deps_file_path,
145                                         self._compile_dependencies)
146
147   def get_deps_for_android_build_and_test(self, deps_file_path):
148     """This is used to calculate the custom_deps list for the Android perf bot.
149     """
150     if not deps_file_path:
151       raise Exception('You need to specify a DEPS file path.')
152     return self._make_gclient_blacklist(deps_file_path,
153                                         self._compile_dependencies +
154                                         self._test_data_dependencies)
155
156   def get_deps_for_android_merge(self, _):
157     """Calculates the list of deps that need to be merged into the Android tree
158     in order to build the C++ and Java android_webview code."""
159     return self._snapshot_into_android_dependencies
160
161   def get_deps_for_license_check(self, _):
162     """Calculates the list of deps that need to be checked for Android license
163     compatibility"""
164     return self._compile_dependencies
165
166   def execute_method(self, method_name, deps_file_path):
167     methods = {
168       'android_build': self.get_deps_for_android_build,
169       'android_build_and_test':
170         self.get_deps_for_android_build_and_test,
171       'android_merge': self.get_deps_for_android_merge,
172       'license_check': self.get_deps_for_license_check
173     }
174     if not method_name in methods:
175       raise Exception('Method name %s is not valid. Valid choices are %s' %
176                       (method_name, methods.keys()))
177     return methods[method_name](deps_file_path)
178
179 def main():
180   parser = argparse.ArgumentParser()
181   parser.add_argument('--method', help='Method to use to fetch from whitelist.',
182                       required=True)
183   parser.add_argument('--path-to-deps', help='Path to DEPS file.')
184   parser.add_argument('--output-json', help='Name of file to write output to.')
185   parser.add_argument('verbose', action='store_true', default=False)
186   opts = parser.parse_args()
187
188   logging.getLogger().setLevel(logging.DEBUG if opts.verbose else logging.WARN)
189
190   deps_whitelist = DepsWhitelist()
191   blacklist = deps_whitelist.execute_method(opts.method, opts.path_to_deps)
192
193   if (opts.output_json):
194     output_dict = {
195         'blacklist' : blacklist
196     }
197     with open(opts.output_json, 'w') as output_json_file:
198       json.dump(output_dict, output_json_file)
199   else:
200     print blacklist
201
202   return 0
203
204
205 if __name__ == '__main__':
206   sys.exit(main())