Dist build.ninja and Android.bp.list
Debugging issues on the build servers can be difficult because the
intermediate files are not visible. Gzip ninja file and Makefiles
generated by Soong and the ninja files generated by Kati to the dist
directory, and also copy all of the finder output files.
Bug: 157656545
Test: m dist nothing
Change-Id: I48d75305e551ccae81c7a55721981cf58acd838b
diff --git a/ui/build/build.go b/ui/build/build.go
index 89c3fad..396f54c 100644
--- a/ui/build/build.go
+++ b/ui/build/build.go
@@ -243,6 +243,8 @@
// Write combined ninja file
createCombinedBuildNinjaFile(ctx, config)
+ distGzipFile(ctx, config, config.CombinedNinjaFile())
+
if what&RunBuildTests != 0 {
testForDanglingRules(ctx, config)
}
@@ -256,3 +258,47 @@
runNinja(ctx, config)
}
}
+
+// distGzipFile writes a compressed copy of src to the distDir if dist is enabled. Failures
+// are printed but non-fatal.
+func distGzipFile(ctx Context, config Config, src string, subDirs ...string) {
+ if !config.Dist() {
+ return
+ }
+
+ subDir := filepath.Join(subDirs...)
+ destDir := filepath.Join(config.DistDir(), "soong_ui", subDir)
+
+ err := os.MkdirAll(destDir, 0777)
+ if err != nil {
+ ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
+
+ }
+
+ err = gzipFileToDir(src, destDir)
+ if 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
+// non-fatal.
+func distFile(ctx Context, config Config, src string, subDirs ...string) {
+ if !config.Dist() {
+ return
+ }
+
+ subDir := filepath.Join(subDirs...)
+ destDir := filepath.Join(config.DistDir(), "soong_ui", subDir)
+
+ err := os.MkdirAll(destDir, 0777)
+ if err != nil {
+ ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
+
+ }
+
+ _, err = copyFile(src, filepath.Join(destDir, filepath.Base(src)))
+ if err != nil {
+ ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error())
+ }
+}
diff --git a/ui/build/finder.go b/ui/build/finder.go
index 0f34b5e..6786337 100644
--- a/ui/build/finder.go
+++ b/ui/build/finder.go
@@ -86,7 +86,7 @@
os.MkdirAll(dumpDir, 0777)
androidMks := f.FindFirstNamedAt(".", "Android.mk")
- err := dumpListToFile(androidMks, filepath.Join(dumpDir, "Android.mk.list"))
+ err := dumpListToFile(ctx, config, androidMks, filepath.Join(dumpDir, "Android.mk.list"))
if err != nil {
ctx.Fatalf("Could not export module list: %v", err)
}
@@ -94,25 +94,25 @@
androidProductsMks := f.FindNamedAt("device", "AndroidProducts.mk")
androidProductsMks = append(androidProductsMks, f.FindNamedAt("vendor", "AndroidProducts.mk")...)
androidProductsMks = append(androidProductsMks, f.FindNamedAt("product", "AndroidProducts.mk")...)
- err = dumpListToFile(androidProductsMks, filepath.Join(dumpDir, "AndroidProducts.mk.list"))
+ err = dumpListToFile(ctx, config, androidProductsMks, filepath.Join(dumpDir, "AndroidProducts.mk.list"))
if err != nil {
ctx.Fatalf("Could not export product list: %v", err)
}
cleanSpecs := f.FindFirstNamedAt(".", "CleanSpec.mk")
- err = dumpListToFile(cleanSpecs, filepath.Join(dumpDir, "CleanSpec.mk.list"))
+ err = dumpListToFile(ctx, config, cleanSpecs, filepath.Join(dumpDir, "CleanSpec.mk.list"))
if err != nil {
ctx.Fatalf("Could not export module list: %v", err)
}
owners := f.FindNamedAt(".", "OWNERS")
- err = dumpListToFile(owners, filepath.Join(dumpDir, "OWNERS.list"))
+ err = dumpListToFile(ctx, config, owners, filepath.Join(dumpDir, "OWNERS.list"))
if err != nil {
ctx.Fatalf("Could not find OWNERS: %v", err)
}
testMappings := f.FindNamedAt(".", "TEST_MAPPING")
- err = dumpListToFile(testMappings, filepath.Join(dumpDir, "TEST_MAPPING.list"))
+ err = dumpListToFile(ctx, config, testMappings, filepath.Join(dumpDir, "TEST_MAPPING.list"))
if err != nil {
ctx.Fatalf("Could not find TEST_MAPPING: %v", err)
}
@@ -122,18 +122,24 @@
if len(androidBps) == 0 {
ctx.Fatalf("No Android.bp found")
}
- err = dumpListToFile(androidBps, filepath.Join(dumpDir, "Android.bp.list"))
+ err = dumpListToFile(ctx, config, androidBps, filepath.Join(dumpDir, "Android.bp.list"))
if err != nil {
ctx.Fatalf("Could not find modules: %v", err)
}
}
-func dumpListToFile(list []string, filePath string) (err error) {
+func dumpListToFile(ctx Context, config Config, list []string, filePath string) (err error) {
desiredText := strings.Join(list, "\n")
desiredBytes := []byte(desiredText)
actualBytes, readErr := ioutil.ReadFile(filePath)
if readErr != nil || !bytes.Equal(desiredBytes, actualBytes) {
err = ioutil.WriteFile(filePath, desiredBytes, 0777)
+ if err != nil {
+ return err
+ }
}
- return err
+
+ distFile(ctx, config, filePath, "module_paths")
+
+ return nil
}
diff --git a/ui/build/kati.go b/ui/build/kati.go
index 2eb7850..1cd5fea 100644
--- a/ui/build/kati.go
+++ b/ui/build/kati.go
@@ -156,6 +156,8 @@
runKati(ctx, config, katiBuildSuffix, args, func(env *Environment) {})
+ distGzipFile(ctx, config, config.KatiBuildNinjaFile())
+
cleanCopyHeaders(ctx, config)
cleanOldInstalledFiles(ctx, config)
}
@@ -251,6 +253,8 @@
env.Set("DIST_DIR", config.DistDir())
}
})
+
+ distGzipFile(ctx, config, config.KatiPackageNinjaFile())
}
func runKatiCleanSpec(ctx Context, config Config) {
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 6a12add..749acb3 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -139,6 +139,13 @@
soongBuildMetrics := loadSoongBuildMetrics(ctx, config)
logSoongBuildMetrics(ctx, soongBuildMetrics)
+ distGzipFile(ctx, config, config.SoongNinjaFile(), "soong")
+
+ if !config.SkipMake() {
+ distGzipFile(ctx, config, config.SoongAndroidMk(), "soong")
+ distGzipFile(ctx, config, config.SoongMakeVarsMk(), "soong")
+ }
+
if ctx.Metrics != nil {
ctx.Metrics.SetSoongBuildMetrics(soongBuildMetrics)
}
diff --git a/ui/build/util.go b/ui/build/util.go
index d44cd6d..d4c3431 100644
--- a/ui/build/util.go
+++ b/ui/build/util.go
@@ -15,6 +15,8 @@
package build
import (
+ "compress/gzip"
+ "fmt"
"io"
"os"
"path/filepath"
@@ -142,3 +144,29 @@
return io.Copy(destination, source)
}
+
+// gzipFileToDir writes a compressed copy of src to destDir with the suffix ".gz".
+func gzipFileToDir(src, destDir string) error {
+ in, err := os.Open(src)
+ if err != nil {
+ return fmt.Errorf("failed to open %s: %s", src, err.Error())
+ }
+ defer in.Close()
+
+ dest := filepath.Join(destDir, filepath.Base(src)+".gz")
+
+ out, err := os.OpenFile(dest, os.O_CREATE|os.O_WRONLY, 0666)
+ if err != nil {
+ return fmt.Errorf("failed to open %s: %s", dest, err.Error())
+ }
+ defer out.Close()
+ gz := gzip.NewWriter(out)
+ defer gz.Close()
+
+ _, err = io.Copy(gz, in)
+ if err != nil {
+ return fmt.Errorf("failed to gzip %s: %s", dest, err.Error())
+ }
+
+ return nil
+}