From 33b3a638a5748d50350787cfb8552557c89f95a2 Mon Sep 17 00:00:00 2001 From: "Priyanka Advani (xWF)" Date: Wed, 28 Aug 2024 23:10:29 +0000 Subject: Revert^3 "Implement detecting container violations." 2a88491afc72707c21a125b81f7dcd252d2fc5f1 Change-Id: Iba4527f391a093703978fe01177b56fec4604b28 --- android/container.go | 65 ---------------------------------------------------- 1 file changed, 65 deletions(-) (limited to 'android/container.go') diff --git a/android/container.go b/android/container.go index 63fb362ad..43dccf635 100644 --- a/android/container.go +++ b/android/container.go @@ -15,10 +15,8 @@ package android import ( - "fmt" "reflect" "slices" - "strings" "github.com/google/blueprint" ) @@ -397,40 +395,6 @@ func (c *ContainersInfo) UpdatableApex() bool { var ContainersInfoProvider = blueprint.NewProvider[ContainersInfo]() -func satisfyAllowedExceptions(ctx ModuleContext, allowedExceptionLabels []exceptionHandleFuncLabel, m, dep Module) bool { - for _, label := range allowedExceptionLabels { - if exceptionHandleFunctionsTable[label](ctx, m, dep) { - return true - } - } - return false -} - -func (c *ContainersInfo) GetViolations(mctx ModuleContext, m, dep Module, depInfo ContainersInfo) []string { - var violations []string - - // Any containers that the module belongs to but the dependency does not belong to must be examined. - _, containersUniqueToModule, _ := ListSetDifference(c.belongingContainers, depInfo.belongingContainers) - - // Apex container should be examined even if both the module and the dependency belong to - // the apex container to check that the two modules belong to the same apex. - if InList(ApexContainer, c.belongingContainers) && !InList(ApexContainer, containersUniqueToModule) { - containersUniqueToModule = append(containersUniqueToModule, ApexContainer) - } - - for _, containerUniqueToModule := range containersUniqueToModule { - for _, restriction := range containerUniqueToModule.restricted { - if InList(restriction.dependency, depInfo.belongingContainers) { - if !satisfyAllowedExceptions(mctx, restriction.allowedExceptions, m, dep) { - violations = append(violations, restriction.errorMessage) - } - } - } - } - - return violations -} - func generateContainerInfo(ctx ModuleContext) ContainersInfo { var containers []*container @@ -472,32 +436,3 @@ func setContainerInfo(ctx ModuleContext) { SetProvider(ctx, ContainersInfoProvider, containersInfo) } } - -func checkContainerViolations(ctx ModuleContext) { - if _, ok := ctx.Module().(InstallableModule); ok { - containersInfo, _ := getContainerModuleInfo(ctx, ctx.Module()) - ctx.VisitDirectDepsIgnoreBlueprint(func(dep Module) { - if !dep.Enabled(ctx) { - return - } - - // Pre-existing violating dependencies are tracked in containerDependencyViolationAllowlist. - // If this dependency is allowlisted, do not check for violation. - // If not, check if this dependency matches any restricted dependency and - // satisfies any exception functions, which allows bypassing the - // restriction. If all of the exceptions are not satisfied, throw an error. - if depContainersInfo, ok := getContainerModuleInfo(ctx, dep); ok { - if allowedViolations, ok := ContainerDependencyViolationAllowlist[ctx.ModuleName()]; ok && InList(dep.Name(), allowedViolations) { - return - } else { - violations := containersInfo.GetViolations(ctx, ctx.Module(), dep, depContainersInfo) - if len(violations) > 0 { - errorMessage := fmt.Sprintf("%s cannot depend on %s. ", ctx.ModuleName(), dep.Name()) - errorMessage += strings.Join(violations, " ") - ctx.ModuleErrorf(errorMessage) - } - } - } - }) - } -} -- cgit v1.2.3-59-g8ed1b