Use soong_javac_wrapper in soong javac compiles

Test: m checkbuild
Change-Id: I0f9ff0a719ac550a011c2878fc51595dc3427aed
diff --git a/cmd/javac_wrapper/javac_wrapper.go b/cmd/javac_wrapper/javac_wrapper.go
index a86f1e9..4df4938 100644
--- a/cmd/javac_wrapper/javac_wrapper.go
+++ b/cmd/javac_wrapper/javac_wrapper.go
@@ -17,6 +17,11 @@
 //
 // It also hides the unhelpful and unhideable "warning there is a warning"
 // messages.
+//
+// Each javac build statement has an order-only dependency on the
+// soong_javac_wrapper tool, which means the javac command will not be rerun
+// if soong_javac_wrapper changes.  That means that soong_javac_wrapper must
+// not do anything that will affect the results of the build.
 package main
 
 import (
diff --git a/java/builder.go b/java/builder.go
index a03f892..9086d51 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -39,14 +39,15 @@
 	javac = pctx.AndroidGomaStaticRule("javac",
 		blueprint.RuleParams{
 			Command: `rm -rf "$outDir" "$annoDir" && mkdir -p "$outDir" "$annoDir" && ` +
-				`${config.JavacWrapper}${config.JavacCmd} ${config.JavacHeapFlags} ${config.CommonJdkFlags} ` +
+				`${config.SoongJavacWrapper} ${config.JavacWrapper}${config.JavacCmd} ${config.JavacHeapFlags} ${config.CommonJdkFlags} ` +
 				`$javacFlags $sourcepath $bootClasspath $classpath ` +
 				`-source $javaVersion -target $javaVersion ` +
 				`-d $outDir -s $annoDir @$out.rsp && ` +
 				`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
-			CommandDeps:    []string{"${config.JavacCmd}", "${config.SoongZipCmd}"},
-			Rspfile:        "$out.rsp",
-			RspfileContent: "$in",
+			CommandDeps:      []string{"${config.JavacCmd}", "${config.SoongZipCmd}"},
+			CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
+			Rspfile:          "$out.rsp",
+			RspfileContent:   "$in",
 		},
 		"javacFlags", "sourcepath", "bootClasspath", "classpath", "outDir", "annoDir", "javaVersion")
 
@@ -69,7 +70,7 @@
 	errorprone = pctx.AndroidStaticRule("errorprone",
 		blueprint.RuleParams{
 			Command: `rm -rf "$outDir" "$annoDir" && mkdir -p "$outDir" "$annoDir" && ` +
-				`${config.ErrorProneCmd} ` +
+				`${config.SoongJavacWrapper} ${config.ErrorProneCmd} ` +
 				`$javacFlags $sourcepath $bootClasspath $classpath ` +
 				`-source $javaVersion -target $javaVersion ` +
 				`-d $outDir -s $annoDir @$out.rsp && ` +
@@ -80,8 +81,9 @@
 				"${config.ErrorProneJar}",
 				"${config.SoongZipCmd}",
 			},
-			Rspfile:        "$out.rsp",
-			RspfileContent: "$in",
+			CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
+			Rspfile:          "$out.rsp",
+			RspfileContent:   "$in",
 		},
 		"javacFlags", "sourcepath", "bootClasspath", "classpath", "outDir", "annoDir", "javaVersion")
 
diff --git a/java/config/config.go b/java/config/config.go
index 7d1fa29..eb71ddb 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -15,7 +15,6 @@
 package config
 
 import (
-	"path/filepath"
 	"strings"
 
 	_ "github.com/google/blueprint/bootstrap"
@@ -76,12 +75,14 @@
 	pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar")
 
 	pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
-	pctx.StaticVariable("SoongZipCmd", filepath.Join("${bootstrap.ToolDir}", "soong_zip"))
-	pctx.StaticVariable("MergeZipsCmd", filepath.Join("${bootstrap.ToolDir}", "merge_zips"))
+	pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
+	pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips")
 	pctx.HostBinToolVariable("DxCmd", "dx")
 	pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
 	pctx.HostJavaToolVariable("DesugarJar", "desugar.jar")
 
+	pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper")
+
 	pctx.VariableFunc("JavacWrapper", func(config interface{}) (string, error) {
 		if override := config.(android.Config).Getenv("JAVAC_WRAPPER"); override != "" {
 			return override + " ", nil
diff --git a/java/config/makevars.go b/java/config/makevars.go
index 1453a07..6b49592 100644
--- a/java/config/makevars.go
+++ b/java/config/makevars.go
@@ -56,4 +56,6 @@
 		ctx.Strict("JLINK", "${JlinkCmd}")
 		ctx.Strict("JMOD", "${JmodCmd}")
 	}
+
+	ctx.Strict("SOONG_JAVAC_WRAPPER", "${SoongJavacWrapper}")
 }