• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 2014 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"""Embeds standalone JavaScript snippets in C++ code.
7
8The script requires the OverridesView file from WebKit that lists the known
9mobile devices to be passed in as the only argument. The list of known devices
10will be written to a C-style string to be parsed with JSONReader.
11"""
12
13import optparse
14import os
15import sys
16
17import cpp_source
18
19
20def main():
21  parser = optparse.OptionParser()
22  parser.add_option(
23      '', '--directory', type='string', default='.',
24      help='Path to directory where the cc/h files should be created')
25  options, args = parser.parse_args()
26
27  devices = '['
28  file_name = args[0]
29  inside_list = False
30  with open(file_name, 'r') as f:
31    for line in f:
32      if not inside_list:
33        if 'WebInspector.OverridesSupport._phones = [' in line or \
34           'WebInspector.OverridesSupport._tablets = [' in line:
35          inside_list = True
36      else:
37        if line.strip() == '];':
38          inside_list = False
39          continue
40        devices += line.strip()
41
42  devices += ']'
43  cpp_source.WriteSource('mobile_device_list',
44                         'chrome/test/chromedriver/chrome',
45                         options.directory, {'kMobileDevices': devices})
46
47
48if __name__ == '__main__':
49  sys.exit(main())
50