aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2015-09-03 13:00:29 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-09-03 14:42:04 +0000
commitf1ac09940559008e0537ef35b0400093d17ea194 (patch)
tree775741e42ee39346ffc599b4fb9873226c706b15 /src/main
parentfde4509e926af53df20db000d380d8fae486b587 (diff)
Make Python rules work in external repositories.
This is necessary to make mobile-install work using an android_local_tools_repository. Fixes #415. -- MOS_MIGRATED_REVID=102235910
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt
index cbdde6869a..911315003f 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt
@@ -60,6 +60,21 @@ def Main():
raise AssertionError('Cannot find .runfiles directory for %s' %
sys.argv[0])
+ python_path_entries = [module_space]
+
+ external_dir = os.path.join(module_space, 'external')
+ if os.path.isdir(external_dir):
+ external_entries = [os.path.join(external_dir, d) for d in os.listdir(external_dir)]
+ repositories = [d for d in external_entries if os.path.isdir(d)]
+ python_path_entries += repositories
+
+ old_python_path = os.environ.get('PYTHONPATH')
+ python_path = ':'.join(python_path_entries)
+ if old_python_path:
+ python_path += ':' + old_python_path
+
+ new_env['PYTHONPATH'] = python_path
+
# Now look for my main python source file.
# The magic string percent-main-percent is replaced with the filename of the
# main file of the Python binary in BazelPythonSemantics.java.
@@ -69,12 +84,6 @@ def Main():
assert os.access(main_filename, os.R_OK), \
'Cannot exec() %r: file not readable.' % main_filename
- python_path = os.environ.get('PYTHONPATH')
- if not python_path:
- new_env['PYTHONPATH'] = module_space
- else:
- new_env['PYTHONPATH'] = '%s:%s' % (module_space, python_path)
-
program = python_program = FindPythonBinary()
if python_program is None:
raise AssertionError('Could not find python binary: ' + PYTHON_BINARY)