Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2838c818 authored by Jingwen Chen's avatar Jingwen Chen
Browse files

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
parent b26070ef
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -228,7 +228,8 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
		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 @@ func (c *config) HostJavaToolPath(ctx PathContext, path string) Path {
	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 @@ func (c *config) HostSystemTool(name string) string {
			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
+1 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ var macTools = &macPlatformTools{}

func getMacTools(ctx android.PackageVarContext) *macPlatformTools {
	macTools.once.Do(func() {
		xcrunTool := ctx.Config().HostSystemTool("xcrun")
		xcrunTool := ctx.Config().NonHermeticHostSystemTool("xcrun")

		xcrun := func(args ...string) string {
			if macTools.err != nil {