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

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

commit 40e37e919332c6255b84af91d34318884140320c
Author: Michal Gorecki <[email protected]>
AuthorDate: Thu Feb 1 10:59:39 2024 +0100

    newt/cli: Add target info command
    
    This command prints all target's packages that contain app.flags
    field and it's values. In the future this command
    might be extended to show other miscellaneous info about
    specified target.
---
 newt/cli/target_cmds.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index a4fa89f8..b3a13e54 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -23,6 +23,7 @@ import (
        "bytes"
        "fmt"
        "io/ioutil"
+       "mynewt.apache.org/newt/newt/ycfg"
        "os"
        "sort"
        "strings"
@@ -249,6 +250,50 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
        }
 }
 
+func printCflags(appCflags []ycfg.YCfgEntry) {
+       for _, f := range appCflags {
+               if itfVals, ok := f.Value.([]interface{}); ok {
+                       for _, itfVal := range itfVals {
+                               if strVal, ok := itfVal.(string); ok {
+                                       fmt.Println(strVal)
+                               }
+                       }
+               }
+       }
+}
+
+func targetInfoCmd(cmd *cobra.Command, args []string) {
+       if len(args) < 1 {
+               NewtUsage(cmd,
+                       util.NewNewtError("Must specify target name"))
+       }
+
+       TryGetProject()
+
+       b, err := TargetBuilderForTargetOrUnittest(args[0])
+       if err != nil {
+               NewtUsage(cmd, err)
+       }
+
+       if err := b.PrepBuild(); err != nil {
+               NewtUsage(nil, err)
+       }
+
+       fmt.Println("Packages containing app.cflags:")
+
+       for _, rpkg := range b.AppBuilder.SortedRpkgs() {
+               appCflags, err := rpkg.Lpkg.PkgY.Get("app.cflags", nil)
+               if err != nil {
+                       NewtUsage(nil, err)
+               }
+               if appCflags != nil {
+                       fmt.Println(rpkg.Lpkg.Name())
+                       printCflags(appCflags)
+                       fmt.Println("")
+               }
+       }
+}
+
 func targetListCmd(cmd *cobra.Command, args []string) {
        TryGetProject()
        targetNames := []string{}
@@ -937,6 +982,21 @@ func AddTargetCommands(cmd *cobra.Command) {
                return append(targetList(), unittestList()...)
        })
 
+       infoHelpText := "Shows which packages contain app cflags in the target 
specified " +
+               "by <target-name>."
+       infoHelpEx := "  newt target info <target-name>\n"
+       infoHelpEx += "  newt target info my_target1"
+
+       infoCmd := &cobra.Command{
+               Use:     "info",
+               Short:   "Show packages with global cflags",
+               Long:    infoHelpText,
+               Example: infoHelpEx,
+               Run:     targetInfoCmd,
+       }
+       targetCmd.AddCommand(infoCmd)
+       AddTabCompleteFn(infoCmd, targetList)
+
        for _, cmd := range targetCfgCmdAll() {
                targetCmd.AddCommand(cmd)
        }

Reply via email to