Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions newt/cli/target_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sort"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"mynewt.apache.org/newt/newt/builder"
Expand Down Expand Up @@ -252,6 +253,37 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
}
}

func targetEnvCmd(cmd *cobra.Command, args []string) {
if len(args) < 1 {
NewtUsage(cmd, util.NewNewtError("Must specify target"))
}

TryGetProject()

t := ResolveTarget(args[0])
if t == nil {
NewtUsage(cmd, util.NewNewtError("Invalid target name: " + args[0]))
}

b, err := builder.NewTargetBuilder(t)
if err != nil {
NewtUsage(nil, err)
}

log.SetLevel(log.ErrorLevel)

if err := b.PrepBuild(); err != nil {
NewtUsage(nil, err)
}

fmt.Printf("APP_ELF_PATH=" + b.AppBuilder.AppElfPath() + "\n")
fmt.Printf("APP_IMG_PATH=" + b.AppBuilder.AppImgPath() + "\n")
fmt.Printf("APP_HEX_PATH=" + b.AppBuilder.AppHexPath() + "\n")
fmt.Printf("APP_BIN_PATH=" + b.AppBuilder.AppBinPath() + "\n")
fmt.Printf("BUILD_TARGET_DIR=" + builder.TargetBinDir(b.GetTarget().Name()) + "\n")
fmt.Printf("BUILD_APP_DIR=" + b.AppBuilder.AppBinBasePath() + "\n")
}

func printCflags(appCflags []ycfg.YCfgEntry) {
for _, f := range appCflags {
if itfVals, ok := f.Value.([]interface{}); ok {
Expand Down Expand Up @@ -802,6 +834,21 @@ func AddTargetCommands(cmd *cobra.Command) {
targetCmd.AddCommand(showCmd)
AddTabCompleteFn(showCmd, targetList)

envHelpText := "Show environment variables pointing to the binaries produced for the given " +
"<target-name>."
envHelpEx := " newt target env <target-name>\n"
envHelpEx += " newt target env my_target1"

envCmd := &cobra.Command{
Use: "env",
Short: "Print target environmental variables",
Long: envHelpText,
Example: envHelpEx,
Run: targetEnvCmd,
}
targetCmd.AddCommand(envCmd)
AddTabCompleteFn(envCmd, targetList)

listHelpText := "List all available targets."
listHelpEx := " newt target list"

Expand Down
Loading