@@ -132,7 +132,7 @@ def _pex_library_impl(ctx):
132132 )
133133
134134
135- def _gen_manifest (py , runfiles ):
135+ def _gen_manifest (py , runfiles , strip_pex_path_prefixes ):
136136 """Generate a manifest for pex_wrapper.
137137
138138 Returns:
@@ -149,6 +149,12 @@ def _gen_manifest(py, runfiles):
149149 dpath = f .short_path
150150 if dpath .startswith ("../" ):
151151 dpath = dpath [3 :]
152+
153+ for prefix in strip_pex_path_prefixes :
154+ if dpath .startswith (prefix ):
155+ dpath = dpath [len (prefix ):]
156+ break
157+
152158 pex_files .append (
153159 struct (
154160 src = f .path ,
@@ -165,6 +171,7 @@ def _gen_manifest(py, runfiles):
165171
166172def _pex_binary_impl (ctx ):
167173 transitive_files = set (ctx .files .srcs )
174+ strip_pex_path_prefixes = ctx .attr .strip_pex_path_prefixes
168175
169176 if ctx .attr .entrypoint and ctx .file .main :
170177 fail ("Please specify either entrypoint or main, not both." )
@@ -177,7 +184,13 @@ def _pex_binary_impl(ctx):
177184 main_file = pex_file_types .filter (ctx .files .srcs )[0 ]
178185 if main_file :
179186 # Translate main_file's short path into a python module name
180- main_pkg = main_file .short_path .replace ('/' , '.' )[:- 3 ]
187+ main_file = main_file .short_path
188+ for prefix in strip_pex_path_prefixes :
189+ if main_file .startswith (prefix ):
190+ main_file = main_file [len (prefix ):]
191+ break
192+
193+ main_pkg = main_file .replace ('/' , '.' )[:- 3 ]
181194 transitive_files += [main_file ]
182195
183196 deploy_pex = ctx .new_file (
@@ -196,7 +209,7 @@ def _pex_binary_impl(ctx):
196209 manifest_file = ctx .new_file (
197210 ctx .configuration .bin_dir , deploy_pex , '_manifest' )
198211
199- manifest = _gen_manifest (py , runfiles )
212+ manifest = _gen_manifest (py , runfiles , strip_pex_path_prefixes )
200213
201214 ctx .file_action (
202215 output = manifest_file ,
@@ -328,7 +341,6 @@ pex_attrs = {
328341 allow_files = repo_file_types ),
329342 "data" : attr .label_list (allow_files = True ,
330343 cfg = "data" ),
331-
332344 # Used by pex_binary and pex_*test, not pex_library:
333345 "_pexbuilder" : attr .label (
334346 default = Label ("//pex:pex_wrapper" ),
@@ -357,6 +369,7 @@ pex_bin_attrs = _dmerge(pex_attrs, {
357369 default = True ,
358370 mandatory = False ,
359371 ),
372+ "strip_pex_path_prefixes" : attr .string_list (),
360373})
361374
362375pex_library = rule (
0 commit comments