1*105f6285SAndroid Build Coastguard Worker// Copyright 2022 The Android Open Source Project 2*105f6285SAndroid Build Coastguard Worker// 3*105f6285SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*105f6285SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*105f6285SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*105f6285SAndroid Build Coastguard Worker// 7*105f6285SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*105f6285SAndroid Build Coastguard Worker// 9*105f6285SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*105f6285SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*105f6285SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*105f6285SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*105f6285SAndroid Build Coastguard Worker// limitations under the License. 14*105f6285SAndroid Build Coastguard Worker 15*105f6285SAndroid Build Coastguard Workerpackage main 16*105f6285SAndroid Build Coastguard Worker 17*105f6285SAndroid Build Coastguard Workerimport ( 18*105f6285SAndroid Build Coastguard Worker "context" 19*105f6285SAndroid Build Coastguard Worker "fmt" 20*105f6285SAndroid Build Coastguard Worker "io" 21*105f6285SAndroid Build Coastguard Worker "path/filepath" 22*105f6285SAndroid Build Coastguard Worker 23*105f6285SAndroid Build Coastguard Worker "tools/treble/build/report/report" 24*105f6285SAndroid Build Coastguard Worker) 25*105f6285SAndroid Build Coastguard Worker 26*105f6285SAndroid Build Coastguard Workertype hostReport struct { 27*105f6285SAndroid Build Coastguard Worker toolPath string 28*105f6285SAndroid Build Coastguard Worker} 29*105f6285SAndroid Build Coastguard Worker 30*105f6285SAndroid Build Coastguard Worker// Determine host tools 31*105f6285SAndroid Build Coastguard Workerfunc (h *hostReport) Run(ctx context.Context, rtx *report.Context, rsp *response) error { 32*105f6285SAndroid Build Coastguard Worker var err error 33*105f6285SAndroid Build Coastguard Worker rsp.Host, err = report.ResolveHostTools(ctx, h.toolPath) 34*105f6285SAndroid Build Coastguard Worker if err != nil { 35*105f6285SAndroid Build Coastguard Worker return err 36*105f6285SAndroid Build Coastguard Worker } 37*105f6285SAndroid Build Coastguard Worker rsp.Targets = append(rsp.Targets, rsp.Host.Targets...) 38*105f6285SAndroid Build Coastguard Worker return nil 39*105f6285SAndroid Build Coastguard Worker} 40*105f6285SAndroid Build Coastguard Worker 41*105f6285SAndroid Build Coastguard Workerfunc (h *hostReport) PrintText(w io.Writer, rsp *response, verbose bool) { 42*105f6285SAndroid Build Coastguard Worker if rsp.Host != nil { 43*105f6285SAndroid Build Coastguard Worker // Get the unique number of inputs 44*105f6285SAndroid Build Coastguard Worker hostSourceFileMap := make(map[string]bool) 45*105f6285SAndroid Build Coastguard Worker hostSourceProjectMap := make(map[string]bool) 46*105f6285SAndroid Build Coastguard Worker 47*105f6285SAndroid Build Coastguard Worker for _, t := range rsp.Host.Targets { 48*105f6285SAndroid Build Coastguard Worker // Find target in report 49*105f6285SAndroid Build Coastguard Worker if bt, exists := rsp.Report.Targets[t]; exists { 50*105f6285SAndroid Build Coastguard Worker for name, proj := range bt.Projects { 51*105f6285SAndroid Build Coastguard Worker hostSourceProjectMap[name] = true 52*105f6285SAndroid Build Coastguard Worker for f := range proj.Files { 53*105f6285SAndroid Build Coastguard Worker hostSourceFileMap[filepath.Join(name, f)] = true 54*105f6285SAndroid Build Coastguard Worker } 55*105f6285SAndroid Build Coastguard Worker } 56*105f6285SAndroid Build Coastguard Worker // Remove the target from being printed 57*105f6285SAndroid Build Coastguard Worker delete(rsp.Report.Targets, t) 58*105f6285SAndroid Build Coastguard Worker } 59*105f6285SAndroid Build Coastguard Worker } 60*105f6285SAndroid Build Coastguard Worker 61*105f6285SAndroid Build Coastguard Worker fmt.Fprintln(w, " Host Tools") 62*105f6285SAndroid Build Coastguard Worker fmt.Fprintf(w, " %-20s : %s\n", "Directory", rsp.Host.Path) 63*105f6285SAndroid Build Coastguard Worker fmt.Fprintf(w, " %-20s : %d\n", "Tools", len(rsp.Host.Targets)) 64*105f6285SAndroid Build Coastguard Worker fmt.Fprintf(w, " %-20s : %d\n", "Prebuilts", rsp.Host.SymLinks) 65*105f6285SAndroid Build Coastguard Worker fmt.Fprintf(w, " %-20s : %d\n", "Inputs", len(hostSourceFileMap)) 66*105f6285SAndroid Build Coastguard Worker fmt.Fprintf(w, " %-20s : %d\n", "Projects", len(hostSourceProjectMap)) 67*105f6285SAndroid Build Coastguard Worker 68*105f6285SAndroid Build Coastguard Worker if verbose { 69*105f6285SAndroid Build Coastguard Worker for proj, _ := range hostSourceProjectMap { 70*105f6285SAndroid Build Coastguard Worker fmt.Fprintf(w, " %s\n", proj) 71*105f6285SAndroid Build Coastguard Worker } 72*105f6285SAndroid Build Coastguard Worker } 73*105f6285SAndroid Build Coastguard Worker } 74*105f6285SAndroid Build Coastguard Worker 75*105f6285SAndroid Build Coastguard Worker} 76