Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. 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 from compiler.ast import Const | 5 from compiler.ast import Const |
| 6 from compiler.ast import Dict | 6 from compiler.ast import Dict |
| 7 from compiler.ast import Discard | 7 from compiler.ast import Discard |
| 8 from compiler.ast import List | 8 from compiler.ast import List |
| 9 from compiler.ast import Module | 9 from compiler.ast import Module |
| 10 from compiler.ast import Node | 10 from compiler.ast import Node |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 new_target = gyp.simple_copy.deepcopy(target) | 334 new_target = gyp.simple_copy.deepcopy(target) |
| 335 new_target['toolset'] = build | 335 new_target['toolset'] = build |
| 336 new_target_list.append(new_target) | 336 new_target_list.append(new_target) |
| 337 target['toolset'] = toolsets[0] | 337 target['toolset'] = toolsets[0] |
| 338 new_target_list.append(target) | 338 new_target_list.append(target) |
| 339 data['targets'] = new_target_list | 339 data['targets'] = new_target_list |
| 340 if 'conditions' in data: | 340 if 'conditions' in data: |
| 341 for condition in data['conditions']: | 341 for condition in data['conditions']: |
| 342 if type(condition) is list: | 342 if type(condition) is list: |
| 343 for condition_dict in condition[1:]: | 343 for condition_dict in condition[1:]: |
| 344 ProcessToolsetsInDict(condition_dict) | 344 if type(condition_dict) is dict: |
| 345 ProcessToolsetsInDict(condition_dict) | |
| 345 | 346 |
| 346 | 347 |
| 347 # TODO(mark): I don't love this name. It just means that it's going to load | 348 # TODO(mark): I don't love this name. It just means that it's going to load |
| 348 # a build file that contains targets and is expected to provide a targets dict | 349 # a build file that contains targets and is expected to provide a targets dict |
| 349 # that contains the targets... | 350 # that contains the targets... |
| 350 def LoadTargetBuildFile(build_file_path, data, aux_data, variables, includes, | 351 def LoadTargetBuildFile(build_file_path, data, aux_data, variables, includes, |
| 351 depth, check, load_dependencies): | 352 depth, check, load_dependencies): |
| 352 # If depth is set, predefine the DEPTH variable to be a relative path from | 353 # If depth is set, predefine the DEPTH variable to be a relative path from |
| 353 # this build file's directory to the directory identified by depth. | 354 # this build file's directory to the directory identified by depth. |
| 354 if depth: | 355 if depth: |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 | 1031 |
| 1031 # The same condition is often evaluated over and over again so it | 1032 # The same condition is often evaluated over and over again so it |
| 1032 # makes sense to cache as much as possible between evaluations. | 1033 # makes sense to cache as much as possible between evaluations. |
| 1033 cached_conditions_asts = {} | 1034 cached_conditions_asts = {} |
| 1034 | 1035 |
| 1035 def EvalCondition(condition, conditions_key, phase, variables, build_file): | 1036 def EvalCondition(condition, conditions_key, phase, variables, build_file): |
| 1036 """Returns the dict that should be used or None if the result was | 1037 """Returns the dict that should be used or None if the result was |
| 1037 that nothing should be used.""" | 1038 that nothing should be used.""" |
| 1038 if type(condition) is not list: | 1039 if type(condition) is not list: |
| 1039 raise GypError(conditions_key + ' must be a list') | 1040 raise GypError(conditions_key + ' must be a list') |
| 1040 if len(condition) != 2 and len(condition) != 3: | 1041 if len(condition) < 2: |
| 1041 # It's possible that condition[0] won't work in which case this | 1042 # It's possible that condition[0] won't work in which case this |
| 1042 # attempt will raise its own IndexError. That's probably fine. | 1043 # attempt will raise its own IndexError. That's probably fine. |
| 1043 raise GypError(conditions_key + ' ' + condition[0] + | 1044 raise GypError(conditions_key + ' ' + condition[0] + |
| 1044 ' must be length 2 or 3, not ' + str(len(condition))) | 1045 ' must be at least length 2, not ' + str(len(condition))) |
| 1045 | 1046 |
| 1046 [cond_expr, true_dict] = condition[0:2] | 1047 i = 0 |
| 1047 false_dict = None | 1048 result = None |
| 1048 if len(condition) == 3: | 1049 while result == None and i < len(condition): |
|
scottmg
2014/11/14 17:09:44
what does the error look like if you mix up the co
Shezan Baig (Bloomberg)
2014/11/14 17:25:44
If there are two dicts in a row, it would treat th
| |
| 1049 false_dict = condition[2] | 1050 cond_expr = condition[i] |
| 1051 true_dict = condition[i + 1] | |
| 1052 if len(condition) > i + 2 and type(condition[i + 2]) is dict: | |
| 1053 false_dict = condition[i + 2] | |
| 1054 i = i + 3 | |
| 1055 else: | |
| 1056 false_dict = None | |
| 1057 i = i + 2 | |
| 1058 result = EvalSingleCondition( | |
| 1059 cond_expr, true_dict, false_dict, phase, variables, build_file) | |
| 1050 | 1060 |
| 1061 return result | |
| 1062 | |
| 1063 | |
| 1064 def EvalSingleCondition( | |
| 1065 cond_expr, true_dict, false_dict, phase, variables, build_file): | |
| 1066 """Returns true_dict if cond_expr evaluates to true, and false_dict | |
| 1067 otherwise.""" | |
| 1051 # Do expansions on the condition itself. Since the conditon can naturally | 1068 # Do expansions on the condition itself. Since the conditon can naturally |
| 1052 # contain variable references without needing to resort to GYP expansion | 1069 # contain variable references without needing to resort to GYP expansion |
| 1053 # syntax, this is of dubious value for variables, but someone might want to | 1070 # syntax, this is of dubious value for variables, but someone might want to |
| 1054 # use a command expansion directly inside a condition. | 1071 # use a command expansion directly inside a condition. |
| 1055 cond_expr_expanded = ExpandVariables(cond_expr, phase, variables, | 1072 cond_expr_expanded = ExpandVariables(cond_expr, phase, variables, |
| 1056 build_file) | 1073 build_file) |
| 1057 if type(cond_expr_expanded) not in (str, int): | 1074 if type(cond_expr_expanded) not in (str, int): |
| 1058 raise ValueError, \ | 1075 raise ValueError, \ |
| 1059 'Variable expansion in this context permits str and int ' + \ | 1076 'Variable expansion in this context permits str and int ' + \ |
| 1060 'only, found ' + cond_expr_expanded.__class__.__name__ | 1077 'only, found ' + cond_expr_expanded.__class__.__name__ |
| (...skipping 1803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2864 ValidateRunAsInTarget(target, target_dict, build_file) | 2881 ValidateRunAsInTarget(target, target_dict, build_file) |
| 2865 ValidateActionsInTarget(target, target_dict, build_file) | 2882 ValidateActionsInTarget(target, target_dict, build_file) |
| 2866 | 2883 |
| 2867 # Generators might not expect ints. Turn them into strs. | 2884 # Generators might not expect ints. Turn them into strs. |
| 2868 TurnIntIntoStrInDict(data) | 2885 TurnIntIntoStrInDict(data) |
| 2869 | 2886 |
| 2870 # TODO(mark): Return |data| for now because the generator needs a list of | 2887 # TODO(mark): Return |data| for now because the generator needs a list of |
| 2871 # build files that came in. In the future, maybe it should just accept | 2888 # build files that came in. In the future, maybe it should just accept |
| 2872 # a list, and not the whole data dict. | 2889 # a list, and not the whole data dict. |
| 2873 return [flat_list, targets, data] | 2890 return [flat_list, targets, data] |
| OLD | NEW |