Merge "Pass TARGET_DEVICE_DIR from dumpvars to later kati runs"
diff --git a/ui/build/config.go b/ui/build/config.go
index 530c3a8..5622dff 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -44,10 +44,11 @@
 	skipMake   bool
 
 	// From the product config
-	katiArgs     []string
-	ninjaArgs    []string
-	katiSuffix   string
-	targetDevice string
+	katiArgs        []string
+	ninjaArgs       []string
+	katiSuffix      string
+	targetDevice    string
+	targetDeviceDir string
 
 	brokenDupRules bool
 }
@@ -568,3 +569,11 @@
 func (c *configImpl) BuildBrokenDupRules() bool {
 	return c.brokenDupRules
 }
+
+func (c *configImpl) SetTargetDeviceDir(dir string) {
+	c.targetDeviceDir = dir
+}
+
+func (c *configImpl) TargetDeviceDir() string {
+	return c.targetDeviceDir
+}
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index eb43ed6..cc9e742 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -157,6 +157,9 @@
 		// To find target/product/<DEVICE>
 		"TARGET_DEVICE",
 
+		// So that later Kati runs can find BoardConfig.mk faster
+		"TARGET_DEVICE_DIR",
+
 		// Whether --werror_overriding_commands will work
 		"BUILD_BROKEN_DUP_RULES",
 	}, exportEnvVars...), BannerVars...)
@@ -182,6 +185,7 @@
 	config.SetKatiArgs(strings.Fields(make_vars["KATI_GOALS"]))
 	config.SetNinjaArgs(strings.Fields(make_vars["NINJA_GOALS"]))
 	config.SetTargetDevice(make_vars["TARGET_DEVICE"])
+	config.SetTargetDeviceDir(make_vars["TARGET_DEVICE_DIR"])
 
 	config.SetBuildBrokenDupRules(make_vars["BUILD_BROKEN_DUP_RULES"] != "false")
 }
diff --git a/ui/build/kati.go b/ui/build/kati.go
index a73ebdf..752a2c2 100644
--- a/ui/build/kati.go
+++ b/ui/build/kati.go
@@ -94,7 +94,8 @@
 	args = append(args,
 		"BUILDING_WITH_NINJA=true",
 		"SOONG_ANDROID_MK="+config.SoongAndroidMk(),
-		"SOONG_MAKEVARS_MK="+config.SoongMakeVarsMk())
+		"SOONG_MAKEVARS_MK="+config.SoongMakeVarsMk(),
+		"TARGET_DEVICE_DIR="+config.TargetDeviceDir())
 
 	if config.UseGoma() {
 		args = append(args, "-j"+strconv.Itoa(config.Parallel()))
@@ -199,6 +200,7 @@
 		"-f", "build/make/core/cleanbuild.mk",
 		"BUILDING_WITH_NINJA=true",
 		"SOONG_MAKEVARS_MK=" + config.SoongMakeVarsMk(),
+		"TARGET_DEVICE_DIR=" + config.TargetDeviceDir(),
 	}
 
 	cmd := Command(ctx, config, "ckati", executable, args...)