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 '''Base types for nodes in a GRIT resource tree. | 6 '''Base types for nodes in a GRIT resource tree. |
7 ''' | 7 ''' |
8 | 8 |
9 import collections | 9 import collections |
10 import os | 10 import os |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 return [child for child in self if isinstance(child, type)] | 435 return [child for child in self if isinstance(child, type)] |
436 | 436 |
437 def GetTextualIds(self): | 437 def GetTextualIds(self): |
438 '''Returns a list of the textual ids of this node. | 438 '''Returns a list of the textual ids of this node. |
439 ''' | 439 ''' |
440 if 'name' in self.attrs: | 440 if 'name' in self.attrs: |
441 return [self.attrs['name']] | 441 return [self.attrs['name']] |
442 return [] | 442 return [] |
443 | 443 |
444 @classmethod | 444 @classmethod |
445 def GetPlatformAssertion(cls, target_platform): | |
446 '''If the platform is a specific well-known platform, this returns | |
447 the is_xyz string representing that platform (e.g. is_linux), | |
448 otherwise the empty string. | |
449 ''' | |
450 platform = '' | |
451 if target_platform == 'darwin': | |
452 platform = 'is_macosx' | |
453 elif target_platform.startswith('linux'): | |
454 platform = 'is_linux' | |
455 elif target_platform in ('cygwin', 'win32'): | |
456 platform = 'is_win' | |
457 elif target_platform in ('android', 'ios'): | |
458 platform = 'is_%s' % target_platform | |
459 return platform | |
460 | |
461 @classmethod | |
445 def EvaluateExpression(cls, expr, defs, target_platform, extra_variables=None) : | 462 def EvaluateExpression(cls, expr, defs, target_platform, extra_variables=None) : |
446 '''Worker for EvaluateCondition (below) and conditions in XTB files.''' | 463 '''Worker for EvaluateCondition (below) and conditions in XTB files.''' |
447 cache_dict = cls.eval_expr_cache[ | 464 cache_dict = cls.eval_expr_cache[ |
448 (tuple(defs.iteritems()), target_platform, extra_variables)] | 465 (tuple(defs.iteritems()), target_platform, extra_variables)] |
449 if expr in cache_dict: | 466 if expr in cache_dict: |
450 return cache_dict[expr] | 467 return cache_dict[expr] |
451 def pp_ifdef(symbol): | 468 def pp_ifdef(symbol): |
452 return symbol in defs | 469 return symbol in defs |
453 def pp_if(symbol): | 470 def pp_if(symbol): |
454 return defs.get(symbol, False) | 471 return defs.get(symbol, False) |
472 platform_assertion = Node.GetPlatformAssertion(target_platform) | |
455 variable_map = { | 473 variable_map = { |
456 'defs' : defs, | 474 'defs' : defs, |
457 'os': target_platform, | 475 'os': target_platform, |
458 'is_linux': target_platform.startswith('linux'), | 476 'is_linux': platform_assertion == 'is_linux', |
459 'is_macosx': target_platform == 'darwin', | 477 'is_macosx': platform_assertion == 'is_macosx', |
460 'is_win': target_platform in ('cygwin', 'win32'), | 478 'is_win': platform_assertion == 'is_win', |
461 'is_android': target_platform == 'android', | 479 'is_android': platform_assertion == 'is_android', |
462 'is_ios': target_platform == 'ios', | 480 'is_ios': platform_assertion == 'is_ios', |
Nico
2013/12/27 16:55:24
nit (optional, and since this is already landed be
| |
463 'is_posix': (target_platform in ('darwin', 'linux2', 'linux3', 'sunos5', | 481 # is_posix is not mutually exclusive of the others |
464 'android', 'ios') | 482 'is_posix': (target_platform in ('darwin', 'linux2', 'linux3', 'sunos5') |
465 or 'bsd' in target_platform), | 483 or 'bsd' in sys.platform), |
Nico
2014/01/28 20:48:35
Hey, it looks like you dropped 'ios' and 'android'
Jói
2014/01/29 13:41:39
Whoops, that looks like a bad merge maybe. Not int
| |
466 'pp_ifdef' : pp_ifdef, | 484 'pp_ifdef' : pp_ifdef, |
467 'pp_if' : pp_if, | 485 'pp_if' : pp_if, |
468 } | 486 } |
469 if extra_variables: | 487 if extra_variables: |
470 variable_map.update(extra_variables) | 488 variable_map.update(extra_variables) |
471 eval_result = cache_dict[expr] = eval(expr, {}, variable_map) | 489 eval_result = cache_dict[expr] = eval(expr, {}, variable_map) |
472 return eval_result | 490 return eval_result |
473 | 491 |
474 def EvaluateCondition(self, expr): | 492 def EvaluateCondition(self, expr): |
475 '''Returns true if and only if the Python expression 'expr' evaluates | 493 '''Returns true if and only if the Python expression 'expr' evaluates |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 def ExpandVariables(self): | 576 def ExpandVariables(self): |
559 '''Whether we need to expand variables on a given node.''' | 577 '''Whether we need to expand variables on a given node.''' |
560 return False | 578 return False |
561 | 579 |
562 | 580 |
563 class ContentNode(Node): | 581 class ContentNode(Node): |
564 '''Convenience baseclass for nodes that can have content.''' | 582 '''Convenience baseclass for nodes that can have content.''' |
565 def _ContentType(self): | 583 def _ContentType(self): |
566 return self._CONTENT_TYPE_MIXED | 584 return self._CONTENT_TYPE_MIXED |
567 | 585 |
OLD | NEW |