Avoid rewriting soong_build outputs if unchanged
This changes bp2build codegen, symlink forest generation, and soong_build so that they do not rewrite output files if the contents are unchanged. Bug: 266983462 Test: m droid Test: canonical_perf.sh benchmarking Test: Manually verified that rerunning analysis did not regenerate out/soong/workspace/prebuilts/sdk/BUILD.bazel unless contents changed Change-Id: I5ec227df7a32b53c7fa0d741fb1403a51931024b
This commit is contained in:
@@ -16,7 +16,6 @@ package android
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -2099,13 +2098,16 @@ func maybeRelErr(basePath string, targetPath string) (string, bool, error) {
|
|||||||
|
|
||||||
// Writes a file to the output directory. Attempting to write directly to the output directory
|
// Writes a file to the output directory. Attempting to write directly to the output directory
|
||||||
// will fail due to the sandbox of the soong_build process.
|
// will fail due to the sandbox of the soong_build process.
|
||||||
|
// Only writes the file if the file doesn't exist or if it has different contents, to prevent
|
||||||
|
// updating the timestamp if no changes would be made. (This is better for incremental
|
||||||
|
// performance.)
|
||||||
func WriteFileToOutputDir(path WritablePath, data []byte, perm os.FileMode) error {
|
func WriteFileToOutputDir(path WritablePath, data []byte, perm os.FileMode) error {
|
||||||
absPath := absolutePath(path.String())
|
absPath := absolutePath(path.String())
|
||||||
err := os.MkdirAll(filepath.Dir(absPath), 0777)
|
err := os.MkdirAll(filepath.Dir(absPath), 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(absPath, data, perm)
|
return pathtools.WriteFileIfChanged(absPath, data, perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveAllOutputDir(path WritablePath) error {
|
func RemoveAllOutputDir(path WritablePath) error {
|
||||||
|
@@ -25,6 +25,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"android/soong/shared"
|
"android/soong/shared"
|
||||||
|
"github.com/google/blueprint/pathtools"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A tree structure that describes what to do at each directory in the created
|
// A tree structure that describes what to do at each directory in the created
|
||||||
@@ -116,25 +117,13 @@ func mergeBuildFiles(output string, srcBuildFile string, generatedBuildFile stri
|
|||||||
generatedBuildFileContent = packageDefaultVisibilityRegex.ReplaceAll(generatedBuildFileContent, []byte{})
|
generatedBuildFileContent = packageDefaultVisibilityRegex.ReplaceAll(generatedBuildFileContent, []byte{})
|
||||||
}
|
}
|
||||||
|
|
||||||
outFile, err := os.Create(output)
|
newContents := generatedBuildFileContent
|
||||||
if err != nil {
|
if newContents[len(newContents)-1] != '\n' {
|
||||||
return err
|
newContents = append(newContents, '\n')
|
||||||
}
|
}
|
||||||
|
newContents = append(newContents, srcBuildFileContent...)
|
||||||
|
|
||||||
_, err = outFile.Write(generatedBuildFileContent)
|
return pathtools.WriteFileIfChanged(output, newContents, 0666)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if generatedBuildFileContent[len(generatedBuildFileContent)-1] != '\n' {
|
|
||||||
_, err = outFile.WriteString("\n")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = outFile.Write(srcBuildFileContent)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calls readdir() and returns it as a map from the basename of the files in dir
|
// Calls readdir() and returns it as a map from the basename of the files in dir
|
||||||
|
Reference in New Issue
Block a user