func (c *ToolCmd) Execute(args []string) error { cmdName, err := toolchain.Command(string(c.Args.Toolchain)) if err != nil { log.Fatal(err) } cmd := exec.Command(cmdName) if c.Args.Tool != "" { cmd.Args = append(cmd.Args, string(c.Args.Tool)) cmd.Args = append(cmd.Args, c.Args.ToolArgs...) } cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if GlobalOpt.Verbose { log.Printf("Running tool: %v", cmd.Args) } return cmd.Run() }
// scanUnitsIntoConfig uses cfg to scan for source units. It modifies // cfg.SourceUnits, merging the scanned source units with those already present // in cfg. func scanUnitsIntoConfig(cfg *config.Repository, quiet bool) error { scanners := make([][]string, len(cfg.Scanners)) for i, scannerRef := range cfg.Scanners { cmdName, err := toolchain.Command(scannerRef.Toolchain) if err != nil { return err } scanners[i] = []string{cmdName, scannerRef.Subcmd} } units, err := scan.ScanMulti(scanners, scan.Options{Quiet: quiet}, cfg.Config) if err != nil { return err } // Merge the repo/tree config with each source unit's config. if cfg.Config == nil { cfg.Config = map[string]interface{}{} } for _, u := range units { for k, v := range cfg.Config { if uv, present := u.Config[k]; present { log.Printf("Both the scanned source unit %q and the Srcfile specify a Config key %q. Using the value from the scanned source unit (%+v).", u.ID(), k, uv) } else { if u.Config == nil { u.Config = map[string]interface{}{} } u.Config[k] = v } } } // collect manually specified source units by ID manualUnits := make(map[unit.ID]*unit.SourceUnit, len(cfg.SourceUnits)) for _, u := range cfg.SourceUnits { manualUnits[u.ID()] = u xf, err := unit.ExpandPaths(".", u.Files) if err != nil { return err } u.Files = xf } for _, u := range units { if mu, present := manualUnits[u.ID()]; present { log.Printf("Found manually specified source unit %q with same ID as scanned source unit. Using manually specified unit, ignoring scanned source unit.", mu.ID()) continue } unitDir := u.Dir if unitDir == "" && len(u.Files) > 0 { // in case the unit doesn't specify a Dir, obtain it from the first file unitDir = filepath.Dir(u.Files[0]) } // heed SkipDirs if pathHasAnyPrefix(unitDir, cfg.SkipDirs) { continue } skip := false for _, skipUnit := range cfg.SkipUnits { if u.Name == skipUnit.Name && u.Type == skipUnit.Type { skip = true break } } if skip { continue } cfg.SourceUnits = append(cfg.SourceUnits, u) } return nil }