1// Copyright 2022 The Bazel Authors. 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 extractaar 16 17import ( 18 "fmt" 19 "strings" 20) 21 22// BuildozerError represent a rule configuration error fixable with a buildozer command. 23type BuildozerError struct { 24 Msg string 25 RuleAttr string 26 NewValue string 27} 28 29func mergeBuildozerErrors(label string, errs []*BuildozerError) string { 30 var msg strings.Builder 31 msg.WriteString(fmt.Sprintf("error(s) found while processing aar '%s':\n", label)) 32 var buildozerCommand strings.Builder 33 buildozerCommand.WriteString("Use the following command to fix the target:\nbuildozer ") 34 useBuildozer := false 35 for _, err := range errs { 36 msg.WriteString(fmt.Sprintf("\t- %s\n", err.Msg)) 37 if err.NewValue != "" { 38 useBuildozer = true 39 buildozerCommand.WriteString(fmt.Sprintf("'set %s %s' ", err.RuleAttr, err.NewValue)) 40 } 41 } 42 buildozerCommand.WriteString(label) 43 44 if useBuildozer { 45 msg.WriteString(buildozerCommand.String()) 46 } 47 return msg.String() 48} 49