Use the correct `package` in the generated `AutoBuilder_Foo` class.

Previously it was erroneously using the package from the `ofClass` class. That's often the same package, but when it isn't the generated code was wrong.

RELNOTES=n/a
PiperOrigin-RevId: 371342620
diff --git a/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java b/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java
index 7d0ef2e..5952f62 100644
--- a/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java
+++ b/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java
@@ -143,7 +143,7 @@
     vars.build = build(executable);
     vars.types = typeUtils();
     vars.toBuilderConstructor = false;
-    defineSharedVarsForType(ofClass, ImmutableSet.of(), vars);
+    defineSharedVarsForType(autoBuilderType, ImmutableSet.of(), vars);
     String text = vars.toText();
     text = TypeEncoder.decode(text, processingEnv, vars.pkg, autoBuilderType.asType());
     text = Reformatter.fixup(text);
diff --git a/value/src/main/java/com/google/auto/value/processor/autobuilder.vm b/value/src/main/java/com/google/auto/value/processor/autobuilder.vm
index fd8ef09..01f61b9 100644
--- a/value/src/main/java/com/google/auto/value/processor/autobuilder.vm
+++ b/value/src/main/java/com/google/auto/value/processor/autobuilder.vm
@@ -14,7 +14,7 @@
 
 ## Template for each generated AutoValue_Foo class.
 ## This template uses the Apache Velocity Template Language (VTL).
-## The variables ($pkg, $props, and so on) are defined by the fields of AutoValueTemplateVars.
+## The variables ($pkg, $props, and so on) are defined by the fields of AutoBuilderTemplateVars.
 ##
 ## Comments, like this one, begin with ##. The comment text extends up to and including the newline
 ## character at the end of the line. So comments also serve to join a line to the next one.
diff --git a/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java b/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java
index aabdbc7..ddf12ff 100644
--- a/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java
+++ b/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java
@@ -155,6 +155,49 @@
   }
 
   @Test
+  public void buildOtherPackage() {
+    JavaFileObject built =
+        JavaFileObjects.forSourceLines(
+            "com.example.Built",
+            "package com.example;",
+            "",
+            "public class Built {",
+            "  private final int anInt;",
+            "  private final String aString;",
+            "",
+            "  public Built(int anInt, String aString) {",
+            "    this.anInt = anInt;",
+            "    this.aString = aString;",
+            "  }",
+            "}");
+    JavaFileObject builder =
+        JavaFileObjects.forSourceLines(
+            "foo.bar.Builder",
+            "package foo.bar;",
+            "",
+            "import com.example.Built;",
+            "import com.google.auto.value.AutoBuilder;",
+            "",
+            "@AutoBuilder(ofClass = Built.class)",
+            "public interface Builder {",
+            "  public static Builder builder() {",
+            "    return new AutoBuilder_Builder();",
+            "  }",
+            "",
+            "  Builder setAnInt(int x);",
+            "  Builder setAString(String x);",
+            "  Built build();",
+            "}");
+    Compilation compilation =
+        javac()
+            .withProcessors(new AutoBuilderProcessor())
+            .withOptions("-Acom.google.auto.value.AutoBuilderIsUnstable")
+            .compile(built, builder);
+    assertThat(compilation).succeededWithoutWarnings();
+    assertThat(compilation).generatedSourceFile("foo.bar.AutoBuilder_Builder");
+  }
+
+  @Test
   public void autoBuilderOnEnum() {
     JavaFileObject javaFileObject =
         JavaFileObjects.forSourceLines(