Merge "find bazel-related files and add them to bazel.list and ninja deps"

This commit is contained in:
Christopher Parsons
2020-10-14 16:27:25 +00:00
committed by Gerrit Code Review
5 changed files with 126 additions and 7 deletions

View File

@@ -18,11 +18,15 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"sync"
"github.com/google/blueprint/bootstrap"
)
// Map key to describe bazel cquery requests.
@@ -237,3 +241,28 @@ func (context *bazelContext) InvokeBazel() error {
context.requests = map[cqueryKey]bool{}
return nil
}
// Singleton used for registering BUILD file ninja dependencies (needed
// for correctness of builds which use Bazel.
func BazelSingleton() Singleton {
return &bazelSingleton{}
}
type bazelSingleton struct{}
func (c *bazelSingleton) GenerateBuildActions(ctx SingletonContext) {
if ctx.Config().BazelContext.BazelEnabled() {
bazelBuildList := absolutePath(filepath.Join(
filepath.Dir(bootstrap.ModuleListFile), "bazel.list"))
ctx.AddNinjaFileDeps(bazelBuildList)
data, err := ioutil.ReadFile(bazelBuildList)
if err != nil {
ctx.Errorf(err.Error())
}
files := strings.Split(strings.TrimSpace(string(data)), "\n")
for _, file := range files {
ctx.AddNinjaFileDeps(file)
}
}
}