Copy kernel_configs.txt and kernel_version.txt to target_files.zip

Move extractKernelVersionAndConfigs before buildTargetFilesZip. The
intermediate kernel_configs.txt and kernel_version.txt will be copied to
the META subdirectory of target_files.zip

Test: Built soong's target_files.zip locally
Bug: 399788685
Change-Id: Iae3efce1958ebcf7e06169771e359a332120ece4
diff --git a/filesystem/android_device.go b/filesystem/android_device.go
index 56a0a84..005dc34 100644
--- a/filesystem/android_device.go
+++ b/filesystem/android_device.go
@@ -109,6 +109,8 @@
 	proguardDictZip     android.Path
 	proguardDictMapping android.Path
 	proguardUsageZip    android.Path
+	kernelConfig        android.Path
+	kernelVersion       android.Path
 }
 
 func AndroidDeviceFactory() android.Module {
@@ -183,9 +185,9 @@
 
 	allInstalledModules := a.allInstalledModules(ctx)
 
+	a.kernelConfig, a.kernelVersion = a.extractKernelVersionAndConfigs(ctx)
 	a.buildTargetFilesZip(ctx, allInstalledModules)
 	a.buildProguardZips(ctx, allInstalledModules)
-	a.extractKernelVersionAndConfigs(ctx)
 
 	var deps []android.Path
 	if proptools.String(a.partitionProps.Super_partition_name) != "" {
@@ -637,6 +639,14 @@
 		builder.Command().Textf("cp").Input(fastbootInfo).Textf(" %s/META/fastboot-info.txt", targetFilesDir.String())
 	}
 
+	// kernel_configs.txt and kernel_version.txt
+	if a.kernelConfig != nil {
+		builder.Command().Textf("cp").Input(a.kernelConfig).Textf(" %s/META/", targetFilesDir.String())
+	}
+	if a.kernelVersion != nil {
+		builder.Command().Textf("cp").Input(a.kernelVersion).Textf(" %s/META/", targetFilesDir.String())
+	}
+
 	if a.partitionProps.Super_partition_name != nil {
 		superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
 		if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok {