• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2023 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18	"android/soong/android"
19
20	"github.com/google/blueprint"
21)
22
23func init() {
24	RegisterFdoProfileBuildComponents(android.InitRegistrationContext)
25}
26
27func RegisterFdoProfileBuildComponents(ctx android.RegistrationContext) {
28	ctx.RegisterModuleType("fdo_profile", fdoProfileFactory)
29}
30
31type fdoProfile struct {
32	android.ModuleBase
33
34	properties fdoProfileProperties
35}
36
37type fdoProfileProperties struct {
38	Profile *string `android:"arch_variant"`
39}
40
41// FdoProfileInfo is provided by FdoProfileProvider
42type FdoProfileInfo struct {
43	Path android.Path
44}
45
46// FdoProfileProvider is used to provide path to an fdo profile
47var FdoProfileProvider = blueprint.NewMutatorProvider(FdoProfileInfo{}, "fdo_profile")
48
49// FdoProfileMutatorInterface is the interface implemented by fdo_profile module type
50// module types that can depend on an fdo_profile module
51type FdoProfileMutatorInterface interface {
52	// FdoProfileMutator eithers set or get FdoProfileProvider
53	fdoProfileMutator(ctx android.BottomUpMutatorContext)
54}
55
56var _ FdoProfileMutatorInterface = (*fdoProfile)(nil)
57
58// GenerateAndroidBuildActions of fdo_profile does not have any build actions
59func (fp *fdoProfile) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
60
61// FdoProfileMutator sets FdoProfileProvider to fdo_profile module
62// or sets afdo.Properties.FdoProfilePath to path in FdoProfileProvider of the depended fdo_profile
63func (fp *fdoProfile) fdoProfileMutator(ctx android.BottomUpMutatorContext) {
64	if fp.properties.Profile != nil {
65		path := android.PathForModuleSrc(ctx, *fp.properties.Profile)
66		ctx.SetProvider(FdoProfileProvider, FdoProfileInfo{
67			Path: path,
68		})
69	}
70}
71
72// fdoProfileMutator calls the generic fdoProfileMutator function of fdoProfileMutator
73// which is implemented by cc and cc.FdoProfile
74func fdoProfileMutator(ctx android.BottomUpMutatorContext) {
75	if f, ok := ctx.Module().(FdoProfileMutatorInterface); ok {
76		f.fdoProfileMutator(ctx)
77	}
78}
79
80func fdoProfileFactory() android.Module {
81	m := &fdoProfile{}
82	m.AddProperties(&m.properties)
83	android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibBoth)
84	return m
85}
86