Merge "1:1 mapping between prebuilt_kernel_modules and _dlkm filesystem modules" into main
diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go
index 5282636..fe590a9 100644
--- a/fsgen/filesystem_creator.go
+++ b/fsgen/filesystem_creator.go
@@ -231,38 +231,28 @@
 }
 
 // createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the
-// autogenerated *_dlkm filsystem modules.
-// The input `kernelModules` is a space separated list of .ko files in the workspace. This will be partitioned per directory
-// and a `prebuilt_kernel_modules` will be created per partition.
-// These autogenerated modules will be subsequently added to the deps of the top level *_dlkm android_filesystem
+// autogenerated *_dlkm filsystem modules. Each _dlkm partition should have a single prebuilt_kernel_modules dependency.
+// This ensures that the depmod artifacts (modules.* installed in /lib/modules/) are generated with a complete view.
+
+// The input `kernelModules` is a space separated list of .ko files in the workspace.
 func (f *filesystemCreator) createPrebuiltKernelModules(ctx android.LoadHookContext, partitionType string, kernelModules []string) {
-	// Partition the files per directory
-	dirToFiles := map[string][]string{}
-	for _, kernelModule := range kernelModules {
-		dir := filepath.Dir(kernelModule)
-		base := filepath.Base(kernelModule)
-		dirToFiles[dir] = append(dirToFiles[dir], base)
-	}
-	// Create a prebuilt_kernel_modules module per partition
 	fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
-	for index, dir := range android.SortedKeys(dirToFiles) {
-		name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules-%s", partitionType, strconv.Itoa(index)))
-		props := &struct {
-			Name *string
-			Srcs []string
-		}{
-			Name: proptools.StringPtr(name),
-			Srcs: dirToFiles[dir],
-		}
-		kernelModule := ctx.CreateModuleInDirectory(
-			kernel.PrebuiltKernelModulesFactory,
-			dir,
-			props,
-		)
-		kernelModule.HideFromMake()
-		// Add to deps
-		(*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config())
+	name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules", partitionType))
+	props := &struct {
+		Name *string
+		Srcs []string
+	}{
+		Name: proptools.StringPtr(name),
+		Srcs: kernelModules,
 	}
+	kernelModule := ctx.CreateModuleInDirectory(
+		kernel.PrebuiltKernelModulesFactory,
+		".", // create in root directory for now
+		props,
+	)
+	kernelModule.HideFromMake()
+	// Add to deps
+	(*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config())
 }
 
 // Create a build_prop and android_info module. This will be used to create /vendor/build.prop