func (pkg *LocalPackage) Save() error {
	dirpath := pkg.BasePath()
	if err := os.MkdirAll(dirpath, 0755); err != nil {
		return util.NewNewtError(err.Error())
	}
	file, err := os.Create(pkg.PkgYamlPath())
	if err != nil {
		return util.NewNewtError(err.Error())
	}
	defer file.Close()
	file.WriteString("pkg.name: " + yaml.EscapeString(pkg.Name()) + "\n")
	file.WriteString("pkg.type: " +
		yaml.EscapeString(PackageTypeNames[pkg.Type()]) + "\n")
	file.WriteString("pkg.description: " +
		yaml.EscapeString(pkg.Desc().Description) + "\n")
	file.WriteString("pkg.author: " +
		yaml.EscapeString(pkg.Desc().Author) + "\n")
	file.WriteString("pkg.homepage: " +
		yaml.EscapeString(pkg.Desc().Homepage) + "\n")
	file.WriteString("\n")
	file.WriteString(pkg.sequenceString("pkg.aflags"))
	file.WriteString(pkg.sequenceString("pkg.cflags"))
	file.WriteString(pkg.sequenceString("pkg.cxxflags"))
	file.WriteString(pkg.sequenceString("pkg.lflags"))
	return nil
}
Saves the package's pkg.yml file.
NOTE: This does not save every field in the package.  Only the fields
necessary for creating a new target get saved.
package pkg
import (
	"bytes"
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"mynewt.apache.org/newt/newt/config"
	"mynewt.apache.org/newt/newt/interfaces"
	"mynewt.apache.org/newt/newt/newtutil"
	"mynewt.apache.org/newt/newt/repo"
	"mynewt.apache.org/newt/newt/ycfg"
	"mynewt.apache.org/newt/util"
	"mynewt.apache.org/newt/yaml"
)
var PackageHashIgnoreDirs = map[string]bool{
	"obj": true,
	"bin": true,
	".":   true,
}
var LocalPackageSpecialNames = map[string]bool{
	"src":     true,
	"include": true,
	"bin":     true,
}
type LocalPackage struct {
	repo        *repo.Repo
	name        string
	basePath    string
	packageType interfaces.PackageType
	linkedName  string
	desc *PackageDesc
	injectedSettings map[string]string
	PkgY ycfg.YCfg
	SyscfgY ycfg.YCfg
	cfgFilenames []string
}
func NewLocalPackage(r *repo.Repo, pkgDir string) *LocalPackage {
	pkg := &LocalPackage{
		desc:             &PackageDesc{},
		repo:             r,
		basePath:         filepath.ToSlash(filepath.Clean(pkgDir)),
		injectedSettings: map[string]string{},
	}
	pkg.PkgY = ycfg.NewYCfg(pkg.PkgYamlPath())
	pkg.SyscfgY = ycfg.NewYCfg(pkg.SyscfgYamlPath())
	return pkg
}
func (pkg *LocalPackage) Name() string {
	return pkg.name
}
func (pkg *LocalPackage) NameWithRepo() string {
	r := pkg.Repo()
	return newtutil.BuildPackageString(r.Name(), pkg.Name())
}
func (pkg *LocalPackage) FullName() string {
	r := pkg.Repo()
	if r.IsLocal() {
		return pkg.Name()
	} else {
		return pkg.NameWithRepo()
	}
}
func (pkg *LocalPackage) LinkedName() string {
	return pkg.linkedName
}
func (pkg *LocalPackage) BasePath() string {
	return pkg.basePath
}
func (pkg *LocalPackage) RelativePath() string {
	proj := interfaces.GetProject()
	return strings.TrimPrefix(pkg.BasePath(), proj.Path())
}
func (pkg *LocalPackage) PkgYamlPath() string {
	return fmt.Sprintf("%s/%s", pkg.BasePath(), PACKAGE_FILE_NAME)
}
func (pkg *LocalPackage) SyscfgYamlPath() string {
	return fmt.Sprintf("%s/%s", pkg.BasePath(), SYSCFG_YAML_FILENAME)
}
func (pkg *LocalPackage) Type() interfaces.PackageType {
	return pkg.packageType
}
func (pkg *LocalPackage) Repo() interfaces.RepoInterface {
	return pkg.repo
}
func (pkg *LocalPackage) Desc() *PackageDesc {
	return pkg.desc
}
func (pkg *LocalPackage) SetName(name string) {
	pkg.name = name
}
func (pkg *LocalPackage) SetBasePath(basePath string) {
	pkg.basePath = filepath.ToSlash(filepath.Clean(basePath))
}
func (pkg *LocalPackage) SetType(packageType interfaces.PackageType) {
	pkg.packageType = packageType
}
func (pkg *LocalPackage) SetDesc(desc *PackageDesc) {
	pkg.desc = desc
}
func (pkg *LocalPackage) SetRepo(r *repo.Repo) {
	pkg.repo = r
}
func (pkg *LocalPackage) CfgFilenames() []string {
	return pkg.cfgFilenames
}
func (pkg *LocalPackage) AddCfgFilename(cfgFilename string) {
	pkg.cfgFilenames = append(pkg.cfgFilenames, cfgFilename)
}
func (pkg *LocalPackage) readDesc(yc ycfg.YCfg) (*PackageDesc, error) {
	pdesc := &PackageDesc{}
	var err error
	pdesc.Author, err = yc.GetValString("pkg.author", nil)
	util.OneTimeWarningError(err)
	pdesc.Homepage, err = yc.GetValString("pkg.homepage", nil)
	util.OneTimeWarningError(err)
	pdesc.Description, err = yc.GetValString("pkg.description", nil)
	util.OneTimeWarningError(err)
	pdesc.Keywords, err = yc.GetValStringSlice("pkg.keywords", nil)
	util.OneTimeWarningError(err)
	return pdesc, nil
}
func (pkg *LocalPackage) sequenceString(key string) string {
	var buffer bytes.Buffer
	vals, err := pkg.PkgY.GetValStringSlice(key, nil)
	util.OneTimeWarningError(err)
	for _, f := range vals {
		buffer.WriteString("    - " + yaml.EscapeString(f) + "\n")
	}
	if buffer.Len() == 0 {
		return ""
	} else {
		return key + ":\n" + buffer.String()
	}
}
func (lpkg *LocalPackage) SaveSyscfg() error {
	dirpath := lpkg.BasePath()
	if err := os.MkdirAll(dirpath, 0755); err != nil {
		return util.NewNewtError(err.Error())
	}
	file, err := os.Create(lpkg.SyscfgYamlPath())
	if err != nil {
		return util.NewNewtError(err.Error())
	}
	defer file.Close()
	s := lpkg.SyscfgY.YAML()
	file.WriteString(s)
	return nil
}