OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Handling of the <include> element. | 6 """Handling of the <include> element. |
7 """ | 7 """ |
8 | 8 |
9 import os | 9 import os |
10 import sys | 10 import sys |
11 | 11 |
12 from grit import exception | 12 from grit import exception |
13 from grit import util | 13 from grit import util |
14 import grit.format.gzip_string | 14 import grit.format.gzip_string |
15 import grit.format.html_inline | 15 import grit.format.html_inline |
16 import grit.format.rc | 16 import grit.format.rc |
17 import grit.format.rc_header | 17 import grit.format.rc_header |
18 from grit.format import minifier | |
18 from grit.node import base | 19 from grit.node import base |
19 | 20 |
20 class IncludeNode(base.Node): | 21 class IncludeNode(base.Node): |
21 """An <include> element.""" | 22 """An <include> element.""" |
22 | 23 |
23 RESERVED_HEADER = '\xff\x1f\x8b' | 24 RESERVED_HEADER = '\xff\x1f\x8b' |
24 | 25 |
25 def __init__(self): | 26 def __init__(self): |
26 super(IncludeNode, self).__init__() | 27 super(IncludeNode, self).__init__() |
27 | 28 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 input_path = self.GetInputPath() | 78 input_path = self.GetInputPath() |
78 if input_path is None: | 79 if input_path is None: |
79 return None | 80 return None |
80 | 81 |
81 return self.ToRealPath(input_path) | 82 return self.ToRealPath(input_path) |
82 | 83 |
83 def GetDataPackPair(self, lang, encoding): | 84 def GetDataPackPair(self, lang, encoding): |
84 """Returns a (id, string) pair that represents the resource id and raw | 85 """Returns a (id, string) pair that represents the resource id and raw |
85 bytes of the data. This is used to generate the data pack data file. | 86 bytes of the data. This is used to generate the data pack data file. |
86 """ | 87 """ |
87 # TODO(benrg/joi): Move this and other implementations of GetDataPackPair | 88 # TODO(benrg/joi): Move this and other implementations of GetDataPackPair |
Lei Zhang
2016/08/02 16:47:48
So there's another GetDataPackPair() in structure.
aberent
2016/08/02 20:27:42
Done, indirectly, in chrome_html.py
| |
88 # to grit.format.data_pack? | 89 # to grit.format.data_pack? |
89 from grit.format import rc_header | 90 from grit.format import rc_header |
90 id_map = rc_header.GetIds(self.GetRoot()) | 91 id_map = rc_header.GetIds(self.GetRoot()) |
91 id = id_map[self.GetTextualIds()[0]] | 92 id = id_map[self.GetTextualIds()[0]] |
93 filename = self.ToRealPath(self.GetInputPath()) | |
92 if self.attrs['flattenhtml'] == 'true': | 94 if self.attrs['flattenhtml'] == 'true': |
93 allow_external_script = self.attrs['allowexternalscript'] == 'true' | 95 allow_external_script = self.attrs['allowexternalscript'] == 'true' |
94 data = self._GetFlattenedData(allow_external_script=allow_external_script) | 96 data = self._GetFlattenedData(allow_external_script=allow_external_script) |
95 else: | 97 else: |
96 filename = self.ToRealPath(self.GetInputPath()) | |
97 data = util.ReadFile(filename, util.BINARY) | 98 data = util.ReadFile(filename, util.BINARY) |
98 | 99 # Note that the minifier will only do anything if a minifier command |
100 # has been set in the command line. | |
101 data = minifier.Minify(data, os.path.splitext(filename)[1]) | |
99 if 'compress' in self.attrs and self.attrs['compress'] == 'gzip': | 102 if 'compress' in self.attrs and self.attrs['compress'] == 'gzip': |
100 # We only use rsyncable compression on Linux. | 103 # We only use rsyncable compression on Linux. |
101 # We exclude ChromeOS since ChromeOS bots are Linux based but do not have | 104 # We exclude ChromeOS since ChromeOS bots are Linux based but do not have |
102 # the --rsyncable option built in for gzip. See crbug.com/617950. | 105 # the --rsyncable option built in for gzip. See crbug.com/617950. |
103 if sys.platform == 'linux2' and 'chromeos' not in self.GetRoot().defines: | 106 if sys.platform == 'linux2' and 'chromeos' not in self.GetRoot().defines: |
104 data = grit.format.gzip_string.GzipStringRsyncable(data) | 107 data = grit.format.gzip_string.GzipStringRsyncable(data) |
105 else: | 108 else: |
106 data = grit.format.gzip_string.GzipString(data) | 109 data = grit.format.gzip_string.GzipString(data) |
107 data = self.RESERVED_HEADER[0] + data | 110 data = self.RESERVED_HEADER[0] + data |
108 elif data[:3] == self.RESERVED_HEADER: | 111 elif data[:3] == self.RESERVED_HEADER: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 node.StartParsing('include', parent) | 171 node.StartParsing('include', parent) |
169 node.HandleAttribute('name', name) | 172 node.HandleAttribute('name', name) |
170 node.HandleAttribute('type', type) | 173 node.HandleAttribute('type', type) |
171 node.HandleAttribute('file', file) | 174 node.HandleAttribute('file', file) |
172 node.HandleAttribute('translateable', translateable) | 175 node.HandleAttribute('translateable', translateable) |
173 node.HandleAttribute('filenameonly', filenameonly) | 176 node.HandleAttribute('filenameonly', filenameonly) |
174 node.HandleAttribute('mkoutput', mkoutput) | 177 node.HandleAttribute('mkoutput', mkoutput) |
175 node.HandleAttribute('relativepath', relativepath) | 178 node.HandleAttribute('relativepath', relativepath) |
176 node.EndParsing() | 179 node.EndParsing() |
177 return node | 180 return node |
OLD | NEW |