@@ -31,7 +31,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
3131load ("//pkg:providers.bzl" , "PackageDirsInfo" , "PackageFilegroupInfo" , "PackageFilesInfo" , "PackageSymlinkInfo" )
3232load ("//pkg/private:util.bzl" , "get_repo_mapping_manifest" )
3333
34- # TODO(#333): strip_prefix module functions should produce unique outputs. In
34+ # TODO(#333): strip_prefix module functions should produce unique outputs. In
3535# particular, this one and `_sp_from_pkg` can overlap.
3636_PKGFILEGROUP_STRIP_ALL = "."
3737
@@ -43,14 +43,12 @@ def _sp_files_only():
4343def _sp_from_pkg (path = "" ):
4444 if path .startswith ("/" ):
4545 return path [1 :]
46- else :
47- return path
46+ return path
4847
4948def _sp_from_root (path = "" ):
5049 if path .startswith ("/" ):
5150 return path
52- else :
53- return "/" + path
51+ return "/" + path
5452
5553strip_prefix = struct (
5654 _doc = """pkg_files `strip_prefix` helper. Instructs `pkg_files` what to do with directory prefixes of files.
@@ -148,21 +146,20 @@ def _do_strip_prefix(path, to_strip, src_file):
148146
149147 if path_norm .startswith (to_strip_norm ):
150148 return path_norm [len (to_strip_norm ):]
151- elif src_file .is_directory and (path_norm + "/" ) == to_strip_norm :
149+ if src_file .is_directory and (path_norm + "/" ) == to_strip_norm :
152150 return ""
153- else :
154- # Avoid user surprise by failing if prefix stripping doesn't work as
155- # expected.
156- #
157- # We already leave enough breadcrumbs, so if File.owner() returns None,
158- # this won't be a problem.
159- failmsg = "Could not strip prefix '{}' from file {} ({})" .format (to_strip , str (src_file ), str (src_file .owner ))
160- if src_file .is_directory :
161- failmsg += """\n \n NOTE: prefix stripping does not operate within TreeArtifacts (directory outputs)
151+
152+ # Avoid user surprise by failing if prefix stripping doesn't work as expected.
153+ #
154+ # We already leave enough breadcrumbs, so if File.owner() returns None,
155+ # this won't be a problem.
156+ failmsg = "Could not strip prefix '{}' from file {} ({})" .format (to_strip , str (src_file ), str (src_file .owner ))
157+ if src_file .is_directory :
158+ failmsg += """\n \n NOTE: prefix stripping does not operate within TreeArtifacts (directory outputs)
162159
163160To strip the directory named by the TreeArtifact itself, see documentation for the `renames` attribute.
164161"""
165- fail (failmsg )
162+ fail (failmsg )
166163
167164# The below routines make use of some path checking magic that may difficult to
168165# understand out of the box. This following table may be helpful to demonstrate
@@ -189,8 +186,7 @@ def _owner(file):
189186 # File.owner returns a Label structure
190187 if file .owner == None :
191188 fail ("File {} ({}) has no owner attribute; cannot continue" .format (file , file .path ))
192- else :
193- return file .owner
189+ return file .owner
194190
195191def _relative_workspace_root (label ):
196192 # Helper function that returns the workspace root relative to the bazel File
@@ -219,7 +215,7 @@ def _path_relative_to_repo_root(file):
219215 )
220216
221217def _pkg_files_impl (ctx ):
222- # The input sources are already known. Let's calculate the destinations...
218+ # The input sources are already known. Let's calculate the destinations...
223219
224220 # Exclude excludes
225221 srcs = [] # srcs is source File objects, not Targets
@@ -263,7 +259,7 @@ def _pkg_files_impl(ctx):
263259 # rename_src.files is a depset
264260 rename_src_files = rename_src .files .to_list ()
265261
266- # Need to do a length check before proceeding. We cannot rename
262+ # Need to do a length check before proceeding. We cannot rename
267263 # multiple files simultaneously.
268264 if len (rename_src_files ) != 1 :
269265 fail (
0 commit comments