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 main 16 17import ( 18 "context" 19 "fmt" 20 "io" 21 "path/filepath" 22 23 "tools/treble/build/report/report" 24) 25 26type hostReport struct { 27 toolPath string 28} 29 30// Determine host tools 31func (h *hostReport) Run(ctx context.Context, rtx *report.Context, rsp *response) error { 32 var err error 33 rsp.Host, err = report.ResolveHostTools(ctx, h.toolPath) 34 if err != nil { 35 return err 36 } 37 rsp.Targets = append(rsp.Targets, rsp.Host.Targets...) 38 return nil 39} 40 41func (h *hostReport) PrintText(w io.Writer, rsp *response, verbose bool) { 42 if rsp.Host != nil { 43 // Get the unique number of inputs 44 hostSourceFileMap := make(map[string]bool) 45 hostSourceProjectMap := make(map[string]bool) 46 47 for _, t := range rsp.Host.Targets { 48 // Find target in report 49 if bt, exists := rsp.Report.Targets[t]; exists { 50 for name, proj := range bt.Projects { 51 hostSourceProjectMap[name] = true 52 for f := range proj.Files { 53 hostSourceFileMap[filepath.Join(name, f)] = true 54 } 55 } 56 // Remove the target from being printed 57 delete(rsp.Report.Targets, t) 58 } 59 } 60 61 fmt.Fprintln(w, " Host Tools") 62 fmt.Fprintf(w, " %-20s : %s\n", "Directory", rsp.Host.Path) 63 fmt.Fprintf(w, " %-20s : %d\n", "Tools", len(rsp.Host.Targets)) 64 fmt.Fprintf(w, " %-20s : %d\n", "Prebuilts", rsp.Host.SymLinks) 65 fmt.Fprintf(w, " %-20s : %d\n", "Inputs", len(hostSourceFileMap)) 66 fmt.Fprintf(w, " %-20s : %d\n", "Projects", len(hostSourceProjectMap)) 67 68 if verbose { 69 for proj, _ := range hostSourceProjectMap { 70 fmt.Fprintf(w, " %s\n", proj) 71 } 72 } 73 } 74 75} 76