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

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

Merge "Remove overriden modules from deps of autogenerated filesystem modules" into main

parents 99eae48c e1860e45
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -119,6 +119,10 @@ type Module interface {
	// The usage of this method is experimental and should not be used outside of fsgen package.
	// This will be removed once product packaging migration to Soong is complete.
	DecodeMultilib(ctx ConfigContext) (string, string)

	// WARNING: This should not be used outside build/soong/fsgen
	// Overrides returns the list of modules which should not be installed if this module is installed.
	Overrides() []string
}

// Qualified id for a module
@@ -2292,6 +2296,10 @@ func (m *ModuleBase) DecodeMultilib(ctx ConfigContext) (string, string) {
	return decodeMultilib(ctx, m)
}

func (m *ModuleBase) Overrides() []string {
	return m.commonProperties.Overrides
}

type ConfigContext interface {
	Config() Config
}
+4 −0
Original line number Diff line number Diff line
@@ -205,3 +205,7 @@ func (m ModuleProxy) ConfigurableEvaluator(ctx ConfigurableEvaluatorContext) pro
func (m ModuleProxy) DecodeMultilib(ctx ConfigContext) (string, string) {
	panic("method is not implemented on ModuleProxy")
}

func (m ModuleProxy) Overrides() []string {
	panic("method is not implemented on ModuleProxy")
}
+63 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ func RegisterCollectFileSystemDepsMutators(ctx android.RegisterMutatorsContext)
}

var fsGenStateOnceKey = android.NewOnceKey("FsGenState")
var fsGenRemoveOverridesOnceKey = android.NewOnceKey("FsGenRemoveOverrides")

// Map of partition module name to its partition that may be generated by Soong.
// Note that it is not guaranteed that all modules returned by this function are successfully
@@ -79,6 +80,13 @@ type FsGenState struct {
	soongGeneratedPartitions []string
	// Mutex to protect the fsDeps
	fsDepsMutex sync.Mutex
	// Map of _all_ soong module names to their corresponding installation properties
	moduleToInstallationProps map[string]installationProperties
}

type installationProperties struct {
	Required  []string
	Overrides []string
}

func newMultilibDeps() multilibDeps {
@@ -149,6 +157,7 @@ func createFsGenState(ctx android.LoadHookContext) *FsGenState {
			},
			soongGeneratedPartitions:  generatedPartitions,
			fsDepsMutex:               sync.Mutex{},
			moduleToInstallationProps: map[string]installationProperties{},
		}
	}).(*FsGenState)
}
@@ -193,6 +202,16 @@ func collectDepsMutator(mctx android.BottomUpMutatorContext) {
		}
		fsGenState.fsDepsMutex.Unlock()
	}
	// store the map of module to (required,overrides) even if the module is not in PRODUCT_PACKAGES.
	// the module might be installed transitively.
	if m.Target().Os.Class == android.Device && m.Enabled(mctx) && m.ExportedToMake() {
		fsGenState.fsDepsMutex.Lock()
		fsGenState.moduleToInstallationProps[m.Name()] = installationProperties{
			Required:  m.RequiredModuleNames(mctx),
			Overrides: m.Overrides(),
		}
		fsGenState.fsDepsMutex.Unlock()
	}
}

type depsStruct struct {
@@ -231,6 +250,7 @@ func getBitness(archTypes []android.ArchType) (ret []string) {
}

func setDepsMutator(mctx android.BottomUpMutatorContext) {
	removeOverriddenDeps(mctx)
	fsGenState := mctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
	fsDeps := fsGenState.fsDeps
	soongGeneratedPartitionMap := getAllSoongGeneratedPartitionNames(mctx.Config(), fsGenState.soongGeneratedPartitions)
@@ -243,6 +263,47 @@ func setDepsMutator(mctx android.BottomUpMutatorContext) {
	}
}

// removeOverriddenDeps collects PRODUCT_PACKAGES and (transitive) required deps.
// it then removes any modules which appear in `overrides` of the above list.
func removeOverriddenDeps(mctx android.BottomUpMutatorContext) {
	mctx.Config().Once(fsGenRemoveOverridesOnceKey, func() interface{} {
		fsGenState := mctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
		fsDeps := fsGenState.fsDeps
		overridden := map[string]bool{}
		allDeps := []string{}

		// Step 1: Initialization: Append PRODUCT_PACKAGES to the queue
		for _, fsDep := range fsDeps {
			for depName, _ := range *fsDep {
				allDeps = append(allDeps, depName)
			}
		}

		// Step 2: Process the queue, and add required modules to the queue.
		i := 0
		for {
			if i == len(allDeps) {
				break
			}
			depName := allDeps[i]
			for _, overrides := range fsGenState.moduleToInstallationProps[depName].Overrides {
				overridden[overrides] = true
			}
			// add required dep to the queue.
			allDeps = append(allDeps, fsGenState.moduleToInstallationProps[depName].Required...)
			i += 1
		}

		// Step 3: Delete all the overridden modules.
		for overridden, _ := range overridden {
			for partition, _ := range fsDeps {
				delete(*fsDeps[partition], overridden)
			}
		}
		return nil
	})
}

func generateDepStruct(deps map[string]*depCandidateProps) *packagingPropsStruct {
	depsStruct := packagingPropsStruct{}
	for depName, depProps := range deps {
+36 −0
Original line number Diff line number Diff line
@@ -217,3 +217,39 @@ func TestFileSystemCreatorDepsWithNamespace(t *testing.T) {
		"//c/d:bar",
	)
}

func TestRemoveOverriddenModulesFromDeps(t *testing.T) {
	result := android.GroupFixturePreparers(
		android.PrepareForIntegrationTestWithAndroid,
		android.PrepareForTestWithAndroidBuildComponents,
		android.PrepareForTestWithAllowMissingDependencies,
		prepareForTestWithFsgenBuildComponents,
		java.PrepareForTestWithJavaBuildComponents,
		android.FixtureMergeMockFs(android.MockFS{
			"external/avb/test/data/testkey_rsa4096.pem": nil,
			"build/soong/fsgen/Android.bp": []byte(`
			soong_filesystem_creator {
				name: "foo",
			}
			`),
		}),
		android.FixtureModifyConfig(func(config android.Config) {
			config.TestProductVariables.PartitionVarsForSoongMigrationOnlyDoNotUse.ProductPackages = []string{"libfoo", "libbar"}
		}),
	).RunTestWithBp(t, `
java_library {
	name: "libfoo",
}
java_library {
	name: "libbar",
	required: ["libbaz"],
}
java_library {
	name: "libbaz",
	overrides: ["libfoo"], // overrides libfoo
}
	`)
	resolvedSystemDeps := result.TestContext.Config().Get(fsGenStateOnceKey).(*FsGenState).fsDeps["system"]
	_, libFooInDeps := (*resolvedSystemDeps)["libfoo"]
	android.AssertBoolEquals(t, "libfoo should not appear in deps because it has been overridden by libbaz. The latter is a required dep of libbar, which is listed in PRODUCT_PACKAGES", false, libFooInDeps)
}