Reland "[gclient] Make getdep and setdep to provide builtin vars"
This is a reland of 5705acabe03a84815779adda7c0928b67dfaa6ae
If a gclient config is not found, then built-in variables wont
be supported.
Original change's description:
> [gclient] Make getdep and setdep to provide builtin vars
>
> Bug: 906114
> Change-Id: I069cc21343911f7fdb3c91ecbd8fcba53fc8099f
> Reviewed-on: https://chromium-review.googlesource.com/c/1340461
> Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
> Commit-Queue: Eric Boren <borenet@chromium.org>
Bug: 906114
Change-Id: I72f30d10b5f0180fd5c616a42393f5b12055ce8e
Reviewed-on: https://chromium-review.googlesource.com/c/1341039
Reviewed-by: Eric Boren <borenet@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/gclient.py b/gclient.py
index 03177c3..e5b1c46 100755
--- a/gclient.py
+++ b/gclient.py
@@ -2814,7 +2814,7 @@
dest='vars', metavar='VAR', default=[],
help='Gets the value of a given variable.')
parser.add_option('-r', '--revision', action='append',
- dest='revisions', metavar='DEP', default=[],
+ dest='getdep_revisions', metavar='DEP', default=[],
help='Gets the revision/version for the given dependency. '
'If it is a git dependency, dep must be a path. If it '
'is a CIPD dependency, dep must be of the form '
@@ -2831,12 +2831,21 @@
'DEPS file %s does not exist.' % options.deps_file)
with open(options.deps_file) as f:
contents = f.read()
- local_scope = gclient_eval.Exec(contents, options.deps_file)
+ client = GClient.LoadCurrentConfig(options)
+ if client is not None:
+ builtin_vars = client.get_builtin_vars()
+ else:
+ logging.warn(
+ 'Couldn\'t find a valid gclient config. Will attempt to parse the DEPS '
+ 'file without support for built-in variables.')
+ builtin_vars = None
+ local_scope = gclient_eval.Exec(contents, options.deps_file,
+ builtin_vars=builtin_vars)
for var in options.vars:
print(gclient_eval.GetVar(local_scope, var))
- for name in options.revisions:
+ for name in options.getdep_revisions:
if ':' in name:
name, _, package = name.partition(':')
if not name or not package:
@@ -2856,7 +2865,7 @@
help='Sets a variable to the given value with the format '
'name=value.')
parser.add_option('-r', '--revision', action='append',
- dest='revisions', metavar='DEP@REV', default=[],
+ dest='setdep_revisions', metavar='DEP@REV', default=[],
help='Sets the revision/version for the dependency with '
'the format dep@rev. If it is a git dependency, dep '
'must be a path and rev must be a git hash or '
@@ -2881,7 +2890,18 @@
'DEPS file %s does not exist.' % options.deps_file)
with open(options.deps_file) as f:
contents = f.read()
- local_scope = gclient_eval.Exec(contents, options.deps_file)
+
+ client = GClient.LoadCurrentConfig(options)
+ if client is not None:
+ builtin_vars = client.get_builtin_vars()
+ else:
+ logging.warn(
+ 'Couldn\'t find a valid gclient config. Will attempt to parse the DEPS '
+ 'file without support for built-in variables.')
+ builtin_vars = None
+
+ local_scope = gclient_eval.Exec(contents, options.deps_file,
+ builtin_vars=builtin_vars)
for var in options.vars:
name, _, value = var.partition('=')
@@ -2893,7 +2913,7 @@
else:
gclient_eval.AddVar(local_scope, name, value)
- for revision in options.revisions:
+ for revision in options.setdep_revisions:
name, _, value = revision.partition('@')
if not name or not value:
parser.error(