Fail if non-allowlisted host system tool is used.
This CL improves the clarity of the non-hermetic nature of using
HostSystemTools, and make the build fail if a caller tries to use a host
system tool that isn't allowlisted in config.go.
The only caller seems to be for xcrun, which is a special case that is
pretty hard to remove.
Test: TH presubmit
Change-Id: Icd3e7330406a08c00ac9682e37e2d42669f2e6b7
diff --git a/android/config.go b/android/config.go
index d833c5c..48eb960 100644
--- a/android/config.go
+++ b/android/config.go
@@ -228,7 +228,8 @@
envCopy[k] = v
}
- // Copy the real PATH value to the test environment, it's needed by HostSystemTool() used in x86_darwin_host.go
+ // Copy the real PATH value to the test environment, it's needed by
+ // NonHermeticHostSystemTool() used in x86_darwin_host.go
envCopy["PATH"] = originalEnv["PATH"]
config := &config{
@@ -530,9 +531,12 @@
return PathForOutput(ctx, "host", c.PrebuiltOS(), "framework", path)
}
-// HostSystemTool looks for non-hermetic tools from the system we're running on.
-// Generally shouldn't be used, but useful to find the XCode SDK, etc.
-func (c *config) HostSystemTool(name string) string {
+// NonHermeticHostSystemTool looks for non-hermetic tools from the system we're
+// running on. These tools are not checked-in to AOSP, and therefore could lead
+// to reproducibility problems. Should not be used for other than finding the
+// XCode SDK (xcrun, sw_vers), etc. See ui/build/paths/config.go for the
+// allowlist of host system tools.
+func (c *config) NonHermeticHostSystemTool(name string) string {
for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
path := filepath.Join(dir, name)
if s, err := os.Stat(path); err != nil {
@@ -541,7 +545,10 @@
return path
}
}
- return name
+ panic(fmt.Errorf(
+ "Unable to use '%s' as a host system tool for build system "+
+ "hermeticity reasons. See build/soong/ui/build/paths/config.go "+
+ "for the full list of allowed host tools on your system.", name))
}
// PrebuiltOS returns the name of the host OS used in prebuilts directories