| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import copy | 6 import copy |
| 7 from datetime import datetime | 7 from datetime import datetime |
| 8 from functools import partial | 8 from functools import partial |
| 9 import os | 9 import os |
| 10 | 10 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 no_parent_values = ['noparent' in v for v in feature_value] | 453 no_parent_values = ['noparent' in v for v in feature_value] |
| 454 no_parent = all(no_parent_values) | 454 no_parent = all(no_parent_values) |
| 455 assert no_parent or not any(no_parent_values), ( | 455 assert no_parent or not any(no_parent_values), ( |
| 456 '"%s:" All child features must contain the same noparent value' % | 456 '"%s:" All child features must contain the same noparent value' % |
| 457 feature_name) | 457 feature_name) |
| 458 else: | 458 else: |
| 459 no_parent = 'noparent' in feature_value | 459 no_parent = 'noparent' in feature_value |
| 460 sep = feature_name.rfind('.') | 460 sep = feature_name.rfind('.') |
| 461 if sep is -1 or no_parent: | 461 if sep is -1 or no_parent: |
| 462 return None | 462 return None |
| 463 |
| 463 parent_name = feature_name[:sep] | 464 parent_name = feature_name[:sep] |
| 464 if parent_name not in self._features: | 465 while sep != -1 and parent_name not in self._features: |
| 466 # This recursion allows for a feature to have a parent that isn't a direct |
| 467 # ancestor. For instance, we could have feature 'alpha', and feature |
| 468 # 'alpha.child.child', where 'alpha.child.child' inherits from 'alpha'. |
| 469 # TODO(devlin): Is this useful? Or logical? |
| 470 sep = feature_name.rfind('.', 0, sep) |
| 471 parent_name = feature_name[:sep] |
| 472 |
| 473 if sep == -1: |
| 465 # TODO(devlin): It'd be kind of nice to be able to assert that the | 474 # TODO(devlin): It'd be kind of nice to be able to assert that the |
| 466 # deduced parent name is in our features, but some dotted features don't | 475 # deduced parent name is in our features, but some dotted features don't |
| 467 # have parents and also don't have noparent, e.g. system.cpu. We should | 476 # have parents and also don't have noparent, e.g. system.cpu. We should |
| 468 # probably just noparent them so that we can assert this. | 477 # probably just noparent them so that we can assert this. |
| 469 # raise KeyError('Could not find parent "%s" for feature "%s".' % | 478 # raise KeyError('Could not find parent "%s" for feature "%s".' % |
| 470 # (parent_name, feature_name)) | 479 # (parent_name, feature_name)) |
| 471 return None | 480 return None |
| 472 parent_value = self._features[parent_name] | 481 parent_value = self._features[parent_name] |
| 473 parent = parent_value | 482 parent = parent_value |
| 474 if type(parent_value) is list: | 483 if type(parent_value) is list: |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 parser.add_argument('source_files', type=str, nargs='+', | 603 parser.add_argument('source_files', type=str, nargs='+', |
| 595 help='The source features.json files') | 604 help='The source features.json files') |
| 596 args = parser.parse_args() | 605 args = parser.parse_args() |
| 597 if args.feature_class not in FEATURE_CLASSES: | 606 if args.feature_class not in FEATURE_CLASSES: |
| 598 raise NameError('Unknown feature class: %s' % args.feature_class) | 607 raise NameError('Unknown feature class: %s' % args.feature_class) |
| 599 c = FeatureCompiler(args.chrome_root, args.source_files, args.feature_class, | 608 c = FeatureCompiler(args.chrome_root, args.source_files, args.feature_class, |
| 600 args.provider_class, args.out_root, | 609 args.provider_class, args.out_root, |
| 601 args.out_base_filename) | 610 args.out_base_filename) |
| 602 c.Compile() | 611 c.Compile() |
| 603 c.Write() | 612 c.Write() |
| OLD | NEW |