• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2022 The Android Open Source Project
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 rust
16
17import (
18	"fmt"
19
20	"android/soong/cc"
21)
22
23const afdoFlagFormat = "-Zprofile-sample-use=%s"
24
25type afdo struct {
26	Properties cc.AfdoProperties
27}
28
29func (afdo *afdo) props() []interface{} {
30	return []interface{}{&afdo.Properties}
31}
32
33func (afdo *afdo) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
34	if ctx.Host() {
35		return flags, deps
36	}
37
38	if afdo != nil && afdo.Properties.Afdo {
39		if profileFile := afdo.Properties.GetAfdoProfileFile(ctx, ctx.ModuleName()); profileFile.Valid() {
40			profileUseFlag := fmt.Sprintf(afdoFlagFormat, profileFile)
41			flags.RustFlags = append(flags.RustFlags, profileUseFlag)
42
43			profileFilePath := profileFile.Path()
44			deps.AfdoProfiles = append(deps.AfdoProfiles, profileFilePath)
45		}
46	}
47	return flags, deps
48}
49