2016-11-01 19:10:51 +01:00
|
|
|
// Copyright 2016 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 bootstrap
|
|
|
|
|
|
|
|
import (
|
Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.
We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.
To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.
Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.
Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 06:56:59 +02:00
|
|
|
"bytes"
|
2016-11-01 19:10:51 +01:00
|
|
|
"fmt"
|
2021-04-06 02:20:34 +02:00
|
|
|
"hash/fnv"
|
|
|
|
"io"
|
2021-08-12 11:41:20 +02:00
|
|
|
"io/ioutil"
|
2016-11-01 19:10:51 +01:00
|
|
|
"path/filepath"
|
2021-04-06 02:20:34 +02:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2016-11-01 19:10:51 +01:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
"github.com/google/blueprint/pathtools"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This file supports globbing source files in Blueprints files.
|
|
|
|
//
|
|
|
|
// The build.ninja file needs to be regenerated any time a file matching the glob is added
|
|
|
|
// or removed. The naive solution is to have the build.ninja file depend on all the
|
|
|
|
// traversed directories, but this will cause the regeneration step to run every time a
|
|
|
|
// non-matching file is added to a traversed directory, including backup files created by
|
|
|
|
// editors.
|
|
|
|
//
|
|
|
|
// The solution implemented here optimizes out regenerations when the directory modifications
|
|
|
|
// don't match the glob by having the build.ninja file depend on an intermedate file that
|
|
|
|
// is only updated when a file matching the glob is added or removed. The intermediate file
|
|
|
|
// depends on the traversed directories via a depfile. The depfile is used to avoid build
|
|
|
|
// errors if a directory is deleted - a direct dependency on the deleted directory would result
|
|
|
|
// in a build failure with a "missing and no known rule to make it" error.
|
|
|
|
|
|
|
|
var (
|
2022-11-04 04:19:48 +01:00
|
|
|
_ = pctx.VariableFunc("globCmd", func(ctx blueprint.VariableFuncContext, config interface{}) (string, error) {
|
2021-10-29 22:09:09 +02:00
|
|
|
return filepath.Join(config.(BootstrapConfig).SoongOutDir(), "bpglob"), nil
|
|
|
|
})
|
|
|
|
|
2016-11-01 19:10:51 +01:00
|
|
|
// globRule rule traverses directories to produce a list of files that match $glob
|
|
|
|
// and writes it to $out if it has changed, and writes the directories to $out.d
|
|
|
|
GlobRule = pctx.StaticRule("GlobRule",
|
|
|
|
blueprint.RuleParams{
|
2021-11-04 11:46:57 +01:00
|
|
|
Command: "$globCmd -o $out $args",
|
2021-10-29 22:09:09 +02:00
|
|
|
CommandDeps: []string{"$globCmd"},
|
2021-04-06 02:20:34 +02:00
|
|
|
Description: "glob",
|
2016-11-01 19:10:51 +01:00
|
|
|
|
|
|
|
Restat: true,
|
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
Depfile: "$out.d",
|
|
|
|
},
|
2021-11-04 09:56:07 +01:00
|
|
|
"args")
|
2016-11-01 19:10:51 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// GlobFileContext is the subset of ModuleContext and SingletonContext needed by GlobFile
|
|
|
|
type GlobFileContext interface {
|
2021-04-06 02:20:34 +02:00
|
|
|
Config() interface{}
|
2016-11-01 19:10:51 +01:00
|
|
|
Build(pctx blueprint.PackageContext, params blueprint.BuildParams)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobFile creates a rule to write to fileListFile a list of the files that match the specified
|
|
|
|
// pattern but do not match any of the patterns specified in excludes. The file will include
|
2020-11-10 21:22:58 +01:00
|
|
|
// appropriate dependencies to regenerate the file if and only if the list of matching files has
|
|
|
|
// changed.
|
|
|
|
func GlobFile(ctx GlobFileContext, pattern string, excludes []string, fileListFile string) {
|
2021-04-06 02:20:34 +02:00
|
|
|
args := `-p "` + pattern + `"`
|
|
|
|
if len(excludes) > 0 {
|
|
|
|
args += " " + joinWithPrefixAndQuote(excludes, "-e ")
|
|
|
|
}
|
2016-11-01 19:10:51 +01:00
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: GlobRule,
|
|
|
|
Outputs: []string{fileListFile},
|
|
|
|
Args: map[string]string{
|
2021-11-04 09:56:07 +01:00
|
|
|
"args": args,
|
2016-11-01 19:10:51 +01:00
|
|
|
},
|
2021-04-06 02:20:34 +02:00
|
|
|
Description: "glob " + pattern,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// multipleGlobFilesRule creates a rule to write to fileListFile a list of the files that match the specified
|
|
|
|
// pattern but do not match any of the patterns specified in excludes. The file will include
|
|
|
|
// appropriate dependencies to regenerate the file if and only if the list of matching files has
|
|
|
|
// changed.
|
|
|
|
func multipleGlobFilesRule(ctx GlobFileContext, fileListFile string, shard int, globs pathtools.MultipleGlobResults) {
|
|
|
|
args := strings.Builder{}
|
|
|
|
|
|
|
|
for i, glob := range globs {
|
|
|
|
if i != 0 {
|
|
|
|
args.WriteString(" ")
|
|
|
|
}
|
|
|
|
args.WriteString(`-p "`)
|
|
|
|
args.WriteString(glob.Pattern)
|
|
|
|
args.WriteString(`"`)
|
|
|
|
for _, exclude := range glob.Excludes {
|
|
|
|
args.WriteString(` -e "`)
|
|
|
|
args.WriteString(exclude)
|
|
|
|
args.WriteString(`"`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: GlobRule,
|
|
|
|
Outputs: []string{fileListFile},
|
|
|
|
Args: map[string]string{
|
2021-11-04 09:56:07 +01:00
|
|
|
"args": args.String(),
|
2021-04-06 02:20:34 +02:00
|
|
|
},
|
|
|
|
Description: fmt.Sprintf("regenerate globs shard %d of %d", shard, numGlobBuckets),
|
2016-11-01 19:10:51 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func joinWithPrefixAndQuote(strs []string, prefix string) string {
|
|
|
|
if len(strs) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(strs) == 1 {
|
|
|
|
return prefix + `"` + strs[0] + `"`
|
|
|
|
}
|
|
|
|
|
|
|
|
n := len(" ") * (len(strs) - 1)
|
|
|
|
for _, s := range strs {
|
|
|
|
n += len(prefix) + len(s) + len(`""`)
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := make([]byte, 0, n)
|
|
|
|
for i, s := range strs {
|
|
|
|
if i != 0 {
|
|
|
|
ret = append(ret, ' ')
|
|
|
|
}
|
|
|
|
ret = append(ret, prefix...)
|
|
|
|
ret = append(ret, '"')
|
|
|
|
ret = append(ret, s...)
|
|
|
|
ret = append(ret, '"')
|
|
|
|
}
|
|
|
|
return string(ret)
|
|
|
|
}
|
|
|
|
|
2021-08-17 17:52:15 +02:00
|
|
|
// GlobSingleton collects any glob patterns that were seen by Context and writes out rules to
|
2016-11-01 19:10:51 +01:00
|
|
|
// re-evaluate them whenever the contents of the searched directories change, and retrigger the
|
|
|
|
// primary builder if the results change.
|
2021-08-17 17:52:15 +02:00
|
|
|
type GlobSingleton struct {
|
|
|
|
// A function that returns the glob results of individual glob buckets
|
|
|
|
GlobLister func() pathtools.MultipleGlobResults
|
|
|
|
|
|
|
|
// Ninja file that contains instructions for validating the glob list files
|
|
|
|
GlobFile string
|
|
|
|
|
|
|
|
// Directory containing the glob list files
|
|
|
|
GlobDir string
|
|
|
|
|
|
|
|
// The source directory
|
|
|
|
SrcDir string
|
2016-11-01 19:10:51 +01:00
|
|
|
}
|
|
|
|
|
2021-08-17 17:52:15 +02:00
|
|
|
func globBucketName(globDir string, globBucket int) string {
|
|
|
|
return filepath.Join(globDir, strconv.Itoa(globBucket))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the directory where glob list files live
|
|
|
|
func GlobDirectory(buildDir, globListDir string) string {
|
2021-09-01 08:58:07 +02:00
|
|
|
return filepath.Join(buildDir, "globs", globListDir)
|
2016-11-01 19:10:51 +01:00
|
|
|
}
|
|
|
|
|
2021-08-17 17:52:15 +02:00
|
|
|
func (s *GlobSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
|
2021-04-06 02:20:34 +02:00
|
|
|
// Sort the list of globs into buckets. A hash function is used instead of sharding so that
|
|
|
|
// adding a new glob doesn't force rerunning all the buckets by shifting them all by 1.
|
|
|
|
globBuckets := make([]pathtools.MultipleGlobResults, numGlobBuckets)
|
2021-08-17 17:52:15 +02:00
|
|
|
for _, g := range s.GlobLister() {
|
2021-04-06 02:20:34 +02:00
|
|
|
bucket := globToBucket(g)
|
|
|
|
globBuckets[bucket] = append(globBuckets[bucket], g)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, globs := range globBuckets {
|
2021-08-17 17:52:15 +02:00
|
|
|
fileListFile := globBucketName(s.GlobDir, i)
|
|
|
|
|
|
|
|
// Called from generateGlobNinjaFile. Write out the file list to disk, and add a ninja
|
|
|
|
// rule to run bpglob if any of the dependencies (usually directories that contain
|
|
|
|
// globbed files) have changed. The file list produced by bpglob should match exactly
|
|
|
|
// with the file written here so that restat can prevent rerunning the primary builder.
|
|
|
|
//
|
|
|
|
// We need to write the file list here so that it has an older modified date
|
|
|
|
// than the build.ninja (otherwise we'd run the primary builder twice on
|
|
|
|
// every new glob)
|
|
|
|
//
|
|
|
|
// We don't need to write the depfile because we're guaranteed that ninja
|
|
|
|
// will run the command at least once (to record it into the ninja_log), so
|
|
|
|
// the depfile will be loaded from that execution.
|
2024-06-05 20:25:24 +02:00
|
|
|
absoluteFileListFile := blueprint.JoinPath(s.SrcDir, fileListFile)
|
2021-08-17 17:52:15 +02:00
|
|
|
err := pathtools.WriteFileIfChanged(absoluteFileListFile, globs.FileList(), 0666)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("error writing %s: %s", fileListFile, err))
|
Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.
We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.
To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.
Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.
Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 06:56:59 +02:00
|
|
|
}
|
2021-08-17 17:52:15 +02:00
|
|
|
|
|
|
|
// Write out the ninja rule to run bpglob.
|
|
|
|
multipleGlobFilesRule(ctx, fileListFile, i, globs)
|
Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.
We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.
To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.
Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.
Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 06:56:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-17 17:52:15 +02:00
|
|
|
// Writes a .ninja file that contains instructions for regenerating the glob
|
|
|
|
// files that contain the results of every glob that was run. The list of files
|
|
|
|
// is available as the result of GlobFileListFiles().
|
2023-06-20 11:29:19 +02:00
|
|
|
func WriteBuildGlobsNinjaFile(glob *GlobSingleton, config interface{}) error {
|
2021-08-17 17:52:15 +02:00
|
|
|
buffer, errs := generateGlobNinjaFile(glob, config)
|
2021-08-12 11:41:20 +02:00
|
|
|
if len(errs) > 0 {
|
2023-06-20 11:29:19 +02:00
|
|
|
return fatalErrors(errs)
|
2021-08-12 11:41:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const outFilePermissions = 0666
|
2024-06-05 20:25:24 +02:00
|
|
|
err := ioutil.WriteFile(blueprint.JoinPath(glob.SrcDir, glob.GlobFile), buffer, outFilePermissions)
|
2021-08-12 11:41:20 +02:00
|
|
|
if err != nil {
|
2023-06-20 11:29:19 +02:00
|
|
|
return fmt.Errorf("error writing %s: %s", glob.GlobFile, err)
|
2021-08-12 11:41:20 +02:00
|
|
|
}
|
2023-06-20 11:29:19 +02:00
|
|
|
|
|
|
|
return nil
|
2021-08-12 11:41:20 +02:00
|
|
|
}
|
2023-06-20 11:29:19 +02:00
|
|
|
|
2021-08-17 17:52:15 +02:00
|
|
|
func generateGlobNinjaFile(glob *GlobSingleton, config interface{}) ([]byte, []error) {
|
2021-04-06 02:20:34 +02:00
|
|
|
|
Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.
We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.
To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.
Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.
Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 06:56:59 +02:00
|
|
|
ctx := blueprint.NewContext()
|
|
|
|
ctx.RegisterSingletonType("glob", func() blueprint.Singleton {
|
2021-08-17 17:52:15 +02:00
|
|
|
return glob
|
2023-05-15 22:59:49 +02:00
|
|
|
}, false)
|
Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.
We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.
To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.
Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.
Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 06:56:59 +02:00
|
|
|
|
2021-03-12 08:31:19 +01:00
|
|
|
extraDeps, errs := ctx.ResolveDependencies(config)
|
Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.
We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.
To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.
Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.
Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 06:56:59 +02:00
|
|
|
if len(extraDeps) > 0 {
|
|
|
|
return nil, []error{fmt.Errorf("shouldn't have extra deps")}
|
2016-11-01 19:10:51 +01:00
|
|
|
}
|
Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.
We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.
To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.
Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.
Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 06:56:59 +02:00
|
|
|
if len(errs) > 0 {
|
|
|
|
return nil, errs
|
|
|
|
}
|
|
|
|
|
2022-12-20 23:30:18 +01:00
|
|
|
// PrepareBuildActions() will write $OUTDIR/soong/globs/$m/$i files
|
|
|
|
// where $m=bp2build|build and $i=0..numGlobBuckets
|
2021-03-12 08:31:19 +01:00
|
|
|
extraDeps, errs = ctx.PrepareBuildActions(config)
|
Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.
We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.
To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.
Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.
Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 06:56:59 +02:00
|
|
|
if len(extraDeps) > 0 {
|
|
|
|
return nil, []error{fmt.Errorf("shouldn't have extra deps")}
|
|
|
|
}
|
|
|
|
if len(errs) > 0 {
|
|
|
|
return nil, errs
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := bytes.NewBuffer(nil)
|
2024-05-15 21:16:55 +02:00
|
|
|
err := ctx.WriteBuildFile(buf, false, "")
|
Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the
next phase, run bpglob earlier to check dependencies.
We've run into issues where the environment is slightly different
between bootstrapping phase and the main build phase. It's also a
problem because our primary builder (Soong) exports information used by
another tool (Kati) that runs in between the bootstrapping phases and
the main phase. When Soong would run in the main phase, it could get out
of sync, and would require the build to be run again.
To do this, add a "subninja" include a build-globs.ninja file to each
build.ninja file. The first time, this will be an empty file, but we'll
always run minibp / the primary builder anyway. When the builder runs,
in addition to writing a dependency file, write out the
build-globs.ninja file with the rules to run bpglob.
Since bpglob may need to be run very early, before it would normally be
built, build it with microfactory.
Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
2018-07-06 06:56:59 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, []error{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf.Bytes(), nil
|
2016-11-01 19:10:51 +01:00
|
|
|
}
|
2021-04-06 02:20:34 +02:00
|
|
|
|
2021-08-17 17:52:15 +02:00
|
|
|
// GlobFileListFiles returns the list of files that contain the result of globs
|
|
|
|
// in the build. It is suitable for inclusion in build.ninja.d (so that
|
|
|
|
// build.ninja is regenerated if the globs change). The instructions to
|
|
|
|
// regenerate these files are written by WriteBuildGlobsNinjaFile().
|
|
|
|
func GlobFileListFiles(globDir string) []string {
|
2021-04-06 02:20:34 +02:00
|
|
|
var fileListFiles []string
|
|
|
|
for i := 0; i < numGlobBuckets; i++ {
|
2021-08-17 17:52:15 +02:00
|
|
|
fileListFile := globBucketName(globDir, i)
|
|
|
|
fileListFiles = append(fileListFiles, fileListFile)
|
2021-04-06 02:20:34 +02:00
|
|
|
}
|
|
|
|
return fileListFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
const numGlobBuckets = 1024
|
|
|
|
|
|
|
|
// globToBucket converts a pathtools.GlobResult into a hashed bucket number in the range
|
|
|
|
// [0, numGlobBuckets).
|
|
|
|
func globToBucket(g pathtools.GlobResult) int {
|
|
|
|
hash := fnv.New32a()
|
|
|
|
io.WriteString(hash, g.Pattern)
|
|
|
|
for _, e := range g.Excludes {
|
|
|
|
io.WriteString(hash, e)
|
|
|
|
}
|
|
|
|
return int(hash.Sum32() % numGlobBuckets)
|
|
|
|
}
|