kleaf: *_clang_toolchain allow further customization.

Add a few more attributes to _clang_toolchain_internal so we can
customize a toolchain further in a future CL.

Test: TH
Bug: 253562056
Change-Id: I0002d23532c9882da4f04f2f1b1c6c7e4447c393
diff --git a/kleaf/BUILD.bazel b/kleaf/BUILD.bazel
index 3b47f66..bbe89af 100644
--- a/kleaf/BUILD.bazel
+++ b/kleaf/BUILD.bazel
@@ -47,6 +47,7 @@
 
 [clang_toolchain(
     name = "{}_{}_clang_toolchain".format(target_os, target_cpu),
+    clang_pkg = "//prebuilts/clang/host/linux-x86/clang-{}".format(VARS["CLANG_VERSION"]),
     clang_version = VARS["CLANG_VERSION"],
     target_cpu = target_cpu,
     target_os = target_os,
@@ -64,6 +65,7 @@
 
 [clang_toolchain(
     name = "{}_{}_{}_clang_toolchain".format(version, target_os, target_cpu),
+    clang_pkg = "//prebuilts/clang/host/linux-x86/clang-{}".format(version),
     clang_version = version,
     extra_compatible_with = [version],
     target_cpu = target_cpu,
diff --git a/kleaf/clang_toolchain.bzl b/kleaf/clang_toolchain.bzl
index 830cc64..a77dace 100644
--- a/kleaf/clang_toolchain.bzl
+++ b/kleaf/clang_toolchain.bzl
@@ -27,6 +27,7 @@
         clang_version,
         target_cpu,
         target_os,
+        clang_pkg,
         linker_files = None,
         sysroot_label = None,
         sysroot_path = None,
@@ -39,6 +40,10 @@
         clang_version: value of `CLANG_VERSION`, e.g. `r475365b`.
         target_cpu: CPU that the toolchain cross-compiles to
         target_os: OS that the toolchain cross-compiles to
+        clang_pkg: Label to any target in the clang toolchain package.
+
+            This is used as an anchor to locate other targets in the package.
+            Name of the label is ignored.
         linker_files: Additional dependencies to the linker
         sysroot_label: Label to a list of files from sysroot
         sysroot_path: Path to sysroot
@@ -59,13 +64,13 @@
     if extra_compatible_with == None:
         extra_compatible_with = []
 
-    clang_pkg = "//prebuilts/clang/host/linux-x86/clang-{}".format(clang_version)
-    clang_includes = Label("{}:includes".format(clang_pkg))
+    clang_pkg = native.package_relative_label(clang_pkg)
+    clang_includes = clang_pkg.relative(":includes")
 
     # Technically we can split the binaries into those for compiler, linker
     # etc., but since these binaries are usually updated together, it is okay
     # to use a superset here.
-    clang_all_binaries = Label("{}:binaries".format(clang_pkg))
+    clang_all_binaries = clang_pkg.relative(":binaries")
 
     # Individual binaries
     # From _setup_env.sh
@@ -83,12 +88,12 @@
     #
     # Note: ld.lld does not recognize --target etc. from android.bzl,
     # so just use clang directly
-    clang = Label("{}:bin/clang".format(clang_pkg))
-    clang_plus_plus = Label("{}:bin/clang++".format(clang_pkg))
+    clang = clang_pkg.relative(":bin/clang")
+    clang_plus_plus = clang_pkg.relative(":bin/clang++")
     ld = clang
-    strip = Label("{}:bin/llvm-strip".format(clang_pkg))
-    ar = Label("{}:bin/llvm-ar".format(clang_pkg))
-    objcopy = Label("{}:bin/llvm-objcopy".format(clang_pkg))
+    strip = clang_pkg.relative(":bin/llvm-strip")
+    ar = clang_pkg.relative(":bin/llvm-ar")
+    objcopy = clang_pkg.relative(":bin/llvm-objcopy")
     # cc_* rules doesn't seem to need nm, obj-dump, size, and readelf
 
     native.filegroup(
@@ -160,6 +165,7 @@
 def clang_toolchain(
         name,
         clang_version,
+        clang_pkg,
         target_cpu,
         target_os,
         extra_compatible_with = None):
@@ -170,6 +176,10 @@
     Args:
         name: name of the toolchain
         clang_version: nonconfigurable. version of the toolchain
+        clang_pkg: Label to any target in the clang toolchain package.
+
+            This is used as an anchor to locate other targets in the package.
+            Name of the label is ignored.
         target_cpu: nonconfigurable. CPU of the toolchain
         target_os: nonconfigurable. OS of the toolchain
         extra_compatible_with: nonconfigurable. extra `exec_compatible_with` and `target_compatible_with`
@@ -185,6 +195,7 @@
         clang_version = clang_version,
         target_os = target_os,
         target_cpu = target_cpu,
+        clang_pkg = clang_pkg,
         extra_compatible_with = extra_compatible_with,
         **extra_kwargs
     )