generator_lib.py: correctly handle lack of --jinja2-path.

Python's list.index() method raises an exception when the item isn't
present in the list. Fix this check that was instead expecting a
negative index.

BUG=dawn:225

Change-Id: I8e67d71ff7384f49533a95d5cbe04da1cf7bb0bc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11301
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez 2019-09-18 00:59:40 +00:00 committed by Commit Bot service account
parent 5e9082daa4
commit 45f9185de5
1 changed files with 6 additions and 2 deletions

View File

@ -80,11 +80,15 @@ class Generator:
# NOTE: If this argument appears several times, this only uses the first
# value, while argparse would typically keep the last one!
kJinja2Path = '--jinja2-path'
jinja2_path_argv_index = sys.argv.index(kJinja2Path)
if jinja2_path_argv_index >= 0:
try:
jinja2_path_argv_index = sys.argv.index(kJinja2Path)
# Add parent path for the import to succeed.
path = os.path.join(sys.argv[jinja2_path_argv_index + 1], os.pardir)
sys.path.insert(1, path)
except ValueError:
# --jinja2-path isn't passed, ignore the exception and just import Jinja2
# assuming it already is in the Python PATH.
pass
import jinja2