Пример #1
0
// CreateMakefile creates a Makefile to build a tree. The cwd should
// be the root of the tree you want to make (due to some probably
// unnecessary assumptions that CreateMaker makes).
func CreateMakefile(execOpt ToolchainExecOpt, verbose bool) (*makex.Makefile, error) {
	localRepo, err := OpenRepo(".")
	if err != nil {
		return nil, err
	}
	buildStore, err := buildstore.LocalRepo(localRepo.RootDir)
	if err != nil {
		return nil, err
	}

	treeConfig, err := config.ReadCached(buildStore.Commit(localRepo.CommitID))
	if err != nil {
		return nil, err
	}
	if len(treeConfig.SourceUnits) == 0 {
		log.Printf("No source unit files found. Did you mean to run `%s config`? (This is not an error; it just means that srclib didn't find anything to build or analyze here.)", srclib.CommandName)
	}

	toolchainExecOptArgs, err := flagutil.MarshalArgs(&execOpt)
	if err != nil {
		return nil, err
	}

	// TODO(sqs): buildDataDir is hardcoded.
	buildDataDir := filepath.Join(buildstore.BuildDataDirName, localRepo.CommitID)
	mf, err := plan.CreateMakefile(buildDataDir, buildStore, localRepo.VCSType, treeConfig, plan.Options{
		ToolchainExecOpt: strings.Join(toolchainExecOptArgs, " "),
		Verbose:          verbose,
	})
	if err != nil {
		return nil, err
	}
	return mf, nil
}
Пример #2
0
Файл: scan.go Проект: xuy/srclib
func Scan(scanner []string, opt Options, treeConfig map[string]interface{}) ([]*unit.SourceUnit, error) {
	args, err := flagutil.MarshalArgs(&opt)
	if err != nil {
		return nil, fmt.Errorf("marshalling arguments for the scanner failed with: %s", err)
	}

	var errw bytes.Buffer
	cmd := exec.Command(scanner[0], scanner[1])
	cmd.Args = append(cmd.Args, args...)
	if opt.Quiet {
		cmd.Stderr = &errw
	} else {
		cmd.Stderr = io.MultiWriter(&errw, os.Stderr)
	}

	stdin, err := cmd.StdinPipe()
	if err != nil {
		return nil, fmt.Errorf("connecting to the STDIN of the scanner failed with: %s", err)
	}
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, fmt.Errorf("connecting to the STDOUT of the scanner failed with: %s", err)
	}
	if err := cmd.Start(); err != nil {
		return nil, fmt.Errorf("starting the scanner failed with: %s", err)
	}
	defer func() {
		if cmd.Process != nil {
			cmd.Process.Kill()
		}
	}()

	// Write the treeConfig into stdin.
	w := bufio.NewWriter(stdin)
	if err := json.NewEncoder(w).Encode(treeConfig); err != nil {
		w.Flush()
		return nil, fmt.Errorf("writing the STDIN of the scanner failed with: %s", err)
	}
	if err := w.Flush(); err != nil {
		return nil, fmt.Errorf("flushing the STDIN of the scanner failed with: %s", err)
	}
	if err := stdin.Close(); err != nil {
		return nil, fmt.Errorf("closing the STDIN of the scanner failed with: %s", err)
	}

	// Read on stdout into the list of source units.
	var units []*unit.SourceUnit
	if err := json.NewDecoder(stdout).Decode(&units); err != nil {
		return nil, fmt.Errorf("parsing the STDOUT of the scanner failed with: %s", err)
	}
	if err := cmd.Wait(); err != nil {
		return nil, fmt.Errorf("waiting on the scanner failed with: %s", err)
	}

	return units, nil
}
Пример #3
0
Файл: scan.go Проект: vkz/srclib
func Scan(scanner toolchain.Tool, opt Options, treeConfig map[string]interface{}) ([]*unit.SourceUnit, error) {
	args, err := flagutil.MarshalArgs(&opt)
	if err != nil {
		return nil, err
	}

	if opt.Quiet {
		scanner.SetLogger(log.New(ioutil.Discard, "", 0))
	}
	var units []*unit.SourceUnit
	if err := scanner.Run(args, treeConfig, &units); err != nil {
		return nil, err
	}

	for _, u := range units {
		u.Repo = opt.Repo
	}

	return units, nil
}