• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright (c) 2012 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.
5import optparse
6import parse_deps
7import sys
8import os
9
10srcdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))
11
12js_warning_message = """/**
13// Copyright (c) 2012 The Chromium Authors. All rights reserved.
14// Use of this source code is governed by a BSD-style license that can be
15// found in the LICENSE file.
16
17* WARNING: This file is generated by generate_standalone_timeline_view.py
18*
19*        Do not edit directly.
20*/
21"""
22
23css_warning_message = """/**
24/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
25 * Use of this source code is governed by a BSD-style license that can be
26 * found in the LICENSE file. */
27
28* WARNING: This file is generated by generate_standalone_timeline_view.py
29*
30*        Do not edit directly.
31*/
32"""
33
34py_warning_message = """#!/usr/bin/env python
35#
36# Copyright (c) 2012 The Chromium Authors. All rights reserved.
37# Use of this source code is governed by a BSD-style license that can be
38# found in the LICENSE file. */
39#
40# WARNING: This file is generated by generate_standalone_timeline_view.py
41#
42#        Do not edit directly.
43#
44"""
45
46def _sopen(filename, mode):
47  if filename != '-':
48    return open(filename, mode)
49  return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
50
51def _get_input_filenames():
52  return [os.path.join(srcdir, f)
53          for f in ['base.js', 'timeline_view.js']]
54
55def generate_css():
56  filenames = _get_input_filenames()
57  load_sequence = parse_deps.calc_load_sequence(filenames, srcdir)
58
59  style_sheet_chunks = [css_warning_message, '\n']
60  for module in load_sequence:
61    for style_sheet in module.style_sheets:
62      style_sheet_chunks.append("""%s\n""" % style_sheet.contents)
63
64  return ''.join(style_sheet_chunks)
65
66def generate_js():
67  filenames = _get_input_filenames()
68  load_sequence = parse_deps.calc_load_sequence(filenames, srcdir)
69
70  js_chunks = [js_warning_message, '\n']
71  js_chunks.append("window.FLATTENED = {};\n")
72
73  for module in load_sequence:
74    js_chunks.append( "window.FLATTENED['%s'] = true;\n" % module.name)
75
76  for module in load_sequence:
77    js_chunks.append(module.contents)
78    js_chunks.append("\n")
79
80  return ''.join(js_chunks)
81
82def main(args):
83  parser = optparse.OptionParser(
84    usage="%prog --js=<filename> --css=<filename>",
85    epilog="""
86A script to takes all of the javascript and css files that comprise trace-viewer
87and merges them together into two giant js and css files, taking into account various
88ordering restrictions between them.
89""")
90  parser.add_option("--js", dest="js_file",
91                    help="Where to place generated javascript file")
92  parser.add_option("--css", dest="css_file",
93                    help="Where to place generated css file")
94  options, args = parser.parse_args(args)
95
96  if not options.js_file and not options.css_file:
97    sys.stderr.write("ERROR: Must specify one or both of --js=<filename> or --css=<filename>\n\n")
98    parser.print_help()
99    return 1
100
101  if options.js_file:
102    with _sopen(options.js_file, 'w') as f:
103      f.write(generate_js())
104
105  if options.css_file:
106    with _sopen(options.css_file, 'w') as f:
107      f.write(generate_css())
108
109  return 0
110
111
112if __name__ == "__main__":
113  sys.exit(main(sys.argv))
114