diff options
author | iancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-07 20:34:15 +0000 |
---|---|---|
committer | iancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-07 20:34:15 +0000 |
commit | e6467532778cf6d1d2a230def845af729fdc63a2 (patch) | |
tree | ec077985288f6cbe6ad0507657d926650234d959 /tools/cr | |
parent | 66aa6680ff060f3e6610610d9f959b7a3ef888d4 (diff) | |
download | chromium_src-e6467532778cf6d1d2a230def845af729fdc63a2.zip chromium_src-e6467532778cf6d1d2a230def845af729fdc63a2.tar.gz chromium_src-e6467532778cf6d1d2a230def845af729fdc63a2.tar.bz2 |
[cr tool] Trigger fixup hooks for missing variables, use it to get a better trail print so you can see what variables might affect a command
BUG=309573
Review URL: https://codereview.chromium.org/267593004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268928 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/cr')
-rw-r--r-- | tools/cr/cr/base/host.py | 15 | ||||
-rw-r--r-- | tools/cr/cr/config.py | 7 | ||||
-rw-r--r-- | tools/cr/cr/visitor.py | 5 |
3 files changed, 19 insertions, 8 deletions
diff --git a/tools/cr/cr/base/host.py b/tools/cr/cr/base/host.py index f60b55b5..5ff7ed8 100644 --- a/tools/cr/cr/base/host.py +++ b/tools/cr/cr/base/host.py @@ -14,6 +14,13 @@ import cr # Controls what verbosity level turns on command trail logging _TRAIL_VERBOSITY = 2 +def PrintTrail(trail): + print 'Command expanded the following variables:' + for key, value in trail: + if value == None: + value = '' + print ' ', key, '=', value + class Host(cr.Plugin, cr.Plugin.Type): """Base class for implementing cr hosts. @@ -75,9 +82,7 @@ class Host(cr.Plugin, cr.Plugin.Type): if cr.context.verbose: print ' '.join(command) if cr.context.verbose >= _TRAIL_VERBOSITY: - print 'Command expanded the following variables:' - for key, value in trail: - print ' ', key, '=', value + PrintTrail(trail) if ignore_dry_run or not cr.context.dry_run: out = None if capture: @@ -93,9 +98,7 @@ class Host(cr.Plugin, cr.Plugin.Type): print 'Failed to exec', command # Don't log the trail if we already have if cr.context.verbose < _TRAIL_VERBOSITY: - print 'Variables used to build the command were:' - for key, value in trail: - print ' ', key, '=', value + PrintTrail(trail) exit(1) try: if ignore_interrupt_signal: diff --git a/tools/cr/cr/config.py b/tools/cr/cr/config.py index bd0ede2..7c235b6 100644 --- a/tools/cr/cr/config.py +++ b/tools/cr/cr/config.py @@ -142,7 +142,7 @@ class Config(cr.visitor.Node, cr.loader.AutoExport): Raw values can be callable, simple values, or contain format strings. Args: - visitor: The vistior asking to resolve a value. + visitor: The visitor asking to resolve a value. key: The key being visited. value: The unresolved value associated with the key. Returns: @@ -165,6 +165,11 @@ class Config(cr.visitor.Node, cr.loader.AutoExport): value = hook(self, key, value) return value + def Missing(self, key): + for hook in self.fixup_hooks: + hook(self, key, None) + raise KeyError(key) + @staticmethod def ParseValue(value): """Converts a string to a value. diff --git a/tools/cr/cr/visitor.py b/tools/cr/cr/visitor.py index 339040c..8e01c70 100644 --- a/tools/cr/cr/visitor.py +++ b/tools/cr/cr/visitor.py @@ -239,11 +239,14 @@ class Node(object): def Get(self, key, raise_errors=False): search = SearchVisitor(key).VisitNode(self) if not search.found: - raise KeyError(key) + self.Missing(key) if search.error and raise_errors: raise search.error # bad type inference pylint: disable=raising-bad-type return search.value + def Missing(self, key): + raise KeyError(key) + def Resolve(self, visitor, key, value): _ = visitor, key return value |