This is an automated email from the ASF dual-hosted git repository.

mgorecki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
     new a62a1c1e newt/cli: Add target env command
a62a1c1e is described below

commit a62a1c1eff84519b7909d05c3b426a9ebba8a946
Author: Michal Gorecki <[email protected]>
AuthorDate: Tue Dec 2 14:22:44 2025 +0100

    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>
---
 newt/cli/target_cmds.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index 75ed4e06..168d6933 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -28,6 +28,7 @@ import (
        "sort"
        "strings"
 
+       log "github.com/sirupsen/logrus"
        "github.com/spf13/cobra"
 
        "mynewt.apache.org/newt/newt/builder"
@@ -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 {
@@ -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"
 

Reply via email to