fix(whl_library): track sources in whl_library (#2526)

This is reusing a bit of code used in `evaluate_markers` and makes use
of the RECORD files in the `whl` files that we use to extract whls in
`whl_library`. This should be merged before #2514 to avoid any cache
invalidation issues downstream.

Fixes #2468
diff --git a/python/private/pypi/whl_library.bzl b/python/private/pypi/whl_library.bzl
index 79a58a8..ef4077f 100644
--- a/python/private/pypi/whl_library.bzl
+++ b/python/private/pypi/whl_library.bzl
@@ -19,7 +19,7 @@
 load("//python/private:is_standalone_interpreter.bzl", "is_standalone_interpreter")
 load("//python/private:repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils")
 load(":attrs.bzl", "ATTRS", "use_isolated")
-load(":deps.bzl", "all_repo_names")
+load(":deps.bzl", "all_repo_names", "record_files")
 load(":generate_whl_library_build_bazel.bzl", "generate_whl_library_build_bazel")
 load(":parse_whl_name.bzl", "parse_whl_name")
 load(":patch_whl.bzl", "patch_whl")
@@ -242,7 +242,7 @@
         else:
             op_tmpl = "whl_library.ResolveRequirement({name}, {requirement})"
 
-        repo_utils.execute_checked(
+        pypi_repo_utils.execute_checked(
             rctx,
             # truncate the requirement value when logging it / reporting
             # progress since it may contain several ' --hash=sha256:...
@@ -250,6 +250,7 @@
             op = op_tmpl.format(name = rctx.attr.name, requirement = rctx.attr.requirement.split(" ", 1)[0]),
             arguments = args,
             environment = environment,
+            srcs = rctx.attr._python_srcs,
             quiet = rctx.attr.quiet,
             timeout = rctx.attr.timeout,
             logger = logger,
@@ -291,13 +292,14 @@
                 )
             ]
 
-    repo_utils.execute_checked(
+    pypi_repo_utils.execute_checked(
         rctx,
         op = "whl_library.ExtractWheel({}, {})".format(rctx.attr.name, whl_path),
         arguments = args + [
             "--whl-file",
             whl_path,
         ] + ["--platform={}".format(p) for p in target_platforms],
+        srcs = rctx.attr._python_srcs,
         environment = environment,
         quiet = rctx.attr.quiet,
         timeout = rctx.attr.timeout,
@@ -450,6 +452,16 @@
             for repo in all_repo_names
         ],
     ),
+    "_python_srcs": attr.label_list(
+        # Used as a default value in a rule to ensure we fetch the dependencies.
+        default = [
+            Label("//python/private/pypi/whl_installer:platform.py"),
+            Label("//python/private/pypi/whl_installer:wheel.py"),
+            Label("//python/private/pypi/whl_installer:wheel_installer.py"),
+            Label("//python/private/pypi/whl_installer:arguments.py"),
+            Label("//python/private/pypi/whl_installer:namespace_pkgs.py"),
+        ] + record_files.values(),
+    ),
     "_rule_name": attr.string(default = "whl_library"),
 }, **ATTRS)
 whl_library_attrs.update(AUTH_ATTRS)