Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: pylib/gyp/input.py

Issue 601353002: Add support for "else if" in gyp conditions (Closed) Base URL: http://gyp.googlecode.com/svn/trunk
Patch Set: Better tests Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/conditions/elseif/elseif.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 i < len(condition):
1049 false_dict = condition[2] 1050 cond_expr = condition[i]
1051 true_dict = condition[i + 1]
1052 if type(true_dict) is not dict:
1053 raise GypError('{} {} must be followed by a dictionary, not {}'.format(
1054 conditions_key, cond_expr, type(true_dict)))
1055 if len(condition) > i + 2 and type(condition[i + 2]) is dict:
1056 false_dict = condition[i + 2]
1057 i = i + 3
1058 if i != len(condition):
1059 raise GypError('{} {} has {} unexpected trailing items'.format(
1060 conditions_key, cond_expr, len(condition) - i))
1061 else:
1062 false_dict = None
1063 i = i + 2
1064 if result == None:
1065 result = EvalSingleCondition(
1066 cond_expr, true_dict, false_dict, phase, variables, build_file)
1050 1067
1068 return result
1069
1070
1071 def EvalSingleCondition(
1072 cond_expr, true_dict, false_dict, phase, variables, build_file):
1073 """Returns true_dict if cond_expr evaluates to true, and false_dict
1074 otherwise."""
1051 # Do expansions on the condition itself. Since the conditon can naturally 1075 # Do expansions on the condition itself. Since the conditon can naturally
1052 # contain variable references without needing to resort to GYP expansion 1076 # contain variable references without needing to resort to GYP expansion
1053 # syntax, this is of dubious value for variables, but someone might want to 1077 # syntax, this is of dubious value for variables, but someone might want to
1054 # use a command expansion directly inside a condition. 1078 # use a command expansion directly inside a condition.
1055 cond_expr_expanded = ExpandVariables(cond_expr, phase, variables, 1079 cond_expr_expanded = ExpandVariables(cond_expr, phase, variables,
1056 build_file) 1080 build_file)
1057 if type(cond_expr_expanded) not in (str, int): 1081 if type(cond_expr_expanded) not in (str, int):
1058 raise ValueError, \ 1082 raise ValueError, \
1059 'Variable expansion in this context permits str and int ' + \ 1083 'Variable expansion in this context permits str and int ' + \
1060 'only, found ' + cond_expr_expanded.__class__.__name__ 1084 'only, found ' + cond_expr_expanded.__class__.__name__
(...skipping 1772 matching lines...) Expand 10 before | Expand all | Expand 10 after
2833 ValidateRunAsInTarget(target, target_dict, build_file) 2857 ValidateRunAsInTarget(target, target_dict, build_file)
2834 ValidateActionsInTarget(target, target_dict, build_file) 2858 ValidateActionsInTarget(target, target_dict, build_file)
2835 2859
2836 # Generators might not expect ints. Turn them into strs. 2860 # Generators might not expect ints. Turn them into strs.
2837 TurnIntIntoStrInDict(data) 2861 TurnIntIntoStrInDict(data)
2838 2862
2839 # TODO(mark): Return |data| for now because the generator needs a list of 2863 # TODO(mark): Return |data| for now because the generator needs a list of
2840 # build files that came in. In the future, maybe it should just accept 2864 # build files that came in. In the future, maybe it should just accept
2841 # a list, and not the whole data dict. 2865 # a list, and not the whole data dict.
2842 return [flat_list, targets, data] 2866 return [flat_list, targets, data]
OLDNEW
« no previous file with comments | « no previous file | test/conditions/elseif/elseif.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698