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.
6 """Embeds standalone JavaScript snippets in C++ code.
8 The script requires the devtools/front_end/toolbox/OverridesUI.js file from
9 WebKit that lists the known mobile devices to be passed in as the only argument.
10 The list of known devices will be written to a C-style string to be parsed with
23 def quotizeKeys(s
, keys
):
24 """Returns the string s with each instance of each key wrapped in quotes.
27 s: a string containing keys that need to be wrapped in quotes.
28 keys: an iterable of keys to be wrapped in quotes in the string.
31 s
= re
.sub('%s: ' % key
, '"%s": ' % key
, s
)
36 parser
= optparse
.OptionParser()
38 '', '--directory', type='string', default
='.',
39 help='Path to directory where the cc/h files should be created')
40 options
, args
= parser
.parse_args()
45 with
open(file_name
, 'r') as f
:
48 if 'WebInspector.OverridesUI._phones = [' in line
:
50 if 'WebInspector.OverridesUI._tablets = [' in line
:
54 if line
.strip() == '];':
57 devices
+= line
.strip()
59 output_dir
= 'chrome/test/chromedriver/chrome'
61 devices
= quotizeKeys(devices
,
62 ['title', 'width', 'height', 'deviceScaleFactor',
63 'userAgent', 'touch', 'mobile'])
64 cpp_source
.WriteSource('mobile_device_list',
66 options
.directory
, {'kMobileDevices': devices
})
68 clang_format
= ['clang-format', '-i']
69 subprocess
.Popen(clang_format
+ ['%s/mobile_device_list.cc' % output_dir
])
70 subprocess
.Popen(clang_format
+ ['%s/mobile_device_list.h' % output_dir
])
73 if __name__
== '__main__':