Merge "Encode directly into file" into main
This commit is contained in:
19
cc/compdb.go
19
cc/compdb.go
@@ -85,23 +85,24 @@ func (c *compdbGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCon
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not create file %s: %s", compDBFile, err)
|
log.Fatalf("Could not create file %s: %s", compDBFile, err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer func() {
|
||||||
|
if err := f.Close(); err != nil {
|
||||||
|
log.Fatalf("Could not close file %s: %s", compDBFile, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
v := make([]compDbEntry, 0, len(m))
|
v := make([]compDbEntry, 0, len(m))
|
||||||
|
|
||||||
for _, value := range m {
|
for _, value := range m {
|
||||||
v = append(v, value)
|
v = append(v, value)
|
||||||
}
|
}
|
||||||
var dat []byte
|
|
||||||
|
w := json.NewEncoder(f)
|
||||||
if outputCompdbDebugInfo {
|
if outputCompdbDebugInfo {
|
||||||
dat, err = json.MarshalIndent(v, "", " ")
|
w.SetIndent("", " ")
|
||||||
} else {
|
|
||||||
dat, err = json.Marshal(v)
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err := w.Encode(v); err != nil {
|
||||||
log.Fatalf("Failed to marshal: %s", err)
|
log.Fatalf("Failed to encode: %s", err)
|
||||||
}
|
}
|
||||||
f.Write(dat)
|
|
||||||
|
|
||||||
if finalLinkDir := ctx.Config().Getenv(envVariableCompdbLink); finalLinkDir != "" {
|
if finalLinkDir := ctx.Config().Getenv(envVariableCompdbLink); finalLinkDir != "" {
|
||||||
finalLinkPath := filepath.Join(finalLinkDir, compdbFilename)
|
finalLinkPath := filepath.Join(finalLinkDir, compdbFilename)
|
||||||
|
Reference in New Issue
Block a user