ccollins476ad commented on a change in pull request #77: Create 
compile_commands.json file on build
URL: https://github.com/apache/mynewt-newt/pull/77#discussion_r128611122
 
 

 ##########
 File path: newt/builder/build.go
 ##########
 @@ -568,6 +571,35 @@ func (b *Builder) Build() error {
                }
        }
 
+       var compileCommands []toolchain.CompileCommand
+
+       for _, bpkg := range bpkgs {
+               c := bpkgCompilerMap[bpkg]
+               if c != nil {
+                       compileCommands = append(compileCommands,
+                               c.GetCompileCommands()...)
+               }
+       }
+
+       projectPath := interfaces.GetProject().Path() + "/"
+       for i := range compileCommands {
+               compileCommands[i].Directory = projectPath
+       }
+
+       cmdBytes, err := json.MarshalIndent(compileCommands, "", "    ")
+       if err != nil {
+               log.Error("Unable to encode compilation commands as JSON")
+               return nil
+       }
+
+       outDir := filepath.Dir(b.AppElfPath())
+       cmdPath := outDir + "/compile_commands.json"
+       errWrite := ioutil.WriteFile(cmdPath, cmdBytes, 0644)
+       if errWrite != nil {
+               log.Error("Unable to write compile_commands.json file")
+               return nil
 
 Review comment:
   I think this failure should abort the build (i.e., return a NewtError here). 
 Also, I would include the original error text in the message so that the user 
knows why file creation failed.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to