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

Side by Side Diff: build/android/pylib/flag_changer.py

Issue 1414403002: Add CommandLineArgumentParameter and use it for WebView tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-cr-526885-read-nested-annotations
Patch Set: Comments addressed Created 5 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
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 logging 5 import logging
6 6
7 from devil.android import device_errors 7 from devil.android import device_errors
8 8
9 9
10 class FlagChanger(object): 10 class FlagChanger(object):
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 self._UpdateCommandLineFile() 49 self._UpdateCommandLineFile()
50 50
51 def AddFlags(self, flags): 51 def AddFlags(self, flags):
52 """Appends flags to the command line if they aren't already there. 52 """Appends flags to the command line if they aren't already there.
53 Saves the current flags state on the stack, so a call to Restore will 53 Saves the current flags state on the stack, so a call to Restore will
54 change the state back to the one preceeding the call to AddFlags. 54 change the state back to the one preceeding the call to AddFlags.
55 55
56 Args: 56 Args:
57 flags: A sequence of flags to add on, eg. ['--single-process']. 57 flags: A sequence of flags to add on, eg. ['--single-process'].
58 """ 58 """
59 new_flags = self._state_stack[-1].copy() 59 self.PushFlags(add=flags)
60 new_flags.update(flags)
61 self.ReplaceFlags(new_flags)
62 60
63 def RemoveFlags(self, flags): 61 def RemoveFlags(self, flags):
64 """Removes flags from the command line, if they exist. 62 """Removes flags from the command line, if they exist.
65 Saves the current flags state on the stack, so a call to Restore will 63 Saves the current flags state on the stack, so a call to Restore will
66 change the state back to the one preceeding the call to RemoveFlags. 64 change the state back to the one preceeding the call to RemoveFlags.
67 65
68 Note that calling RemoveFlags after AddFlags will result in having 66 Note that calling RemoveFlags after AddFlags will result in having
69 two nested states. 67 two nested states.
70 68
71 Args: 69 Args:
72 flags: A sequence of flags to remove, eg. ['--single-process']. Note 70 flags: A sequence of flags to remove, eg. ['--single-process']. Note
73 that we expect a complete match when removing flags; if you want 71 that we expect a complete match when removing flags; if you want
74 to remove a switch with a value, you must use the exact string 72 to remove a switch with a value, you must use the exact string
75 used to add it in the first place. 73 used to add it in the first place.
76 """ 74 """
75 self.PushFlags(remove=flags)
76
77 def PushFlags(self, add=None, remove=None):
78 """Appends and removes flags to/from the command line if they aren't already
79 there. Saves the current flags state on the stack, so a call to Restore
80 will change the state back to the one preceeding the call to PushFlags.
81
82 Args:
83 add: A list of flags to add on, eg. ['--single-process'].
84 remove: A list of flags to remove, eg. ['--single-process']. Note that we
85 expect a complete match when removing flags; if you want to remove
86 a switch with a value, you must use the exact string used to add
87 it in the first place.
88 """
77 new_flags = self._state_stack[-1].copy() 89 new_flags = self._state_stack[-1].copy()
78 new_flags.difference_update(flags) 90 if add:
91 new_flags.update(add)
92 if remove:
93 new_flags.difference_update(remove)
79 self.ReplaceFlags(new_flags) 94 self.ReplaceFlags(new_flags)
80 95
81 def Restore(self): 96 def Restore(self):
82 """Restores the flags to their state prior to the last AddFlags or 97 """Restores the flags to their state prior to the last AddFlags or
83 RemoveFlags call. 98 RemoveFlags call.
84 """ 99 """
85 # The initial state must always remain on the stack. 100 # The initial state must always remain on the stack.
86 assert len(self._state_stack) > 1, ( 101 assert len(self._state_stack) > 1, (
87 "Mismatch between calls to Add/RemoveFlags and Restore") 102 "Mismatch between calls to Add/RemoveFlags and Restore")
88 self._state_stack.pop() 103 self._state_stack.pop()
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 166
152 # Tack on the last flag. 167 # Tack on the last flag.
153 if not current_flag: 168 if not current_flag:
154 if within_quotations: 169 if within_quotations:
155 logging.warn('Unterminated quoted argument: ' + line) 170 logging.warn('Unterminated quoted argument: ' + line)
156 else: 171 else:
157 tokenized_flags.append(current_flag) 172 tokenized_flags.append(current_flag)
158 173
159 # Return everything but the program name. 174 # Return everything but the program name.
160 return tokenized_flags[1:] 175 return tokenized_flags[1:]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698