Implement fdo_profile module type
Introducing fdo_profile module type to reimplement the afdo support in cc moduels. This change allows the feature to be compatible with Bazel migration. How it works: PreDepsMutators: * BeginMutator: If non-static cc modules sets afdo prop, search and add corresponding fdo_profile module as a dep with fdoProfileTag * fdoProfileMutator: * If in fdo_profile module, set FdoProfileProvider with full path to profile * If in cc module, read FdoProfileProvider from dep with fdoProfileTag and set FdoProfileInfo.Path to FdoProfilePath field PostDepsMutators: * afdoDepsMutator: If a module has FdoProfilePath set, walk to its static deps and set itself to the deps' AfdoRdeps * afdoMutator: If a static dep has AfdoRDeps set, create afdo variant. Ignore-AOSP-First: Other CLs in the same topic are internal-only Test: go test Bug: b/267229065 Change-Id: I687d798a02d9743c92804fea36fb4ae3a7a0e5e3
This commit is contained in:
85
cc/fdo_profile.go
Normal file
85
cc/fdo_profile.go
Normal file
@@ -0,0 +1,85 @@
|
||||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cc
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterFdoProfileBuildComponents(android.InitRegistrationContext)
|
||||
}
|
||||
|
||||
func RegisterFdoProfileBuildComponents(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("fdo_profile", fdoProfileFactory)
|
||||
}
|
||||
|
||||
type fdoProfile struct {
|
||||
android.ModuleBase
|
||||
|
||||
properties fdoProfileProperties
|
||||
}
|
||||
|
||||
type fdoProfileProperties struct {
|
||||
Profile *string `android:"arch_variant"`
|
||||
}
|
||||
|
||||
// FdoProfileInfo is provided by FdoProfileProvider
|
||||
type FdoProfileInfo struct {
|
||||
Path android.Path
|
||||
}
|
||||
|
||||
// FdoProfileProvider is used to provide path to an fdo profile
|
||||
var FdoProfileProvider = blueprint.NewMutatorProvider(FdoProfileInfo{}, "fdo_profile")
|
||||
|
||||
// FdoProfileMutatorInterface is the interface implemented by fdo_profile module type
|
||||
// module types that can depend on an fdo_profile module
|
||||
type FdoProfileMutatorInterface interface {
|
||||
// FdoProfileMutator eithers set or get FdoProfileProvider
|
||||
FdoProfileMutator(ctx android.BottomUpMutatorContext)
|
||||
}
|
||||
|
||||
var _ FdoProfileMutatorInterface = (*fdoProfile)(nil)
|
||||
|
||||
// GenerateAndroidBuildActions of fdo_profile does not have any build actions
|
||||
func (fp *fdoProfile) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
|
||||
|
||||
// FdoProfileMutator sets FdoProfileProvider to fdo_profile module
|
||||
// or sets afdo.Properties.FdoProfilePath to path in FdoProfileProvider of the depended fdo_profile
|
||||
func (fp *fdoProfile) FdoProfileMutator(ctx android.BottomUpMutatorContext) {
|
||||
if fp.properties.Profile != nil {
|
||||
path := android.PathForModuleSrc(ctx, *fp.properties.Profile)
|
||||
ctx.SetProvider(FdoProfileProvider, FdoProfileInfo{
|
||||
Path: path,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// fdoProfileMutator calls the generic FdoProfileMutator function of FdoProfileMutator
|
||||
// which is implemented by cc and cc.FdoProfile
|
||||
func fdoProfileMutator(ctx android.BottomUpMutatorContext) {
|
||||
if f, ok := ctx.Module().(FdoProfileMutatorInterface); ok {
|
||||
f.FdoProfileMutator(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func fdoProfileFactory() android.Module {
|
||||
m := &fdoProfile{}
|
||||
m.AddProperties(&m.properties)
|
||||
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibBoth)
|
||||
return m
|
||||
}
|
Reference in New Issue
Block a user