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

Commit e52b978c authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Soong: Define a new Soong module named prebuilt_firmware."

parents fe49f175 057a8b11
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ func init() {
	RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
	RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
	RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
	RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)

	PreDepsMutators(func(ctx RegisterMutatorsContext) {
		ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel()
@@ -62,6 +63,8 @@ type PrebuiltEtc struct {
	outputFilePath OutputPath
	// The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
	installDirBase string
	// The base install location when soc_specific property is set to true, e.g. "firmware" for prebuilt_firmware.
	socInstallDirBase      string
	installDirPath         OutputPath
	additionalDependencies *Paths
}
@@ -121,7 +124,14 @@ func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx ModuleContext) {
		return
	}
	p.outputFilePath = PathForModuleOut(ctx, filename).OutputPath
	p.installDirPath = PathForModuleInstall(ctx, p.installDirBase, String(p.properties.Sub_dir))

	// If soc install dir was specified and SOC specific is set, set the installDirPath to the specified
	// socInstallDirBase.
	installBaseDir := p.installDirBase
	if ctx.SocSpecific() && p.socInstallDirBase != "" {
		installBaseDir = p.socInstallDirBase
	}
	p.installDirPath = PathForModuleInstall(ctx, installBaseDir, String(p.properties.Sub_dir))

	// This ensures that outputFilePath has the correct name for others to
	// use, as the source file may have a different name.
@@ -250,3 +260,14 @@ func PrebuiltFontFactory() Module {
	InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
	return module
}

// prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system image.
// If soc_specific property is set to true, the firmware file is installed to the vendor <partition>/firmware
// directory for vendor image.
func PrebuiltFirmwareFactory() Module {
	module := &PrebuiltEtc{installDirBase: "etc/firmware", socInstallDirBase: "firmware"}
	InitPrebuiltEtcModule(module)
	// This module is device-only
	InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
	return module
}
+37 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) {
	ctx.RegisterModuleType("prebuilt_usr_share", ModuleFactoryAdaptor(PrebuiltUserShareFactory))
	ctx.RegisterModuleType("prebuilt_usr_share_host", ModuleFactoryAdaptor(PrebuiltUserShareHostFactory))
	ctx.RegisterModuleType("prebuilt_font", ModuleFactoryAdaptor(PrebuiltFontFactory))
	ctx.RegisterModuleType("prebuilt_firmware", ModuleFactoryAdaptor(PrebuiltFirmwareFactory))
	ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
		ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel()
	})
@@ -235,3 +236,39 @@ func TestPrebuiltFontInstallDirPath(t *testing.T) {
		t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
	}
}

func TestPrebuiltFirmwareDirPath(t *testing.T) {
	targetPath := "target/product/test_device"
	tests := []struct {
		description  string
		config       string
		expectedPath string
	}{{
		description: "prebuilt: system firmware",
		config: `
			prebuilt_firmware {
				name: "foo.conf",
				src: "foo.conf",
			}`,
		expectedPath: filepath.Join(targetPath, "system/etc/firmware"),
	}, {
		description: "prebuilt: vendor firmware",
		config: `
			prebuilt_firmware {
				name: "foo.conf",
				src: "foo.conf",
				soc_specific: true,
				sub_dir: "sub_dir",
			}`,
		expectedPath: filepath.Join(targetPath, "vendor/firmware/sub_dir"),
	}}
	for _, tt := range tests {
		t.Run(tt.description, func(t *testing.T) {
			ctx, _ := testPrebuiltEtc(t, tt.config)
			p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc)
			if p.installDirPath.RelPathString() != tt.expectedPath {
				t.Errorf("expected %q, got %q", tt.expectedPath, p.installDirPath)
			}
		})
	}
}