blob: 4bdffaa034eadb2571143f5259cc25b0bf5795a3 [file] [log] [blame]
Cole Faust2a9ff762025-02-21 12:20:43 -08001// Copyright 2025 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 "strings"
20)
21
22func init() {
23 android.InitRegistrationContext.RegisterSingletonType("cc_misc_disted_files", ccMiscDistedFilesSingletonFactory)
24}
25
26func ccMiscDistedFilesSingletonFactory() android.Singleton {
27 return &ccMiscDistedFilesSingleton{}
28}
29
30type ccMiscDistedFilesSingleton struct {
31 warningsAllowed []string
32 usingWnoErrors []string
33}
34
35func (s *ccMiscDistedFilesSingleton) GenerateBuildActions(ctx android.SingletonContext) {
36 var warningsAllowed []string
37 var usingWnoErrors []string
38 var missingProfiles []string
39 ctx.VisitAllModules(func(module android.Module) {
40 if v, ok := android.OtherModuleProvider(ctx, module, CcMakeVarsInfoProvider); ok {
41 warningsAllowed = android.AppendIfNotZero(warningsAllowed, v.WarningsAllowed)
42 usingWnoErrors = android.AppendIfNotZero(usingWnoErrors, v.UsingWnoError)
43 missingProfiles = android.AppendIfNotZero(missingProfiles, v.MissingProfile)
44 }
45 })
46
47 warningsAllowed = android.SortedUniqueStrings(warningsAllowed)
48 usingWnoErrors = android.SortedUniqueStrings(usingWnoErrors)
49 missingProfiles = android.SortedUniqueStrings(missingProfiles)
50
51 s.warningsAllowed = warningsAllowed
52 s.usingWnoErrors = usingWnoErrors
53
54 var sb strings.Builder
55 sb.WriteString("# Modules using -Wno-error\n")
56 for _, nwe := range usingWnoErrors {
57 sb.WriteString(nwe)
58 sb.WriteString("\n")
59 }
60 sb.WriteString("# Modules that allow warnings\n")
61 for _, wa := range warningsAllowed {
62 sb.WriteString(wa)
63 sb.WriteString("\n")
64 }
65 wallWerrFile := android.PathForOutput(ctx, "wall_werror.txt")
66 android.WriteFileRuleVerbatim(ctx, wallWerrFile, sb.String())
67
68 // Only dist this file in soong-only builds. In soong+make builds, it contains information
69 // from make modules, so we'll still rely on make to build and dist it.
70 if !ctx.Config().KatiEnabled() {
71 ctx.DistForGoal("droidcore-unbundled", wallWerrFile)
72 }
73
74 var sb2 strings.Builder
75 sb2.WriteString("# Modules missing PGO profile files\n")
76 for _, mp := range missingProfiles {
77 sb2.WriteString(mp)
78 sb2.WriteString("\n")
79 }
80 profileMissingFile := android.PathForOutput(ctx, "pgo_profile_file_missing.txt")
81 android.WriteFileRuleVerbatim(ctx, profileMissingFile, sb2.String())
82
83 ctx.DistForGoal("droidcore-unbundled", profileMissingFile)
84}
85
86func (s *ccMiscDistedFilesSingleton) MakeVars(ctx android.MakeVarsContext) {
87 ctx.Strict("SOONG_MODULES_WARNINGS_ALLOWED", strings.Join(s.warningsAllowed, " "))
88 ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", strings.Join(s.usingWnoErrors, " "))
89}