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

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: Final version 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 24 matching lines...) Expand all
35 self._state_stack = [set(self._TokenizeFlags(stored_flags))] 35 self._state_stack = [set(self._TokenizeFlags(stored_flags))]
36 36
37 def AddFlags(self, flags): 37 def AddFlags(self, flags):
38 """Appends flags to the command line if they aren't already there. 38 """Appends flags to the command line if they aren't already there.
39 Saves the current flags state on the stack, so a call to Restore will 39 Saves the current flags state on the stack, so a call to Restore will
40 change the state back to the one preceeding the call to AddFlags. 40 change the state back to the one preceeding the call to AddFlags.
41 41
42 Args: 42 Args:
43 flags: A list of flags to add on, eg. ['--single-process']. 43 flags: A list of flags to add on, eg. ['--single-process'].
44 """ 44 """
45 if flags: 45 self.PushFlags(add=flags)
46 assert flags[0] != 'chrome'
47
48 new_flags = self._state_stack[-1].copy()
49 for flag in flags:
50 new_flags.add(flag)
51 self._state_stack.append(new_flags)
52 self._UpdateCommandLineFile()
53 46
54 def RemoveFlags(self, flags): 47 def RemoveFlags(self, flags):
55 """Removes flags from the command line, if they exist. 48 """Removes flags from the command line, if they exist.
56 Saves the current flags state on the stack, so a call to Restore will 49 Saves the current flags state on the stack, so a call to Restore will
57 change the state back to the one preceeding the call to RemoveFlags. 50 change the state back to the one preceeding the call to RemoveFlags.
58 51
59 Note that calling RemoveFlags after AddFlags will result in having 52 Note that calling RemoveFlags after AddFlags will result in having
60 two nested states. 53 two nested states.
61 54
62 Args: 55 Args:
63 flags: A list of flags to remove, eg. ['--single-process']. Note that we 56 flags: A list of flags to remove, eg. ['--single-process']. Note that we
64 expect a complete match when removing flags; if you want to remove 57 expect a complete match when removing flags; if you want to remove
65 a switch with a value, you must use the exact string used to add 58 a switch with a value, you must use the exact string used to add
66 it in the first place. 59 it in the first place.
67 """ 60 """
68 if flags: 61 self.PushFlags(remove=flags)
69 assert flags[0] != 'chrome'
70 62
63 def PushFlags(self, add=None, remove=None):
64 """Appends and removes flags to/from the command line if they aren't already
65 there. Saves the current flags state on the stack, so a call to Restore
66 will change the state back to the one preceeding the call to PushFlags.
67
68 Args:
69 add: A list of flags to add on, eg. ['--single-process'].
70 remove: A list of flags to remove, eg. ['--single-process']. Note that we
71 expect a complete match when removing flags; if you want to remove
72 a switch with a value, you must use the exact string used to add
73 it in the first place.
74 """
71 new_flags = self._state_stack[-1].copy() 75 new_flags = self._state_stack[-1].copy()
72 for flag in flags: 76 if add:
73 new_flags.discard(flag) 77 assert add[0] != 'chrome'
78 for flag in add:
79 new_flags.add(flag)
80 if remove:
81 assert remove[0] != 'chrome'
82 for flag in remove:
83 new_flags.discard(flag)
74 self._state_stack.append(new_flags) 84 self._state_stack.append(new_flags)
75 self._UpdateCommandLineFile() 85 self._UpdateCommandLineFile()
76 86
77 def Restore(self): 87 def Restore(self):
78 """Restores the flags to their state prior to the last AddFlags or 88 """Restores the flags to their state prior to the last AddFlags or
79 RemoveFlags call. 89 RemoveFlags call.
80 """ 90 """
81 # The initial state must always remain on the stack. 91 # The initial state must always remain on the stack.
82 assert len(self._state_stack) > 1, ( 92 assert len(self._state_stack) > 1, (
83 "Mismatch between calls to Add/RemoveFlags and Restore") 93 "Mismatch between calls to Add/RemoveFlags and Restore")
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 157
148 # Tack on the last flag. 158 # Tack on the last flag.
149 if not current_flag: 159 if not current_flag:
150 if within_quotations: 160 if within_quotations:
151 logging.warn('Unterminated quoted argument: ' + line) 161 logging.warn('Unterminated quoted argument: ' + line)
152 else: 162 else:
153 tokenized_flags.append(current_flag) 163 tokenized_flags.append(current_flag)
154 164
155 # Return everything but the program name. 165 # Return everything but the program name.
156 return tokenized_flags[1:] 166 return tokenized_flags[1:]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698