8000 runfiles: Remove dead code (#1011) · cflewis/rules_python@86b01a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 86b01a3

Browse files
authored
runfiles: Remove dead code (bazel-contrib#1011)
Runfiles discovery relative to `argv[0]` isn't used as that logic lives in the launcher.
1 parent f94c195 commit 86b01a3

File tree

2 files changed

+0
-181
lines changed

2 files changed

+0
-181
lines changed

python/runfiles/runfiles.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -366,56 +366,3 @@ def EnvVars(self):
366366
# pick up RUNFILES_DIR.
367367
"JAVA_RUNFILES": self._runfiles_root,
368368
}
369-
370-
371-
def _PathsFrom(
372-
argv0, runfiles_mf, runfiles_dir, is_runfiles_manifest, is_runfiles_directory
373-
):
374-
# type: (str, str, str, Callable[[str], bool], Callable[[str], bool]) -> Tuple[str, str]
375-
"""Discover runfiles manifest and runfiles directory paths.
376-
377-
Args:
378-
argv0: string; the value of sys.argv[0]
379-
runfiles_mf: string; the value of the RUNFILES_MANIFEST_FILE environment
380-
variable
381-
runfiles_dir: string; the value of the RUNFILES_DIR environment variable
382-
is_runfiles_manifest: lambda(string):bool; returns true if the argument is
383-
the path of a runfiles manifest file
384-
is_runfiles_directory: lambda(string):bool; returns true if the argument is
385-
the path of a runfiles directory
386-
387-
Returns:
388-
(string, string) pair, first element is the path to the runfiles manifest,
389-
second element is the path to the runfiles directory. If the first element
390-
is non-empty, then is_runfiles_manifest returns true for it. Same goes for
391-
the second element and is_runfiles_directory respectively. If both elements
392-
are empty, then this function could not find a manifest or directory for
393-
which is_runfiles_manifest or is_runfiles_directory returns true.
394-
"""
395-
mf_alid = is_runfiles_manifest(runfiles_mf)
396-
dir_valid = is_runfiles_directory(runfiles_dir)
397-
398-
if not mf_alid and not dir_valid:
399-
runfiles_mf = argv0 + ".runfiles/MANIFEST"
400-
runfiles_dir = argv0 + ".runfiles"
401-
mf_alid = is_runfiles_manifest(runfiles_mf)
402-
dir_valid = is_runfiles_directory(runfiles_dir)
403-
if not mf_alid:
404-
runfiles_mf = argv0 + ".runfiles_manifest"
405-
mf_alid = is_runfiles_manifest(runfiles_mf)
406-
407-
if not mf_alid and not dir_valid:
408-
return ("", "")
409-
410-
if not mf_alid:
411-
runfiles_mf = runfiles_dir + "/MANIFEST"
412-
mf_alid = is_runfiles_manifest(runfiles_mf)
413-
if not mf_alid:
414-
runfiles_mf = runfiles_dir + "_manifest"
415-
mf_alid = is_runfiles_manifest(runfiles_mf)
416-
417-
if not dir_valid:
418-
runfiles_dir = runfiles_mf[:-9] # "_manifest" or "/MANIFEST"
419-
dir_valid = is_runfiles_directory(runfiles_dir)
420-
421-
return (runfiles_mf if mf_alid else "", runfiles_dir if dir_valid else "")

tests/runfiles/runfiles_test.py

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -505,134 +505,6 @@ def testDirectoryBasedRlocationWithRepoMappingFromOtherRepo(self):
505505
r.Rlocation("config.json", "protobuf~3.19.2"), dir + "/config.json"
506506
)
507507

508-
def testPathsFromEnvvars(self):
509-
# Both envvars have a valid value.
510-
mf, dr = runfiles._PathsFrom(
511-
"argv0",
512-
"mock1/MANIFEST",
513-
"mock2",
514-
lambda path: path == "mock1/MANIFEST",
515-
lambda path: path == "mock2",
516-
)
517-
self.assertEqual(mf, "mock1/MANIFEST")
518-
self.assertEqual(dr, "mock2")
519-
520-
# RUNFILES_MANIFEST_FILE is invalid but RUNFILES_DIR is good and there's a
521-
# runfiles manifest in the runfiles directory.
522-
mf, dr = runfiles._PathsFrom(
523-
"argv0",
524-
"mock1/MANIFEST",
525-
"mock2",
526-
lambda path: path == "mock2/MANIFEST",
527-
lambda path: path == "mock2",
528-
)
529-
self.assertEqual(mf, "mock2/MANIFEST")
530-
self.assertEqual(dr, "mock2")
531-
532-
# RUNFILES_MANIFEST_FILE is invalid but RUNFILES_DIR is good, but there's no
533-
# runfiles manifest in the runfiles directory.
534-
mf, dr = runfiles._PathsFrom(
535-
"argv0",
536-
"mock1/MANIFEST",
537-
"mock2",
538-
lambda path: False,
539-
lambda path: path == "mock2",
540-
)
541-
self.assertEqual(mf, "")
542-
self.assertEqual(dr, "mock2")
543-
544-
# RUNFILES_DIR is invalid but RUNFILES_MANIFEST_FILE is good, and it is in
545-
# a valid-looking runfiles directory.
546-
mf, dr = runfiles._PathsFrom(
547-
"argv0",
548-
"mock1/MANIFEST",
549-
"mock2",
550-
lambda path: path == "mock1/MANIFEST",
551-
lambda path: path == "mock1",
552-
)
553-
self.assertEqual(mf, "mock1/MANIFEST")
554-
self.assertEqual(dr, "mock1")
555-
556-
# RUNFILES_DIR is invalid but RUNFILES_MANIFEST_FILE is good, but it is not
557-
# in any valid-looking runfiles directory.
558-
mf, dr = runfiles._PathsFrom(
559-
"argv0",
560-
"mock1/MANIFEST",
561-
"mock2",
562-
lambda path: path == "mock1/MANIFEST",
563-
lambda path: False,
564-
)
565-
self.assertEqual(mf, "mock1/MANIFEST")
566-
self.assertEqual(dr, "")
567-
568-
# Both envvars are invalid, but there's a manifest in a runfiles directory
569-
# next to argv0, however there's no other content in the runfiles directory.
570-
mf, dr = runfiles._PathsFrom(
571-
"argv0",
572-
"mock1/MANIFEST",
573-
"mock2",
574-
lambda path: path == "argv0.runfiles/MANIFEST",
575-
lambda path: False,
576-
)
577-
self.assertEqual(mf, "argv0.runfiles/MANIFEST")
578-
self.assertEqual(dr, "")
579-
580-
# Both envvars are invalid, but there's a manifest next to argv0. There's
581-
# no runfiles tree anywhere.
582-
mf, dr = runfiles._PathsFrom(
583-
"argv0",
584-
"mock1/MANIFEST",
585-
"mock2",
586-
lambda path: path == "argv0.runfiles_manifest",
587-
lambda path: False,
588-
)
589-
self.assertEqual(mf, "argv0.runfiles_manifest")
590-
self.assertEqual(dr, "")
591-
592-
# Both envvars are invalid, but there's a valid manifest next to argv0, and
593-
# a valid runfiles directory (without a manifest in it).
594-
mf, dr = runfiles._PathsFrom(
595-
"argv0",
596-
"mock1/MANIFEST",
597-
"mock2",
598-
lambda path: path == "argv0.runfiles_manifest",
599-
lambda path: path == "argv0.runfiles",
600-
)
601-
self.assertEqual(mf, "argv0.runfiles_manifest")
602-
self.assertEqual(dr, "argv0.runfiles")
603-
604-
# Both envvars are invalid, but there's a valid runfiles directory next to
605-
# argv0, though no manifest in it.
606-
mf, dr = runfiles._PathsFrom(
607-
"argv0",
608-
"mock1/MANIFEST",
609-
"mock2",
610-
lambda path: False,
611-
lambda path: path == "argv0.runfiles",
612-
)
613-
self.assertEqual(mf, "")
614-
self.assertEqual(dr, "argv0.runfiles")
615-
616-
# Both envvars are invalid, but there's a valid runfiles directory next to
617-
# argv0 with a valid manifest in it.
618-
mf, dr = runfiles._PathsFrom(
619-
"argv0",
620-
"mock1/MANIFEST",
621-
"mock2",
622-
lambda path: path == "argv0.runfiles/MANIFEST",
623-
lambda path: path == "argv0.runfiles",
624-
)
625-
self.assertEqual(mf, "argv0.runfiles/MANIFEST")
626-
self.assertEqual(dr, "argv0.runfiles")
627-
628-
# Both envvars are invalid and there's no runfiles directory or manifest
629-
# next to the argv0.
630-
mf, dr = runfiles._PathsFrom(
631-
"argv0", "mock1/MANIFEST", "mock2", lambda path: False, lambda path: False
632-
)
633-
self.assertEqual(mf, "")
634-
self.assertEqual(dr, "")
635-
636508
def testCurrentRepository(self):
637509
# This test assumes that it is running without --enable_bzlmod as the
638510
# correct result with Bzlmod would be the empty string - the canonical

0 commit comments

Comments
 (0)
0