Merge changes I1fb78d7c,Ic836282f
* changes: Background distGzipFile to speed up CI builds Fix some problems with soong metrics loading
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"android/soong/ui/metrics"
|
"android/soong/ui/metrics"
|
||||||
@@ -205,6 +206,8 @@ func Build(ctx Context, config Config) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer waitForDist(ctx)
|
||||||
|
|
||||||
// checkProblematicFiles aborts the build if Android.mk or CleanSpec.mk are found at the root of the tree.
|
// checkProblematicFiles aborts the build if Android.mk or CleanSpec.mk are found at the root of the tree.
|
||||||
checkProblematicFiles(ctx)
|
checkProblematicFiles(ctx)
|
||||||
|
|
||||||
@@ -329,8 +332,18 @@ func Build(ctx Context, config Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var distWaitGroup sync.WaitGroup
|
||||||
|
|
||||||
|
// waitForDist waits for all backgrounded distGzipFile and distFile writes to finish
|
||||||
|
func waitForDist(ctx Context) {
|
||||||
|
ctx.BeginTrace("soong_ui", "dist")
|
||||||
|
defer ctx.EndTrace()
|
||||||
|
|
||||||
|
distWaitGroup.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
// distGzipFile writes a compressed copy of src to the distDir if dist is enabled. Failures
|
// distGzipFile writes a compressed copy of src to the distDir if dist is enabled. Failures
|
||||||
// are printed but non-fatal.
|
// are printed but non-fatal. Uses the distWaitGroup func for backgrounding (optimization).
|
||||||
func distGzipFile(ctx Context, config Config, src string, subDirs ...string) {
|
func distGzipFile(ctx Context, config Config, src string, subDirs ...string) {
|
||||||
if !config.Dist() {
|
if !config.Dist() {
|
||||||
return
|
return
|
||||||
@@ -343,13 +356,17 @@ func distGzipFile(ctx Context, config Config, src string, subDirs ...string) {
|
|||||||
ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
|
ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gzipFileToDir(src, destDir); err != nil {
|
distWaitGroup.Add(1)
|
||||||
ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error())
|
go func() {
|
||||||
}
|
defer distWaitGroup.Done()
|
||||||
|
if err := gzipFileToDir(src, destDir); err != nil {
|
||||||
|
ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// distFile writes a copy of src to the distDir if dist is enabled. Failures are printed but
|
// distFile writes a copy of src to the distDir if dist is enabled. Failures are printed but
|
||||||
// non-fatal.
|
// non-fatal. Uses the distWaitGroup func for backgrounding (optimization).
|
||||||
func distFile(ctx Context, config Config, src string, subDirs ...string) {
|
func distFile(ctx Context, config Config, src string, subDirs ...string) {
|
||||||
if !config.Dist() {
|
if !config.Dist() {
|
||||||
return
|
return
|
||||||
@@ -362,7 +379,11 @@ func distFile(ctx Context, config Config, src string, subDirs ...string) {
|
|||||||
ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
|
ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := copyFile(src, filepath.Join(destDir, filepath.Base(src))); err != nil {
|
distWaitGroup.Add(1)
|
||||||
ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error())
|
go func() {
|
||||||
}
|
defer distWaitGroup.Done()
|
||||||
|
if _, err := copyFile(src, filepath.Join(destDir, filepath.Base(src))); err != nil {
|
||||||
|
ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,9 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -491,10 +493,14 @@ func runSoong(ctx Context, config Config) {
|
|||||||
|
|
||||||
ninja("bootstrap", "bootstrap.ninja", targets...)
|
ninja("bootstrap", "bootstrap.ninja", targets...)
|
||||||
|
|
||||||
var soongBuildMetrics *soong_metrics_proto.SoongBuildMetrics
|
|
||||||
if shouldCollectBuildSoongMetrics(config) {
|
if shouldCollectBuildSoongMetrics(config) {
|
||||||
soongBuildMetrics := loadSoongBuildMetrics(ctx, config)
|
soongBuildMetrics := loadSoongBuildMetrics(ctx, config)
|
||||||
logSoongBuildMetrics(ctx, soongBuildMetrics)
|
if soongBuildMetrics != nil {
|
||||||
|
logSoongBuildMetrics(ctx, soongBuildMetrics)
|
||||||
|
if ctx.Metrics != nil {
|
||||||
|
ctx.Metrics.SetSoongBuildMetrics(soongBuildMetrics)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
distGzipFile(ctx, config, config.SoongNinjaFile(), "soong")
|
distGzipFile(ctx, config, config.SoongNinjaFile(), "soong")
|
||||||
@@ -504,9 +510,6 @@ func runSoong(ctx Context, config Config) {
|
|||||||
distGzipFile(ctx, config, config.SoongMakeVarsMk(), "soong")
|
distGzipFile(ctx, config, config.SoongMakeVarsMk(), "soong")
|
||||||
}
|
}
|
||||||
|
|
||||||
if shouldCollectBuildSoongMetrics(config) && ctx.Metrics != nil {
|
|
||||||
ctx.Metrics.SetSoongBuildMetrics(soongBuildMetrics)
|
|
||||||
}
|
|
||||||
if config.JsonModuleGraph() {
|
if config.JsonModuleGraph() {
|
||||||
distGzipFile(ctx, config, config.ModuleGraphFile(), "soong")
|
distGzipFile(ctx, config, config.ModuleGraphFile(), "soong")
|
||||||
}
|
}
|
||||||
@@ -538,8 +541,12 @@ func shouldCollectBuildSoongMetrics(config Config) bool {
|
|||||||
|
|
||||||
func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.SoongBuildMetrics {
|
func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.SoongBuildMetrics {
|
||||||
soongBuildMetricsFile := filepath.Join(config.LogsDir(), "soong_build_metrics.pb")
|
soongBuildMetricsFile := filepath.Join(config.LogsDir(), "soong_build_metrics.pb")
|
||||||
buf, err := ioutil.ReadFile(soongBuildMetricsFile)
|
buf, err := os.ReadFile(soongBuildMetricsFile)
|
||||||
if err != nil {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
|
// Soong may not have run during this invocation
|
||||||
|
ctx.Verbosef("Failed to read metrics file, %s: %s", soongBuildMetricsFile, err)
|
||||||
|
return nil
|
||||||
|
} else if err != nil {
|
||||||
ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err)
|
ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err)
|
||||||
}
|
}
|
||||||
soongBuildMetrics := &soong_metrics_proto.SoongBuildMetrics{}
|
soongBuildMetrics := &soong_metrics_proto.SoongBuildMetrics{}
|
||||||
|
Reference in New Issue
Block a user