You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/02/11 02:54:34 UTC
[5/9] incubator-mynewt-newt git commit: update egg to pkg/package,
clutch to pkg-list,
and nest to repo. adjust git import paths to unify w newtmgr.
update egg to pkg/package, clutch to pkg-list, and nest to repo. adjust git import paths to unify w newtmgr.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/be14580e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/be14580e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/be14580e
Branch: refs/heads/master
Commit: be14580ed0139b591af8eb2a5ad2d01800a48b55
Parents: 11b80a2
Author: Sterling Hughes <st...@apache.org>
Authored: Mon Feb 8 21:55:52 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Wed Feb 10 17:54:14 2016 -0800
----------------------------------------------------------------------
newt/cli/build.go | 88 ++--
newt/cli/clutch.go | 1004 ------------------------------------------
newt/cli/egg.go | 788 ---------------------------------
newt/cli/nest.go | 467 --------------------
newt/cli/pkg.go | 788 +++++++++++++++++++++++++++++++++
newt/cli/pkglist.go | 1005 +++++++++++++++++++++++++++++++++++++++++++
newt/cli/project.go | 138 +++---
newt/cli/remotenest.go | 121 ------
newt/cli/remoterepo.go | 121 ++++++
newt/cli/repo.go | 467 ++++++++++++++++++++
newt/cli/target.go | 152 +++----
newt/newt.go | 630 +++++++++++++--------------
12 files changed, 2885 insertions(+), 2884 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/be14580e/newt/cli/build.go
----------------------------------------------------------------------
diff --git a/newt/cli/build.go b/newt/cli/build.go
index 9e52ddf..eff2376 100644
--- a/newt/cli/build.go
+++ b/newt/cli/build.go
@@ -19,43 +19,43 @@ import (
"os"
)
-// Recursively iterates through an egg's dependencies, adding each egg
+// Recursively iterates through an pkg's dependencies, adding each pkg
// encountered to the supplied set.
-func collectDepsAux(clutch *Clutch, egg *Egg, set *map[*Egg]bool) error {
- if (*set)[egg] {
+func collectDepsAux(pkgList *PkgList, pkg *Pkg, set *map[*Pkg]bool) error {
+ if (*set)[pkg] {
return nil
}
- (*set)[egg] = true
+ (*set)[pkg] = true
- for _, dep := range egg.Deps {
+ for _, dep := range pkg.Deps {
if dep.Name == "" {
break
}
- // Get egg structure
- degg, err := clutch.ResolveEggName(dep.Name)
+ // Get pkg structure
+ dpkg, err := pkgList.ResolvePkgName(dep.Name)
if err != nil {
return err
}
- collectDepsAux(clutch, degg, set)
+ collectDepsAux(pkgList, dpkg, set)
}
return nil
}
-// Recursively iterates through an egg's dependencies. The resulting array
-// contains a pointer to each encountered egg.
-func collectDeps(clutch *Clutch, egg *Egg) ([]*Egg, error) {
- set := map[*Egg]bool{}
+// Recursively iterates through an pkg's dependencies. The resulting array
+// contains a pointer to each encountered pkg.
+func collectDeps(pkgList *PkgList, pkg *Pkg) ([]*Pkg, error) {
+ set := map[*Pkg]bool{}
- err := collectDepsAux(clutch, egg, &set)
+ err := collectDepsAux(pkgList, pkg, &set)
if err != nil {
return nil, err
}
- arr := []*Egg{}
+ arr := []*Pkg{}
for p, _ := range set {
arr = append(arr, p)
}
@@ -63,23 +63,23 @@ func collectDeps(clutch *Clutch, egg *Egg) ([]*Egg, error) {
return arr, nil
}
-// Calculates the include paths exported by the specified egg and all of
+// Calculates the include paths exported by the specified pkg and all of
// its recursive dependencies.
-func recursiveIncludePaths(clutch *Clutch, egg *Egg,
+func recursiveIncludePaths(pkgList *PkgList, pkg *Pkg,
t *Target) ([]string, error) {
- deps, err := collectDeps(clutch, egg)
+ deps, err := collectDeps(pkgList, pkg)
if err != nil {
return nil, err
}
incls := []string{}
for _, p := range deps {
- eggIncls, err := p.GetIncludes(t)
+ pkgIncls, err := p.GetIncludes(t)
if err != nil {
return nil, err
}
- incls = append(incls, eggIncls...)
+ incls = append(incls, pkgIncls...)
}
return incls, nil
@@ -87,44 +87,44 @@ func recursiveIncludePaths(clutch *Clutch, egg *Egg,
// Calculates the include paths exported by the specified target's BSP and all
// of its recursive dependencies.
-func BspIncludePaths(clutch *Clutch, t *Target) ([]string, error) {
+func BspIncludePaths(pkgList *PkgList, t *Target) ([]string, error) {
if t.Bsp == "" {
return nil, NewNewtError("Expected a BSP")
}
- bspEgg, err := clutch.ResolveEggName(t.Bsp)
+ bspPkg, err := pkgList.ResolvePkgName(t.Bsp)
if err != nil {
- return nil, NewNewtError("No BSP egg for " + t.Bsp + " exists")
+ return nil, NewNewtError("No BSP pkg for " + t.Bsp + " exists")
}
- return recursiveIncludePaths(clutch, bspEgg, t)
+ return recursiveIncludePaths(pkgList, bspPkg, t)
}
-func buildBsp(t *Target, clutch *Clutch, incls *[]string,
- libs *[]string, capEggs map[string]string) (string, error) {
+func buildBsp(t *Target, pkgList *PkgList, incls *[]string,
+ libs *[]string, capPkgs map[string]string) (string, error) {
if t.Bsp == "" {
return "", NewNewtError("Expected a BSP")
}
- bspEgg, err := clutch.ResolveEggName(t.Bsp)
+ bspPkg, err := pkgList.ResolvePkgName(t.Bsp)
if err != nil {
- return "", NewNewtError("No BSP egg for " + t.Bsp + " exists")
+ return "", NewNewtError("No BSP pkg for " + t.Bsp + " exists")
}
- if err = clutch.Build(t, t.Bsp, *incls, libs); err != nil {
+ if err = pkgList.Build(t, t.Bsp, *incls, libs); err != nil {
return "", err
}
// A BSP doesn't have to contain source; don't fail if no library was
// built.
- if lib := clutch.GetEggLib(t, bspEgg); NodeExist(lib) {
+ if lib := pkgList.GetPkgLib(t, bspPkg); NodeExist(lib) {
*libs = append(*libs, lib)
}
var linkerScript string
- if bspEgg.LinkerScript != "" {
- linkerScript = bspEgg.BasePath + "/" + bspEgg.LinkerScript
+ if bspPkg.LinkerScript != "" {
+ linkerScript = bspPkg.BasePath + "/" + bspPkg.LinkerScript
} else {
linkerScript = ""
}
@@ -134,34 +134,34 @@ func buildBsp(t *Target, clutch *Clutch, incls *[]string,
// Creates the set of compiler flags that should be specified when building a
// particular target-entity pair. The "entity" is what is being built; either
-// an egg or a project.
-func CreateCflags(clutch *Clutch, c *Compiler, t *Target,
+// an pkg or a project.
+func CreateCflags(pkgList *PkgList, c *Compiler, t *Target,
entityCflags string) string {
cflags := c.Cflags + " " + entityCflags + " " + t.Cflags
// The 'test' identity causes the TEST symbol to be defined. This allows
- // egg code to behave differently in test builds.
+ // pkg code to behave differently in test builds.
if t.HasIdentity("test") {
cflags += " -DTEST"
}
cflags += " -DARCH_" + t.Arch
- // If a non-BSP egg is being built, add the BSP's C flags to the list.
- // The BSP's compiler flags get exported to all eggs.
- bspEgg, err := clutch.ResolveEggName(t.Bsp)
- if err == nil && bspEgg.Cflags != entityCflags {
- cflags += " " + bspEgg.Cflags
+ // If a non-BSP pkg is being built, add the BSP's C flags to the list.
+ // The BSP's compiler flags get exported to all pkgs.
+ bspPkg, err := pkgList.ResolvePkgName(t.Bsp)
+ if err == nil && bspPkg.Cflags != entityCflags {
+ cflags += " " + bspPkg.Cflags
}
return cflags
}
-func EggIncludeDirs(egg *Egg, t *Target) []string {
- srcDir := egg.BasePath + "/src/"
+func PkgIncludeDirs(pkg *Pkg, t *Target) []string {
+ srcDir := pkg.BasePath + "/src/"
- incls := egg.Includes
+ incls := pkg.Includes
incls = append(incls, srcDir)
incls = append(incls, srcDir+"/arch/"+t.Arch)
@@ -182,7 +182,7 @@ func BuildDir(srcDir string, c *Compiler, t *Target, ignDirs []string) error {
StatusMessage(VERBOSITY_VERBOSE, "compiling src in base directory: %s\n",
srcDir)
- // First change into the egg src directory, and build all the objects
+ // First change into the pkg src directory, and build all the objects
// there
os.Chdir(srcDir)
@@ -201,7 +201,7 @@ func BuildDir(srcDir string, c *Compiler, t *Target, ignDirs []string) error {
archDir := srcDir + "/arch/" + t.Arch + "/"
StatusMessage(VERBOSITY_VERBOSE,
- "compiling architecture specific src eggs in directory: %s\n",
+ "compiling architecture specific src pkgs in directory: %s\n",
archDir)
if NodeExist(archDir) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/be14580e/newt/cli/clutch.go
----------------------------------------------------------------------
diff --git a/newt/cli/clutch.go b/newt/cli/clutch.go
deleted file mode 100644
index 3027ceb..0000000
--- a/newt/cli/clutch.go
+++ /dev/null
@@ -1,1004 +0,0 @@
-/*
- Copyright 2015 Runtime Inc.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-package cli
-
-import (
- "bytes"
- "fmt"
- "github.com/spf13/viper"
- "io/ioutil"
- "log"
- "os"
- "path/filepath"
- "strings"
-)
-
-type Clutch struct {
- // Nestsitory associated with the Eggs
- Nest *Nest
-
- // List of packages for Nest
- Eggs map[string]*Egg
-
- EggShells map[string]*EggShell
-
- Name string
-
- LarvaFile string
-
- RemoteUrl string
-
- Branch string
-}
-
-// Allocate a new package manager structure, and initialize it.
-func NewClutch(nest *Nest) (*Clutch, error) {
- clutch := &Clutch{
- Nest: nest,
- }
- err := clutch.Init()
-
- return clutch, err
-}
-
-func (clutch *Clutch) LoadConfigs(t *Target, force bool) error {
- for _, egg := range clutch.Eggs {
- if err := egg.LoadConfig(t, force); err != nil {
- return err
- }
- }
- return nil
-}
-
-func (clutch *Clutch) CheckEggDeps(egg *Egg,
- deps map[string]*DependencyRequirement,
- reqcap map[string]*DependencyRequirement,
- caps map[string]*DependencyRequirement,
- capEggs map[string]string) error {
-
- for _, depReq := range egg.Deps {
- // don't process this package if we've already processed it
- if _, ok := deps[depReq.String()]; ok {
- continue
- }
-
- eggName := egg.Name
- StatusMessage(VERBOSITY_VERBOSE,
- "Checking dependency %s for package %s\n", depReq.Name, eggName)
- egg, ok := clutch.Eggs[depReq.Name]
- if !ok {
- return NewNewtError(
- fmt.Sprintf("No package dependency %s found for %s",
- depReq.Name, eggName))
- }
-
- if ok := depReq.SatisfiesDependency(egg); !ok {
- return NewNewtError(fmt.Sprintf("Egg %s doesn't satisfy dependency %s",
- egg.Name, depReq))
- }
-
- // We've checked this dependency requirement, all is gute!
- deps[depReq.String()] = depReq
- }
-
- for _, reqCap := range egg.ReqCapabilities {
- reqcap[reqCap.String()] = reqCap
- }
-
- for _, cap := range egg.Capabilities {
- if caps[cap.String()] != nil && capEggs[cap.String()] != egg.FullName {
- return NewNewtError(fmt.Sprintf("Multiple eggs with capability %s",
- cap.String()))
- }
- caps[cap.String()] = cap
- if capEggs != nil {
- capEggs[cap.String()] = egg.FullName
- }
- }
-
- // Now go through and recurse through the sub-package dependencies
- for _, depReq := range egg.Deps {
- if _, ok := deps[depReq.String()]; ok {
- continue
- }
-
- if err := clutch.CheckEggDeps(clutch.Eggs[depReq.Name], deps,
- reqcap, caps, capEggs); err != nil {
- return err
- }
- }
-
- return nil
-}
-
-func (clutch *Clutch) VerifyCaps(reqcaps map[string]*DependencyRequirement,
- caps map[string]*DependencyRequirement) error {
-
- for name, rcap := range reqcaps {
- capability, ok := caps[name]
- if !ok {
- return NewNewtError(fmt.Sprintf("Required capability %s not found",
- name))
- }
-
- if err := rcap.SatisfiesCapability(capability); err != nil {
- return err
- }
- }
-
- return nil
-}
-
-func (clutch *Clutch) CheckDeps() error {
- // Go through all the packages and check that their dependencies are satisfied
- for _, egg := range clutch.Eggs {
- deps := map[string]*DependencyRequirement{}
- reqcap := map[string]*DependencyRequirement{}
- caps := map[string]*DependencyRequirement{}
-
- if err := clutch.CheckEggDeps(egg, deps, reqcap, caps, nil); err != nil {
- return err
- }
- }
-
- return nil
-}
-
-// Load an individual package specified by eggName into the package list for
-// this repository
-func (clutch *Clutch) loadEgg(eggDir string, eggPrefix string,
- eggName string) error {
- StatusMessage(VERBOSITY_VERBOSE, "Loading Egg "+eggDir+"...\n")
-
- if clutch.Eggs == nil {
- clutch.Eggs = make(map[string]*Egg)
- }
-
- egg, err := NewEgg(clutch.Nest, eggDir)
- if err != nil {
- return nil
- }
-
- clutch.Eggs[eggPrefix+eggName] = egg
-
- return nil
-}
-
-func (clutch *Clutch) String() string {
- str := ""
- for eggName, _ := range clutch.Eggs {
- str += eggName + " "
- }
- return str
-}
-
-// Recursively load a package. Given the baseDir of the packages (e.g. egg/ or
-// hw/bsp), and the base package name.
-func (clutch *Clutch) loadEggDir(baseDir string, eggPrefix string,
- eggName string) error {
- log.Printf("[DEBUG] Loading eggs in %s, starting with egg %s",
- baseDir, eggName)
-
- // first recurse and load subpackages
- list, err := ioutil.ReadDir(baseDir + "/" + eggName)
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- for _, ent := range list {
- if !ent.IsDir() {
- continue
- }
-
- name := ent.Name()
-
- if name == "src" || name == "include" || strings.HasPrefix(name, ".") ||
- name == "bin" {
- continue
- } else {
- if err := clutch.loadEggDir(baseDir, eggPrefix,
- eggName+"/"+name); err != nil {
- return err
- }
- }
- }
-
- if NodeNotExist(baseDir + "/" + eggName + "/egg.yml") {
- return nil
- }
-
- return clutch.loadEgg(baseDir+"/"+eggName, eggPrefix, eggName)
-}
-
-// Load all the packages in the repository into the package structure
-func (clutch *Clutch) loadEggs() error {
- nest := clutch.Nest
-
- // Multiple package directories to be searched
- searchDirs := []string{
- "compiler/",
- "fs/",
- "libs/",
- "net/",
- "hw/bsp/",
- "hw/mcu/",
- "hw/mcu/stm",
- "hw/drivers/",
- "hw/",
- "project/",
- "sys/",
- }
-
- for _, eggDir := range searchDirs {
- eggBaseDir := nest.BasePath + "/" + eggDir
-
- if NodeNotExist(eggBaseDir) {
- continue
- }
-
- eggList, err := ioutil.ReadDir(eggBaseDir)
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- for _, subEggDir := range eggList {
- name := subEggDir.Name()
- if filepath.HasPrefix(name, ".") || filepath.HasPrefix(name, "..") {
- continue
- }
-
- if !subEggDir.IsDir() {
- continue
- }
-
- if err = clutch.loadEggDir(eggBaseDir, eggDir, name); err != nil {
- return err
- }
- }
- }
-
- return nil
-}
-
-// Initialize the package manager
-func (clutch *Clutch) Init() error {
- if err := clutch.loadEggs(); err != nil {
- return err
- }
-
- clutch.EggShells = map[string]*EggShell{}
-
- return nil
-}
-
-// Resolve the package specified by eggName into a package structure.
-func (clutch *Clutch) ResolveEggName(eggName string) (*Egg, error) {
- egg, ok := clutch.Eggs[eggName]
- if !ok {
- return nil, NewNewtError(fmt.Sprintf("Invalid egg '%s' specified "+
- "(eggs = %s)", eggName, clutch))
- }
- return egg, nil
-}
-
-func (clutch *Clutch) ResolveEggShellName(eggName string) (*EggShell, error) {
- eggShell, ok := clutch.EggShells[eggName]
- if !ok {
- return nil, NewNewtError(fmt.Sprintf("Invalid egg '%s' specified "+
- "(eggs = %s)", eggName, clutch))
- }
- return eggShell, nil
-}
-
-func (clutch *Clutch) ResolveEggDir(eggDir string) (*Egg, error) {
- eggDir = filepath.Clean(eggDir)
- for name, egg := range clutch.Eggs {
- if filepath.Clean(egg.BasePath) == eggDir {
- return clutch.Eggs[name], nil
- }
- }
- return nil, NewNewtError(fmt.Sprintf("Cannot resolve package dir %s in "+
- "package manager", eggDir))
-}
-
-// Clean the build for the package specified by eggName. if cleanAll is
-// specified, all architectures are cleaned.
-func (clutch *Clutch) BuildClean(t *Target, eggName string, cleanAll bool) error {
- egg, err := clutch.ResolveEggName(eggName)
- if err != nil {
- return err
- }
-
- if err := egg.LoadConfig(t, false); err != nil {
- return err
- }
-
- tName := t.Name + "/"
- if cleanAll {
- tName = ""
- }
-
- if egg.Clean {
- return nil
- }
- egg.Clean = true
-
- for _, dep := range egg.Deps {
- if err := clutch.BuildClean(t, dep.Name, cleanAll); err != nil {
- return err
- }
- }
-
- c, err := NewCompiler(t.GetCompiler(), t.Cdef, t.Name, []string{})
- if err != nil {
- return err
- }
-
- if NodeExist(egg.BasePath + "/src/") {
- if err := c.RecursiveClean(egg.BasePath+"/src/", tName); err != nil {
- return err
- }
-
- if err := os.RemoveAll(egg.BasePath + "/bin/" + tName); err != nil {
- return NewNewtError(err.Error())
- }
- }
-
- egg.Clean = true
-
- return nil
-}
-
-func (clutch *Clutch) GetEggLib(t *Target, egg *Egg) string {
- libDir := egg.BasePath + "/bin/" + t.Name + "/" +
- "lib" + filepath.Base(egg.Name) + ".a"
- return libDir
-}
-
-// @param incls Extra include paths that get specified during
-// build; not modified by this function.
-// @param libs List of libraries that have been built so far;
-// This function appends entries to this list.
-func (clutch *Clutch) buildDeps(egg *Egg, t *Target, incls *[]string,
- libs *[]string) error {
-
- StatusMessage(VERBOSITY_VERBOSE,
- "Building egg dependencies for %s, target %s\n", egg.Name, t.Name)
-
- var err error
-
- if egg.Includes, err = egg.GetIncludes(t); err != nil {
- return err
- }
-
- if incls == nil {
- incls = &[]string{}
- }
- if libs == nil {
- libs = &[]string{}
- }
-
- for _, dep := range egg.Deps {
- if dep.Name == "" {
- break
- }
-
- log.Printf("[DEBUG] Loading package dependency: %s", dep.Name)
- // Get package structure
- degg, err := clutch.ResolveEggName(dep.Name)
- if err != nil {
- return err
- }
-
- // Build the package
- if err = clutch.Build(t, dep.Name, *incls, libs); err != nil {
- return err
- }
-
- // After build, get dependency package includes. Build function
- // generates all the package includes
- egg.Includes = append(egg.Includes, degg.Includes...)
- if lib := clutch.GetEggLib(t, degg); NodeExist(lib) {
- *libs = append(*libs, lib)
- }
- }
-
- // Add on dependency includes to package includes
- log.Printf("[DEBUG] Egg dependencies for %s built, incls = %s",
- egg.Name, egg.Includes)
-
- return nil
-}
-
-// Build the package specified by eggName
-//
-// @param incls Extra include paths that get specified during
-// build. Note: passed by value.
-// @param lib List of libraries that have been built so far;
-// This function appends entries to this list.
-func (clutch *Clutch) Build(t *Target, eggName string, incls []string,
- libs *[]string) error {
-
- // Look up package structure
- egg, err := clutch.ResolveEggName(eggName)
- if err != nil {
- return err
- }
-
- if err := egg.LoadConfig(t, false); err != nil {
- return err
- }
-
- // already built the package, no need to rebuild. This is to handle
- // recursive calls to Build()
- if egg.Built {
- return nil
- }
- egg.Built = true
-
- if err := clutch.buildDeps(egg, t, &incls, libs); err != nil {
- return err
- }
-
- StatusMessage(VERBOSITY_VERBOSE, "Building egg %s for arch %s\n",
- eggName, t.Arch)
-
- // NOTE: this assignment must happen after the call to buildDeps(), as
- // buildDeps() fills in the package includes.
- incls = append(incls, EggIncludeDirs(egg, t)...)
- log.Printf("[DEBUG] Egg includes for %s are %s", eggName, incls)
-
- srcDir := egg.BasePath + "/src/"
- if NodeNotExist(srcDir) {
- // nothing to compile, return true!
- return nil
- }
-
- // Build the package designated by eggName
- // Initialize a compiler
- c, err := NewCompiler(t.GetCompiler(), t.Cdef, t.Name, incls)
- if err != nil {
- return err
- }
- // setup Cflags, Lflags and Aflags
- c.Cflags = CreateCflags(clutch, c, t, egg.Cflags)
- c.Lflags += " " + egg.Lflags + " " + t.Lflags
- c.Aflags += " " + egg.Aflags + " " + t.Aflags
-
- log.Printf("[DEBUG] compiling src eggs in base egg directory: %s", srcDir)
-
- // For now, ignore test code. Tests get built later if the test identity
- // is in effect.
- ignDirs := []string{"test"}
-
- if err = BuildDir(srcDir, c, t, ignDirs); err != nil {
- return err
- }
-
- // Now build the test code if requested.
- if t.HasIdentity("test") {
- testSrcDir := srcDir + "/test"
- if err = BuildDir(testSrcDir, c, t, ignDirs); err != nil {
- return err
- }
- }
-
- // Archive everything into a static library, which can be linked with a
- // main program
- if err := os.Chdir(egg.BasePath + "/"); err != nil {
- return NewNewtError(err.Error())
- }
-
- binDir := egg.BasePath + "/bin/" + t.Name + "/"
-
- if NodeNotExist(binDir) {
- if err := os.MkdirAll(binDir, 0755); err != nil {
- return NewNewtError(err.Error())
- }
- }
-
- if err = c.CompileArchive(clutch.GetEggLib(t, egg), []string{}); err != nil {
- return err
- }
-
- return nil
-}
-
-// Check the include directories for the package, to make sure there are
-// no conflicts in include paths for source code
-func (clutch *Clutch) checkIncludes(egg *Egg) error {
- incls, err := filepath.Glob(egg.BasePath + "/include/*")
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- // Append all the architecture specific directories
- archDir := egg.BasePath + "/include/" + egg.Name + "/arch/"
- dirs, err := ioutil.ReadDir(archDir)
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- for _, dir := range dirs {
- if !dir.IsDir() {
- return NewNewtError(fmt.Sprintf(
- "Only directories are allowed in architecture dir: %s",
- archDir+dir.Name()))
- }
-
- incls2, err := filepath.Glob(archDir + dir.Name() + "/*")
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- incls = append(incls, incls2...)
- }
-
- for _, incl := range incls {
- finfo, err := os.Stat(incl)
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- bad := false
- if !finfo.IsDir() {
- bad = true
- }
-
- if filepath.Base(incl) != egg.Name {
- if egg.IsBsp && filepath.Base(incl) != "bsp" {
- bad = true
- }
- }
-
- if bad {
- return NewNewtError(fmt.Sprintf("File %s should not exist"+
- "in include directory, only file allowed in include "+
- "directory is a directory with the package name %s",
- incl, egg.Name))
- }
- }
-
- return nil
-}
-
-// Clean the tests in the tests parameter, for the package identified by
-// eggName. If cleanAll is set to true, all architectures will be removed.
-func (clutch *Clutch) TestClean(t *Target, eggName string,
- cleanAll bool) error {
- egg, err := clutch.ResolveEggName(eggName)
- if err != nil {
- return err
- }
-
- if err := egg.LoadConfig(t, false); err != nil {
- return err
- }
-
- tName := t.Name + "/"
- if cleanAll {
- tName = ""
- }
-
- if err := os.RemoveAll(egg.BasePath + "/src/test/bin/" + tName); err != nil {
- return NewNewtError(err.Error())
- }
- if err := os.RemoveAll(egg.BasePath + "/src/test/obj/" + tName); err != nil {
- return NewNewtError(err.Error())
- }
-
- return nil
-}
-
-// Compile tests specified by the tests parameter. The tests are linked
-// to the package specified by the egg parameter
-func (clutch *Clutch) linkTests(t *Target, egg *Egg,
- incls []string, libs *[]string) error {
-
- c, err := NewCompiler(t.GetCompiler(), t.Cdef, t.Name, incls)
- if err != nil {
- return err
- }
-
- // Configure Lflags. Since we are only linking, Cflags and Aflags are
- // unnecessary.
- c.Lflags += " " + egg.Lflags + " " + t.Lflags
-
- testBinDir := egg.BasePath + "/src/test/bin/" + t.Name + "/"
- binFile := testBinDir + egg.TestBinName()
- options := map[string]bool{}
-
- // Determine if the test executable is already up to date.
- linkRequired, err := c.depTracker.LinkRequired(binFile, options, *libs)
- if err != nil {
- return err
- }
-
- // Build the test executable if necessary.
- if linkRequired {
- if NodeNotExist(testBinDir) {
- if err := os.MkdirAll(testBinDir, 0755); err != nil {
- return NewNewtError(err.Error())
- }
- }
-
- err = c.CompileBinary(binFile, options, *libs)
- if err != nil {
- return err
- }
- }
-
- return nil
-}
-
-// Run all the tests in the tests parameter. egg is the package to check for
-// the tests. exitOnFailure specifies whether to exit immediately when a
-// test fails, or continue executing all tests.
-func (clutch *Clutch) runTests(t *Target, egg *Egg, exitOnFailure bool) error {
- StatusMessage(VERBOSITY_DEFAULT, "Testing egg %s for arch %s\n",
- egg.Name, t.Arch)
-
- if err := os.Chdir(egg.BasePath + "/src/test/bin/" + t.Name +
- "/"); err != nil {
- return err
- }
-
- o, err := ShellCommand("./" + egg.TestBinName())
- if err != nil {
- StatusMessage(VERBOSITY_DEFAULT, "%s", string(o))
-
- // Always terminate on test failure since only one test is being run.
- return NewtErrorNoTrace(fmt.Sprintf("Test %s failed",
- egg.TestBinName()))
- } else {
- StatusMessage(VERBOSITY_VERBOSE, "%s", string(o))
- StatusMessage(VERBOSITY_DEFAULT, "Test %s ok!\n", egg.TestBinName())
- return nil
- }
-}
-
-// Check to ensure tests exist. Go through the array of tests specified by
-// the tests parameter. egg is the package to check for these tests.
-func (clutch *Clutch) testsExist(egg *Egg) error {
- dirName := egg.BasePath + "/src/test/"
- if NodeNotExist(dirName) {
- return NewNewtError("No test exists for package " + egg.Name)
- }
-
- return nil
-}
-
-// Test the package identified by eggName, by executing the tests specified.
-// exitOnFailure signifies whether to stop the test program when one of them
-// fails.
-func (clutch *Clutch) Test(t *Target, eggName string,
- exitOnFailure bool) error {
-
- // A few identities are implicitly exported when the test command is used:
- // * test: ensures that the test code gets compiled.
- // * selftest: indicates that there is no project
- t.Identities["test"] = "test"
- t.Identities["selftest"] = "selftest"
-
- egg, err := clutch.ResolveEggName(eggName)
- if err != nil {
- return err
- }
-
- if err := egg.LoadConfig(t, false); err != nil {
- return err
- }
-
- // Make sure the test directories exist
- if err := clutch.testsExist(egg); err != nil {
- return err
- }
-
- // The egg under test must be compiled with the PKG_TEST symbol defined so
- // that the appropriate main function gets built.
- egg.Cflags += " -DPKG_TEST"
-
- incls := []string{}
- libs := []string{}
-
- // If there is a BSP:
- // 1. Calculate the include paths that it and its dependencies export.
- // This set of include paths is accessible during all subsequent
- // builds.
- // 2. Build the BSP package.
- if t.Bsp != "" {
- incls, err = BspIncludePaths(clutch, t)
- if err != nil {
- return err
- }
- _, err = buildBsp(t, clutch, &incls, &libs, nil)
- if err != nil {
- return err
- }
- }
-
- // Build the package under test.
- if err := clutch.Build(t, eggName, incls, &libs); err != nil {
- return err
- }
- lib := clutch.GetEggLib(t, egg)
- if !NodeExist(lib) {
- return NewNewtError("Egg " + eggName + " did not produce binary")
- }
- libs = append(libs, lib)
-
- // Compile the package's test code.
- if err := clutch.linkTests(t, egg, incls, &libs); err != nil {
- return err
- }
-
- // Run the tests.
- if err := clutch.runTests(t, egg, exitOnFailure); err != nil {
- return err
- }
-
- return nil
-}
-
-func (cl *Clutch) LoadFromClutch(local *Clutch) error {
- var err error
- for _, egg := range local.Eggs {
- if err := egg.LoadConfig(nil, false); err != nil {
- return err
- }
-
- log.Printf("[DEBUG] Egg %s loaded, putting it into clutch %s",
- egg.FullName, local.Name)
-
- eggShell := &EggShell{}
- eggShell.FullName = egg.FullName
- eggShell.Deps = egg.Deps
- eggShell.Caps = egg.Capabilities
- eggShell.ReqCaps = egg.ReqCapabilities
- eggShell.Version = egg.Version
- eggShell.Hash, err = egg.GetHash()
- if err != nil {
- return err
- }
-
- cl.EggShells[eggShell.FullName] = eggShell
- }
-
- return nil
-}
-
-func (cl *Clutch) Serialize() (string, error) {
- clStr := "name: " + cl.Name + "\n"
- clStr = clStr + "url: " + cl.RemoteUrl + "\n"
- clStr = clStr + "eggs:\n"
-
- buf := bytes.Buffer{}
-
- indent := " "
- for _, eggShell := range cl.EggShells {
- buf.WriteString(eggShell.Serialize(indent))
- }
-
- return clStr + buf.String(), nil
-}
-
-func (cl *Clutch) strSliceToDr(list []string) ([]*DependencyRequirement, error) {
- drList := []*DependencyRequirement{}
-
- for _, name := range list {
- req, err := NewDependencyRequirementParseString(name)
- if err != nil {
- return nil, err
- }
- drList = append(drList, req)
- }
-
- if len(drList) == 0 {
- return nil, nil
- } else {
- return drList, nil
- }
-}
-
-func (cl *Clutch) fileToEggList(cfg *viper.Viper) (map[string]*EggShell,
- error) {
- eggMap := cfg.GetStringMap("eggs")
-
- eggList := map[string]*EggShell{}
-
- for name, _ := range eggMap {
- eggShell, err := NewEggShell(cl)
- if err != nil {
- return nil, err
- }
- eggShell.FullName = name
-
- eggDef := cfg.GetStringMap("eggs." + name)
- eggShell.Version, err = NewVersParseString(eggDef["vers"].(string))
- if err != nil {
- return nil, err
- }
-
- eggShell.Deps, err = cl.strSliceToDr(
- cfg.GetStringSlice("eggs." + name + ".deps"))
- if err != nil {
- return nil, err
- }
-
- eggShell.Caps, err = cl.strSliceToDr(
- cfg.GetStringSlice("eggs." + name + ".caps"))
- if err != nil {
- return nil, err
- }
-
- eggShell.ReqCaps, err = cl.strSliceToDr(
- cfg.GetStringSlice("eggs." + name + ".req_caps"))
- if err != nil {
- return nil, err
- }
-
- eggList[name] = eggShell
- }
-
- return eggList, nil
-}
-
-// Create the manifest file name, it's the manifest dir + manifest name +
-// branch and a.yml extension
-func (clutch *Clutch) GetClutchFile(name string, branch string) string {
- return name + "@" + branch
-}
-
-func (clutch *Clutch) GetClutchFullFile(name string, branch string) string {
- return clutch.Nest.ClutchPath + clutch.GetClutchFile(name, branch) + ".yml"
-}
-
-func (clutch *Clutch) Load(name string) error {
- cfg, err := ReadConfig(clutch.Nest.ClutchPath, name)
- if err != nil {
- return err
- }
-
- clutchName := name
- branchName := "master"
-
- parts := strings.Split(name, "@")
- if len(parts) == 2 {
- clutchName = parts[0]
- branchName = parts[1]
- }
-
- if cfg.GetString("name") != clutchName {
- return NewNewtError(
- fmt.Sprintf("Wrong name %s in remote larva file (expected %s)",
- cfg.GetString("name"), clutchName))
- }
-
- clutch.Name = cfg.GetString("name")
- clutch.Branch = branchName
- clutch.RemoteUrl = cfg.GetString("url")
-
- clutch.EggShells, err = clutch.fileToEggList(cfg)
- if err != nil {
- return err
- }
-
- clutch.Nest.Clutches[name] = clutch
-
- return nil
-}
-
-func (cl *Clutch) Install(name string, url string, branch string) error {
- clutchFile := cl.GetClutchFullFile(name, branch)
-
- // XXX: Should warn if file already exists, and require force option
- os.Remove(clutchFile)
-
- // Download the manifest
- dl, err := NewDownloader()
- if err != nil {
- return err
- }
-
- StatusMessage(VERBOSITY_DEFAULT, "Downloading clutch.yml from %s/"+
- "%s...", url, branch)
-
- if err := dl.DownloadFile(url, branch, "clutch.yml",
- clutchFile); err != nil {
- return err
- }
-
- StatusMessage(VERBOSITY_DEFAULT, OK_STRING)
-
- // Load the manifest, and ensure that it is in the correct format
- StatusMessage(VERBOSITY_DEFAULT, "Verifying clutch.yml format...\n")
- if err := cl.Load(cl.GetClutchFile(name, branch)); err != nil {
- os.Remove(clutchFile)
- return err
- }
- StatusMessage(VERBOSITY_DEFAULT, OK_STRING)
-
- return nil
-}
-
-func (clutch *Clutch) InstallEgg(eggName string, branch string,
- downloaded []*RemoteNest) ([]*RemoteNest, error) {
- log.Print("[VERBOSE] Looking for ", eggName)
- egg, err := clutch.ResolveEggName(eggName)
- if err == nil {
- log.Printf("[VERBOSE] ", eggName, " installed already")
- return downloaded, nil
- }
- nest := clutch.Nest
- for _, remoteNest := range downloaded {
- egg, err = remoteNest.ResolveEggName(eggName)
- if err == nil {
- log.Print("[VERBOSE] ", eggName, " present in downloaded clutch ",
- remoteNest.Name)
-
- err = remoteNest.fetchEgg(eggName, nest.BasePath)
- if err != nil {
- return downloaded, err
- }
-
- // update local clutch
- err = clutch.loadEggDir(nest.BasePath, "", eggName)
- if err != nil {
- return downloaded, err
- }
-
- deps, err := egg.GetDependencies()
- if err != nil {
- return downloaded, err
- }
- for _, dep := range deps {
- log.Print("[VERBOSE] ", eggName, " checking dependency ",
- dep.Name)
- depBranch := dep.BranchName()
- downloaded, err = clutch.InstallEgg(dep.Name, depBranch,
- downloaded)
- if err != nil {
- return downloaded, err
- }
- }
- return downloaded, nil
- }
- }
-
- // Not in downloaded clutches
- clutches, err := nest.GetClutches()
- if err != nil {
- return downloaded, err
- }
- for _, remoteClutch := range clutches {
- eggShell, err := remoteClutch.ResolveEggShellName(eggName)
- if err == nil {
- log.Print("[VERBOSE] ", eggName, " present in remote clutch ",
- remoteClutch.Name, remoteClutch.Branch)
- if branch == "" {
- branch = remoteClutch.Branch
- }
- remoteNest, err := NewRemoteNest(remoteClutch, branch)
- if err != nil {
- return downloaded, err
- }
- downloaded = append(downloaded, remoteNest)
- return clutch.InstallEgg(eggShell.FullName, branch, downloaded)
- }
- }
-
- return downloaded, NewNewtError(fmt.Sprintf("No package %s found\n", eggName))
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/be14580e/newt/cli/egg.go
----------------------------------------------------------------------
diff --git a/newt/cli/egg.go b/newt/cli/egg.go
deleted file mode 100644
index 0012b64..0000000
--- a/newt/cli/egg.go
+++ /dev/null
@@ -1,788 +0,0 @@
-/*
- Copyright 2015 Runtime Inc.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-package cli
-
-import (
- "crypto/sha1"
- "fmt"
- "io/ioutil"
- "log"
- "os"
- "path/filepath"
- "regexp"
- "strconv"
- "strings"
-)
-
-type VersMatch struct {
- CompareType string
- Vers *Version
-}
-
-type Version struct {
- Major int64
- Minor int64
- Revision int64
-}
-
-type DependencyRequirement struct {
- Name string
- Stability string
- VersMatches []*VersMatch
-}
-
-type Egg struct {
- // Base directory of the egg
- BasePath string
- // Name of the egg
- Name string
- // Full Name of the egg include prefix dir
- FullName string
- // Nest this egg belongs to
- Nest *Nest
- // Egg version
- Version *Version
- // Type of egg
- LinkerScript string
-
- // For BSP egg, how to download
- DownloadScript string
- // For BSP egg, how to start debugger and attach it to target board
- DebugScript string
-
- // Has the dependencies been loaded for this egg
- DepLoaded bool
-
- // Has the configuration been loaded for this egg
- CfgLoaded bool
-
- // Egg sources
- Sources []string
- // Egg include directories
- Includes []string
-
- // Egg compiler flags
- Cflags string
-
- // Egg linker flags
- Lflags string
-
- // Egg assembler flags
- Aflags string
-
- // Whether or not this egg is a BSP
- IsBsp bool
-
- // Capabilities that this egg exports
- Capabilities []*DependencyRequirement
-
- // Capabilities that this egg requires
- ReqCapabilities []*DependencyRequirement
-
- // Whether or not we've already compiled this egg
- Built bool
-
- // Whether or not we've already cleaned this egg
- Clean bool
-
- // Eggs that this egg depends on
- Deps []*DependencyRequirement
-}
-
-type EggShell struct {
- FullName string
- Version *Version
- /* Clutch this eggshell belongs to */
- Clutch *Clutch
- Hash string
- Deps []*DependencyRequirement
- Caps []*DependencyRequirement
- ReqCaps []*DependencyRequirement
-}
-
-func NewEggShell(clutch *Clutch) (*EggShell, error) {
- eShell := &EggShell{
- Clutch: clutch,
- }
-
- return eShell, nil
-}
-
-func (es *EggShell) serializeDepReq(name string,
- drList []*DependencyRequirement, indent string) string {
- drStr := ""
- if len(drList) > 0 {
- drStr += fmt.Sprintf("%s%s:\n", indent, name)
- for _, dr := range drList {
- drStr += fmt.Sprintf("%s - %s\n", indent, dr)
- }
- }
-
- return drStr
-}
-
-func (es *EggShell) Serialize(indent string) string {
- esStr := fmt.Sprintf("%s%s:\n", indent, es.FullName)
- indent += " "
- if es.Version == nil {
- es.Version = &Version{0, 0, 0}
- }
- esStr += fmt.Sprintf("%svers: %s\n", indent, es.Version)
- esStr += fmt.Sprintf("%shash: %s\n", indent, es.Hash)
- esStr += es.serializeDepReq("deps", es.Deps, indent)
- esStr += es.serializeDepReq("caps", es.Caps, indent)
- esStr += es.serializeDepReq("req_caps", es.ReqCaps, indent)
-
- return esStr
-}
-
-func (v *Version) compareVersions(vers1 *Version, vers2 *Version) int64 {
- log.Printf("[DEBUG] Comparing %s to %s (%d %d %d)", vers1, vers2,
- vers1.Major-vers2.Major, vers1.Minor-vers2.Minor,
- vers1.Revision-vers2.Revision)
-
- if r := vers1.Major - vers2.Major; r != 0 {
- return r
- }
-
- if r := vers1.Minor - vers2.Minor; r != 0 {
- return r
- }
-
- if r := vers1.Revision - vers2.Revision; r != 0 {
- return r
- }
-
- return 0
-}
-
-func (v *Version) SatisfiesVersion(versMatches []*VersMatch) bool {
- if versMatches == nil {
- return true
- }
-
- for _, match := range versMatches {
- r := v.compareVersions(match.Vers, v)
- switch match.CompareType {
- case "<":
- if r <= 0 {
- return false
- }
- case "<=":
- if r < 0 {
- return false
- }
- case ">":
- if r >= 0 {
- return false
- }
- case ">=":
- if r > 0 {
- return false
- }
- case "==":
- if r != 0 {
- return false
- }
- }
- }
-
- return true
-}
-
-func (vers *Version) String() string {
- return fmt.Sprintf("%d.%d.%d", vers.Major, vers.Minor, vers.Revision)
-}
-
-func NewVersParseString(versStr string) (*Version, error) {
- var err error
-
- parts := strings.Split(versStr, ".")
- if len(parts) > 3 {
- return nil, NewNewtError(fmt.Sprintf("Invalid version string: %s", versStr))
- }
-
- if strings.Trim(parts[0], " ") == "" || strings.Trim(parts[0], " ") == "none" {
- return nil, nil
- }
-
- v := &Version{}
-
- // convert first string to an int
- if v.Major, err = strconv.ParseInt(parts[0], 0, 64); err != nil {
- return nil, NewNewtError(err.Error())
- }
- if len(parts) >= 2 {
- if v.Minor, err = strconv.ParseInt(parts[1], 0, 64); err != nil {
- return nil, NewNewtError(err.Error())
- }
- }
- if len(parts) == 3 {
- if v.Revision, err = strconv.ParseInt(parts[2], 0, 64); err != nil {
- return nil, NewNewtError(err.Error())
- }
- }
-
- return v, nil
-}
-
-//
-// Set the version comparison constraints on a dependency requirement.
-// The version string contains a list of version constraints in the following format:
-// - <comparison><version>
-// Where <comparison> can be any one of the following comparison
-// operators: <=, <, >, >=, ==
-// And <version> is specified in the form: X.Y.Z where X, Y and Z are all
-// int64 types in decimal form
-func (dr *DependencyRequirement) SetVersStr(versStr string) error {
- var err error
-
- re, err := regexp.Compile(`(<=|>=|==|>|<)([\d\.]+)`)
- if err != nil {
- return err
- }
-
- matches := re.FindAllStringSubmatch(versStr, -1)
- if matches != nil {
- dr.VersMatches = make([]*VersMatch, 0, len(matches))
- for _, match := range matches {
- vm := &VersMatch{}
- vm.CompareType = match[1]
- if vm.Vers, err = NewVersParseString(match[2]); err != nil {
- return err
- }
-
- if vm.Vers != nil {
- dr.VersMatches = append(dr.VersMatches, vm)
- }
- }
- } else {
- dr.VersMatches = make([]*VersMatch, 0)
- vm := &VersMatch{}
- vm.CompareType = "=="
- if vm.Vers, err = NewVersParseString(versStr); err != nil {
- return err
- }
- if vm.Vers != nil {
- dr.VersMatches = append(dr.VersMatches, vm)
- }
- }
-
- if len(dr.VersMatches) == 0 {
- dr.VersMatches = nil
- }
-
- return nil
-}
-
-// Convert the array of version matches into a string for display
-func (dr *DependencyRequirement) VersMatchesString() string {
- if dr.VersMatches != nil {
- str := ""
- for _, match := range dr.VersMatches {
- str += fmt.Sprintf("%s%s", match.CompareType, match.Vers)
- }
- return str
- } else {
- return "none"
- }
-}
-
-// Convert the dependency requirement to a string for display
-func (dr *DependencyRequirement) String() string {
- return fmt.Sprintf("%s@%s#%s", dr.Name, dr.VersMatchesString(), dr.Stability)
-}
-
-func (dr *DependencyRequirement) SatisfiesCapability(
- capability *DependencyRequirement) error {
- if dr.Name != capability.Name {
- return NewNewtError(fmt.Sprintf("Required capability name %s doesn't match "+
- "specified capability name %s", dr.Name, capability.Name))
- }
-
- for _, versMatch := range dr.VersMatches {
- if !versMatch.Vers.SatisfiesVersion(capability.VersMatches) {
- return NewNewtError(fmt.Sprintf("Capability %s doesn't satisfy version "+
- "requirement %s", capability, versMatch.Vers))
- }
- }
-
- return nil
-}
-
-// Check whether the passed in egg satisfies the current dependency requirement
-func (dr *DependencyRequirement) SatisfiesDependency(egg *Egg) bool {
- if egg.FullName != dr.Name {
- return false
- }
-
- if egg.Version.SatisfiesVersion(dr.VersMatches) {
- return true
- }
-
- return false
-}
-
-// Convert the dependency requirement to branch name to look for
-func (dr *DependencyRequirement) BranchName() string {
- if dr.Stability != "stable" {
- // XXX should compare to latest
- return dr.Stability
- }
- for _, versMatch := range dr.VersMatches {
- if versMatch.CompareType == "==" || versMatch.CompareType == "<=" {
- if versMatch.Vers.Minor == 0 && versMatch.Vers.Revision == 0 {
- return fmt.Sprintf("%d", versMatch.Vers.Major)
- } else if versMatch.Vers.Revision == 0 {
- return fmt.Sprintf("%d.%d", versMatch.Vers.Major,
- versMatch.Vers.Minor)
- } else {
- return fmt.Sprintf("%d.%d.%d", versMatch.Vers.Major,
- versMatch.Vers.Minor, versMatch.Vers.Revision)
- }
- }
- // XXX What to do with other version comparisons?
- }
- return "master"
-}
-
-// Create a New DependencyRequirement structure from the contents of the depReq
-// string that has been passed in as an argument.
-func NewDependencyRequirementParseString(depReq string) (*DependencyRequirement,
- error) {
- // Allocate dependency requirement
- dr := &DependencyRequirement{}
- // Split string into multiple parts, @#
- // first, get dependency name
- parts := strings.Split(depReq, "@")
- if len(parts) == 1 {
- parts = strings.Split(depReq, "#")
- dr.Name = parts[0]
- if len(parts) > 1 {
- dr.Stability = parts[1]
- } else {
- dr.Stability = "stable"
- }
- } else if len(parts) == 2 {
- dr.Name = parts[0]
- verParts := strings.Split(parts[1], "#")
-
- if err := dr.SetVersStr(verParts[0]); err != nil {
- return nil, err
- }
- if len(verParts) == 2 {
- dr.Stability = verParts[1]
- } else {
- dr.Stability = "stable"
- }
- }
-
- return dr, nil
-}
-
-// Get a map of egg capabilities. The returned map contains the name of the
-// capability, and its version as the key, and a pointer to the
-// Capability structure associated with that name.
-func (egg *Egg) GetCapabilities() ([]*DependencyRequirement, error) {
- return egg.Capabilities, nil
-}
-
-// Return the egg dependencies for this egg.
-func (egg *Egg) GetDependencies() ([]*DependencyRequirement, error) {
- return egg.Deps, nil
-}
-
-func (egg *Egg) GetReqCapabilities() ([]*DependencyRequirement, error) {
- return egg.ReqCapabilities, nil
-}
-
-func (eggShell *EggShell) GetCapabilities() ([]*DependencyRequirement, error) {
- return eggShell.Caps, nil
-}
-
-// Return the egg dependencies for this eggShell.
-func (eggShell *EggShell) GetDependencies() ([]*DependencyRequirement, error) {
- return eggShell.Deps, nil
-}
-
-func (eggShell *EggShell) GetReqCapabilities() ([]*DependencyRequirement, error) {
- return eggShell.ReqCaps, nil
-}
-
-// Load a egg's configuration information from the egg config
-// file.
-func (egg *Egg) GetIncludes(t *Target) ([]string, error) {
- // Return the include directories for just this egg
- incls := []string{
- egg.BasePath + "/include/",
- egg.BasePath + "/include/" + egg.Name + "/arch/" + t.Arch + "/",
- }
-
- return incls, nil
-}
-
-// Load capabilities from a string containing a list of capabilities.
-// The capability format is expected to be one of:
-// name@version
-// name
-// @param capList An array of capability strings
-// @return On success error is nil, and a list of capabilities is returned,
-// on failure error is non-nil
-func (egg *Egg) loadCaps(capList []string) ([]*DependencyRequirement, error) {
- if len(capList) == 0 {
- return nil, nil
- }
-
- // Allocate an array of capabilities
- caps := make([]*DependencyRequirement, 0)
-
- StatusMessage(VERBOSITY_VERBOSE, "Loading capabilities %s\n",
- strings.Join(capList, " "))
- for _, capItem := range capList {
- dr, err := NewDependencyRequirementParseString(capItem)
- if err != nil {
- return nil, err
- }
-
- caps = append(caps, dr)
- log.Printf("[DEBUG] Appending new capability egg: %s, cap:%s",
- egg.Name, dr)
- }
-
- return caps, nil
-}
-
-// Create a dependency requirement out of an egg
-//
-func (egg *Egg) MakeDependency() (*DependencyRequirement, error) {
- return NewDependencyRequirementParseString(egg.FullName)
-}
-
-// Generate a hash of the contents of an egg. This function recursively
-// processes the contents of a directory, ignoring hidden files and the
-// bin and obj directories. It returns a hash of all the files, their
-// contents.
-func (egg *Egg) GetHash() (string, error) {
- hash := sha1.New()
-
- err := filepath.Walk(egg.BasePath,
- func(path string, info os.FileInfo, err error) error {
- name := info.Name()
- if name == "bin" || name == "obj" || name[0] == '.' {
- return filepath.SkipDir
- }
-
- if info.IsDir() {
- // SHA the directory name into the hash
- hash.Write([]byte(name))
- } else {
- // SHA the file name & contents into the hash
- contents, err := ioutil.ReadFile(path)
- if err != nil {
- return err
- }
- hash.Write(contents)
- }
- return nil
- })
- if err != nil && err != filepath.SkipDir {
- return "", NewNewtError(err.Error())
- }
-
- hashStr := fmt.Sprintf("%x", hash.Sum(nil))
-
- return hashStr, nil
-}
-
-// Load egg's configuration, and collect required capabilities, dependencies, and
-// identities it provides, so we'll have this available when target is being built.
-func (egg *Egg) LoadDependencies(identities map[string]string,
- capabilities map[string]string) error {
-
- if egg.DepLoaded {
- return nil
- }
-
- log.Printf("[DEBUG] Loading dependencies for egg %s", egg.BasePath)
-
- v, err := ReadConfig(egg.BasePath, "egg")
- if err != nil {
- return err
- }
-
- // Append all identities that this egg exposes.
- idents := GetStringSliceIdentities(v, identities, "egg.identities")
-
- // Add these to project identities
- for _, item := range idents {
- StatusMessage(VERBOSITY_VERBOSE, " Adding identity %s - %s\n", item,
- egg.FullName)
- identities[item] = egg.FullName
- }
-
- // Load the list of capabilities that this egg exposes
- egg.Capabilities, err = egg.loadCaps(GetStringSliceIdentities(v, identities,
- "egg.caps"))
- if err != nil {
- return err
- }
-
- // Add these to project capabilities
- for _, cap := range egg.Capabilities {
- if capabilities[cap.String()] != "" &&
- capabilities[cap.String()] != egg.FullName {
-
- return NewNewtError(fmt.Sprintf("Multiple eggs with "+
- "capability %s (%s and %s)",
- cap.String(), capabilities[cap.String()], egg.FullName))
- }
- capabilities[cap.String()] = egg.FullName
- StatusMessage(VERBOSITY_VERBOSE, " Adding capability %s - %s\n",
- cap.String(), egg.FullName)
- }
-
- // Load the list of capabilities that this egg requires
- egg.ReqCapabilities, err = egg.loadCaps(GetStringSliceIdentities(v, identities,
- "egg.req_caps"))
- if err != nil {
- return err
- }
-
- // Load egg dependencies
- depList := GetStringSliceIdentities(v, identities, "egg.deps")
- if len(depList) > 0 {
- egg.Deps = make([]*DependencyRequirement, 0, len(depList))
- for _, depStr := range depList {
- log.Printf("[DEBUG] Loading dependency %s from egg %s", depStr,
- egg.FullName)
- dr, err := NewDependencyRequirementParseString(depStr)
- if err != nil {
- return err
- }
-
- egg.Deps = append(egg.Deps, dr)
- }
- }
- for _, cap := range egg.ReqCapabilities {
- eggName := capabilities[cap.String()]
- if eggName == "" {
- continue
- }
- dr, err := NewDependencyRequirementParseString(eggName)
- if err != nil {
- return err
- }
- egg.Deps = append(egg.Deps, dr)
- }
-
- eggName := identities["LIBC"]
- if eggName != "" {
- dr, err := NewDependencyRequirementParseString(eggName)
- if err != nil {
- return err
- }
- egg.Deps = append(egg.Deps, dr)
- }
-
- // Check these as well
- egg.LinkerScript = GetStringIdentities(v, identities, "egg.linkerscript")
- egg.DownloadScript = GetStringIdentities(v, identities, "egg.downloadscript")
- egg.DebugScript = GetStringIdentities(v, identities, "egg.debugscript")
-
- egg.Cflags = ""
- cflags := GetStringSliceIdentities(v, identities, "egg.cflags")
- for _, name := range cflags {
- egg.Cflags += " " + name
- }
- egg.Lflags = GetStringIdentities(v, identities, "egg.lflags")
- egg.Aflags = GetStringIdentities(v, identities, "egg.aflags")
-
- egg.DepLoaded = true
-
- return nil
-}
-
-// Collect identities and capabilities that egg and it's dependencies provide
-func (egg *Egg) collectDependencies(clutch *Clutch,
- identities map[string]string,
- capabilities map[string]string) error {
-
- if egg.DepLoaded {
- return nil
- }
-
- StatusMessage(VERBOSITY_VERBOSE, " Collecting egg %s dependencies\n", egg.Name)
-
- err := egg.LoadDependencies(identities, capabilities)
- if err != nil {
- return err
- }
-
- for _, dep := range egg.Deps {
- egg, err := clutch.ResolveEggName(dep.Name)
- if err != nil {
- return err
- }
- err = egg.collectDependencies(clutch, identities, capabilities)
- if err != nil {
- return err
- }
- }
- return nil
-}
-
-// Clear the var which says that dependencies have been checked for this egg and
-// it's dependencies
-func (egg *Egg) clearDependencyMarker(clutch *Clutch) {
-
- if egg.DepLoaded == false {
- return
- }
- egg.DepLoaded = false
-
- for _, dep := range egg.Deps {
- egg, err := clutch.ResolveEggName(dep.Name)
- if err == nil {
- egg.clearDependencyMarker(clutch)
- }
- }
-}
-
-// Load a egg's configuration. This allocates & initializes a fair number of
-// the main data structures within the egg.
-func (egg *Egg) LoadConfig(t *Target, force bool) error {
- if egg.CfgLoaded && !force {
- return nil
- }
-
- log.Printf("[DEBUG] Loading configuration for egg %s", egg.BasePath)
-
- v, err := ReadConfig(egg.BasePath, "egg")
- if err != nil {
- return err
- }
-
- egg.FullName = v.GetString("egg.name")
- egg.Name = filepath.Base(egg.FullName)
-
- egg.Version, err = NewVersParseString(v.GetString("egg.vers"))
- if err != nil {
- return err
- }
-
- // Append all the identities that this egg exposes to sub-eggs. This must
- // be done before the remainder of the settings, as some settings depend on
- // identity.
- identities := map[string]string{}
- if t != nil {
- identities = t.Identities;
- idents := GetStringSliceIdentities(v, identities, "egg.identities")
- for _, item := range idents {
- identities[item] = egg.FullName;
- }
- }
-
- egg.LinkerScript = GetStringIdentities(v, identities, "egg.linkerscript")
- egg.DownloadScript = GetStringIdentities(v, identities, "egg.downloadscript")
- egg.DebugScript = GetStringIdentities(v, identities, "egg.debugscript")
-
- egg.Cflags += GetStringIdentities(v, identities, "egg.cflags")
- egg.Lflags += GetStringIdentities(v, identities, "egg.lflags")
- egg.Aflags += GetStringIdentities(v, identities, "egg.aflags")
-
- // Load egg dependencies
- depList := GetStringSliceIdentities(v, identities, "egg.deps")
- if len(depList) > 0 {
- egg.Deps = make([]*DependencyRequirement, 0, len(depList))
- for _, depStr := range depList {
- log.Printf("[DEBUG] Loading dependency %s from egg %s", depStr,
- egg.FullName)
- dr, err := NewDependencyRequirementParseString(depStr)
- if err != nil {
- return err
- }
-
- egg.Deps = append(egg.Deps, dr)
- }
- }
-
- // Load the list of capabilities that this egg exposes
- egg.Capabilities, err = egg.loadCaps(GetStringSliceIdentities(v, identities,
- "egg.caps"))
- if err != nil {
- return err
- }
-
- // Load the list of capabilities that this egg requires
- egg.ReqCapabilities, err = egg.loadCaps(GetStringSliceIdentities(v, identities,
- "egg.req_caps"))
- if err != nil {
- return err
- }
- if len(egg.ReqCapabilities) > 0 {
- for _, reqStr := range egg.ReqCapabilities {
- log.Printf("[DEBUG] Loading reqCap %s from egg %s", reqStr,
- egg.FullName)
- }
- }
- egg.CfgLoaded = true
-
- return nil
-}
-
-// Initialize a egg: loads the egg configuration, and sets up egg data
-// structures. Should only be called from NewEgg
-func (egg *Egg) Init() error {
- return nil
-}
-
-// Allocate and initialize a new egg, and return a fully initialized Egg
-// structure.
-// @param nest The Nest this egg is located in
-// @param basePath The path to this egg, within the specified nest
-// @return On success, error is nil, and a Egg is returned. on failure,
-// error is not nil.
-func NewEgg(nest *Nest, basePath string) (*Egg, error) {
- egg := &Egg{
- BasePath: basePath,
- Nest: nest,
- }
-
- if err := egg.Init(); err != nil {
- return nil, err
- }
-
- return egg, nil
-}
-
-func (egg *Egg) TestBinName() string {
- return "test_" + egg.Name
-}
-
-/*
- * Download egg from a clutch and stick it to nest.
- */
-func (eggShell *EggShell) Install(eggMgr *Clutch, branch string) error {
- downloaded, err := eggMgr.InstallEgg(eggShell.FullName, branch, nil)
- for _, remoteNest := range downloaded {
- remoteNest.Remove()
- }
- return err
-}
-
-func (egg *Egg) Remove() error {
- return os.RemoveAll(egg.BasePath)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/be14580e/newt/cli/nest.go
----------------------------------------------------------------------
diff --git a/newt/cli/nest.go b/newt/cli/nest.go
deleted file mode 100644
index abc2bce..0000000
--- a/newt/cli/nest.go
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- Copyright 2015 Runtime Inc.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-package cli
-
-import (
- "database/sql"
- "fmt"
- _ "github.com/mattn/go-sqlite3"
- "io/ioutil"
- "log"
- "os"
- "path"
- "path/filepath"
-)
-
-type Nest struct {
- // Name of the Nest
- Name string
-
- // Path to the Nest Store
- StorePath string
-
- // Path to the Nest Clutches
- ClutchPath string
-
- // Nest File
- NestFile string
-
- // Base path of the nest
- BasePath string
-
- // Store of Clutches
- Clutches map[string]*Clutch
-
- // Configuration
- Config map[string]map[string]string
-
- // The database handle for the nest configuration database
- db *sql.DB
-}
-
-// Create a new Nest object and initialize it
-func NewNest() (*Nest, error) {
- n := &Nest{}
-
- err := n.Init()
- if err != nil {
- return nil, err
- }
-
- return n, nil
-}
-
-// Create a Nest object constructed out of repo in given path
-func NewNestWithDir(srcDir string) (*Nest, error) {
- n := &Nest{}
-
- err := n.InitPath(srcDir)
- if err != nil {
- return nil, err
- }
-
- return n, nil
-}
-
-func CreateNest(nestName string, destDir string, tadpoleUrl string) error {
- if tadpoleUrl == "" {
- tadpoleUrl = "https://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole.git"
- }
-
- if NodeExist(destDir) {
- return NewNewtError(fmt.Sprintf("Directory %s already exists, "+
- " cannot create new newt nest", destDir))
- }
-
- dl, err := NewDownloader()
- if err != nil {
- return err
- }
-
- StatusMessage(VERBOSITY_DEFAULT, "Downloading nest skeleton from %s...",
- tadpoleUrl)
- if err := dl.DownloadFile(tadpoleUrl, "master", "/",
- destDir); err != nil {
- return err
- }
- StatusMessage(VERBOSITY_DEFAULT, OK_STRING)
-
- // Overwrite nest.yml
- contents := []byte(fmt.Sprintf("nest.name: %s\n", nestName))
- if err := ioutil.WriteFile(destDir+"/nest.yml",
- contents, 0644); err != nil {
- return NewNewtError(err.Error())
- }
-
- // DONE!
-
- return nil
-}
-
-// Get a temporary directory to stick stuff in
-func (nest *Nest) GetTmpDir(dirName string, prefix string) (string, error) {
- tmpDir := dirName
- if NodeNotExist(tmpDir) {
- if err := os.MkdirAll(tmpDir, 0700); err != nil {
- return "", err
- }
- }
-
- name, err := ioutil.TempDir(tmpDir, prefix)
- if err != nil {
- return "", err
- }
-
- return name, nil
-}
-
-// Find the repo file. Searches the current directory, and then recurses
-// parent directories until it finds a file named .repo.yml
-// if no repo file found in the directory heirarchy, an error is returned
-func (nest *Nest) getNestFile() (string, error) {
- rFile := ""
-
- curDir, err := os.Getwd()
- if err != nil {
- return rFile, NewNewtError(err.Error())
- }
-
- for {
- rFile = curDir + "/nest.yml"
- log.Printf("[DEBUG] Searching for nest file at %s", rFile)
- if _, err := os.Stat(rFile); err == nil {
- log.Printf("[DEBUG] Found nest file at %s!", rFile)
- break
- }
-
- curDir = path.Clean(curDir + "../../")
- if curDir == "/" {
- rFile = ""
- err = NewNewtError("No repo file found!")
- break
- }
- }
-
- return rFile, err
-}
-
-// Create the contents of the configuration database
-func (nest *Nest) createDb(db *sql.DB) error {
- query := `
- CREATE TABLE IF NOT EXISTS newt_cfg (
- cfg_name VARCHAR(255) NOT NULL,
- key VARCHAR(255) NOT NULL,
- value TEXT
- )
- `
- _, err := db.Exec(query)
- if err != nil {
- return NewNewtError(err.Error())
- } else {
- return nil
- }
-}
-
-// Initialize the configuration database specified by dbName. If the database
-// doesn't exist, create it.
-func (nest *Nest) initDb(dbName string) error {
- db, err := sql.Open("sqlite3", dbName)
- if err != nil {
- return err
- }
- nest.db = db
-
- err = nest.createDb(db)
- if err != nil {
- return err
- }
-
- // Populate repo configuration
- log.Printf("[DEBUG] Populating Nest configuration from %s", dbName)
-
- rows, err := db.Query("SELECT * FROM newt_cfg")
- if err != nil {
- return NewNewtError(err.Error())
- }
- defer rows.Close()
-
- for rows.Next() {
- var cfgName sql.NullString
- var cfgKey sql.NullString
- var cfgVal sql.NullString
-
- err := rows.Scan(&cfgName, &cfgKey, &cfgVal)
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- log.Printf("[DEBUG] Setting sect %s, key %s to val %s", cfgName.String,
- cfgKey.String, cfgVal.String)
-
- _, ok := nest.Config[cfgName.String]
- if !ok {
- nest.Config[cfgName.String] = make(map[string]string)
- }
-
- nest.Config[cfgName.String][cfgKey.String] = cfgVal.String
- }
-
- return nil
-}
-
-// Get a configuration variable in section sect, with key
-// error is populated if variable doesn't exist
-func (nest *Nest) GetConfig(sect string, key string) (string, error) {
- sectMap, ok := nest.Config[sect]
- if !ok {
- return "", NewNewtError("No configuration section exists")
- }
-
- val, ok := sectMap[key]
- if !ok {
- return "", NewNewtError("No configuration variable exists")
- }
-
- return val, nil
-}
-
-func (nest *Nest) GetConfigSect(sect string) (map[string]string, error) {
- sm, ok := nest.Config[sect]
- if !ok {
- return nil, NewNewtError("No configuration section exists")
- }
-
- return sm, nil
-}
-
-// Delete a configuration variable in section sect with key and val
-// Returns an error if configuration variable cannot be deleted
-// (most likely due to database error or key not existing)
-func (nest *Nest) DelConfig(sect string, key string) error {
- db := nest.db
-
- log.Printf("[DEBUG] Deleting sect %s, key %s", sect, key)
-
- tx, err := db.Begin()
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- stmt, err := tx.Prepare("DELETE FROM newt_cfg WHERE cfg_name=? AND key=?")
- if err != nil {
- return err
- }
- defer stmt.Close()
-
- res, err := stmt.Exec(sect, key)
- if err != nil {
- return err
- }
-
- tx.Commit()
-
- if affected, err := res.RowsAffected(); affected > 0 && err == nil {
- log.Printf("[DEBUG] sect %s, key %s successfully deleted from database",
- sect, key)
- } else {
- log.Printf("[DEBUG] sect %s, key %s not found, considering \"delete\" successful",
- sect, key)
- }
-
- return nil
-}
-
-// Set a configuration variable in section sect with key, and val
-// Returns an error if configuration variable cannot be set
-// (most likely not able to set it in database.)
-func (nest *Nest) SetConfig(sect string, key string, val string) error {
- _, ok := nest.Config[sect]
- if !ok {
- nest.Config[sect] = make(map[string]string)
- }
- nest.Config[sect][key] = val
-
- // Store config
- log.Printf("[DEBUG] Storing value %s into key %s for section %s",
- val, sect, key)
- db := nest.db
-
- tx, err := db.Begin()
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- stmt, err := tx.Prepare(
- "UPDATE newt_cfg SET value=? WHERE cfg_name=? AND key=?")
- if err != nil {
- return NewNewtError(err.Error())
- }
- defer stmt.Close()
-
- res, err := stmt.Exec(val, sect, key)
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- // Value already existed, and we updated it. Mission accomplished!
- // Exit
- if affected, err := res.RowsAffected(); affected > 0 && err == nil {
- tx.Commit()
- log.Printf("[DEBUG] Key %s, sect %s successfully updated to %s", key, sect, val)
- return nil
- }
-
- // Otherwise, insert a new row
- stmt1, err := tx.Prepare("INSERT INTO newt_cfg VALUES (?, ?, ?)")
- if err != nil {
- return NewNewtError(err.Error())
- }
- defer stmt1.Close()
-
- _, err = stmt1.Exec(sect, key, val)
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- tx.Commit()
-
- log.Printf("[DEBUG] Key %s, sect %s successfully create, value set to %s",
- key, sect, val)
-
- return nil
-}
-
-// Load the repo configuration file
-func (nest *Nest) loadConfig() error {
- v, err := ReadConfig(nest.BasePath, "nest")
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- nest.Name = v.GetString("nest.name")
- if nest.Name == "" {
- return NewNewtError("Nest file must specify nest name")
- }
-
- return nil
-}
-
-func (nest *Nest) LoadClutches() error {
- files, err := ioutil.ReadDir(nest.ClutchPath)
- if err != nil {
- return err
- }
- for _, fileInfo := range files {
- file := fileInfo.Name()
- if filepath.Ext(file) == ".yml" {
- name := file[:len(filepath.Base(file))-len(".yml")]
- log.Printf("[DEBUG] Loading Clutch %s", name)
- clutch, err := NewClutch(nest)
- if err != nil {
- return err
- }
- if err := clutch.Load(name); err != nil {
- return err
- }
- }
- }
- return nil
-}
-
-func (nest *Nest) InitPath(nestPath string) error {
- cwd, err := os.Getwd()
- if err != nil {
- return NewNewtError(err.Error())
- }
-
- if err = os.Chdir(nestPath); err != nil {
- return NewNewtError(err.Error())
- }
-
- log.Printf("[DEBUG] Searching for repository, starting in directory %s", cwd)
-
- if nest.NestFile, err = nest.getNestFile(); err != nil {
- return err
- }
-
- log.Printf("[DEBUG] Nest file found, directory %s, loading configuration...",
- nest.NestFile)
-
- nest.BasePath = filepath.ToSlash(path.Dir(nest.NestFile))
-
- if err = nest.loadConfig(); err != nil {
- return err
- }
-
- if err = os.Chdir(cwd); err != nil {
- return NewNewtError(err.Error())
- }
- return nil
-}
-
-// Initialze the repository
-// returns a NewtError on failure, and nil on success
-func (nest *Nest) Init() error {
- var err error
-
- cwd, err := os.Getwd()
- if err != nil {
- return NewNewtError(err.Error())
- }
- if err := nest.InitPath(cwd); err != nil {
- return err
- }
-
- log.Printf("[DEBUG] Configuration loaded! Initializing .nest database")
-
- // Create Nest store directory
- nest.StorePath = nest.BasePath + "/.nest/"
- if NodeNotExist(nest.StorePath) {
- if err := os.MkdirAll(nest.StorePath, 0755); err != nil {
- return NewNewtError(err.Error())
- }
- }
-
- // Create Nest configuration database
- nest.Config = make(map[string]map[string]string)
-
- dbName := nest.StorePath + "/nest.db"
- if err := nest.initDb(dbName); err != nil {
- return err
- }
-
- log.Printf("[DEBUG] Database initialized.")
-
- // Load Clutches for the current Nest
- nest.ClutchPath = nest.StorePath + "/clutches/"
- if NodeNotExist(nest.ClutchPath) {
- if err := os.MkdirAll(nest.ClutchPath, 0755); err != nil {
- return NewNewtError(err.Error())
- }
- }
-
- nest.Clutches = map[string]*Clutch{}
-
- if err := nest.LoadClutches(); err != nil {
- return err
- }
-
- return nil
-}
-
-func (nest *Nest) GetClutches() (map[string]*Clutch, error) {
- return nest.Clutches, nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/be14580e/newt/cli/pkg.go
----------------------------------------------------------------------
diff --git a/newt/cli/pkg.go b/newt/cli/pkg.go
new file mode 100644
index 0000000..95a6c42
--- /dev/null
+++ b/newt/cli/pkg.go
@@ -0,0 +1,788 @@
+/*
+ Copyright 2015 Runtime Inc.
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package cli
+
+import (
+ "crypto/sha1"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "os"
+ "path/filepath"
+ "regexp"
+ "strconv"
+ "strings"
+)
+
+type VersMatch struct {
+ CompareType string
+ Vers *Version
+}
+
+type Version struct {
+ Major int64
+ Minor int64
+ Revision int64
+}
+
+type DependencyRequirement struct {
+ Name string
+ Stability string
+ VersMatches []*VersMatch
+}
+
+type Pkg struct {
+ // Base directory of the pkg
+ BasePath string
+ // Name of the pkg
+ Name string
+ // Full Name of the pkg include prefix dir
+ FullName string
+ // Repo this pkg belongs to
+ Repo *Repo
+ // Pkg version
+ Version *Version
+ // Type of pkg
+ LinkerScript string
+
+ // For BSP pkg, how to download
+ DownloadScript string
+ // For BSP pkg, how to start debugger and attach it to target board
+ DebugScript string
+
+ // Has the dependencies been loaded for this pkg
+ DepLoaded bool
+
+ // Has the configuration been loaded for this pkg
+ CfgLoaded bool
+
+ // Pkg sources
+ Sources []string
+ // Pkg include directories
+ Includes []string
+
+ // Pkg compiler flags
+ Cflags string
+
+ // Pkg linker flags
+ Lflags string
+
+ // Pkg assembler flags
+ Aflags string
+
+ // Whether or not this pkg is a BSP
+ IsBsp bool
+
+ // Capabilities that this pkg exports
+ Capabilities []*DependencyRequirement
+
+ // Capabilities that this pkg requires
+ ReqCapabilities []*DependencyRequirement
+
+ // Whether or not we've already compiled this pkg
+ Built bool
+
+ // Whether or not we've already cleaned this pkg
+ Clean bool
+
+ // Pkgs that this pkg depends on
+ Deps []*DependencyRequirement
+}
+
+type PkgDesc struct {
+ FullName string
+ Version *Version
+ /* PkgList this pkgshell belongs to */
+ PkgList *PkgList
+ Hash string
+ Deps []*DependencyRequirement
+ Caps []*DependencyRequirement
+ ReqCaps []*DependencyRequirement
+}
+
+func NewPkgDesc(pkgList *PkgList) (*PkgDesc, error) {
+ eShell := &PkgDesc{
+ PkgList: pkgList,
+ }
+
+ return eShell, nil
+}
+
+func (es *PkgDesc) serializeDepReq(name string,
+ drList []*DependencyRequirement, indent string) string {
+ drStr := ""
+ if len(drList) > 0 {
+ drStr += fmt.Sprintf("%s%s:\n", indent, name)
+ for _, dr := range drList {
+ drStr += fmt.Sprintf("%s - %s\n", indent, dr)
+ }
+ }
+
+ return drStr
+}
+
+func (es *PkgDesc) Serialize(indent string) string {
+ esStr := fmt.Sprintf("%s%s:\n", indent, es.FullName)
+ indent += " "
+ if es.Version == nil {
+ es.Version = &Version{0, 0, 0}
+ }
+ esStr += fmt.Sprintf("%svers: %s\n", indent, es.Version)
+ esStr += fmt.Sprintf("%shash: %s\n", indent, es.Hash)
+ esStr += es.serializeDepReq("deps", es.Deps, indent)
+ esStr += es.serializeDepReq("caps", es.Caps, indent)
+ esStr += es.serializeDepReq("req_caps", es.ReqCaps, indent)
+
+ return esStr
+}
+
+func (v *Version) compareVersions(vers1 *Version, vers2 *Version) int64 {
+ log.Printf("[DEBUG] Comparing %s to %s (%d %d %d)", vers1, vers2,
+ vers1.Major-vers2.Major, vers1.Minor-vers2.Minor,
+ vers1.Revision-vers2.Revision)
+
+ if r := vers1.Major - vers2.Major; r != 0 {
+ return r
+ }
+
+ if r := vers1.Minor - vers2.Minor; r != 0 {
+ return r
+ }
+
+ if r := vers1.Revision - vers2.Revision; r != 0 {
+ return r
+ }
+
+ return 0
+}
+
+func (v *Version) SatisfiesVersion(versMatches []*VersMatch) bool {
+ if versMatches == nil {
+ return true
+ }
+
+ for _, match := range versMatches {
+ r := v.compareVersions(match.Vers, v)
+ switch match.CompareType {
+ case "<":
+ if r <= 0 {
+ return false
+ }
+ case "<=":
+ if r < 0 {
+ return false
+ }
+ case ">":
+ if r >= 0 {
+ return false
+ }
+ case ">=":
+ if r > 0 {
+ return false
+ }
+ case "==":
+ if r != 0 {
+ return false
+ }
+ }
+ }
+
+ return true
+}
+
+func (vers *Version) String() string {
+ return fmt.Sprintf("%d.%d.%d", vers.Major, vers.Minor, vers.Revision)
+}
+
+func NewVersParseString(versStr string) (*Version, error) {
+ var err error
+
+ parts := strings.Split(versStr, ".")
+ if len(parts) > 3 {
+ return nil, NewNewtError(fmt.Sprintf("Invalid version string: %s", versStr))
+ }
+
+ if strings.Trim(parts[0], " ") == "" || strings.Trim(parts[0], " ") == "none" {
+ return nil, nil
+ }
+
+ v := &Version{}
+
+ // convert first string to an int
+ if v.Major, err = strconv.ParseInt(parts[0], 0, 64); err != nil {
+ return nil, NewNewtError(err.Error())
+ }
+ if len(parts) >= 2 {
+ if v.Minor, err = strconv.ParseInt(parts[1], 0, 64); err != nil {
+ return nil, NewNewtError(err.Error())
+ }
+ }
+ if len(parts) == 3 {
+ if v.Revision, err = strconv.ParseInt(parts[2], 0, 64); err != nil {
+ return nil, NewNewtError(err.Error())
+ }
+ }
+
+ return v, nil
+}
+
+//
+// Set the version comparison constraints on a dependency requirement.
+// The version string contains a list of version constraints in the following format:
+// - <comparison><version>
+// Where <comparison> can be any one of the following comparison
+// operators: <=, <, >, >=, ==
+// And <version> is specified in the form: X.Y.Z where X, Y and Z are all
+// int64 types in decimal form
+func (dr *DependencyRequirement) SetVersStr(versStr string) error {
+ var err error
+
+ re, err := regexp.Compile(`(<=|>=|==|>|<)([\d\.]+)`)
+ if err != nil {
+ return err
+ }
+
+ matches := re.FindAllStringSubmatch(versStr, -1)
+ if matches != nil {
+ dr.VersMatches = make([]*VersMatch, 0, len(matches))
+ for _, match := range matches {
+ vm := &VersMatch{}
+ vm.CompareType = match[1]
+ if vm.Vers, err = NewVersParseString(match[2]); err != nil {
+ return err
+ }
+
+ if vm.Vers != nil {
+ dr.VersMatches = append(dr.VersMatches, vm)
+ }
+ }
+ } else {
+ dr.VersMatches = make([]*VersMatch, 0)
+ vm := &VersMatch{}
+ vm.CompareType = "=="
+ if vm.Vers, err = NewVersParseString(versStr); err != nil {
+ return err
+ }
+ if vm.Vers != nil {
+ dr.VersMatches = append(dr.VersMatches, vm)
+ }
+ }
+
+ if len(dr.VersMatches) == 0 {
+ dr.VersMatches = nil
+ }
+
+ return nil
+}
+
+// Convert the array of version matches into a string for display
+func (dr *DependencyRequirement) VersMatchesString() string {
+ if dr.VersMatches != nil {
+ str := ""
+ for _, match := range dr.VersMatches {
+ str += fmt.Sprintf("%s%s", match.CompareType, match.Vers)
+ }
+ return str
+ } else {
+ return "none"
+ }
+}
+
+// Convert the dependency requirement to a string for display
+func (dr *DependencyRequirement) String() string {
+ return fmt.Sprintf("%s@%s#%s", dr.Name, dr.VersMatchesString(), dr.Stability)
+}
+
+func (dr *DependencyRequirement) SatisfiesCapability(
+ capability *DependencyRequirement) error {
+ if dr.Name != capability.Name {
+ return NewNewtError(fmt.Sprintf("Required capability name %s doesn't match "+
+ "specified capability name %s", dr.Name, capability.Name))
+ }
+
+ for _, versMatch := range dr.VersMatches {
+ if !versMatch.Vers.SatisfiesVersion(capability.VersMatches) {
+ return NewNewtError(fmt.Sprintf("Capability %s doesn't satisfy version "+
+ "requirement %s", capability, versMatch.Vers))
+ }
+ }
+
+ return nil
+}
+
+// Check whether the passed in pkg satisfies the current dependency requirement
+func (dr *DependencyRequirement) SatisfiesDependency(pkg *Pkg) bool {
+ if pkg.FullName != dr.Name {
+ return false
+ }
+
+ if pkg.Version.SatisfiesVersion(dr.VersMatches) {
+ return true
+ }
+
+ return false
+}
+
+// Convert the dependency requirement to branch name to look for
+func (dr *DependencyRequirement) BranchName() string {
+ if dr.Stability != "stable" {
+ // XXX should compare to latest
+ return dr.Stability
+ }
+ for _, versMatch := range dr.VersMatches {
+ if versMatch.CompareType == "==" || versMatch.CompareType == "<=" {
+ if versMatch.Vers.Minor == 0 && versMatch.Vers.Revision == 0 {
+ return fmt.Sprintf("%d", versMatch.Vers.Major)
+ } else if versMatch.Vers.Revision == 0 {
+ return fmt.Sprintf("%d.%d", versMatch.Vers.Major,
+ versMatch.Vers.Minor)
+ } else {
+ return fmt.Sprintf("%d.%d.%d", versMatch.Vers.Major,
+ versMatch.Vers.Minor, versMatch.Vers.Revision)
+ }
+ }
+ // XXX What to do with other version comparisons?
+ }
+ return "master"
+}
+
+// Create a New DependencyRequirement structure from the contents of the depReq
+// string that has been passed in as an argument.
+func NewDependencyRequirementParseString(depReq string) (*DependencyRequirement,
+ error) {
+ // Allocate dependency requirement
+ dr := &DependencyRequirement{}
+ // Split string into multiple parts, @#
+ // first, get dependency name
+ parts := strings.Split(depReq, "@")
+ if len(parts) == 1 {
+ parts = strings.Split(depReq, "#")
+ dr.Name = parts[0]
+ if len(parts) > 1 {
+ dr.Stability = parts[1]
+ } else {
+ dr.Stability = "stable"
+ }
+ } else if len(parts) == 2 {
+ dr.Name = parts[0]
+ verParts := strings.Split(parts[1], "#")
+
+ if err := dr.SetVersStr(verParts[0]); err != nil {
+ return nil, err
+ }
+ if len(verParts) == 2 {
+ dr.Stability = verParts[1]
+ } else {
+ dr.Stability = "stable"
+ }
+ }
+
+ return dr, nil
+}
+
+// Get a map of pkg capabilities. The returned map contains the name of the
+// capability, and its version as the key, and a pointer to the
+// Capability structure associated with that name.
+func (pkg *Pkg) GetCapabilities() ([]*DependencyRequirement, error) {
+ return pkg.Capabilities, nil
+}
+
+// Return the pkg dependencies for this pkg.
+func (pkg *Pkg) GetDependencies() ([]*DependencyRequirement, error) {
+ return pkg.Deps, nil
+}
+
+func (pkg *Pkg) GetReqCapabilities() ([]*DependencyRequirement, error) {
+ return pkg.ReqCapabilities, nil
+}
+
+func (pkgDesc *PkgDesc) GetCapabilities() ([]*DependencyRequirement, error) {
+ return pkgDesc.Caps, nil
+}
+
+// Return the pkg dependencies for this pkgDesc.
+func (pkgDesc *PkgDesc) GetDependencies() ([]*DependencyRequirement, error) {
+ return pkgDesc.Deps, nil
+}
+
+func (pkgDesc *PkgDesc) GetReqCapabilities() ([]*DependencyRequirement, error) {
+ return pkgDesc.ReqCaps, nil
+}
+
+// Load a pkg's configuration information from the pkg config
+// file.
+func (pkg *Pkg) GetIncludes(t *Target) ([]string, error) {
+ // Return the include directories for just this pkg
+ incls := []string{
+ pkg.BasePath + "/include/",
+ pkg.BasePath + "/include/" + pkg.Name + "/arch/" + t.Arch + "/",
+ }
+
+ return incls, nil
+}
+
+// Load capabilities from a string containing a list of capabilities.
+// The capability format is expected to be one of:
+// name@version
+// name
+// @param capList An array of capability strings
+// @return On success error is nil, and a list of capabilities is returned,
+// on failure error is non-nil
+func (pkg *Pkg) loadCaps(capList []string) ([]*DependencyRequirement, error) {
+ if len(capList) == 0 {
+ return nil, nil
+ }
+
+ // Allocate an array of capabilities
+ caps := make([]*DependencyRequirement, 0)
+
+ StatusMessage(VERBOSITY_VERBOSE, "Loading capabilities %s\n",
+ strings.Join(capList, " "))
+ for _, capItem := range capList {
+ dr, err := NewDependencyRequirementParseString(capItem)
+ if err != nil {
+ return nil, err
+ }
+
+ caps = append(caps, dr)
+ log.Printf("[DEBUG] Appending new capability pkg: %s, cap:%s",
+ pkg.Name, dr)
+ }
+
+ return caps, nil
+}
+
+// Create a dependency requirement out of an pkg
+//
+func (pkg *Pkg) MakeDependency() (*DependencyRequirement, error) {
+ return NewDependencyRequirementParseString(pkg.FullName)
+}
+
+// Generate a hash of the contents of an pkg. This function recursively
+// processes the contents of a directory, ignoring hidden files and the
+// bin and obj directories. It returns a hash of all the files, their
+// contents.
+func (pkg *Pkg) GetHash() (string, error) {
+ hash := sha1.New()
+
+ err := filepath.Walk(pkg.BasePath,
+ func(path string, info os.FileInfo, err error) error {
+ name := info.Name()
+ if name == "bin" || name == "obj" || name[0] == '.' {
+ return filepath.SkipDir
+ }
+
+ if info.IsDir() {
+ // SHA the directory name into the hash
+ hash.Write([]byte(name))
+ } else {
+ // SHA the file name & contents into the hash
+ contents, err := ioutil.ReadFile(path)
+ if err != nil {
+ return err
+ }
+ hash.Write(contents)
+ }
+ return nil
+ })
+ if err != nil && err != filepath.SkipDir {
+ return "", NewNewtError(err.Error())
+ }
+
+ hashStr := fmt.Sprintf("%x", hash.Sum(nil))
+
+ return hashStr, nil
+}
+
+// Load pkg's configuration, and collect required capabilities, dependencies, and
+// identities it provides, so we'll have this available when target is being built.
+func (pkg *Pkg) LoadDependencies(identities map[string]string,
+ capabilities map[string]string) error {
+
+ if pkg.DepLoaded {
+ return nil
+ }
+
+ log.Printf("[DEBUG] Loading dependencies for pkg %s", pkg.BasePath)
+
+ v, err := ReadConfig(pkg.BasePath, "pkg")
+ if err != nil {
+ return err
+ }
+
+ // Append all identities that this pkg exposes.
+ idents := GetStringSliceIdentities(v, identities, "pkg.identities")
+
+ // Add these to project identities
+ for _, item := range idents {
+ StatusMessage(VERBOSITY_VERBOSE, " Adding identity %s - %s\n", item,
+ pkg.FullName)
+ identities[item] = pkg.FullName
+ }
+
+ // Load the list of capabilities that this pkg exposes
+ pkg.Capabilities, err = pkg.loadCaps(GetStringSliceIdentities(v, identities,
+ "pkg.caps"))
+ if err != nil {
+ return err
+ }
+
+ // Add these to project capabilities
+ for _, cap := range pkg.Capabilities {
+ if capabilities[cap.String()] != "" &&
+ capabilities[cap.String()] != pkg.FullName {
+
+ return NewNewtError(fmt.Sprintf("Multiple pkgs with "+
+ "capability %s (%s and %s)",
+ cap.String(), capabilities[cap.String()], pkg.FullName))
+ }
+ capabilities[cap.String()] = pkg.FullName
+ StatusMessage(VERBOSITY_VERBOSE, " Adding capability %s - %s\n",
+ cap.String(), pkg.FullName)
+ }
+
+ // Load the list of capabilities that this pkg requires
+ pkg.ReqCapabilities, err = pkg.loadCaps(GetStringSliceIdentities(v, identities,
+ "pkg.req_caps"))
+ if err != nil {
+ return err
+ }
+
+ // Load pkg dependencies
+ depList := GetStringSliceIdentities(v, identities, "pkg.deps")
+ if len(depList) > 0 {
+ pkg.Deps = make([]*DependencyRequirement, 0, len(depList))
+ for _, depStr := range depList {
+ log.Printf("[DEBUG] Loading dependency %s from pkg %s", depStr,
+ pkg.FullName)
+ dr, err := NewDependencyRequirementParseString(depStr)
+ if err != nil {
+ return err
+ }
+
+ pkg.Deps = append(pkg.Deps, dr)
+ }
+ }
+ for _, cap := range pkg.ReqCapabilities {
+ pkgName := capabilities[cap.String()]
+ if pkgName == "" {
+ continue
+ }
+ dr, err := NewDependencyRequirementParseString(pkgName)
+ if err != nil {
+ return err
+ }
+ pkg.Deps = append(pkg.Deps, dr)
+ }
+
+ pkgName := identities["LIBC"]
+ if pkgName != "" {
+ dr, err := NewDependencyRequirementParseString(pkgName)
+ if err != nil {
+ return err
+ }
+ pkg.Deps = append(pkg.Deps, dr)
+ }
+
+ // Check these as well
+ pkg.LinkerScript = GetStringIdentities(v, identities, "pkg.linkerscript")
+ pkg.DownloadScript = GetStringIdentities(v, identities, "pkg.downloadscript")
+ pkg.DebugScript = GetStringIdentities(v, identities, "pkg.debugscript")
+
+ pkg.Cflags = ""
+ cflags := GetStringSliceIdentities(v, identities, "pkg.cflags")
+ for _, name := range cflags {
+ pkg.Cflags += " " + name
+ }
+ pkg.Lflags = GetStringIdentities(v, identities, "pkg.lflags")
+ pkg.Aflags = GetStringIdentities(v, identities, "pkg.aflags")
+
+ pkg.DepLoaded = true
+
+ return nil
+}
+
+// Collect identities and capabilities that pkg and it's dependencies provide
+func (pkg *Pkg) collectDependencies(pkgList *PkgList,
+ identities map[string]string,
+ capabilities map[string]string) error {
+
+ if pkg.DepLoaded {
+ return nil
+ }
+
+ StatusMessage(VERBOSITY_VERBOSE, " Collecting pkg %s dependencies\n", pkg.Name)
+
+ err := pkg.LoadDependencies(identities, capabilities)
+ if err != nil {
+ return err
+ }
+
+ for _, dep := range pkg.Deps {
+ pkg, err := pkgList.ResolvePkgName(dep.Name)
+ if err != nil {
+ return err
+ }
+ err = pkg.collectDependencies(pkgList, identities, capabilities)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// Clear the var which says that dependencies have been checked for this pkg and
+// it's dependencies
+func (pkg *Pkg) clearDependencyMarker(pkgList *PkgList) {
+
+ if pkg.DepLoaded == false {
+ return
+ }
+ pkg.DepLoaded = false
+
+ for _, dep := range pkg.Deps {
+ pkg, err := pkgList.ResolvePkgName(dep.Name)
+ if err == nil {
+ pkg.clearDependencyMarker(pkgList)
+ }
+ }
+}
+
+// Load a pkg's configuration. This allocates & initializes a fair number of
+// the main data structures within the pkg.
+func (pkg *Pkg) LoadConfig(t *Target, force bool) error {
+ if pkg.CfgLoaded && !force {
+ return nil
+ }
+
+ log.Printf("[DEBUG] Loading configuration for pkg %s", pkg.BasePath)
+
+ v, err := ReadConfig(pkg.BasePath, "pkg")
+ if err != nil {
+ return err
+ }
+
+ pkg.FullName = v.GetString("pkg.name")
+ pkg.Name = filepath.Base(pkg.FullName)
+
+ pkg.Version, err = NewVersParseString(v.GetString("pkg.vers"))
+ if err != nil {
+ return err
+ }
+
+ // Append all the identities that this pkg exposes to sub-pkgs. This must
+ // be done before the remainder of the settings, as some settings depend on
+ // identity.
+ identities := map[string]string{}
+ if t != nil {
+ identities = t.Identities;
+ idents := GetStringSliceIdentities(v, identities, "pkg.identities")
+ for _, item := range idents {
+ identities[item] = pkg.FullName;
+ }
+ }
+
+ pkg.LinkerScript = GetStringIdentities(v, identities, "pkg.linkerscript")
+ pkg.DownloadScript = GetStringIdentities(v, identities, "pkg.downloadscript")
+ pkg.DebugScript = GetStringIdentities(v, identities, "pkg.debugscript")
+
+ pkg.Cflags += GetStringIdentities(v, identities, "pkg.cflags")
+ pkg.Lflags += GetStringIdentities(v, identities, "pkg.lflags")
+ pkg.Aflags += GetStringIdentities(v, identities, "pkg.aflags")
+
+ // Load pkg dependencies
+ depList := GetStringSliceIdentities(v, identities, "pkg.deps")
+ if len(depList) > 0 {
+ pkg.Deps = make([]*DependencyRequirement, 0, len(depList))
+ for _, depStr := range depList {
+ log.Printf("[DEBUG] Loading dependency %s from pkg %s", depStr,
+ pkg.FullName)
+ dr, err := NewDependencyRequirementParseString(depStr)
+ if err != nil {
+ return err
+ }
+
+ pkg.Deps = append(pkg.Deps, dr)
+ }
+ }
+
+ // Load the list of capabilities that this pkg exposes
+ pkg.Capabilities, err = pkg.loadCaps(GetStringSliceIdentities(v, identities,
+ "pkg.caps"))
+ if err != nil {
+ return err
+ }
+
+ // Load the list of capabilities that this pkg requires
+ pkg.ReqCapabilities, err = pkg.loadCaps(GetStringSliceIdentities(v, identities,
+ "pkg.req_caps"))
+ if err != nil {
+ return err
+ }
+ if len(pkg.ReqCapabilities) > 0 {
+ for _, reqStr := range pkg.ReqCapabilities {
+ log.Printf("[DEBUG] Loading reqCap %s from pkg %s", reqStr,
+ pkg.FullName)
+ }
+ }
+ pkg.CfgLoaded = true
+
+ return nil
+}
+
+// Initialize a pkg: loads the pkg configuration, and sets up pkg data
+// structures. Should only be called from NewPkg
+func (pkg *Pkg) Init() error {
+ return nil
+}
+
+// Allocate and initialize a new pkg, and return a fully initialized Pkg
+// structure.
+// @param repo The Repo this pkg is located in
+// @param basePath The path to this pkg, within the specified repo
+// @return On success, error is nil, and a Pkg is returned. on failure,
+// error is not nil.
+func NewPkg(repo *Repo, basePath string) (*Pkg, error) {
+ pkg := &Pkg{
+ BasePath: basePath,
+ Repo: repo,
+ }
+
+ if err := pkg.Init(); err != nil {
+ return nil, err
+ }
+
+ return pkg, nil
+}
+
+func (pkg *Pkg) TestBinName() string {
+ return "test_" + pkg.Name
+}
+
+/*
+ * Download pkg from a pkgList and stick it to repo.
+ */
+func (pkgDesc *PkgDesc) Install(pkgMgr *PkgList, branch string) error {
+ downloaded, err := pkgMgr.InstallPkg(pkgDesc.FullName, branch, nil)
+ for _, remoteRepo := range downloaded {
+ remoteRepo.Remove()
+ }
+ return err
+}
+
+func (pkg *Pkg) Remove() error {
+ return os.RemoveAll(pkg.BasePath)
+}