Commit e3337bf3 authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

idl_parser: Add current directory to sys.path

Python 3 doesn't support implicit relative imports.
Fix this by adding the current directory to the search path, so all the files can be found.
This works on both Python 2 and 3.

Traceback (most recent call last):
  File "../../third_party/blink/renderer/bindings/scripts/collect_idl_files.py", line 14, in <module>
    import blink_idl_parser
  File "C:\Google\chromium\src\third_party\blink\renderer\bindings\scripts\blink_idl_parser.py", line 74, in <module>
    from idl_parser.idl_parser import IDLParser  # pylint: disable=import-error
  File "C:\Google\chromium\src\third_party\blink\renderer\bindings\scripts\..\..\..\..\..\tools\idl_parser\idl_parser.py", line 38, in <module>
    from idl_lexer import IDLLexer
ModuleNotFoundError: No module named 'idl_lexer'

Bug: 941669
Change-Id: Ib0e7c88100fd0cc1eee90d252ad8c557e1e25197
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124475
Commit-Queue: Raul Tambre <raul@tambre.ee>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Auto-Submit: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#755073}
parent 05b1e211
......@@ -35,12 +35,16 @@ import os.path
import sys
import time
from idl_lexer import IDLLexer
from idl_node import IDLAttribute
from idl_node import IDLNode
SRC_DIR = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)
sys.path.insert(0, os.path.join(SRC_DIR, 'third_party'))
# Can't use relative imports if we don't have a parent package.
if __package__:
from .idl_lexer import IDLLexer
from .idl_node import IDLAttribute, IDLNode
else:
from idl_lexer import IDLLexer
from idl_node import IDLAttribute, IDLNode
SRC_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(SRC_DIR, os.pardir, os.pardir, 'third_party'))
from ply import lex
from ply import yacc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment