Fix writing module_bp_cc_deps.json
module_bp_cc_deps.json was not written through
android.WriteFileToOuptutDir, so it didn't get the absolute path
prepended when sandboxing was turned on. Reuse the implementation
from module_bp_java_deps.json.
Bug: 147409906
Test: m SOONG_COLLECT_CC_DEPS=1 nothing
Change-Id: I3b255bdfd3b4c442db06fe185765414905531410
diff --git a/cc/ccdeps.go b/cc/ccdeps.go
index 4e23a7b..225405c 100644
--- a/cc/ccdeps.go
+++ b/cc/ccdeps.go
@@ -17,7 +17,6 @@
import (
"encoding/json"
"fmt"
- "os"
"path"
"sort"
"strings"
@@ -106,7 +105,7 @@
moduleDeps.Modules = moduleInfos
- ccfpath := android.PathForOutput(ctx, ccdepsJsonFileName).String()
+ ccfpath := android.PathForOutput(ctx, ccdepsJsonFileName)
err := createJsonFile(moduleDeps, ccfpath)
if err != nil {
ctx.Errorf(err.Error())
@@ -236,17 +235,14 @@
return m
}
-func createJsonFile(moduleDeps ccDeps, ccfpath string) error {
- file, err := os.Create(ccfpath)
- if err != nil {
- return fmt.Errorf("Failed to create file: %s, relative: %v", ccdepsJsonFileName, err)
- }
- defer file.Close()
- moduleDeps.Modules = sortMap(moduleDeps.Modules)
+func createJsonFile(moduleDeps ccDeps, ccfpath android.WritablePath) error {
buf, err := json.MarshalIndent(moduleDeps, "", "\t")
if err != nil {
- return fmt.Errorf("Write file failed: %s, relative: %v", ccdepsJsonFileName, err)
+ return fmt.Errorf("JSON marshal of cc deps failed: %s", err)
}
- fmt.Fprintf(file, string(buf))
+ err = android.WriteFileToOutputDir(ccfpath, buf, 0666)
+ if err != nil {
+ return fmt.Errorf("Writing cc deps to %s failed: %s", ccfpath.String(), err)
+ }
return nil
}