func BasicEnvVars(binBase string, bspPkg *pkg.BspPackage) map[string]string {
	coreRepo := project.GetProject().FindRepo("apache-mynewt-core")
	bspPath := bspPkg.BasePath()
	newtPath, _ := osext.Executable()
	m := map[string]string{
		"CORE_PATH":           coreRepo.Path(),
		"BSP_PATH":            bspPath,
		"BIN_ROOT":            BinRoot(),
		"MYNEWT_PROJECT_ROOT": ProjectRoot(),
		"MYNEWT_NEWT_PATH":    newtPath,
	}
	if binBase != "" {
		m["BIN_BASENAME"] = binBase
	}
	return m
}
BasicEnvVars calculates the basic set of environment variables passed to all
external scripts.  `binBase` is the result of calling `binBasePath()`, or ""
if you don't need the "BIN_BASENAME" setting.
package builder
import (
	"bytes"
	"sort"
	"strconv"
	"strings"
	"github.com/kardianos/osext"
	log "github.com/sirupsen/logrus"
	"mynewt.apache.org/newt/newt/parse"
	"mynewt.apache.org/newt/newt/pkg"
	"mynewt.apache.org/newt/newt/project"
	"mynewt.apache.org/newt/newt/resolve"
	"mynewt.apache.org/newt/newt/toolchain"
	"mynewt.apache.org/newt/util"
)
func TestTargetName(testPkgName string) string {
	return strings.Replace(testPkgName, "/", "_", -1)
}
func FeatureString(settings map[string]string) string {
	var buffer bytes.Buffer
	featureSlice := make([]string, 0, len(settings))
	for k, v := range settings {
		if parse.ValueIsTrue(v) {
			featureSlice = append(featureSlice, k)
		}
	}
	sort.Strings(featureSlice)
	for i, feature := range featureSlice {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(feature)
	}
	return buffer.String()
}
type bpkgSorter struct {
	bpkgs []*BuildPackage
}
func (b bpkgSorter) Len() int {
	return len(b.bpkgs)
}
func (b bpkgSorter) Swap(i, j int) {
	b.bpkgs[i], b.bpkgs[j] = b.bpkgs[j], b.bpkgs[i]
}
func (b bpkgSorter) Less(i, j int) bool {
	return b.bpkgs[i].rpkg.Lpkg.Name() < b.bpkgs[j].rpkg.Lpkg.Name()
}
func (b *Builder) sortedBuildPackages() []*BuildPackage {
	sorter := bpkgSorter{
		bpkgs: make([]*BuildPackage, 0, len(b.PkgMap)),
	}
	for _, bpkg := range b.PkgMap {
		sorter.bpkgs = append(sorter.bpkgs, bpkg)
	}
	sort.Sort(sorter)
	return sorter.bpkgs
}
func (b *Builder) SortedRpkgs() []*resolve.ResolvePackage {
	bpkgs := b.sortedBuildPackages()
	rpkgs := make([]*resolve.ResolvePackage, len(bpkgs), len(bpkgs))
	for i, bpkg := range bpkgs {
		rpkgs[i] = bpkg.rpkg
	}
	return rpkgs
}
func logDepInfo(res *resolve.Resolution) {
	apis := []string{}
	for api, _ := range res.ApiMap {
		apis = append(apis, api)
	}
	sort.Strings(apis)
	log.Debugf("API set:")
	for _, api := range apis {
		rpkg := res.ApiMap[api]
		log.Debugf("    * " + api + " (" + rpkg.Lpkg.FullName() + ")")
	}
	dg, err := depGraph(res.MasterSet)
	if err != nil {
		log.Debugf("Error while constructing dependency graph: %s\n",
			err.Error())
	} else {
		log.Debugf("%s", DepGraphText(dg))
	}
	rdg, err := revdepGraph(res.MasterSet)
	if err != nil {
		log.Debugf("Error while constructing reverse dependency graph: %s\n",
			err.Error())
	} else {
		log.Debugf("%s", RevdepGraphText(rdg))
	}
}
func (b *Builder) binBasePath() (string, error) {
	var rawPath string
	if b.appPkg != nil {
		rawPath = b.AppBinBasePath()
	} else if b.testPkg != nil {
		rawPath = b.TestExePath()
	} else {
		return "", util.NewNewtError("no app or test package specified")
	}
	return util.TryRelPath(rawPath), nil
}