You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/11/21 01:42:47 UTC
[22/42] incubator-mynewt-newt git commit: Move newt source into a
"newt" subdirectory.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/cli/target.go
----------------------------------------------------------------------
diff --git a/cli/target.go b/cli/target.go
deleted file mode 100644
index 789c0d6..0000000
--- a/cli/target.go
+++ /dev/null
@@ -1,806 +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 (
- "bufio"
- "fmt"
- "log"
- "os"
- "path/filepath"
- "sort"
- "strconv"
- "strings"
-)
-
-const TARGET_SECT_PREFIX = "_target_"
-
-type Target struct {
- Vars map[string]string
-
- Identities map[string]string
-
- Capabilities []string
-
- Dependencies []string
-
- Cflags string
- Lflags string
- Aflags string
-
- Name string
-
- Arch string
- Cdef string
-
- Bsp string
-
- Nest *Nest
-}
-
-// Check if the target specified by name exists for the Nest specified by
-// r
-func TargetExists(nest *Nest, name string) bool {
- _, err := nest.GetConfig(TARGET_SECT_PREFIX+name, "name")
- if err == nil {
- return true
- } else {
- return false
- }
-}
-
-func parseTargetStringSlice(str string) ([]string, error) {
- slice := strings.Split(str, " ")
- return slice, nil
-}
-
-func (t *Target) SetDefaults() error {
- var err error
-
- t.Name = t.Vars["name"]
-
- // Must have an architecture set, default to sim.
- if t.Vars["arch"] == "" {
- t.Vars["arch"] = "sim"
- t.Arch = "sim"
- } else {
- t.Arch = t.Vars["arch"]
- }
-
- t.Cdef = t.Vars["compiler_def"]
- if t.Cdef == "" {
- t.Cdef = "default"
- }
-
- t.Bsp = t.Vars["bsp"]
- t.Cflags = t.Vars["cflags"]
- t.Lflags = t.Vars["lflags"]
-
- identities, err := parseTargetStringSlice(t.Vars["identities"])
- if err != nil {
- return err
- }
- t.Identities = map[string]string{}
- for _, ident := range identities {
- StatusMessage(VERBOSITY_VERBOSE, " set default ident %s\n", ident)
- t.Identities[ident] = t.Name
- }
- t.Capabilities, err = parseTargetStringSlice(t.Vars["capabilities"])
- if err != nil {
- return err
- }
-
- t.Dependencies, err = parseTargetStringSlice(t.Vars["dependencies"])
- if err != nil {
- return err
- }
-
- return nil
-}
-
-func (t *Target) HasIdentity(identity string) bool {
- for cur, _ := range t.Identities {
- if cur == identity {
- return true
- }
- }
-
- return false
-}
-
-// Load the target specified by name for the repository specified by r
-func LoadTarget(nest *Nest, name string) (*Target, error) {
- t := &Target{
- Nest: nest,
- }
-
- var err error
-
- t.Vars, err = nest.GetConfigSect(TARGET_SECT_PREFIX + name)
- if err != nil {
- return nil, err
- }
-
- // Cannot have both a project and package set
- err = t.SetDefaults()
- if err != nil {
- return nil, err
- }
-
- return t, nil
-}
-
-// Export a target, or all targets. If exportAll is true, then all targets are exported, if false,
-// then only the target represented by targetName is exported
-func ExportTargets(nest *Nest, name string, exportAll bool, fp *os.File) error {
- targets, err := GetTargets(nest)
- if err != nil {
- return err
- }
-
- for _, target := range targets {
- log.Printf("[DEBUG] Exporting target %s", target.Name)
-
- if !exportAll && target.Name != name {
- continue
- }
-
- fmt.Fprintf(fp, "@target=%s\n", target.Name)
-
- for k, v := range target.GetVars() {
- fmt.Fprintf(fp, "%s=%s\n", k, v)
- }
- }
- fmt.Fprintf(fp, "@endtargets\n")
-
- return nil
-}
-
-func ImportTargets(nest *Nest, name string, importAll bool, fp *os.File) error {
- s := bufio.NewScanner(fp)
-
- var currentTarget *Target = nil
-
- targets := make([]*Target, 0, 10)
-
- if importAll {
- StatusMessage(VERBOSITY_VERBOSE, "Importing all targets from %s",
- fp.Name())
- } else {
- StatusMessage(VERBOSITY_VERBOSE, "Importing target %s from %s",
- name, fp.Name())
- }
-
- for s.Scan() {
- line := s.Text()
-
- // scan lines
- // lines defining a target start with @
- if idx := strings.Index(line, "@"); idx == 0 {
- // save existing target if it exists
- if currentTarget != nil {
- targets = append(targets, currentTarget)
- currentTarget = nil
- }
-
- // look either for an end of target definitions, or a new target definition
- if line == "@endtargets" {
- break
- } else {
- elements := strings.SplitN(line, "=", 2)
- // name is elements[0], and value is elements[1]
-
- if importAll || elements[1] == name {
- // create a current target
- currentTarget = &Target{
- Nest: nest,
- }
-
- var err error
- currentTarget.Vars = map[string]string{}
- if err != nil {
- return err
- }
-
- currentTarget.Vars["name"] = elements[1]
- }
- }
- } else {
- if currentTarget != nil {
- // target variables, set these on the current target
- elements := strings.SplitN(line, "=", 2)
- currentTarget.Vars[elements[0]] = elements[1]
- }
- }
- }
-
- if err := s.Err(); err != nil {
- return err
- }
-
- for _, target := range targets {
- if err := target.SetDefaults(); err != nil {
- return err
- }
-
- if err := target.Save(); err != nil {
- return err
- }
- }
-
- return nil
-}
-
-// Get a list of targets for the repository specified by r
-func GetTargets(nest *Nest) ([]*Target, error) {
- targets := []*Target{}
- for sect, _ := range nest.Config {
- if strings.HasPrefix(sect, TARGET_SECT_PREFIX) {
- target, err := LoadTarget(nest, sect[len(TARGET_SECT_PREFIX):len(sect)])
- if err != nil {
- return nil, err
- }
-
- targets = append(targets, target)
- }
- }
- return targets, nil
-}
-
-// Get a map[] of variables for this target
-func (t *Target) GetVars() map[string]string {
- return t.Vars
-}
-
-// Return the compiler definition file for this target
-func (t *Target) GetCompiler() string {
- path := t.Nest.BasePath + "/compiler/"
- if t.Vars["compiler"] != "" {
- path += t.Vars["compiler"]
- } else {
- path += t.Arch
- }
- path += "/"
-
- return path
-}
-
-// Build the target
-func (t *Target) Build() error {
- if t.Vars["project"] != "" {
- StatusMessage(VERBOSITY_DEFAULT, "Building target %s (project = %s)\n",
- t.Name, t.Vars["project"])
- // Now load and build the project.
- p, err := LoadProject(t.Nest, t, t.Vars["project"])
- if err != nil {
- return err
- }
- // The project is the target, and builds itself.
- if err = p.Build(); err != nil {
- return err
- }
- } else if t.Vars["egg"] != "" {
- clutch, err := NewClutch(t.Nest)
- if err != nil {
- return err
- }
-
- err = clutch.Build(t, t.Vars["egg"], nil, nil)
- if err != nil {
- return err
- }
- }
-
- return nil
-}
-
-func (t *Target) BuildClean(cleanAll bool) error {
- if t.Vars["project"] != "" {
- p, err := LoadProject(t.Nest, t, t.Vars["project"])
- if err != nil {
- return err
- }
-
- // The project is the target, and build cleans itself.
- if err = p.BuildClean(cleanAll); err != nil {
- return err
- }
- } else if t.Vars["egg"] != "" {
- clutch, err := NewClutch(t.Nest)
- if err != nil {
- return err
- }
- err = clutch.BuildClean(t, t.Vars["egg"], cleanAll)
- if err != nil {
- return err
- }
- }
-
- return nil
-}
-
-func (t *Target) Test(cmd string, flag bool) error {
- clutch, err := NewClutch(t.Nest)
- if err != nil {
- return err
- }
-
- switch cmd {
- case "test":
- err = clutch.Test(t, t.Vars["egg"], flag)
- case "testclean":
- err = clutch.TestClean(t, t.Vars["egg"], flag)
- default:
- err = NewNewtError("Unknown command to Test() " + cmd)
- }
- if err != nil {
- return err
- }
-
- return nil
-}
-
-func (t *Target) DeleteVar(name string) error {
- targetCfgSect := TARGET_SECT_PREFIX + t.Vars["name"]
-
- if err := t.Nest.DelConfig(targetCfgSect, name); err != nil {
- return err
- }
-
- return nil
-}
-
-// Save the target's configuration elements
-func (t *Target) Save() error {
- nest := t.Nest
-
- if _, ok := t.Vars["name"]; !ok {
- return NewNewtError("Cannot save a target without a name")
- }
-
- targetCfg := TARGET_SECT_PREFIX + t.Vars["name"]
-
- for k, v := range t.Vars {
- if err := nest.SetConfig(targetCfg, k, v); err != nil {
- return err
- }
- }
-
- return nil
-}
-
-func (t *Target) Remove() error {
- nest := t.Nest
-
- if _, ok := t.Vars["name"]; !ok {
- return NewNewtError("Cannot remove a target without a name")
- }
-
- cfgSect := TARGET_SECT_PREFIX + t.Vars["name"]
-
- for k, _ := range t.Vars {
- if err := nest.DelConfig(cfgSect, k); err != nil {
- return err
- }
- }
-
- return nil
-}
-
-func (t *Target) Download() error {
- clutch, err := NewClutch(t.Nest)
- if err != nil {
- return err
- }
-
- egg, err := clutch.ResolveEggName(t.Bsp)
- if err != nil {
- return err
- }
-
- err = egg.LoadConfig(t, false)
- if err != nil {
- return err
- }
- if egg.DownloadScript == "" {
- return NewNewtError(fmt.Sprintf("No egg.downloadscript defined for %s",
- egg.FullName))
- }
- downloadScript := filepath.Join(egg.BasePath, egg.DownloadScript)
-
- if t.Vars["project"] == "" {
- return NewNewtError(fmt.Sprintf("No project associated with target %s",
- t.Name))
- }
- p, err := LoadProject(t.Nest, t, t.Vars["project"])
- if err != nil {
- return err
- }
-
- os.Chdir(t.Nest.BasePath)
-
- identString := ""
- for ident, _ := range t.Identities {
- identString = identString + ident
- }
-
- StatusMessage(VERBOSITY_DEFAULT, "Downloading with %s\n", downloadScript)
- rsp, err := ShellCommand(fmt.Sprintf("%s %s %s", downloadScript,
- filepath.Join(p.BinPath(), p.Name), identString))
- if err != nil {
- StatusMessage(VERBOSITY_DEFAULT, "%s", rsp);
- return err
- }
-
- return nil
-}
-
-func (t *Target) Debug() error {
- clutch, err := NewClutch(t.Nest)
- if err != nil {
- return err
- }
-
- egg, err := clutch.ResolveEggName(t.Bsp)
- if err != nil {
- return err
- }
-
- err = egg.LoadConfig(t, false)
- if err != nil {
- return err
- }
- if egg.DebugScript == "" {
- return NewNewtError(fmt.Sprintf("No egg.debugscript defined for %s",
- egg.FullName))
- }
- debugScript := filepath.Join(egg.BasePath, egg.DebugScript)
-
- if t.Vars["project"] == "" {
- return NewNewtError(fmt.Sprintf("No project associated with target %s",
- t.Name))
- }
- p, err := LoadProject(t.Nest, t, t.Vars["project"])
- if err != nil {
- return err
- }
-
- os.Chdir(t.Nest.BasePath)
-
- identString := ""
- for ident, _ := range t.Identities {
- identString = identString + ident
- }
-
- StatusMessage(VERBOSITY_DEFAULT, "Debugging with %s %s\n", debugScript, p.Name)
-
- cmdLine := []string{debugScript, filepath.Join(p.BinPath(), p.Name)}
- cmdLine = append(cmdLine, identString)
- err = ShellInteractiveCommand(cmdLine)
- if err != nil {
- return err
- }
-
- return nil
-}
-
-type MemSection struct {
- Name string
- Offset uint64
- EndOff uint64
-}
-type MemSectionArray []*MemSection
-
-func (array MemSectionArray) Len() int {
- return len(array)
-}
-
-func (array MemSectionArray) Less(i, j int) bool {
- return array[i].Offset < array[j].Offset
-}
-
-func (array MemSectionArray) Swap(i, j int) {
- array[i], array[j] = array[j], array[i]
-}
-
-func MakeMemSection(name string, off uint64, size uint64) *MemSection {
- memsection := &MemSection{
- Name: name,
- Offset: off,
- EndOff: off + size,
- }
- return memsection
-}
-
-func (m *MemSection) PartOf(addr uint64) bool {
- if addr >= m.Offset && addr < m.EndOff {
- return true
- } else {
- return false
- }
-}
-
-/*
- * We accumulate the size of libraries to elements in this.
- */
-type EggSize struct {
- Name string
- Sizes map[string]uint32 /* Sizes indexed by mem section name */
-}
-
-type EggSizeArray []*EggSize
-
-func (array EggSizeArray) Len() int {
- return len(array)
-}
-
-func (array EggSizeArray) Less(i, j int) bool {
- return array[i].Name < array[j].Name
-}
-
-func (array EggSizeArray) Swap(i, j int) {
- array[i], array[j] = array[j], array[i]
-}
-
-func MakeEggSize(name string, memSections map[string]*MemSection) *EggSize {
- eggSize := &EggSize{
- Name: name,
- }
- eggSize.Sizes = make(map[string]uint32)
- for secName, _ := range memSections {
- eggSize.Sizes[secName] = 0
- }
- return eggSize
-}
-
-/*
- * Go through GCC generated mapfile, and collect info about symbol sizes
- */
-func ParseMapFileSizes(fileName string) (map[string]*EggSize, map[string]*MemSection,
- error) {
- var state int = 0
-
- file, err := os.Open(fileName)
- if err != nil {
- return nil, nil, err
- }
-
- memSections := make(map[string]*MemSection)
- eggSizes := make(map[string]*EggSize)
-
- scanner := bufio.NewScanner(file)
- for scanner.Scan() {
- switch state {
- case 0:
- if strings.Contains(scanner.Text(), "Memory Configuration") {
- state = 1
- }
- case 1:
- if strings.Contains(scanner.Text(), "Origin") {
- state = 2
- }
- case 2:
- if strings.Contains(scanner.Text(), "*default*") {
- state = 3
- continue
- }
- array := strings.Fields(scanner.Text())
- offset, err := strconv.ParseUint(array[1], 0, 64)
- if err != nil {
- return nil, nil, NewNewtError("Can't parse mem info")
- }
- size, err := strconv.ParseUint(array[2], 0, 64)
- if err != nil {
- return nil, nil, NewNewtError("Can't parse mem info")
- }
- memSections[array[0]] = MakeMemSection(array[0], offset,
- size)
- case 3:
- if strings.Contains(scanner.Text(),
- "Linker script and memory map") {
- state = 4
- }
- case 4:
- var addrStr string = ""
- var sizeStr string = ""
- var srcFile string = ""
-
- if strings.Contains(scanner.Text(), "/DISCARD/") ||
- strings.HasPrefix(scanner.Text(), "OUTPUT(") {
- /*
- * After this there is only discarded symbols
- */
- state = 5
- continue
- }
-
- array := strings.Fields(scanner.Text())
- switch len(array) {
- case 1:
- /*
- * section name on it's own, e.g.
- * *(.text*)
- *
- * section name + symbol name, e.g.
- * .text.Reset_Handler
- *
- * ignore these for now
- */
- continue
- case 2:
- /*
- * Either stuff from beginning to first useful data e.g.
- * END GROUP
- *
- * or address of symbol + symbol name, e.g.
- * 0x00000000080002c8 SystemInit
- *
- * or section names with multiple input things, e.g.
- * *(.ARM.extab* .gnu.linkonce.armextab.*)
- *
- * or space set aside in linker script e.g.
- * 0x0000000020002e80 0x400
- * (that's the initial stack)
- *
- * ignore these for now
- */
- continue
- case 3:
- /*
- * address, size, and name of file, e.g.
- * 0x000000000800bb04 0x1050 /Users/marko/foo/tadpole/hw//mcu/stm/stm32f3xx/bin/blinky_f3/libstm32f3xx.a(stm32f30x_syscfg.o)
- *
- * padding, or empty areas defined in linker script:
- * *fill* 0x000000000800cb71 0x3
- *
- * output section name, location, size, e.g.:
- * .bss 0x0000000020000ab0 0x23d0
- */
- /*
- * Record addr, size and name to find library.
- */
- if array[0] == "*fill*" {
- addrStr = array[1]
- sizeStr = array[2]
- srcFile = array[0]
- } else {
- addrStr = array[0]
- sizeStr = array[1]
- srcFile = array[2]
- }
- case 4:
- /*
- * section, address, size, name of file, e.g.
- * COMMON 0x0000000020002d28 0x8 /Users/marko/foo/tadpole/libs//os/bin/blinky_f3/libos.a(os_arch_arm.o)
- *
- * linker script symbol definitions:
- * 0x0000000020002e80 _ebss = .
- *
- * crud, e.g.:
- * 0x8 (size before relaxing)
- */
- addrStr = array[1]
- sizeStr = array[2]
- srcFile = array[3]
- default:
- continue
- }
- addr, err := strconv.ParseUint(addrStr, 0, 64)
- if err != nil {
- continue
- }
- size, err := strconv.ParseUint(sizeStr, 0, 64)
- if err != nil {
- continue
- }
- if size == 0 {
- continue
- }
- tmpStrArr := strings.Split(srcFile, "(")
- srcLib := filepath.Base(tmpStrArr[0])
- for name, section := range memSections {
- if section.PartOf(addr) {
- eggSize := eggSizes[srcLib]
- if eggSize == nil {
- eggSize =
- MakeEggSize(srcLib, memSections)
- eggSizes[srcLib] = eggSize
- }
- eggSize.Sizes[name] += uint32(size)
- break
- }
- }
- default:
- }
- }
- file.Close()
- for name, section := range memSections {
- StatusMessage(VERBOSITY_VERBOSE, "Mem %s: 0x%x-0x%x\n",
- name, section.Offset, section.EndOff)
- }
-
- return eggSizes, memSections, nil
-}
-
-/*
- * Return a printable string containing size data for the libraries
- */
-func PrintSizes(libs map[string]*EggSize,
- sectMap map[string]*MemSection) (string, error) {
- ret := ""
-
- /*
- * Order sections by offset, and display lib sizes in that order.
- */
- memSections := make(MemSectionArray, len(sectMap))
- var i int = 0
- for _, sec := range sectMap {
- memSections[i] = sec
- i++
- }
- sort.Sort(memSections)
-
- /*
- * Order libraries by name, and display them in that order.
- */
- eggSizes := make(EggSizeArray, len(libs))
- i = 0
- for _, es := range libs {
- eggSizes[i] = es
- i++
- }
- sort.Sort(eggSizes)
-
- for _, sec := range memSections {
- ret += fmt.Sprintf("%7s ", sec.Name)
- }
- ret += "\n"
- for _, es := range eggSizes {
- for i := 0; i < len(memSections); i++ {
- ret += fmt.Sprintf("%7d ", es.Sizes[memSections[i].Name])
- }
- ret += fmt.Sprintf("%s\n", es.Name)
- }
- return ret, nil
-}
-
-func (t *Target) GetSize() (string, error) {
- if t.Vars["project"] != "" {
- StatusMessage(VERBOSITY_DEFAULT, "Inspecting target %s (project = %s)\n",
- t.Name, t.Vars["project"])
- // Now load the project, mapfile settings
- p, err := LoadProject(t.Nest, t, t.Vars["project"])
- if err != nil {
- return "", err
- }
-
- c, err := NewCompiler(t.GetCompiler(), t.Cdef, t.Name, []string{})
- if err != nil {
- return "", err
- }
- if c.ldMapFile != true {
- return "", NewNewtError("Build does not generate mapfile")
- }
- mapFile := p.BinPath() + p.Name + ".elf.map"
-
- eggSizes, memSections, err := ParseMapFileSizes(mapFile)
- if err != nil {
- return "", err
- }
- return PrintSizes(eggSizes, memSections)
- }
- return "", NewNewtError("Target needs a project")
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/cli/util.go
----------------------------------------------------------------------
diff --git a/cli/util.go b/cli/util.go
deleted file mode 100644
index a938bf1..0000000
--- a/cli/util.go
+++ /dev/null
@@ -1,357 +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 (
- "bufio"
- "bytes"
- "fmt"
- "github.com/hashicorp/logutils"
- "github.com/spf13/viper"
- "io/ioutil"
- "log"
- "os"
- "os/exec"
- "os/signal"
- "path/filepath"
- "runtime"
- "strings"
- "syscall"
- "time"
-)
-
-type NewtError struct {
- Text string
- StackTrace []byte
-}
-
-var Logger *log.Logger
-var Verbosity int
-var OK_STRING = " ok!\n"
-
-const (
- VERBOSITY_SILENT = 0
- VERBOSITY_QUIET = 1
- VERBOSITY_DEFAULT = 2
- VERBOSITY_VERBOSE = 3
-)
-
-func (se *NewtError) Error() string {
- return se.Text + "\n" + string(se.StackTrace)
-}
-
-func NewNewtError(msg string) *NewtError {
- err := &NewtError{
- Text: msg,
- StackTrace: make([]byte, 1<<16),
- }
-
- runtime.Stack(err.StackTrace, true)
-
- return err
-}
-
-func NewtErrorNoTrace(msg string) *NewtError {
- return &NewtError{
- Text: msg,
- StackTrace: nil,
- }
-}
-
-// Initialize the CLI module
-func Init(level string, silent bool, quiet bool, verbose bool) {
- if level == "" {
- level = "WARN"
- }
-
- filter := &logutils.LevelFilter{
- Levels: []logutils.LogLevel{"DEBUG", "VERBOSE", "INFO",
- "WARN", "ERROR"},
- MinLevel: logutils.LogLevel(level),
- Writer: os.Stderr,
- }
-
- log.SetOutput(filter)
-
- if silent {
- Verbosity = VERBOSITY_SILENT
- } else if quiet {
- Verbosity = VERBOSITY_QUIET
- } else if verbose {
- Verbosity = VERBOSITY_VERBOSE
- } else {
- Verbosity = VERBOSITY_DEFAULT
- }
-}
-
-func checkBoolMap(mapVar map[string]bool, item string) bool {
- v, ok := mapVar[item]
- return v && ok
-}
-
-// Read in the configuration file specified by name, in path
-// return a new viper config object if successful, and error if not
-func ReadConfig(path string, name string) (*viper.Viper, error) {
- v := viper.New()
- v.SetConfigType("yaml")
- v.SetConfigName(name)
- v.AddConfigPath(path)
-
- err := v.ReadInConfig()
- if err != nil {
- return nil, NewNewtError(err.Error())
- } else {
- return v, nil
- }
-}
-
-func GetStringIdentities(v *viper.Viper, idents map[string]string, key string) string {
- val := v.GetString(key)
-
- for ident, _ := range idents {
- overwriteVal := v.GetString(key + "." + ident + ".OVERWRITE")
- if overwriteVal != "" {
- val = strings.Trim(overwriteVal, "\n")
- break
- }
-
- appendVal := v.GetString(key + "." + ident)
- if appendVal != "" {
- val += " " + strings.Trim(appendVal, "\n")
- }
- }
- return strings.TrimSpace(val)
-}
-
-func GetStringSliceIdentities(v *viper.Viper, idents map[string]string,
- key string) []string {
-
- val := v.GetStringSlice(key)
-
- // string empty items
- result := []string{}
- for _, item := range val {
- if item == "" || item == " " {
- continue
- }
- result = append(result, item)
- }
-
- for item, _ := range idents {
- result = append(result, v.GetStringSlice(key+"."+item)...)
- }
-
- return result
-}
-
-func NodeExist(path string) bool {
- if _, err := os.Stat(path); err == nil {
- return true
- } else {
- return false
- }
-}
-
-// Check whether the node (either dir or file) specified by path exists
-func NodeNotExist(path string) bool {
- if _, err := os.Stat(path); os.IsNotExist(err) {
- return true
- } else {
- return false
- }
-}
-
-func FileModificationTime(path string) (time.Time, error) {
- fileInfo, err := os.Stat(path)
- if err != nil {
- epoch := time.Unix(0, 0)
- if os.IsNotExist(err) {
- return epoch, nil
- } else {
- return epoch, NewNewtError(err.Error())
- }
- }
-
- return fileInfo.ModTime(), nil
-}
-
-// Execute the command specified by cmdStr on the shell and return results
-func ShellCommand(cmdStr string) ([]byte, error) {
- log.Print("[VERBOSE] " + cmdStr)
- cmd := exec.Command("sh", "-c", cmdStr)
-
- o, err := cmd.CombinedOutput()
- log.Print("[VERBOSE] o=" + string(o))
- if err != nil {
- return o, NewNewtError(err.Error())
- } else {
- return o, nil
- }
-}
-
-// Run interactive shell command
-func ShellInteractiveCommand(cmdStr []string) error {
- log.Print("[VERBOSE] " + cmdStr[0])
-
- //
- // Block SIGINT, at least.
- // Otherwise Ctrl-C meant for gdb would kill newt.
- //
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt)
- signal.Notify(c, syscall.SIGTERM)
- go func(){
- <-c
- }()
-
- // Transfer stdin, stdout, and stderr to the new process
- // and also set target directory for the shell to start in.
- pa := os.ProcAttr {
- Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
- }
-
- // Start up a new shell.
- proc, err := os.StartProcess(cmdStr[0], cmdStr, &pa)
- if err != nil {
- signal.Stop(c)
- return NewNewtError(err.Error())
- }
-
- // Release and exit
- _, err = proc.Wait()
- if err != nil {
- signal.Stop(c)
- return NewNewtError(err.Error())
- }
- signal.Stop(c)
- return nil
-}
-
-func CopyFile(srcFile string, destFile string) error {
- _, err := ShellCommand(fmt.Sprintf("mkdir -p %s", filepath.Dir(destFile)))
- if err != nil {
- return err
- }
- if _, err := ShellCommand(fmt.Sprintf("cp -Rf %s %s", srcFile,
- destFile)); err != nil {
- return err
- }
- return nil
-}
-
-func CopyDir(srcDir, destDir string) error {
- return CopyFile(srcDir, destDir)
-}
-
-// Print Silent, Quiet and Verbose aware status messages
-func StatusMessage(level int, message string, args ...interface{}) {
- if Verbosity >= level {
- fmt.Printf(message, args...)
- }
-}
-
-// Reads each line from the specified text file into an array of strings. If a
-// line ends with a backslash, it is concatenated with the following line.
-func ReadLines(path string) ([]string, error) {
- file, err := os.Open(path)
- if err != nil {
- return nil, NewNewtError(err.Error())
- }
- defer file.Close()
-
- lines := []string{}
- scanner := bufio.NewScanner(file)
-
- for scanner.Scan() {
- line := scanner.Text()
- concatted := false
-
- if len(lines) != 0 {
- prevLine := lines[len(lines)-1]
- if len(prevLine) > 0 && prevLine[len(prevLine)-1:] == "\\" {
- prevLine = prevLine[:len(prevLine)-1]
- prevLine += line
- lines[len(lines)-1] = prevLine
-
- concatted = true
- }
- }
-
- if !concatted {
- lines = append(lines, line)
- }
- }
-
- if scanner.Err() != nil {
- return lines, NewNewtError(scanner.Err().Error())
- }
-
- return lines, nil
-}
-
-// Determines if a file was previously built with a command line invocation
-// different from the one specified.
-//
-// @param dstFile The output file whose build invocation is being
-// tested.
-// @param cmd The command that would be used to generate the
-// specified destination file.
-//
-// @return true if the command has changed or if the
-// destination file was never built;
-// false otherwise.
-func CommandHasChanged(dstFile string, cmd string) bool {
- cmdFile := dstFile + ".cmd"
- prevCmd, err := ioutil.ReadFile(cmdFile)
- if err != nil {
- return true
- }
-
- return bytes.Compare(prevCmd, []byte(cmd)) != 0
-}
-
-// Writes a file containing the command-line invocation used to generate the
-// specified file. The file that this function writes can be used later to
-// determine if the set of compiler options has changed.
-//
-// @param dstFile The output file whose build invocation is being
-// recorded.
-// @param cmd The command to write.
-func WriteCommandFile(dstFile string, cmd string) error {
- cmdPath := dstFile + ".cmd"
- err := ioutil.WriteFile(cmdPath, []byte(cmd), 0644)
- if err != nil {
- return err
- }
-
- return nil
-}
-
-// Removes all duplicate strings from the specified array, while preserving
-// order.
-func UniqueStrings(elems []string) []string {
- set := make(map[string]bool)
- result := make([]string, 0)
-
- for _, elem := range elems {
- if !set[elem] {
- result = append(result, elem)
- set[elem] = true
- }
- }
-
- return result
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/coding_style.txt
----------------------------------------------------------------------
diff --git a/coding_style.txt b/coding_style.txt
deleted file mode 100644
index 0fb9a12..0000000
--- a/coding_style.txt
+++ /dev/null
@@ -1,57 +0,0 @@
-Newt Coding Style
---
-
-- Line length is fixed to no more than 90 characters
-
-- At least every function should have documentation above it in godoc format.
-Err on the side of more comments rather than fewer.
-
-- Where possible, the form:
-
- if err := func(); err != nil {
- return err
- }
-
-Is the preferred method of doing error checking. Note that "err" should be
-assigned using the := operator to avoid conflicting with enclosing scope.
-
-- In cases where it is infeasible to create an error variable, i.e. when
-using multiple assignments on structure properties, the err variable should
-be defined at the top of the function scope. i.e.:
-
- func (inst *Installer) SetName(name string) {
- // declaration at the top of the function
- var err error
-
- // ...some code here...
- inst.Name, err = inst.ParseString(name)
- if err != nil {
- return err
- }
- }
-
-
-- Every object which requires allocation, shall follow this pattern:
- - The object itself has an Init() function which accesses to initialize
- the object. e.g.:
-
- func (inst *Installer) Init() error {
- // Initialization functions here
- }
-
- - There shall be a New<Object Name> function which allocates a new
- object of <Object Name> type, and calls the init function prior to
- allocating the new object. e.g.:
-
- func NewInstaller() (*Installer, error) {
- inst := &Installer{}
- if err := inst.Init(); err != nil {
- return nil, err
- }
- return inst, nil
- }
-
-- Accessors are for object properties SHOULD ALWAYS be provided when setting
-class properties. For reading object properties, accessor functions are
-should be provided where it makes sense (i.e. to provide an implementation
-contract.)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/design.txt
----------------------------------------------------------------------
diff --git a/design.txt b/design.txt
deleted file mode 100644
index 83a374e..0000000
--- a/design.txt
+++ /dev/null
@@ -1,370 +0,0 @@
- Design of Newt System
-
-
-
-1. Introduction
-
-
-The newt tool allows for building and distributing embedded projects. It's
-goal is to make it simple for developers to create a source project and
-manage that project, with an embedded twist. In embedded systems, the core
-operating system is often built and distributed along with system libraries
-and applications. Additionally, there is a fair amount of complexity in
-managing driver interfaces, board support packages, and both development and
-production builds. Right now, all of this is done for every project, and
-everybody does it in a different way.
-
-Newt introduces the following core concepts:
-
-Repository
- The base directory of your embedded software. A repository can contain
- multiple projects, and reflect multiple end products. It is meant to be
- a logical collection of your source code.
-
-Project
- Projects represent the individual build configurations of your embedded
- system. The project files are what dictate the resulting binary that is
- generated.
-
-Package
- Packages represent libraries that are distributed. Packages have multiple
- types (e.g. "bsp", "library", "os") that represent their function within
- the newt system.
-
-
-In order to bring sanity to your embedded life (lonelieness and cat obsession
-left as an exercise for the user), Newt allows you to:
-
-Build architecture specific binaries
- Newt contains the ability to manage and build for multiple different CPU
- architectures, project definitions and board support packages.
-
-Manage your drivers, board support and libraries
- Newt provides an infrastructure that helps you manage board capabilities,
- and drivers based upon what low-level features your libraries and projects
- use.
-
-Distribute Binaries
- Newt provides the ability to generate signed firmware images, suitable for
- booting with n-boot. Flash can also take n-boot images + project images
- and create a full flash map.
-
-Distribute Source
- Newt makes it easy to distribute and download libraries. By providing a
- clear interface to the lower layer drivers, and dependency checking across
- both architecture and board support package: newt makes it easy to
- develop reusable software components across embedded projects.
-
-Test
- Newt provides a test framework that allows you to easily define regression
- and unit tests, and have them run automatically.
-
-
-2. Usage
-
-To get started with newt, first create a new repository:
-
- $ newt create repo <fw>
-
-This creates a new repository in the directory specified by <fw>.
-
-The repository has the following contents:
- $ newt repo create test_repo_1
- Repo test_repo_1 successfully created!
- $ cd test_repo_1/
- $ tree
- .
- ├── compiler
- ├── hw
- │ └── bsp
- ├── libs
- ├── project
- └── repo.yml
-
-
-The arch/ directory contains the architecture specific information for the
-new repository. By default, the sim architecture and compiler is installed:
-which allows you to build new projects and software on your native OS and
-try it out.
-
-The newt tool also creates a directory .<fw> -- this contains the
-environment and configuration information for the current project. More
-information about this directory is contained in Appendix A.
-
-Once you have a repo, you can enter that repo, and begin composing your
-project.
-
-The first step to composing a project is to setup a build environment and
-board support package for that product. There are a set of board support
-packages and architectures available at the following URL:
-http://www.github.com/XXX.
-
-Let's start with the board support package for the STM32-E407, which is a
-test board for the ARM Cortex-M4, provided by Olimex
-(https://www.olimex.com/Products/ARM/ST/STM32-E407/open-source-hardware).
-To install the Olimex board support package, cd into the <fw> directory
-and type:
-
- $ newt install bsp http://www.github.com/XXX/STM32-E407
- Downloading Board Support Definition from
- http://www.github.com/XXX/STM32-E407 ... ok
- Board Support Definition STM32-E407 requires ARM architecture to be
- installed (http://www.github.com/XXX/ARM), is that OK? [Y/n] y
- Downloading ARM architecture support ... ok
- Successfully installed BSP for STM32-E407!
- $
-
-The "install bsp" command goes out and installs the board support package
-defined by the URL provided in the link. In this case, the bsp is defined
-on github. Once the newt tool downloads the BSP, it notices that the BSP
-requires the ARM architecture to be installed, and its currently not in the
-workspace. Newt will then download the definiton from the github URL, and
-install the necessary architecture information.
-
-After the dependency to the compiler has been fufilled, the bsp support
-packages are installed into the working directory. After the command
-has finished, the following directory structure should exist:
-
- $ tree
- .
- └── arch/
- └── sim/
- └── compiler/
- └── compiler.yml
- └── arm/
- └── compiler/
- └── arm-gcc
- └── bin
- └── arm-gcc
- └── arm-as
- └── .. <snip> ..
- └── compiler.yml
- └── include/
- └── rt_CMSIS.h
- └── mcu/
- └── stm32/
- └── arch_gpio.c
- └── arch_gpio.h
- └── .. <snip> ..
- └── bsp
- └── stm32-e407
- └── layout
- └── debug
- └── stm32-e407.lds
- └── prod
- └── stm32-e407.lds
- └── stm32-e407.yml
- └── bsp_flash_layout.h
- └── bsp_boot.s
- └── .. <snip> ..
- └── .<fw>
- └── <fw>.yml
- └── <fw>.db
-
-
-As you can see, a couple of new directories were created:
-
-arch/arm
- Definition files specific to the ARM architecture. This is directory
- contains generic definition files across multiple MCU architectures.
-
-arch/arm/mcu/stm32
- This directory contains definition files specific to the
- STM32 MCU. This includes things like SPI and UART definitions.
-
-arch/arm/compiler
- The compiler for the ARM architecture definition. This includes an
- up-to-date, tested version of the arm-gcc compiler. By default Newt uses
- this compiler, however it can be overridden to use a system compiler as
- well.
-
-bsp/stm32-e407
- This directory contains the board support files specific to the
- STM32-E407 development board.
-
-bsp/stm32-e407/layout
- This contains the memory layouts for build layouts, which can often be
- different for debug and production builds (e.g. run out of SRAM for debug
- and Flash for prod.)
-
-
-The next step is to create a project that will build on the test board. Let's
-say the first project is "blink_leds" a project that will load onto the
-STM32-E407 and blink LED1.
-
-To create the project, in the main directory enter:
-
- $ newt create project blink_leds
- Creating project blink_leds in project/ ... ok
- Creating project scaffolding for blink_leds ... ok
- $
-
-This will create the following directory structure:
-
- $ tree
- ..<snip>.. (same as previous step)
- └── project
- └── blink_leds
- └── blink_leds.yml
- └── blink_leds.c
- $
-
-The file blink_leds.c will contain base scaffolding in order to build:
-
- #include <newt/core.h>
-
- int
- main(int argc, char **argv)
- {
- while (1) { /* your code here */ }
- return (0);
- }
-
-
-In order to blink LEDs, the next step is to install the LED package. The LED
-package contains a standard API definition for controlling board LEDs, and
-the architecture and board specific definitions for LEDs.
-
- $ newt install driver http://www.github.com/XXX/led-driver
- Downloading driver ... ok
- Checking for necessary bsp support, bsps found: sim, STM32-E407 ... ok
- Installing driver ... ok
- $
-
-Installing the driver will create the following directories in the root
-directory of your project:
-
- $ tree
- ..<snip>.. (same as previous step)
- └── drivers
- └── led-driver
- └── led-driver.yml
- └── src
- └── led-driver.c
- └── include
- └── led-driver.h
- └── bsp
- └── stm32-e407
- └── stm32-e407.c
- └── stm32-e407.h
-
-This driver will then be accessible in your project. The next step is to
-enable it in your project definition, in order to do that, enter:
-
- $ newt project blink_leds use driver led-driver
- Enabling led-driver in blink_leds project.
-
-Now edit project/blink_leds/blink_leds.c, and write the following code:
-
- #include <newt/core.h>
- #include <led_driver/led_driver.h>
-
- int
- main(int argc, char **argv)
- {
- int toggle = 0;
-
- while (1) {
- if ((toggle++ % 2) == 0) {
- led_off(LED_DRIVER_LED1);
- } else {
- led_on(LED_DRIVER_LED1);
- }
- }
-
- return (0);
- }
-
-Once this file is edited, you can now build your project. In order to
-build an image that can be loaded on the board, create a build definition:
-
- $ newt build_def create blink_leds_arm_build
- $ newt build_def edit blink_leds_arm_build set bsp=stm32-e407
- $ newt build_def edit blink_leds_arm_build set project=blink_leds
- $ newt build_def edit blink_leds_arm_build set layout=debug
-
-This build definition is stored in the project build definition, and can now
-be referenced with the newt build command:
-
- $ newt build blink_leds_arm_build
- Building project blink_leds with bsp stm32-e407, layout debug ... ok
- $
-
-In order to see the output of the build, check the bin/ directory in the base
-directory of your repo:
-
- $ cd bin; tree
- └── bin
- └── blink_leds
- └── stm32-e407
- └── blink_leds.elf
- └── blink_leds.map
-
-
-In order to load these files onto your board using GDB, please see the
-Debugger Support section of this document.
-
-3. Packages
-
-Newt distributes libraries in the form of source packages, making it easy to
-bundle and reuse source code across multiple repositories and projects.
-Outside of the core architecture & board specific setup, all source code in
-a newt project should be encapsulated within a package.
-
-A package has the following directory structure:
-
- $ cd pkg/os; tree
- └── os
- └── os.yml
- └── include
- └── arch
- └── sim
- └── os_arch.h
- └── arm
- └── os_arch.h
- └── os
- └── os_mutex.h
- └── os_sem.h
- └── os.h
- └── src
- └── arch
- └── sim
- └── os_arch_sim.c
- └── arm
- └── os_arch_arm.c
- └── os_mutex.c
- └── os_sched.c
- └── test
- └── os_mutex_test
- └── os_mutex_test.c
-
-Building a Package
-
-In order to build a package, either:
-
- a) Include it in a project definition, in which case it will be built as a
- library and linked with the main application.
-
- b) Build it with target "test" in which case the specified regression test
- will be executed. If no regression test is specified, all regression tests
- will be run.
-
-
-Running a Package's Unit Tests
-
-To run a package's unit tests, cd into the package directory and run newt build
-test:
-
- $ cd pkg/os
- $ newt build test
- Building regression tests in OS
- Building OS ... ok
- Building Regression Tests ... ok
- Running test os_mutex_test ... ok
- $
-
-Including a Package in a Project file
-
-
-
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/newt.go
----------------------------------------------------------------------
diff --git a/newt.go b/newt.go
deleted file mode 100644
index 02b32a5..0000000
--- a/newt.go
+++ /dev/null
@@ -1,1395 +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 main
-
-import (
- "fmt"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt.git/cli"
- "github.com/spf13/cobra"
- "log"
- "os"
- "path/filepath"
- "regexp"
- "sort"
- "strings"
-)
-
-var ExitOnFailure bool = false
-var ExportAll bool = false
-var ImportAll bool = false
-var NewtVersion string = "0.1"
-var NewtLogLevel string = ""
-var NewtNest *cli.Nest
-var newtSilent bool
-var newtQuiet bool
-var newtVerbose bool
-var NewtBranchClutch string
-var NewtBranchEgg string
-
-func NewtUsage(cmd *cobra.Command, err error) {
- if err != nil {
- sErr := err.(*cli.NewtError)
- log.Printf("[DEBUG] %s", sErr.StackTrace)
- fmt.Fprintf(os.Stderr, "Error: %s\n", sErr.Text)
- }
-
- if cmd != nil {
- cmd.Help()
- }
- os.Exit(1)
-}
-
-// Display help text with a max line width of 79 characters
-func formatHelp(text string) string {
- // first compress all new lines and extra spaces
- words := regexp.MustCompile("\\s+").Split(text, -1)
- linelen := 0
- fmtText := ""
- for _, word := range words {
- word = strings.Trim(word, "\n ") + " "
- tmplen := linelen + len(word)
- if tmplen >= 80 {
- fmtText += "\n"
- linelen = 0
- }
- fmtText += word
- linelen += len(word)
- }
- return fmtText
-}
-
-// Extracts "<key>=<value>" strings from the supplied slice and inserts them
-// into the specified target's variable map.
-func extractTargetVars(args []string, t *cli.Target) error {
- for i := 0; i < len(args); i++ {
- pair := strings.SplitN(args[i], "=", 2)
- if len(pair) != 2 {
- return cli.NewNewtError("invalid argument: " + args[i])
- }
-
- t.Vars[pair[0]] = pair[1]
- }
-
- return nil
-}
-
-func targetSetCmd(cmd *cobra.Command, args []string) {
- if len(args) != 2 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify two arguments (sect & k=v) to set"))
- }
-
- t, err := cli.LoadTarget(NewtNest, args[0])
- if err != nil {
- NewtUsage(cmd, err)
- }
- ar := strings.Split(args[1], "=")
-
- t.Vars[ar[0]] = ar[1]
-
- if err := t.Save(); err != nil {
- NewtUsage(cmd, err)
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully set %s to %s\n", args[0], ar[0], ar[1])
-}
-
-func targetUnsetCmd(cmd *cobra.Command, args []string) {
- if len(args) != 2 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify two arguments (sect & k) to unset"))
- }
-
- t, err := cli.LoadTarget(NewtNest, args[0])
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- if err := t.DeleteVar(args[1]); err != nil {
- NewtUsage(cmd, err)
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully unset %s\n", args[0], args[1])
-}
-
-// Type for sorting an array of target pointers alphabetically by name.
-type ByName []*cli.Target
-
-func (a ByName) Len() int { return len(a) }
-func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-func (a ByName) Less(i, j int) bool { return a[i].Vars["name"] < a[j].Vars["name"] }
-
-func targetShowCmd(cmd *cobra.Command, args []string) {
- dispSect := ""
- if len(args) == 1 {
- dispSect = args[0]
- }
-
- targets, err := cli.GetTargets(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- sort.Sort(ByName(targets))
-
- for _, target := range targets {
- if dispSect == "" || dispSect == target.Vars["name"] {
- cli.StatusMessage(cli.VERBOSITY_QUIET, target.Vars["name"]+"\n")
-
- vars := target.GetVars()
- var keys []string
- for k := range vars {
- keys = append(keys, k)
- }
-
- sort.Strings(keys)
- for _, k := range keys {
- cli.StatusMessage(cli.VERBOSITY_QUIET, " %s: %s\n", k, vars[k])
- }
- }
- }
-}
-
-func targetCreateCmd(cmd *cobra.Command, args []string) {
- if len(args) != 1 {
- NewtUsage(cmd, cli.NewNewtError("Wrong number of args to create cmd."))
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Creating target "+args[0]+"\n")
-
- if cli.TargetExists(NewtNest, args[0]) {
- NewtUsage(cmd, cli.NewNewtError(
- "Target already exists, cannot create target with same name."))
- }
-
- target := &cli.Target{
- Nest: NewtNest,
- Vars: map[string]string{},
- }
- target.Vars["name"] = args[0]
-
- err := target.Save()
- if err != nil {
- NewtUsage(nil, err)
- } else {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully created!\n", args[0])
- }
-}
-
-func targetBuildCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 {
- NewtUsage(cmd, cli.NewNewtError("Must specify target to build"))
- }
-
- t, err := cli.LoadTarget(NewtNest, args[0])
- if err != nil {
- NewtUsage(nil, err)
- }
-
- if len(args) > 1 && args[1] == "clean" {
- if len(args) > 2 && args[2] == "all" {
- err = t.BuildClean(true)
- } else {
- err = t.BuildClean(false)
- }
- if err != nil {
- NewtUsage(nil, err)
- }
- } else {
- // Parse any remaining key-value pairs and insert them into the target.
- err = extractTargetVars(args[1:], t)
- if err != nil {
- NewtUsage(nil, err)
- }
-
- err = t.Build()
- if err != nil {
- NewtUsage(nil, err)
- }
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Successfully run!\n")
-}
-
-func targetDelCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 {
- NewtUsage(cmd, cli.NewNewtError("Must specify target to delete"))
- }
-
- t, err := cli.LoadTarget(NewtNest, args[0])
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- // Clean target prior to deletion; ignore errors during clean.
- t.BuildClean(false)
-
- if err := t.Remove(); err != nil {
- NewtUsage(cmd, err)
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully removed\n", args[0])
-}
-
-func targetTestCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 {
- NewtUsage(cmd, cli.NewNewtError("Must specify target to build"))
- }
-
- t, err := cli.LoadTarget(NewtNest, args[0])
- if err != nil {
- NewtUsage(nil, err)
- }
-
- if len(args) > 1 && args[1] == "clean" {
- if len(args) > 2 && args[2] == "all" {
- err = t.Test("testclean", true)
- } else {
- err = t.Test("testclean", false)
- }
- if err != nil {
- NewtUsage(nil, err)
- }
- } else {
- // Parse any remaining key-value pairs and insert them into the target.
- err = extractTargetVars(args[1:], t)
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- err = t.Test("test", ExitOnFailure)
- if err != nil {
- NewtUsage(nil, err)
- }
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Successfully run!\n")
-}
-
-func targetSizeCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 {
- NewtUsage(cmd, cli.NewNewtError("Must specify target for sizing"))
- }
-
- t, err := cli.LoadTarget(NewtNest, args[0])
- if err != nil {
- NewtUsage(nil, err)
- }
-
- txt, err := t.GetSize()
- if err != nil {
- NewtUsage(nil, err)
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "%s", txt)
-}
-
-func targetDownloadCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 {
- NewtUsage(cmd, cli.NewNewtError("Must specify target to download"))
- }
-
- t, err := cli.LoadTarget(NewtNest, args[0])
- if err != nil {
- NewtUsage(nil, err)
- }
-
- err = t.Download()
- if err != nil {
- NewtUsage(nil, err)
- }
-}
-
-func targetDebugCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 {
- NewtUsage(cmd, cli.NewNewtError("Must specify target for debug"))
- }
-
- t, err := cli.LoadTarget(NewtNest, args[0])
- if err != nil {
- NewtUsage(nil, err)
- }
-
- err = t.Debug()
- if err != nil {
- NewtUsage(nil, err)
- }
-}
-
-func targetExportCmd(cmd *cobra.Command, args []string) {
- var targetName string
- if ExportAll {
- targetName = ""
- } else {
- if len(args) < 1 {
- NewtUsage(cmd, cli.NewNewtError("Must either specify -a flag or name of "+
- "target to export"))
- }
- targetName = args[0]
- }
-
- err := cli.ExportTargets(NewtNest, targetName, ExportAll, os.Stdout)
- if err != nil {
- NewtUsage(cmd, err)
- }
-}
-
-func targetImportCmd(cmd *cobra.Command, args []string) {
- var targetName string
- if ImportAll {
- targetName = ""
- } else {
- if len(args) < 1 {
- NewtUsage(cmd, cli.NewNewtError("Must either specify -a flag or name of "+
- "target to import"))
- }
-
- targetName = args[0]
- }
-
- err := cli.ImportTargets(NewtNest, targetName, ImportAll, os.Stdin)
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target(s) successfully imported!\n")
-}
-
-func targetAddCmds(base *cobra.Command) {
- targetHelpText := formatHelp(`Targets tell the newt tool how to build the source
- code within a given nest.`)
- targetHelpEx := " newt target create <target-name>\n"
- targetHelpEx += " newt target set <target-name> <var-name>=<value>\n"
- targetHelpEx += " newt target unset <target-name> <var-name>\n"
- targetHelpEx += " newt target show <target-name>\n"
- targetHelpEx += " newt target delete <target-name>\n"
- targetHelpEx += " newt target build <target-name> [clean[ all]]\n"
- targetHelpEx += " newt target test <target-name> [clean[ all]]\n"
- targetHelpEx += " newt target size <target-name>\n"
- targetHelpEx += " newt target download <target-name>\n"
- targetHelpEx += " newt target debug <target-name>\n"
- targetHelpEx += " newt target export [-a -export-all] [<target-name>]\n"
- targetHelpEx += " newt target import [-a -import-all] [<target-name>]"
-
- targetCmd := &cobra.Command{
- Use: "target",
- Short: "Set and view target information",
- Long: targetHelpText,
- Example: targetHelpEx,
- PersistentPreRun: func(cmd *cobra.Command, args []string) {
- cli.Init(NewtLogLevel, newtSilent, newtQuiet, newtVerbose)
-
- var err error
- NewtNest, err = cli.NewNest()
- if err != nil {
- NewtUsage(nil, err)
- }
- },
- Run: func(cmd *cobra.Command, args []string) {
- cmd.Usage()
- },
- }
-
- setHelpText := formatHelp(`Set a target variable (<var-name>) on target
- <target-name> to value <value>.`)
- setHelpEx := " newt target set <target-name> <var-name>=<value>\n"
- setHelpEx += " newt target set my_target1 var_name=value\n"
- setHelpEx += " newt target set my_target1 arch=cortex_m4"
-
- setCmd := &cobra.Command{
- Use: "set",
- Short: "Set target configuration variable",
- Long: setHelpText,
- Example: setHelpEx,
- Run: targetSetCmd,
- }
-
- targetCmd.AddCommand(setCmd)
-
- unsetHelpText := formatHelp(`Unset a target variable (<var-name>) on target
- <target-name>.`)
- unsetHelpEx := " newt target unset <target-name> <var-name>\n"
- unsetHelpEx += " newt target unset my_target1 var_name"
-
- unsetCmd := &cobra.Command{
- Use: "unset",
- Short: "Unset target configuration variable",
- Long: unsetHelpText,
- Example: unsetHelpEx,
- Run: targetUnsetCmd,
- }
-
- targetCmd.AddCommand(unsetCmd)
-
- delHelpText := formatHelp(`Delete the target specified by <target-name>.`)
- delHelpEx := " newt target delete <target-name>\n"
- delHelpEx += " newt target delete my_target1"
-
- delCmd := &cobra.Command{
- Use: "delete",
- Short: "Delete target",
- Long: delHelpText,
- Example: delHelpEx,
- Run: targetDelCmd,
- }
-
- targetCmd.AddCommand(delCmd)
-
- createHelpText := formatHelp(`Create a target specified by <target-name>.`)
- createHelpEx := " newt target create <target-name>\n"
- createHelpEx += " newt target create my_target1"
-
- createCmd := &cobra.Command{
- Use: "create",
- Short: "Create a target",
- Long: createHelpText,
- Example: createHelpEx,
- Run: targetCreateCmd,
- }
-
- targetCmd.AddCommand(createCmd)
-
- showHelpText := formatHelp(`Show all the variables for the target specified
- by <target-name>.`)
- showHelpEx := " newt target show <target-name>\n"
- showHelpEx += " newt target show my_target1"
-
- showCmd := &cobra.Command{
- Use: "show",
- Short: "View target configuration variables",
- Long: showHelpText,
- Example: showHelpEx,
- Run: targetShowCmd,
- }
-
- targetCmd.AddCommand(showCmd)
-
- buildHelpText := formatHelp(`Build the target specified by <target-name>.
- If clean is specified, then all the binaries and object files for this
- target will be removed. If the all option is specified, all binaries
- and object files for all targets will be removed.`)
- buildHelpEx := " newt target build <target-name> [clean[ all]]\n"
- buildHelpEx += " newt target build my_target1\n"
- buildHelpEx += " newt target build my_target1 clean\n"
- buildHelpEx += " newt target build my_target1 clean all\n"
-
- buildCmd := &cobra.Command{
- Use: "build",
- Short: "Build target",
- Long: buildHelpText,
- Example: buildHelpEx,
- Run: targetBuildCmd,
- }
-
- targetCmd.AddCommand(buildCmd)
-
- testHelpText := formatHelp(`Test the target specified by <target-name>. If
- clean is specified, then all the test binaries and object files for this
- target will be removed. If the all option is specified, all test
- binaries and object files for all targets will be removed.`)
- testHelpEx := " newt target test <target-name> [clean, [all]]\n"
- testHelpEx += " newt target test mytarget1\n"
- testHelpEx += " newt target test mytarget1 clean\n"
- testHelpEx += " newt target test mytarget1 clean all"
-
- testCmd := &cobra.Command{
- Use: "test",
- Short: "Test target",
- Long: testHelpText,
- Example: testHelpEx,
- Run: targetTestCmd,
- }
-
- targetCmd.AddCommand(testCmd)
-
- sizeHelpText := formatHelp(`Calculate the size of target components specified by
- <target-name>.`)
- sizeHelpEx := " newt target size <target-name>\n"
-
- sizeCmd := &cobra.Command{
- Use: "size",
- Short: "Size of the target",
- Long: sizeHelpText,
- Example: sizeHelpEx,
- Run: targetSizeCmd,
- }
-
- targetCmd.AddCommand(sizeCmd)
-
- downloadHelpText := formatHelp(`Download project image to target for
- <target-name>.`)
- downloadHelpEx := " newt target download <target-name>\n"
-
- downloadCmd := &cobra.Command{
- Use: "download",
- Short: "Download project to target",
- Long: downloadHelpText,
- Example: downloadHelpEx,
- Run: targetDownloadCmd,
- }
- targetCmd.AddCommand(downloadCmd)
-
- debugHelpText := formatHelp(`Download project image to target for
- <target-name>.`)
- debugHelpEx := " newt target download <target-name>\n"
-
- debugCmd := &cobra.Command{
- Use: "debug",
- Short: "Open debugger session to target",
- Long: debugHelpText,
- Example: debugHelpEx,
- Run: targetDebugCmd,
- }
- targetCmd.AddCommand(debugCmd)
-
- exportHelpText := formatHelp(`Export build targets from the current nest, and
- print them to standard output. If the -a (or -export-all) option is
- specified, then all targets will be exported. Otherwise, <target-name>
- must be specified, and only that target will be exported.`)
- exportHelpEx := " newt target export [-a -export-all] [<target-name>]\n"
- exportHelpEx += " newt target export -a > my_exports.txt\n"
- exportHelpEx += " newt target export my_target > my_target_export.txt"
-
- exportCmd := &cobra.Command{
- Use: "export",
- Short: "Export target",
- Long: exportHelpText,
- Example: exportHelpEx,
- Run: targetExportCmd,
- }
-
- exportCmd.PersistentFlags().BoolVarP(&ExportAll, "export-all", "a", false,
- "If present, export all targets")
-
- targetCmd.AddCommand(exportCmd)
-
- importHelpText := formatHelp(`Import build targets from standard input. If
- the -a (or -import-all) option is specified, then all targets will be
- imported. Otherwise, a <target-name> must be specified, and only that
- target will be imported.`)
- importHelpEx := " newt target import [-a -import-all] [<target-name>]\n"
- importHelpEx += " newt target import -a < exported_targets.txt\n"
- importHelpEx += " newt target import ex_tgt_1 < exported_targets.txt"
-
- importCmd := &cobra.Command{
- Use: "import",
- Short: "Import target",
- Long: importHelpText,
- Example: importHelpEx,
- Run: targetImportCmd,
- }
-
- importCmd.PersistentFlags().BoolVarP(&ImportAll, "import-all", "a", false,
- "If present, import all targets")
-
- targetCmd.AddCommand(importCmd)
-
- base.AddCommand(targetCmd)
-}
-
-func dispEgg(egg *cli.Egg) error {
- cli.StatusMessage(cli.VERBOSITY_QUIET, "Egg %s, version %s\n",
- egg.FullName, egg.Version)
- cli.StatusMessage(cli.VERBOSITY_QUIET, " path: %s\n",
- filepath.Clean(egg.BasePath))
- if egg.Capabilities != nil {
- cli.StatusMessage(cli.VERBOSITY_QUIET, " capabilities: ")
- caps, err := egg.GetCapabilities()
- if err != nil {
- return err
- }
- for _, capability := range caps {
- cli.StatusMessage(cli.VERBOSITY_QUIET, "%s ", capability)
- }
- cli.StatusMessage(cli.VERBOSITY_QUIET, "\n")
- }
- if egg.ReqCapabilities != nil {
- cli.StatusMessage(cli.VERBOSITY_QUIET, " required capabilities: ")
- caps, err := egg.GetReqCapabilities()
- if err != nil {
- return err
- }
- for _, capability := range caps {
- cli.StatusMessage(cli.VERBOSITY_QUIET, "%s ", capability)
- }
- cli.StatusMessage(cli.VERBOSITY_QUIET, "\n")
- }
- if len(egg.Deps) > 0 {
- cli.StatusMessage(cli.VERBOSITY_QUIET, " deps: ")
- for _, dep := range egg.Deps {
- if dep == nil {
- continue
- }
- cli.StatusMessage(cli.VERBOSITY_QUIET, "%s ", dep)
- }
- cli.StatusMessage(cli.VERBOSITY_QUIET, "\n")
- }
-
- if egg.LinkerScript != "" {
- cli.StatusMessage(cli.VERBOSITY_QUIET, " linkerscript: %s\n",
- egg.LinkerScript)
- }
- return nil
-}
-
-func dispEggShell(eggShell *cli.EggShell) error {
- cli.StatusMessage(cli.VERBOSITY_QUIET, "Egg %s from clutch %s, version %s\n",
- eggShell.FullName, eggShell.Clutch.Name, eggShell.Version)
-
- if eggShell.Caps != nil {
- cli.StatusMessage(cli.VERBOSITY_QUIET, " capabilities: ")
- caps, err := eggShell.GetCapabilities()
- if err != nil {
- return err
- }
- for _, capability := range caps {
- cli.StatusMessage(cli.VERBOSITY_QUIET, "%s ", capability)
- }
- cli.StatusMessage(cli.VERBOSITY_QUIET, "\n")
- }
- if eggShell.ReqCaps != nil {
- cli.StatusMessage(cli.VERBOSITY_QUIET, " required capabilities: ")
- caps, err := eggShell.GetReqCapabilities()
- if err != nil {
- return err
- }
- for _, capability := range caps {
- cli.StatusMessage(cli.VERBOSITY_QUIET, "%s ", capability)
- }
- cli.StatusMessage(cli.VERBOSITY_QUIET, "\n")
- }
- if len(eggShell.Deps) > 0 {
- cli.StatusMessage(cli.VERBOSITY_QUIET, " deps: ")
- for _, dep := range eggShell.Deps {
- if dep == nil {
- continue
- }
- cli.StatusMessage(cli.VERBOSITY_QUIET, "%s ", dep)
- }
- cli.StatusMessage(cli.VERBOSITY_QUIET, "\n")
- }
-
- return nil
-}
-
-func eggListCmd(cmd *cobra.Command, args []string) {
- eggMgr, err := cli.NewClutch(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
- if err := eggMgr.LoadConfigs(nil, false); err != nil {
- NewtUsage(cmd, err)
- }
- for _, egg := range eggMgr.Eggs {
- if err := dispEgg(egg); err != nil {
- NewtUsage(cmd, err)
- }
- }
-}
-
-func eggCheckDepsCmd(cmd *cobra.Command, args []string) {
- eggMgr, err := cli.NewClutch(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- if err := eggMgr.LoadConfigs(nil, false); err != nil {
- NewtUsage(cmd, err)
- }
-
- if err := eggMgr.CheckDeps(); err != nil {
- NewtUsage(cmd, err)
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Dependencies successfully resolved!\n")
-}
-
-func eggHuntCmd(cmd *cobra.Command, args []string) {
- var err error
-
- if len(args) != 1 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify string to hunt for"))
- }
-
- /*
- * First check local.
- */
- eggMgr, err := cli.NewClutch(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
- if err := eggMgr.LoadConfigs(nil, false); err != nil {
- NewtUsage(cmd, err)
- }
-
- found := false
- for _, egg := range eggMgr.Eggs {
- contains := strings.Contains(egg.FullName, args[0])
- if contains == true {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Installed egg %s@%s\n",
- egg.FullName, egg.Version)
- found = true
- }
- }
-
- /*
- * Then check remote clutches.
- */
- clutches, err := NewtNest.GetClutches()
- if err != nil {
- NewtUsage(cmd, err)
- }
- for _, clutch := range clutches {
- for _, eggShell := range clutch.EggShells {
- contains := strings.Contains(eggShell.FullName, args[0])
- if contains == true {
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Clutch %s has egg %s@%s\n",
- clutch.Name, eggShell.FullName,
- eggShell.Version)
- found = true
- }
- }
- }
-
- if found == false {
- cli.StatusMessage(cli.VERBOSITY_QUIET, "No egg found!\n")
- }
-}
-
-func eggShowCmd(cmd *cobra.Command, args []string) {
- var eggName string
- var clutchName string = ""
-
- if len(args) < 1 || len(args) > 2 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify full name of the egg"))
- }
-
- if len(args) == 1 {
- eggName = args[0]
- } else {
- clutchName = args[0]
- eggName = args[1]
- }
-
- eggMgr, err := cli.NewClutch(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
- if err := eggMgr.LoadConfigs(nil, false); err != nil {
- NewtUsage(cmd, err)
- }
-
- egg, err := eggMgr.ResolveEggName(eggName)
- if err == nil {
- egg.LoadConfig(nil, false)
- dispEgg(egg)
- }
-
- clutches, err := NewtNest.GetClutches()
- if err != nil {
- NewtUsage(cmd, err)
- }
- for _, clutch := range clutches {
- if clutchName == "" || clutch.Name == clutchName {
- eggShell, err := clutch.ResolveEggShellName(eggName)
- if err == nil {
- dispEggShell(eggShell)
- }
- }
- }
-}
-
-func eggShellInstall(eggShell *cli.EggShell) error {
- eggMgr, err := cli.NewClutch(NewtNest)
- if err != nil {
- return err
- }
-
- if err := eggMgr.LoadConfigs(nil, false); err != nil {
- return err
- }
-
- _, err = eggMgr.ResolveEggName(eggShell.FullName)
- if err == nil {
- return cli.NewNewtError(fmt.Sprintf("Egg %s already installed!",
- eggShell.FullName))
- }
- err = eggShell.Install(eggMgr, NewtBranchEgg)
- if err != nil {
- return err
- }
- return nil
-}
-
-func eggInstallCmd(cmd *cobra.Command, args []string) {
- var eggName string
- var clutchName string = ""
- var clutch *cli.Clutch
- var eggShell *cli.EggShell
-
- if len(args) < 1 || len(args) > 2 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify full name of the egg"))
- }
-
- if len(args) == 1 {
- eggName = args[0]
- } else {
- clutchName = args[0]
- eggName = args[1]
- }
-
- /*
- * Find the eggShell to install.
- */
- clutches, err := NewtNest.GetClutches()
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- if clutchName != "" {
- clutch = clutches[clutchName]
- }
- if clutch != nil {
- eggShell, err := clutch.ResolveEggShellName(eggName)
- if err != nil {
- NewtUsage(cmd, err)
- }
- err = eggShellInstall(eggShell)
- if err != nil {
- NewtUsage(cmd, err)
- }
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Installation was a success!\n")
- return
- }
- eggShell = nil
- for _, tmpClutch := range clutches {
- if clutchName == "" || tmpClutch.Name == clutchName {
- tmpEggShell, err := tmpClutch.ResolveEggShellName(eggName)
- if err != nil && eggShell != nil {
- NewtUsage(cmd,
- cli.NewNewtError(fmt.Sprintf("Ambiguous source "+
- "egg %s in clutches %s and %s",
- eggName, clutch.Name, tmpClutch.Name)))
- } else {
- eggShell = tmpEggShell
- clutch = tmpClutch
- }
- }
- }
-
- if eggShell == nil {
- NewtUsage(cmd,
- cli.NewNewtError(fmt.Sprintf("Can't find egg with name %s",
- eggName)))
- }
-
- err = eggShellInstall(eggShell)
- if err != nil {
- NewtUsage(cmd, err)
- }
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Installation was a success!\n")
-}
-
-func eggRemoveCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 || len(args) > 2 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify full name of the egg"))
- }
-
- eggName := args[0]
-
- eggMgr, err := cli.NewClutch(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
- if err := eggMgr.LoadConfigs(nil, false); err != nil {
- NewtUsage(cmd, err)
- }
-
- egg, err := eggMgr.ResolveEggName(eggName)
- if err != nil {
- NewtUsage(cmd,
- cli.NewNewtError(fmt.Sprintf("Egg %s has not been installed",
- eggName)))
- }
- err = egg.Remove()
- if err != nil {
- NewtUsage(cmd, err)
- }
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "Removed successfully!\n")
-}
-
-func eggAddCmds(baseCmd *cobra.Command) {
- eggHelpText := formatHelp(`Commands to search, display and install eggs
- in the current nest. Eggs are newt's version of packages, and are
- the fundamental building blocks of nests.`)
- eggHelpEx := " newt egg list\n"
- eggHelpEx += " newt egg checkdeps\n"
- eggHelpEx += " newt egg hunt <egg-name>\n"
- eggHelpEx += " newt egg show [<clutch-name> ] <egg-name>\n"
- eggHelpEx += " newt egg install [<clutch-name> ] <egg-name>\n"
- eggHelpEx += " newt egg remove [<clutch-name> ] <egg-name>"
-
- eggCmd := &cobra.Command{
- Use: "egg",
- Short: "Commands to list and inspect eggs on a nest",
- Long: eggHelpText,
- Example: eggHelpEx,
- PersistentPreRun: func(cmd *cobra.Command, args []string) {
- cli.Init(NewtLogLevel, newtSilent, newtQuiet, newtVerbose)
-
- var err error
- NewtNest, err = cli.NewNest()
- if err != nil {
- NewtUsage(nil, err)
- }
- },
- Run: func(cmd *cobra.Command, args []string) {
- NewtUsage(cmd, nil)
- },
- }
-
- listHelpText := formatHelp(`List all of the eggs in the current nest.`)
- listHelpEx := " newt egg list"
-
- listCmd := &cobra.Command{
- Use: "list",
- Short: "List eggs in the current nest",
- Long: listHelpText,
- Example: listHelpEx,
- Run: eggListCmd,
- }
-
- eggCmd.AddCommand(listCmd)
-
- checkDepsHelpText := formatHelp(`Resolve all dependencies in the local
- nest. This command goes through all eggs currently installed, checks
- their dependencies, and prints any unresolved dependencies between
- eggs.`)
- checkDepsHelpEx := " newt egg checkdeps"
-
- checkDepsCmd := &cobra.Command{
- Use: "checkdeps",
- Short: "Check egg dependencies",
- Long: checkDepsHelpText,
- Example: checkDepsHelpEx,
- Run: eggCheckDepsCmd,
- }
-
- eggCmd.AddCommand(checkDepsCmd)
-
- huntHelpText := formatHelp(`Hunt for an egg, specified by <egg-name>.
- The local nest, along with all remote nests (clutches) are
- searched. All matched eggs are shown.`)
- huntHelpEx := " newt egg hunt <egg-name>"
-
- huntCmd := &cobra.Command{
- Use: "hunt",
- Short: "Search for egg from clutches",
- Long: huntHelpText,
- Example: huntHelpEx,
- Run: eggHuntCmd,
- }
-
- eggCmd.AddCommand(huntCmd)
-
- showHelpText := formatHelp(`Show the contents of the egg, specified by
- <egg-name>. <egg-name> is resolved using all the clutches installed
- in the current nest or, if <clutch-name> is specified, only
- <clutch-name> will be searched.`)
- showHelpEx := " newt egg show [<clutch-name> ] <egg-name>"
-
- showCmd := &cobra.Command{
- Use: "show",
- Short: "Show the contents of an egg.",
- Long: showHelpText,
- Example: showHelpEx,
- Run: eggShowCmd,
- }
-
- eggCmd.AddCommand(showCmd)
-
- installHelpText := formatHelp(`Install the egg specified by <egg-name> to
- the local nest. <egg-name> is searched for throughout the clutches in
- the local nest. If <clutch-name> is specified, then only <clutch-name>
- is searched for <egg-name>.`)
- installHelpEx := " newt egg install [<clutch-name> ] <egg-name>"
-
- installCmd := &cobra.Command{
- Use: "install",
- Short: "Install an egg",
- Long: installHelpText,
- Example: installHelpEx,
- Run: eggInstallCmd,
- }
-
- installCmd.Flags().StringVarP(&NewtBranchEgg, "branch", "b", "",
- "Branch (or tag) of the clutch to install from.")
-
- eggCmd.AddCommand(installCmd)
-
- removeHelpText := formatHelp(`Remove the egg, specified by <egg-name> from
- the local nest. If present the egg is taking only from the clutch
- specified by <clutch-name>.`)
- removeHelpEx := " newt egg remove [<clutch-name> ] <egg-name>"
-
- removeCmd := &cobra.Command{
- Use: "remove",
- Short: "Remove an egg",
- Long: removeHelpText,
- Example: removeHelpEx,
- Run: eggRemoveCmd,
- }
-
- eggCmd.AddCommand(removeCmd)
-
- baseCmd.AddCommand(eggCmd)
-}
-
-func nestGenerateClutchCmd(cmd *cobra.Command, args []string) {
- if len(args) != 2 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify name and URL to lay clutch file"))
- }
-
- clutchName := args[0]
- clutchUrl := args[1]
-
- clutch, err := cli.NewClutch(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
- clutch.Name = clutchName
- clutch.RemoteUrl = clutchUrl
-
- local, err := cli.NewClutch(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- if err := clutch.LoadFromClutch(local); err != nil {
- NewtUsage(cmd, err)
- }
-
- clutchStr, err := clutch.Serialize()
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT, "%s", clutchStr)
-}
-
-func nestAddClutchCmd(cmd *cobra.Command, args []string) {
- if len(args) != 2 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify both name and URL to "+
- "larva install command"))
- }
-
- name := args[0]
- url := args[1]
-
- clutch, err := cli.NewClutch(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- if err := clutch.Install(name, url, NewtBranchClutch); err != nil {
- NewtUsage(cmd, err)
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Clutch "+name+" successfully installed to Nest.\n")
-}
-
-func nestListClutchesCmd(cmd *cobra.Command, args []string) {
- clutches, err := NewtNest.GetClutches()
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- for name, clutch := range clutches {
- cli.StatusMessage(cli.VERBOSITY_QUIET,
- "Remote clutch %s (eggshells: %d)\n", name, len(clutch.EggShells))
- }
-}
-
-func nestCreateCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify a nest name to create"))
- }
-
- wd, err := os.Getwd()
- if err != nil {
- NewtUsage(cmd, cli.NewNewtError(err.Error()))
- }
-
- nestDir := wd + "/" + args[0]
- if len(args) > 1 {
- nestDir = args[1]
- }
-
- tadpoleUrl := ""
- if len(args) > 2 {
- tadpoleUrl = args[2]
- }
-
- if err := cli.CreateNest(args[0], nestDir, tadpoleUrl); err != nil {
- NewtUsage(cmd, err)
- }
-
- cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Nest %s successfully created in %s\n", args[0], nestDir)
-}
-
-func nestShowClutchCmd(cmd *cobra.Command, args []string) {
- if len(args) != 1 {
- NewtUsage(cmd,
- cli.NewNewtError("Must specify a clutch name to show-clutch command"))
- }
-
- clutch, err := cli.NewClutch(NewtNest)
- if err != nil {
- NewtUsage(cmd, err)
- }
-
- if err := clutch.Load(args[0]); err != nil {
- NewtUsage(cmd, err)
- }
-
- // Clutch loaded, now print out clutch information
- cli.StatusMessage(cli.VERBOSITY_QUIET, "Clutch Name: %s\n", clutch.Name)
- cli.StatusMessage(cli.VERBOSITY_QUIET, "Clutch URL: %s\n",
- clutch.RemoteUrl)
-
- i := 0
- for _, eggShell := range clutch.EggShells {
- i++
- cli.StatusMessage(cli.VERBOSITY_QUIET, " %s@%s", eggShell.FullName,
- eggShell.Version)
- if i%4 == 0 {
- cli.StatusMessage(cli.VERBOSITY_QUIET, "\n")
- }
- }
- if i%4 != 0 {
- cli.StatusMessage(cli.VERBOSITY_QUIET, "\n")
- }
-}
-
-func nestAddCmds(baseCmd *cobra.Command) {
- var nestCmd *cobra.Command
- var createCmd *cobra.Command
-
- nestHelpText := formatHelp(`The nest commands help manage the local nest.
- A nest represents the workspace for one or more projects, each project being a
- collection of eggs (packages.) In addition to containing eggs, a local nest contains the
- target (build) definitions, and a list of clutches (snapshots of remote nests
- which contain eggs that can be installed into the current nest.)`)
- nestHelpEx := " newt nest create <nest-name> [, <nest-skele-url>]\n"
- nestHelpEx += " newt nest list-clutches\n"
- nestHelpEx += " newt nest show-clutch <clutch-name>\n"
- nestHelpEx += " newt nest add-clutch <clutch-name> <clutch-url>\n"
- nestHelpEx += " newt nest generate-clutch <clutch-name> <clutch-url>"
-
- nestCmd = &cobra.Command{
- Use: "nest",
- Short: "Commands to manage nests & clutches (remote egg repositories)",
- Long: nestHelpText,
- Example: nestHelpEx,
- PersistentPreRun: func(cmd *cobra.Command, args []string) {
- cli.Init(NewtLogLevel, newtSilent, newtQuiet, newtVerbose)
-
- var err error
-
- if cmd != nestCmd && cmd != createCmd {
- NewtNest, err = cli.NewNest()
- if err != nil {
- NewtUsage(cmd, err)
- }
- }
- },
- Run: func(cmd *cobra.Command, args []string) {
- NewtUsage(cmd, nil)
- },
- }
-
- createHelpText := formatHelp(`Create a new nest, specified by <nest-name>.
- If the optional <nest-url> parameter is specified, then download the
- skeleton of the nest file from that URL, instead of using the default.`)
-
- createHelpEx := " newt nest create <nest-name> [, <nest-url>]\n"
- createHelpEx += " newt nest create mynest"
-
- createCmd = &cobra.Command{
- Use: "create",
- Short: "Create a new nest",
- Long: createHelpText,
- Example: createHelpEx,
- Run: nestCreateCmd,
- }
-
- nestCmd.AddCommand(createCmd)
-
- generateHelpText := formatHelp(`Generate a clutch file from a snapshot
- of the eggs in the current directory. generate-clutch takes two
- arguments, the name of the current nest and the URL at which
- the nest is located.`)
-
- generateHelpEx := " newt nest generate-clutch <name> <url>\n"
- generateHelpEx += " newt nest generate-clutch larva " +
- "https://www.github.com/mynewt/larva"
-
- generateCmd := &cobra.Command{
- Use: "generate-clutch",
- Short: "Generate a clutch file from the eggs in the current directory",
- Long: generateHelpText,
- Example: generateHelpEx,
- Run: nestGenerateClutchCmd,
- }
-
- nestCmd.AddCommand(generateCmd)
-
- addClutchHelpText := formatHelp(`Add a remote clutch to the current nest.
- When search for eggs to install, the clutch specified by clutch-name
- and clutch-url will be searched for eggs that match the search. This
- includes both direct searches with newt egg hunt, as well as resolving
- dependencies in egg.yml files.`)
-
- addClutchHelpEx := " newt nest add-clutch <clutch-name> <clutch-url>\n"
- addClutchHelpEx += " newt nest add-clutch larva " +
- "https://www.github.com/mynewt/larva"
-
- addClutchCmd := &cobra.Command{
- Use: "add-clutch",
- Short: "Add a remote clutch, and put it in the current nest",
- Long: addClutchHelpText,
- Example: addClutchHelpEx,
- Run: nestAddClutchCmd,
- }
-
- addClutchCmd.Flags().StringVarP(&NewtBranchClutch, "branch", "b", "master",
- "Branch (or tag) of the clutch to install from.")
-
- nestCmd.AddCommand(addClutchCmd)
-
- listClutchesHelpText := formatHelp(`List the clutches installed in the current
- nest. A clutch represents a collection of eggs in a nest. List clutches
- includes the current nest, along with any remote clutches that have been
- added using the add-clutch command.`)
-
- listClutchesHelpEx := " newt nest list-clutches"
-
- listClutchesCmd := &cobra.Command{
- Use: "list-clutches",
- Short: "List the clutches installed in the current nest",
- Long: listClutchesHelpText,
- Example: listClutchesHelpEx,
- Run: nestListClutchesCmd,
- }
-
- nestCmd.AddCommand(listClutchesCmd)
-
- showClutchHelpText := formatHelp(`Show information about a clutch, given by the
- <clutch-name> parameter. Displays the clutch name, URL and packages
- associated with a given clutch.`)
-
- showClutchHelpEx := " newt nest show-clutch <clutch-name>\n"
- showClutchHelpEx += " newt nest show-clutch larva"
-
- showClutchCmd := &cobra.Command{
- Use: "show-clutch",
- Short: "Show an individual clutch in the current nest",
- Long: showClutchHelpText,
- Example: showClutchHelpEx,
- Run: nestShowClutchCmd,
- }
-
- nestCmd.AddCommand(showClutchCmd)
-
- baseCmd.AddCommand(nestCmd)
-}
-
-func parseCmds() *cobra.Command {
- newtHelpText := formatHelp(`Newt allows you to create your own embedded
- project based on the Mynewt operating system. Newt provides both
- build and package management in a single tool, which allows you to
- compose an embedded workspace, and set of projects, and then build
- the necessary artifacts from those projects. For more information
- on the Mynewt operating system, please visit
- https://www.github.com/mynewt/documentation.`)
- newtHelpText += "\n\n" + formatHelp(`Please use the newt help command,
- and specify the name of the command you want help for, for help on
- how to use a specific command`)
- newtHelpEx := " newt\n"
- newtHelpEx += " newt help [<command-name>]\n"
- newtHelpEx += " For help on <command-name>. If not specified, " +
- "print this message."
-
- newtCmd := &cobra.Command{
- Use: "newt",
- Short: "Newt is a tool to help you compose and build your own OS",
- Long: newtHelpText,
- Example: newtHelpEx,
- Run: func(cmd *cobra.Command, args []string) {
- cmd.Help()
- },
- }
-
- newtCmd.PersistentFlags().BoolVarP(&newtVerbose, "verbose", "v", false,
- "Enable verbose output when executing commands.")
- newtCmd.PersistentFlags().BoolVarP(&newtQuiet, "quiet", "q", false,
- "Be quiet; only display error output.")
- newtCmd.PersistentFlags().BoolVarP(&newtSilent, "silent", "s", false,
- "Be silent; don't output anything.")
- newtCmd.PersistentFlags().StringVarP(&NewtLogLevel, "loglevel", "l",
- "WARN", "Log level, defaults to WARN.")
-
- versHelpText := formatHelp(`Display the Newt version number.`)
- versHelpEx := " newt version"
- versCmd := &cobra.Command{
- Use: "version",
- Short: "Display the Newt version number.",
- Long: versHelpText,
- Example: versHelpEx,
- Run: func(cmd *cobra.Command, args []string) {
- fmt.Printf("Newt version: %s\n", NewtVersion)
- },
- }
-
- newtCmd.AddCommand(versCmd)
-
- targetAddCmds(newtCmd)
- eggAddCmds(newtCmd)
- nestAddCmds(newtCmd)
-
- return newtCmd
-}
-
-func main() {
- cmd := parseCmds()
- cmd.Execute()
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/newt/Godeps/Godeps.json
----------------------------------------------------------------------
diff --git a/newt/Godeps/Godeps.json b/newt/Godeps/Godeps.json
new file mode 100644
index 0000000..ff5e92a
--- /dev/null
+++ b/newt/Godeps/Godeps.json
@@ -0,0 +1,70 @@
+{
+ "ImportPath": "github.com/mynewt/newt",
+ "GoVersion": "go1.4.2",
+ "Deps": [
+ {
+ "ImportPath": "github.com/BurntSushi/toml",
+ "Comment": "v0.1.0-21-g056c9bc",
+ "Rev": "056c9bc7be7190eaa7715723883caffa5f8fa3e4"
+ },
+ {
+ "ImportPath": "github.com/andelf/go-curl",
+ "Comment": "compatible-with-go-release.r60-63-gc965868",
+ "Rev": "c965868dde67fef2abe524c33f1661d9ad233fac"
+ },
+ {
+ "ImportPath": "github.com/hashicorp/logutils",
+ "Rev": "0dc08b1671f34c4250ce212759ebd880f743d883"
+ },
+ {
+ "ImportPath": "github.com/inconshreveable/mousetrap",
+ "Rev": "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75"
+ },
+ {
+ "ImportPath": "github.com/kr/pretty",
+ "Comment": "go.weekly.2011-12-22-27-ge6ac2fc",
+ "Rev": "e6ac2fc51e89a3249e82157fa0bb7a18ef9dd5bb"
+ },
+ {
+ "ImportPath": "github.com/kr/text",
+ "Rev": "e373e137fafd8abd480af49182dea0513914adb4"
+ },
+ {
+ "ImportPath": "github.com/magiconair/properties",
+ "Comment": "v1.5.3",
+ "Rev": "624009598839a9432bd97bb75552389422357723"
+ },
+ {
+ "ImportPath": "github.com/mattn/go-sqlite3",
+ "Rev": "542ae647f8601bafd96233961b150cae198e0295"
+ },
+ {
+ "ImportPath": "github.com/mitchellh/mapstructure",
+ "Rev": "2caf8efc93669b6c43e0441cdc6aed17546c96f3"
+ },
+ {
+ "ImportPath": "github.com/spf13/cast",
+ "Rev": "4d07383ffe94b5e5a6fa3af9211374a4507a0184"
+ },
+ {
+ "ImportPath": "github.com/spf13/cobra",
+ "Rev": "66816bcd0378e248c613e3c443c020f544c28804"
+ },
+ {
+ "ImportPath": "github.com/spf13/jwalterweatherman",
+ "Rev": "3d60171a64319ef63c78bd45bd60e6eab1e75f8b"
+ },
+ {
+ "ImportPath": "github.com/spf13/pflag",
+ "Rev": "67cbc198fd11dab704b214c1e629a97af392c085"
+ },
+ {
+ "ImportPath": "github.com/spf13/viper",
+ "Rev": "db7ff930a189b98d602179d9001d33345f42b8c7"
+ },
+ {
+ "ImportPath": "gopkg.in/yaml.v2",
+ "Rev": "c1cd2254a6dd314c9d73c338c12688c9325d85c6"
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/newt/Godeps/Readme
----------------------------------------------------------------------
diff --git a/newt/Godeps/Readme b/newt/Godeps/Readme
new file mode 100644
index 0000000..4cdaa53
--- /dev/null
+++ b/newt/Godeps/Readme
@@ -0,0 +1,5 @@
+This directory tree is generated automatically by godep.
+
+Please do not edit.
+
+See https://github.com/tools/godep for more information.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/newt/Godeps/_workspace/.gitignore
----------------------------------------------------------------------
diff --git a/newt/Godeps/_workspace/.gitignore b/newt/Godeps/_workspace/.gitignore
new file mode 100644
index 0000000..f037d68
--- /dev/null
+++ b/newt/Godeps/_workspace/.gitignore
@@ -0,0 +1,2 @@
+/pkg
+/bin
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/.gitignore
----------------------------------------------------------------------
diff --git a/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/.gitignore b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/.gitignore
new file mode 100644
index 0000000..0cd3800
--- /dev/null
+++ b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/.gitignore
@@ -0,0 +1,5 @@
+TAGS
+tags
+.*.swp
+tomlcheck/tomlcheck
+toml.test
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/.travis.yml
----------------------------------------------------------------------
diff --git a/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/.travis.yml b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/.travis.yml
new file mode 100644
index 0000000..43caf6d
--- /dev/null
+++ b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/.travis.yml
@@ -0,0 +1,12 @@
+language: go
+go:
+ - 1.1
+ - 1.2
+ - tip
+install:
+ - go install ./...
+ - go get github.com/BurntSushi/toml-test
+script:
+ - export PATH="$PATH:$HOME/gopath/bin"
+ - make test
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/COMPATIBLE
----------------------------------------------------------------------
diff --git a/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/COMPATIBLE b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/COMPATIBLE
new file mode 100644
index 0000000..21e0938
--- /dev/null
+++ b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/COMPATIBLE
@@ -0,0 +1,3 @@
+Compatible with TOML version
+[v0.2.0](https://github.com/mojombo/toml/blob/master/versions/toml-v0.2.0.md)
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/COPYING
----------------------------------------------------------------------
diff --git a/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/COPYING b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/COPYING
new file mode 100644
index 0000000..5a8e332
--- /dev/null
+++ b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/COPYING
@@ -0,0 +1,14 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sa...@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/Makefile
----------------------------------------------------------------------
diff --git a/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/Makefile b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/Makefile
new file mode 100644
index 0000000..3600848
--- /dev/null
+++ b/newt/Godeps/_workspace/src/github.com/BurntSushi/toml/Makefile
@@ -0,0 +1,19 @@
+install:
+ go install ./...
+
+test: install
+ go test -v
+ toml-test toml-test-decoder
+ toml-test -encoder toml-test-encoder
+
+fmt:
+ gofmt -w *.go */*.go
+ colcheck *.go */*.go
+
+tags:
+ find ./ -name '*.go' -print0 | xargs -0 gotags > TAGS
+
+push:
+ git push origin master
+ git push github master
+