diff options
author | Jeff Gaston <jeffrygaston@google.com> | 2017-08-04 12:30:12 -0700 |
---|---|---|
committer | Jeff Gaston <jeffrygaston@google.com> | 2017-08-16 14:56:00 -0700 |
commit | b64fc1cab5d9238d02584c137b98bbd3ea249819 (patch) | |
tree | d9df4a2662682ea617261ce13aa61bafd980ef2a /ui/build | |
parent | 16c04e0621ab75e26d278f876cefb56da0883b98 (diff) | |
download | build_soong-b64fc1cab5d9238d02584c137b98bbd3ea249819.tar.gz build_soong-b64fc1cab5d9238d02584c137b98bbd3ea249819.tar.bz2 build_soong-b64fc1cab5d9238d02584c137b98bbd3ea249819.zip |
Run the Finder and make its results available to Kati
The Finder runs roughly 200ms faster than findleaves.py in aosp,
and runs roughly 400ms faster in internal master.
Bug: 64363847
Test: m -j
Change-Id: I62db8dacc90871e913576fe2443021fb1749a483
Diffstat (limited to 'ui/build')
-rw-r--r-- | ui/build/Android.bp | 2 | ||||
-rw-r--r-- | ui/build/build.go | 1 | ||||
-rw-r--r-- | ui/build/config.go | 4 | ||||
-rw-r--r-- | ui/build/finder.go | 102 |
4 files changed, 109 insertions, 0 deletions
diff --git a/ui/build/Android.bp b/ui/build/Android.bp index 548baeed..7640e84d 100644 --- a/ui/build/Android.bp +++ b/ui/build/Android.bp @@ -19,6 +19,7 @@ bootstrap_go_package { "soong-ui-logger", "soong-ui-tracer", "soong-shared", + "soong-finder", ], srcs: [ "build.go", @@ -27,6 +28,7 @@ bootstrap_go_package { "context.go", "environment.go", "exec.go", + "finder.go", "kati.go", "make.go", "ninja.go", diff --git a/ui/build/build.go b/ui/build/build.go index 9650eaa2..076e15e4 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -32,6 +32,7 @@ func SetupOutDir(ctx Context, config Config) { // The ninja_build file is used by our buildbots to understand that the output // can be parsed as ninja output. ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "ninja_build")) + ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), ".out-dir")) } var combinedBuildNinjaTemplate = template.Must(template.New("combined").Parse(` diff --git a/ui/build/config.go b/ui/build/config.go index 045f6748..1c2f73be 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -280,6 +280,10 @@ func (c *configImpl) TempDir() string { return shared.TempDirForOutDir(c.SoongOutDir()) } +func (c *configImpl) FileListDir() string { + return filepath.Join(c.OutDir(), ".module_paths") +} + func (c *configImpl) KatiSuffix() string { if c.katiSuffix != "" { return c.katiSuffix diff --git a/ui/build/finder.go b/ui/build/finder.go new file mode 100644 index 00000000..05dec3ae --- /dev/null +++ b/ui/build/finder.go @@ -0,0 +1,102 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package build + +import ( + "android/soong/finder" + "android/soong/fs" + "android/soong/ui/logger" + "bytes" + "io/ioutil" + "os" + "path/filepath" + "strings" +) + +// This file provides an interface to the Finder for use in Soong UI +// This file stores configuration information about which files to find + +// NewSourceFinder returns a new Finder configured to search for source files. +// Callers of NewSourceFinder should call <f.Shutdown()> when done +func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) { + ctx.BeginTrace("find modules") + defer ctx.EndTrace() + + dir, err := os.Getwd() + if err != nil { + ctx.Fatalf("No working directory for module-finder: %v", err.Error()) + } + cacheParams := finder.CacheParams{ + WorkingDirectory: dir, + RootDirs: []string{"."}, + ExcludeDirs: []string{".git", ".repo"}, + PruneFiles: []string{".out-dir", ".find-ignore"}, + IncludeFiles: []string{"Android.mk", "Android.bp", "Blueprints", "CleanSpec.mk"}, + } + dumpDir := config.FileListDir() + f, err = finder.New(cacheParams, fs.OsFs, logger.New(ioutil.Discard), + filepath.Join(dumpDir, "files.db")) + if err != nil { + ctx.Fatalf("Could not create module-finder: %v", err) + } + return f +} + +// FindSources searches for source files known to <f> and writes them to the filesystem for +// use later. +func FindSources(ctx Context, config Config, f *finder.Finder) { + // note that dumpDir in FindSources may be different than dumpDir in NewSourceFinder + // if a caller such as multiproduct_kati wants to share one Finder among several builds + dumpDir := config.FileListDir() + os.MkdirAll(dumpDir, 0777) + + androidMks := f.FindFirstNamedAt(".", "Android.mk") + err := dumpListToFile(androidMks, filepath.Join(dumpDir, "Android.mk.list")) + if err != nil { + ctx.Fatalf("Could not export module list: %v", err) + } + + cleanSpecs := f.FindFirstNamedAt(".", "CleanSpec.mk") + dumpListToFile(cleanSpecs, filepath.Join(dumpDir, "CleanSpec.mk.list")) + if err != nil { + ctx.Fatalf("Could not export module list: %v", err) + } + + isBlueprintFile := func(dir finder.DirEntries) (dirs []string, files []string) { + files = []string{} + for _, file := range dir.FileNames { + if file == "Android.bp" || file == "Blueprints" { + files = append(files, file) + } + } + + return dir.DirNames, files + } + androidBps := f.FindMatching(".", isBlueprintFile) + err = dumpListToFile(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) { + 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) + } + return err +} |