blob: 789afad17e743156bcdf6e4e2f5f1c27fb3dece0 [file] [log] [blame]
Dan Willemsen01f0a052019-02-05 13:44:20 -08001// Copyright 2019 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
15// This is a script that can be used to analyze the results from
16// build/soong/build_test.bash and recommend what devices need changes to their
17// BUILD_BROKEN_* flags.
18//
19// To use, download the logs.zip from one or more branches, and extract them
20// into subdirectories of the current directory. So for example, I have:
21//
22// ./aosp-master/aosp_arm/std_full.log
23// ./aosp-master/aosp_arm64/std_full.log
24// ./aosp-master/...
25// ./internal-master/aosp_arm/std_full.log
26// ./internal-master/aosp_arm64/std_full.log
27// ./internal-master/...
28//
29// Then I use `go run path/to/build_broken_logs.go *`
30package main
31
32import (
33 "fmt"
34 "io/ioutil"
35 "log"
36 "os"
37 "path/filepath"
38 "sort"
39 "strings"
40)
41
42func main() {
43 for _, branch := range os.Args[1:] {
44 fmt.Printf("\nBranch %s:\n", branch)
45 PrintResults(ParseBranch(branch))
46 }
47}
48
49type BuildBrokenBehavior int
50
51const (
52 DefaultFalse BuildBrokenBehavior = iota
53 DefaultTrue
54 DefaultDeprecated
55)
56
57var buildBrokenSettings = []struct {
58 name string
59 behavior BuildBrokenBehavior
60 warnings []string
61}{
62 {
63 name: "BUILD_BROKEN_DUP_COPY_HEADERS",
64 behavior: DefaultDeprecated,
65 warnings: []string{"Duplicate header copy:"},
66 },
67 {
68 name: "BUILD_BROKEN_DUP_RULES",
69 behavior: DefaultFalse,
70 warnings: []string{"overriding commands for target"},
71 },
72 {
73 name: "BUILD_BROKEN_ANDROIDMK_EXPORTS",
Dan Willemsen60977462019-04-18 09:40:15 -070074 behavior: DefaultDeprecated,
Dan Willemsen01f0a052019-02-05 13:44:20 -080075 warnings: []string{"export_keyword"},
76 },
77 {
Dan Willemsen01f0a052019-02-05 13:44:20 -080078 name: "BUILD_BROKEN_ENG_DEBUG_TAGS",
Dan Willemsen60977462019-04-18 09:40:15 -070079 behavior: DefaultDeprecated,
Dan Willemsen01f0a052019-02-05 13:44:20 -080080 warnings: []string{
81 "Changes.md#LOCAL_MODULE_TAGS",
82 },
83 },
Dan Willemsen25e6f092019-04-09 10:22:43 -070084 {
85 name: "BUILD_BROKEN_USES_NETWORK",
86 behavior: DefaultDeprecated,
87 },
Dan Willemsen01f0a052019-02-05 13:44:20 -080088}
89
90type ProductBranch struct {
91 Branch string
92 Name string
93}
94
95type ProductLog struct {
96 ProductBranch
97 Log
98 Device string
99}
100
101type Log struct {
102 BuildBroken []*bool
103 HasBroken []bool
104}
105
106func Merge(l, l2 Log) Log {
107 if len(l.BuildBroken) == 0 {
108 l.BuildBroken = make([]*bool, len(buildBrokenSettings))
109 }
110 if len(l.HasBroken) == 0 {
111 l.HasBroken = make([]bool, len(buildBrokenSettings))
112 }
113
114 if len(l.BuildBroken) != len(l2.BuildBroken) || len(l.HasBroken) != len(l2.HasBroken) {
115 panic("mis-matched logs")
116 }
117
118 for i, v := range l.BuildBroken {
119 if v == nil {
120 l.BuildBroken[i] = l2.BuildBroken[i]
121 }
122 }
123 for i := range l.HasBroken {
124 l.HasBroken[i] = l.HasBroken[i] || l2.HasBroken[i]
125 }
126
127 return l
128}
129
130func PrintResults(products []ProductLog) {
131 devices := map[string]Log{}
132 deviceNames := []string{}
133
134 for _, product := range products {
135 device := product.Device
136 if _, ok := devices[device]; !ok {
137 deviceNames = append(deviceNames, device)
138 }
139 devices[device] = Merge(devices[device], product.Log)
140 }
141
142 sort.Strings(deviceNames)
143
144 for i, setting := range buildBrokenSettings {
145 printed := false
146
147 for _, device := range deviceNames {
148 log := devices[device]
149
150 if setting.behavior == DefaultTrue {
151 if log.BuildBroken[i] == nil || *log.BuildBroken[i] == false {
152 if log.HasBroken[i] {
153 printed = true
154 fmt.Printf(" %s needs to set %s := true\n", device, setting.name)
155 }
156 } else if !log.HasBroken[i] {
157 printed = true
158 fmt.Printf(" %s sets %s := true, but does not need it\n", device, setting.name)
159 }
160 } else if setting.behavior == DefaultFalse {
161 if log.BuildBroken[i] == nil {
162 // Nothing to be done
163 } else if *log.BuildBroken[i] == false {
164 printed = true
165 fmt.Printf(" %s sets %s := false, which is the default and can be removed\n", device, setting.name)
166 } else if !log.HasBroken[i] {
167 printed = true
168 fmt.Printf(" %s sets %s := true, but does not need it\n", device, setting.name)
169 }
170 } else if setting.behavior == DefaultDeprecated {
171 if log.BuildBroken[i] != nil {
172 printed = true
173 if log.HasBroken[i] {
174 fmt.Printf(" %s sets %s := %v, which is deprecated, but has failures\n", device, setting.name, *log.BuildBroken[i])
175 } else {
176 fmt.Printf(" %s sets %s := %v, which is deprecated and can be removed\n", device, setting.name, *log.BuildBroken[i])
177 }
178 }
179 }
180 }
181
182 if printed {
183 fmt.Println()
184 }
185 }
186}
187
188func ParseBranch(name string) []ProductLog {
189 products, err := filepath.Glob(filepath.Join(name, "*"))
190 if err != nil {
191 log.Fatal(err)
192 }
193
194 ret := []ProductLog{}
195 for _, product := range products {
196 product = filepath.Base(product)
197
198 ret = append(ret, ParseProduct(ProductBranch{Branch: name, Name: product}))
199 }
200 return ret
201}
202
203func ParseProduct(p ProductBranch) ProductLog {
204 soongLog, err := ioutil.ReadFile(filepath.Join(p.Branch, p.Name, "soong.log"))
205 if err != nil {
206 log.Fatal(err)
207 }
208
209 ret := ProductLog{
210 ProductBranch: p,
211 Log: Log{
212 BuildBroken: make([]*bool, len(buildBrokenSettings)),
213 HasBroken: make([]bool, len(buildBrokenSettings)),
214 },
215 }
216
217 lines := strings.Split(string(soongLog), "\n")
218 for _, line := range lines {
219 fields := strings.Split(line, " ")
220 if len(fields) != 5 {
221 continue
222 }
223
224 if fields[3] == "TARGET_DEVICE" {
225 ret.Device = fields[4]
226 }
227
228 if strings.HasPrefix(fields[3], "BUILD_BROKEN_") {
229 for i, setting := range buildBrokenSettings {
230 if setting.name == fields[3] {
231 ret.BuildBroken[i] = ParseBoolPtr(fields[4])
232 }
233 }
234 }
235 }
236
237 stdLog, err := ioutil.ReadFile(filepath.Join(p.Branch, p.Name, "std_full.log"))
238 if err != nil {
239 log.Fatal(err)
240 }
241 stdStr := string(stdLog)
242
243 for i, setting := range buildBrokenSettings {
244 for _, warning := range setting.warnings {
245 if strings.Contains(stdStr, warning) {
246 ret.HasBroken[i] = true
247 }
248 }
249 }
250
251 return ret
252}
253
254func ParseBoolPtr(str string) *bool {
255 var ret *bool
256 if str != "" {
257 b := str == "true"
258 ret = &b
259 }
260 return ret
261}