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 /finder | |
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 'finder')
-rw-r--r-- | finder/finder.go | 44 | ||||
-rw-r--r-- | finder/finder_test.go | 7 |
2 files changed, 38 insertions, 13 deletions
diff --git a/finder/finder.go b/finder/finder.go index f15c8c13..8f9496d3 100644 --- a/finder/finder.go +++ b/finder/finder.go @@ -148,10 +148,11 @@ type Finder struct { filesystem fs.FileSystem // temporary state - threadPool *threadPool - mutex sync.Mutex - fsErrs []fsErr - errlock sync.Mutex + threadPool *threadPool + mutex sync.Mutex + fsErrs []fsErr + errlock sync.Mutex + shutdownWaitgroup sync.WaitGroup // non-temporary state modifiedFlag int32 @@ -183,6 +184,8 @@ func New(cacheParams CacheParams, filesystem fs.FileSystem, nodes: *newPathMap("/"), DbPath: dbPath, + + shutdownWaitgroup: sync.WaitGroup{}, } f.loadFromFilesystem() @@ -195,9 +198,12 @@ func New(cacheParams CacheParams, filesystem fs.FileSystem, // confirm that every path mentioned in the CacheConfig exists for _, path := range cacheParams.RootDirs { + if !filepath.IsAbs(path) { + path = filepath.Join(f.cacheMetadata.Config.WorkingDirectory, path) + } node := f.nodes.GetNode(filepath.Clean(path), false) if node == nil || node.ModTime == 0 { - return nil, fmt.Errorf("%v does not exist\n", path) + return nil, fmt.Errorf("path %v was specified to be included in the cache but does not exist\n", path) } } @@ -310,20 +316,32 @@ func (f *Finder) FindMatching(rootPath string, filter WalkFunc) []string { return results } -// Shutdown saves the contents of the Finder to its database file +// Shutdown declares that the finder is no longer needed and waits for its cleanup to complete +// Currently, that only entails waiting for the database dump to complete. func (f *Finder) Shutdown() { - f.verbosef("Shutting down\n") + f.waitForDbDump() +} + +// End of public api + +func (f *Finder) goDumpDb() { if f.wasModified() { - err := f.dumpDb() - if err != nil { - f.verbosef("%v\n", err) - } + f.shutdownWaitgroup.Add(1) + go func() { + err := f.dumpDb() + if err != nil { + f.verbosef("%v\n", err) + } + f.shutdownWaitgroup.Done() + }() } else { f.verbosef("Skipping dumping unmodified db\n") } } -// End of public api +func (f *Finder) waitForDbDump() { + f.shutdownWaitgroup.Wait() +} // joinCleanPaths is like filepath.Join but is faster because // joinCleanPaths doesn't have to support paths ending in "/" or containing ".." @@ -353,6 +371,8 @@ func (f *Finder) loadFromFilesystem() { f.startWithoutExternalCache() } + f.goDumpDb() + f.threadPool = nil } diff --git a/finder/finder_test.go b/finder/finder_test.go index 15c3728b..8d1bbd7f 100644 --- a/finder/finder_test.go +++ b/finder/finder_test.go @@ -466,12 +466,13 @@ func TestRelativeFilePaths(t *testing.T) { create(t, "/cwd/hi.txt", filesystem) create(t, "/cwd/a/hi.txt", filesystem) create(t, "/cwd/a/a/hi.txt", filesystem) + create(t, "/rel/a/hi.txt", filesystem) finder := newFinder( t, filesystem, CacheParams{ - RootDirs: []string{"/cwd", "/tmp/include"}, + RootDirs: []string{"/cwd", "../rel", "/tmp/include"}, IncludeFiles: []string{"hi.txt"}, }, ) @@ -491,6 +492,10 @@ func TestRelativeFilePaths(t *testing.T) { "a/hi.txt", "a/a/hi.txt"}) + foundPaths = finder.FindNamedAt("/rel", "hi.txt") + assertSameResponse(t, foundPaths, + []string{"/rel/a/hi.txt"}) + foundPaths = finder.FindNamedAt("/tmp/include", "hi.txt") assertSameResponse(t, foundPaths, []string{"/tmp/include/hi.txt"}) } |