Skip to content

Commit a62a1c1

Browse files
committed
newt/cli: Add target env command
This command prints full paths to target binaries in form of environmental variables definitions like this: APP_ELF_PATH=<path_to_elf> APP_IMG_PATH=<path_to_img> APP_HEX_PATH=<path_to_hex> APP_BIN_PATH=<path_to_bin> BUILD_TARGET_DIR=<path_to_bin_target_dir> BUILD_APP_DIR=<path_to_dir_containing_binaries>
1 parent 6affd38 commit a62a1c1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

newt/cli/target_cmds.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"sort"
2929
"strings"
3030

31+
log "github.com/sirupsen/logrus"
3132
"github.com/spf13/cobra"
3233

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

256+
func targetEnvCmd(cmd *cobra.Command, args []string) {
257+
if len(args) < 1 {
258+
NewtUsage(cmd, util.NewNewtError("Must specify target"))
259+
}
260+
261+
TryGetProject()
262+
263+
t := ResolveTarget(args[0])
264+
if t == nil {
265+
NewtUsage(cmd, util.NewNewtError("Invalid target name: " + args[0]))
266+
}
267+
268+
b, err := builder.NewTargetBuilder(t)
269+
if err != nil {
270+
NewtUsage(nil, err)
271+
}
272+
273+
log.SetLevel(log.ErrorLevel)
274+
275+
if err := b.PrepBuild(); err != nil {
276+
NewtUsage(nil, err)
277+
}
278+
279+
fmt.Printf("APP_ELF_PATH=" + b.AppBuilder.AppElfPath() + "\n")
280+
fmt.Printf("APP_IMG_PATH=" + b.AppBuilder.AppImgPath() + "\n")
281+
fmt.Printf("APP_HEX_PATH=" + b.AppBuilder.AppHexPath() + "\n")
282+
fmt.Printf("APP_BIN_PATH=" + b.AppBuilder.AppBinPath() + "\n")
283+
fmt.Printf("BUILD_TARGET_DIR=" + builder.TargetBinDir(b.GetTarget().Name()) + "\n")
284+
fmt.Printf("BUILD_APP_DIR=" + b.AppBuilder.AppBinBasePath() + "\n")
285+
}
286+
255287
func printCflags(appCflags []ycfg.YCfgEntry) {
256288
for _, f := range appCflags {
257289
if itfVals, ok := f.Value.([]interface{}); ok {
@@ -802,6 +834,21 @@ func AddTargetCommands(cmd *cobra.Command) {
802834
targetCmd.AddCommand(showCmd)
803835
AddTabCompleteFn(showCmd, targetList)
804836

837+
envHelpText := "Show environment variables pointing to the binaries produced for the given " +
838+
"<target-name>."
839+
envHelpEx := " newt target env <target-name>\n"
840+
envHelpEx += " newt target env my_target1"
841+
842+
envCmd := &cobra.Command{
843+
Use: "env",
844+
Short: "Print target environmental variables",
845+
Long: envHelpText,
846+
Example: envHelpEx,
847+
Run: targetEnvCmd,
848+
}
849+
targetCmd.AddCommand(envCmd)
850+
AddTabCompleteFn(envCmd, targetList)
851+
805852
listHelpText := "List all available targets."
806853
listHelpEx := " newt target list"
807854

0 commit comments

Comments
 (0)