(input, phase, variables, build_file)
| 756 | |
| 757 | |
| 758 | def ExpandVariables(input, phase, variables, build_file): |
| 759 | # Look for the pattern that gets expanded into variables |
| 760 | if phase == PHASE_EARLY: |
| 761 | variable_re = early_variable_re |
| 762 | expansion_symbol = "<" |
| 763 | elif phase == PHASE_LATE: |
| 764 | variable_re = late_variable_re |
| 765 | expansion_symbol = ">" |
| 766 | elif phase == PHASE_LATELATE: |
| 767 | variable_re = latelate_variable_re |
| 768 | expansion_symbol = "^" |
| 769 | else: |
| 770 | assert False |
| 771 | |
| 772 | input_str = str(input) |
| 773 | if IsStrCanonicalInt(input_str): |
| 774 | return int(input_str) |
| 775 | |
| 776 | # Do a quick scan to determine if an expensive regex search is warranted. |
| 777 | if expansion_symbol not in input_str: |
| 778 | return input_str |
| 779 | |
| 780 | # Get the entire list of matches as a list of MatchObject instances. |
| 781 | # (using findall here would return strings instead of MatchObjects). |
| 782 | matches = list(variable_re.finditer(input_str)) |
| 783 | if not matches: |
| 784 | return input_str |
| 785 | |
| 786 | output = input_str |
| 787 | # Reverse the list of matches so that replacements are done right-to-left. |
| 788 | # That ensures that earlier replacements won't mess up the string in a |
| 789 | # way that causes later calls to find the earlier substituted text instead |
| 790 | # of what's intended for replacement. |
| 791 | matches.reverse() |
| 792 | for match_group in matches: |
| 793 | match = match_group.groupdict() |
| 794 | gyp.DebugOutput(gyp.DEBUG_VARIABLES, "Matches: %r", match) |
| 795 | # match['replace'] is the substring to look for, match['type'] |
| 796 | # is the character code for the replacement type (< > <! >! <| >| <@ |
| 797 | # >@ <!@ >!@), match['is_array'] contains a '[' for command |
| 798 | # arrays, and match['content'] is the name of the variable (< >) |
| 799 | # or command to run (<! >!). match['command_string'] is an optional |
| 800 | # command string. Currently, only 'pymod_do_main' is supported. |
| 801 | |
| 802 | # run_command is true if a ! variant is used. |
| 803 | run_command = "!" in match["type"] |
| 804 | command_string = match["command_string"] |
| 805 | |
| 806 | # file_list is true if a | variant is used. |
| 807 | file_list = "|" in match["type"] |
| 808 | |
| 809 | # Capture these now so we can adjust them later. |
| 810 | replace_start = match_group.start("replace") |
| 811 | replace_end = match_group.end("replace") |
| 812 | |
| 813 | # Find the ending paren, and re-evaluate the contained string. |
| 814 | (c_start, c_end) = FindEnclosingBracketGroup(input_str[replace_start:]) |
| 815 |
no test coverage detected
searching dependent graphs…