• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 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"""Creates a grd file for packaging the trace-viewer files.
7
8   This file is modified from the devtools generate_devtools_grd.py file.
9"""
10
11import errno
12import os
13import shutil
14import sys
15from xml.dom import minidom
16
17kTracingResourcePrefix = 'IDR_TRACING_'
18kGrdTemplate = '''<?xml version="1.0" encoding="UTF-8"?>
19<grit latest_public_release="0" current_release="1">
20  <outputs>
21    <output filename="grit/tracing_resources.h" type="rc_header">
22      <emit emit_type='prepend'></emit>
23    </output>
24    <output filename="tracing_resources.pak" type="data_package" />
25    <output filename="tracing_resources.rc" type="rc_all" />
26  </outputs>
27  <release seq="1">
28    <includes>
29      <if expr="not is_android"></if>
30    </includes>
31  </release>
32</grit>
33
34'''
35
36
37class ParsedArgs:
38  def __init__(self, source_files, output_filename):
39    self.source_files = source_files
40    self.output_filename = output_filename
41
42
43def parse_args(argv):
44  output_position = argv.index('--output')
45  source_files = argv[:output_position]
46  return ParsedArgs(source_files, argv[output_position + 1])
47
48
49def make_name_from_filename(filename):
50  return kTracingResourcePrefix + (os.path.splitext(filename)[1][1:]).upper()
51
52
53def add_file_to_grd(grd_doc, filename):
54  includes_node = grd_doc.getElementsByTagName('if')[0]
55  includes_node.appendChild(grd_doc.createTextNode('\n        '))
56
57  new_include_node = grd_doc.createElement('include')
58  new_include_node.setAttribute('name', make_name_from_filename(filename))
59  new_include_node.setAttribute('file', filename)
60  new_include_node.setAttribute('type', 'BINDATA')
61  new_include_node.setAttribute('flattenhtml', 'true')
62  if filename.endswith('.html'):
63    new_include_node.setAttribute('allowexternalscript', 'true')
64  includes_node.appendChild(new_include_node)
65
66
67def main(argv):
68  parsed_args = parse_args(argv[1:])
69
70  output_directory = os.path.dirname(parsed_args.output_filename)
71
72  doc = minidom.parseString(kGrdTemplate)
73  for filename in parsed_args.source_files:
74    add_file_to_grd(doc, os.path.basename(filename))
75
76  with open(parsed_args.output_filename, 'w') as output_file:
77    output_file.write(doc.toxml(encoding='UTF-8'))
78
79
80if __name__ == '__main__':
81  sys.exit(main(sys.argv))
82