Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8fe68dcf authored by Spandan Das's avatar Spandan Das
Browse files

Create linker_config_srcs for autogenerated product partition

This will be used to create /product/etc/linker.config.pb. Since
`PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS` are relative to workspace top,
a filegroup soong module will be dynamically created.

Test: checked that /product/etc/linker.config.pb is present in autogenerated
product.img file list (with next CL in stack)

Bug: 376515221
Change-Id: If1cb0d27f79af76c8e5780ead12595518b154b9e
parent 918191e3
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -599,6 +599,7 @@ type PartitionVariables struct {
	ProductPackages         []string `json:",omitempty"`
	ProductPackagesDebug    []string `json:",omitempty"`
	VendorLinkerConfigSrcs  []string `json:",omitempty"`
	ProductLinkerConfigSrcs []string `json:",omitempty"`

	ProductCopyFiles map[string]string `json:",omitempty"`
}
+18 −7
Original line number Diff line number Diff line
@@ -474,8 +474,8 @@ func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partiti
		return false
	}

	if partitionType == "vendor" {
		fsProps.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx)
	if partitionType == "vendor" || partitionType == "product" {
		fsProps.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType)
	}

	var module android.Module
@@ -509,18 +509,29 @@ func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partiti
	return true
}

// createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for _vendor_
// It creates a filegroup for each file in PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS.
// createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions
// 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list)
// 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list)
// It creates a filegroup for each file in the fragment list
// The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`.
func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext) []string {
func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string {
	ret := []string{}
	partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
	if linkerConfigSrcs := android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs); len(linkerConfigSrcs) > 0 {
	var linkerConfigSrcs []string
	if partitionType == "vendor" {
		linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs)
	} else if partitionType == "product" {
		linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs)
	} else {
		ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`")
	}

	if len(linkerConfigSrcs) > 0 {
		// Create a filegroup, and add `:<filegroup_name>` to ret.
		for index, linkerConfigSrc := range linkerConfigSrcs {
			dir := filepath.Dir(linkerConfigSrc)
			base := filepath.Base(linkerConfigSrc)
			fgName := generatedModuleName(ctx.Config(), "vendor-linker-config-src"+strconv.Itoa(index))
			fgName := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-linker-config-src%s", partitionType, strconv.Itoa(index)))
			srcs := []string{base}
			fgProps := &struct {
				Name *string