Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions pex/pex_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,18 @@ def _pex_library_impl(ctx):
)


def _gen_manifest(py, runfiles):
def _strip_import_paths_from_workspace_name(ctx, import_paths=[]):
new_import_paths = set()
workspace_name = ctx.workspace_name

for import_path in import_paths:
if import_path.startswith(workspace_name):
new_import_paths += [import_path[len(workspace_name) + 1:]] # including /

return new_import_paths


def _gen_manifest(py, runfiles, import_paths=[]):
"""Generate a manifest for pex_wrapper.

Returns:
Expand All @@ -124,6 +135,12 @@ def _gen_manifest(py, runfiles):
dpath = f.short_path
if dpath.startswith("../"):
dpath = dpath[3:]

for import_path in import_paths:
if dpath.startswith(import_path):
dpath = dpath[len(import_path) + 1:] # including /
break # don't do multiple replaces

pex_files.append(
struct(
src = f.path,
Expand Down Expand Up @@ -160,8 +177,13 @@ def _pex_binary_impl(ctx):

py = _collect_transitive(ctx)

import_paths = set()

for dep in ctx.attr.deps:
transitive_files += dep.default_runfiles.files
for runfile in dep.default_runfiles.files:
import_paths += dep.py.imports

runfiles = ctx.runfiles(
collect_default = True,
transitive_files = transitive_files,
Expand All @@ -170,7 +192,10 @@ def _pex_binary_impl(ctx):
manifest_file = ctx.new_file(
ctx.configuration.bin_dir, deploy_pex, '_manifest')

manifest = _gen_manifest(py, runfiles)
manifest = _gen_manifest(
py,
runfiles,
_strip_import_paths_from_workspace_name(ctx, import_paths))

ctx.file_action(
output = manifest_file,
Expand Down