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 7066033640f5afbc4dbab81783dc8ffb08090976
Author: Michal Gorecki <[email protected]>
AuthorDate: Mon Nov 6 11:10:31 2023 +0100

    builder: Add app.cflags
    
    This adds possibility to add global cflags in pkgs.
    If one pkg will add app.cflags flag, then all other
    pkgs used by a target will also use this flag during compilation.
---
 newt/builder/build.go | 29 ++++++++++++++++++++++++++++-
 newt/builder/cmake.go |  5 +++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/newt/builder/build.go b/newt/builder/build.go
index 50a10022..543c5cb9 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 a287ec3e..dabb2a99 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())
 

Reply via email to