| 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 """Miscellaneous node types. | 6 """Miscellaneous node types. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import os.path | 9 import os.path |
| 10 import re | 10 import re |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 # Importing this here avoids a circular dependency in the imports. | 316 # Importing this here avoids a circular dependency in the imports. |
| 317 # pylint: disable-msg=C6204 | 317 # pylint: disable-msg=C6204 |
| 318 from grit.node import include | 318 from grit.node import include |
| 319 from grit.node import misc | 319 from grit.node import misc |
| 320 from grit.node import structure | 320 from grit.node import structure |
| 321 from grit.node import variant | 321 from grit.node import variant |
| 322 | 322 |
| 323 # Check if the input is required for any output configuration. | 323 # Check if the input is required for any output configuration. |
| 324 input_files = set() | 324 input_files = set() |
| 325 old_output_language = self.output_language | 325 old_output_language = self.output_language |
| 326 for lang, ctx in self.GetConfigurations(): | 326 for lang, ctx, fallback in self.GetConfigurations(): |
| 327 self.SetOutputLanguage(lang or self.GetSourceLanguage()) | 327 self.SetOutputLanguage(lang or self.GetSourceLanguage()) |
| 328 self.SetOutputContext(ctx) | 328 self.SetOutputContext(ctx) |
| 329 self.SetFallbackToDefaultLayout(fallback) |
| 330 |
| 329 for node in self.ActiveDescendants(): | 331 for node in self.ActiveDescendants(): |
| 330 if isinstance(node, (io.FileNode, include.IncludeNode, misc.PartNode, | 332 if isinstance(node, (io.FileNode, include.IncludeNode, misc.PartNode, |
| 331 structure.StructureNode, variant.SkeletonNode)): | 333 structure.StructureNode, variant.SkeletonNode)): |
| 332 input_files.add(node.GetInputPath()) | 334 input_files.add(node.GetInputPath()) |
| 333 self.SetOutputLanguage(old_output_language) | 335 self.SetOutputLanguage(old_output_language) |
| 334 return sorted(map(self.ToRealPath, input_files)) | 336 return sorted(map(self.ToRealPath, input_files)) |
| 335 | 337 |
| 336 def GetFirstIdsFile(self): | 338 def GetFirstIdsFile(self): |
| 337 """Returns a usable path to the first_ids file, if set, otherwise | 339 """Returns a usable path to the first_ids file, if set, otherwise |
| 338 returns None. | 340 returns None. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 357 """Returns the list of <output> nodes that are descendants of this node's | 359 """Returns the list of <output> nodes that are descendants of this node's |
| 358 <outputs> child and are not enclosed by unsatisfied <if> conditionals. | 360 <outputs> child and are not enclosed by unsatisfied <if> conditionals. |
| 359 """ | 361 """ |
| 360 for child in self.children: | 362 for child in self.children: |
| 361 if child.name == 'outputs': | 363 if child.name == 'outputs': |
| 362 return [node for node in child.ActiveDescendants() | 364 return [node for node in child.ActiveDescendants() |
| 363 if node.name == 'output'] | 365 if node.name == 'output'] |
| 364 raise exception.MissingElement() | 366 raise exception.MissingElement() |
| 365 | 367 |
| 366 def GetConfigurations(self): | 368 def GetConfigurations(self): |
| 367 """Returns the distinct (language, context) pairs from the output nodes. | 369 """Returns the distinct (language, context, fallback_to_default_layout) |
| 370 triples from the output nodes. |
| 368 """ | 371 """ |
| 369 return set((n.GetLanguage(), n.GetContext()) for n in self.GetOutputFiles()) | 372 return set((n.GetLanguage(), n.GetContext(), n.GetFallbackToDefaultLayout())
for n in self.GetOutputFiles()) |
| 370 | 373 |
| 371 def GetSubstitutionMessages(self): | 374 def GetSubstitutionMessages(self): |
| 372 """Returns the list of <message sub_variable="true"> nodes.""" | 375 """Returns the list of <message sub_variable="true"> nodes.""" |
| 373 return [n for n in self.ActiveDescendants() | 376 return [n for n in self.ActiveDescendants() |
| 374 if isinstance(n, message.MessageNode) | 377 if isinstance(n, message.MessageNode) |
| 375 and n.attrs['sub_variable'] == 'true'] | 378 and n.attrs['sub_variable'] == 'true'] |
| 376 | 379 |
| 377 def SetOutputLanguage(self, output_language): | 380 def SetOutputLanguage(self, output_language): |
| 378 """Set the output language. Prepares substitutions. | 381 """Set the output language. Prepares substitutions. |
| 379 | 382 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 390 # The value should match grit.clique.MessageClique.source_language. | 393 # The value should match grit.clique.MessageClique.source_language. |
| 391 output_language = self.GetSourceLanguage() | 394 output_language = self.GetSourceLanguage() |
| 392 if output_language != self.output_language: | 395 if output_language != self.output_language: |
| 393 self.output_language = output_language | 396 self.output_language = output_language |
| 394 self.substituter = None # force recalculate | 397 self.substituter = None # force recalculate |
| 395 | 398 |
| 396 def SetOutputContext(self, output_context): | 399 def SetOutputContext(self, output_context): |
| 397 self.output_context = output_context | 400 self.output_context = output_context |
| 398 self.substituter = None # force recalculate | 401 self.substituter = None # force recalculate |
| 399 | 402 |
| 403 def SetFallbackToDefaultLayout(self, fallback_to_default_layout): |
| 404 self.fallback_to_default_layout = fallback_to_default_layout |
| 405 self.substituter = None # force recalculate |
| 406 |
| 400 def SetDefines(self, defines): | 407 def SetDefines(self, defines): |
| 401 self.defines = defines | 408 self.defines = defines |
| 402 self.substituter = None # force recalculate | 409 self.substituter = None # force recalculate |
| 403 | 410 |
| 404 def SetTargetPlatform(self, target_platform): | 411 def SetTargetPlatform(self, target_platform): |
| 405 self.target_platform = target_platform | 412 self.target_platform = target_platform |
| 406 | 413 |
| 407 def GetSubstituter(self): | 414 def GetSubstituter(self): |
| 408 if self.substituter is None: | 415 if self.substituter is None: |
| 409 self.substituter = util.Substituter() | 416 self.substituter = util.Substituter() |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 by parameters of the same name. | 533 by parameters of the same name. |
| 527 """ | 534 """ |
| 528 node = IdentifierNode() | 535 node = IdentifierNode() |
| 529 node.StartParsing('identifier', parent) | 536 node.StartParsing('identifier', parent) |
| 530 node.HandleAttribute('name', name) | 537 node.HandleAttribute('name', name) |
| 531 node.HandleAttribute('id', id) | 538 node.HandleAttribute('id', id) |
| 532 node.HandleAttribute('comment', comment) | 539 node.HandleAttribute('comment', comment) |
| 533 node.HandleAttribute('systemid', systemid) | 540 node.HandleAttribute('systemid', systemid) |
| 534 node.EndParsing() | 541 node.EndParsing() |
| 535 return node | 542 return node |
| OLD | NEW |