diff --git a/newt/builder/build.go b/newt/builder/build.go index 50a100229..543c5cb91 100644 --- a/newt/builder/build.go +++ b/newt/builder/build.go @@ -635,12 +635,40 @@ func buildWorker( } } +func (b *Builder) appendAppCflags(bpkgs []*BuildPackage) error { + for _, bpkg := range bpkgs { + settings := b.cfg.AllSettingsForLpkg(bpkg.rpkg.Lpkg) + globalAppCflags, err := bpkg.rpkg.Lpkg.PkgY.Get("app.cflags", settings) + if err != nil { + return err + } + for _, f := range globalAppCflags { + if itfVals, ok := f.Value.([]interface{}); ok { + for _, itfVal := range itfVals { + if strVal, ok := itfVal.(string); ok { + b.compilerInfo.Cflags = append(b.compilerInfo.Cflags, strVal) + } + } + } + } + } + + return nil +} + func (b *Builder) Build() error { + var err error + b.CleanArtifacts() // Build the packages alphabetically to ensure a consistent order. bpkgs := b.sortedBuildPackages() + err = b.appendAppCflags(bpkgs) + if err != nil { + return err + } + // Calculate the list of jobs. Each record represents a single file that // needs to be compiled. entries := []toolchain.CompilerJob{} @@ -675,7 +703,6 @@ func (b *Builder) Build() error { go buildWorker(i, jobs, stop, errors) } - var err error for i := 0; i < newtutil.NewtNumJobs; i++ { subErr := <-errors if err == nil && subErr != nil { diff --git a/newt/builder/cmake.go b/newt/builder/cmake.go index a287ec3e3..dabb2a99f 100644 --- a/newt/builder/cmake.go +++ b/newt/builder/cmake.go @@ -212,6 +212,11 @@ func (b *Builder) CMakeTargetWrite(w io.Writer, targetCompiler *toolchain.Compil var linkFlags []string var libraries []string + err := b.appendAppCflags(bpkgs) + if err != nil { + return err + } + c := targetCompiler c.AddInfo(b.GetCompilerInfo()) diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go index a4fa89f84..b3a13e543 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 ." + infoHelpEx := " newt target info \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) }