Skip to content

Commit

Permalink
Attempt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
peterebden committed Nov 29, 2024
1 parent 9558a3a commit f1243fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/core/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ func FindOwningPackage(state *BuildState, file string) BuildLabel {
// suggestTargets suggests the targets in the given package that might be misspellings of
// the requested one.
func suggestTargets(pkg *Package, label, dependent BuildLabel) string {
if pkg == nil {
return ""
}
// The initial haystack only contains target names
haystack := []string{}
for _, t := range pkg.AllTargets() {
Expand Down
7 changes: 6 additions & 1 deletion src/core/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,9 @@ func (state *BuildState) ActivateTarget(pkg *Package, label, dependent BuildLabe
// Bazel allows some things that look like build targets but aren't - notably the syntax
// to load(). It suits us to treat that as though it is one, but we now have to
// implicitly make it available.
exportFile(state, pkg, label)
if pkg != nil {
exportFile(state, pkg, label)
}
} else {
msg := fmt.Sprintf("Parsed build file %s but it doesn't contain target %s", pkg.Filename, label.Name)
if dependent != OriginalTarget {
Expand All @@ -1029,6 +1031,9 @@ func (state *BuildState) ActivateTarget(pkg *Package, label, dependent BuildLabe
if state.ParsePackageOnly && !mode.IsForSubinclude() {
return nil // Some kinds of query don't need a full recursive parse.
} else if label.IsAllTargets() {
if pkg == nil {
return fmt.Errorf("Cannot use :all in this context")
}
if dependent == OriginalTarget {
for _, target := range pkg.AllTargets() {
// Don't activate targets that were added in a post-build function; that causes a race condition
Expand Down
2 changes: 1 addition & 1 deletion src/parse/asp/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func subincludeTarget(s *scope, l core.BuildLabel) *core.BuildTarget {
// If the subinclude is local to this package, it must already exist in the graph. If it already exists in the graph
// but isn't activated, we should activate it otherwise WaitForSubincludedTarget might block. This can happen when
// another package also subincludes this target, and queues it first.
if isLocal && s.pkg != nil {
if isLocal {
t := s.state.Graph.Target(l)
if t == nil {
s.Error("Target :%s is not defined in this package; it has to be defined before the subinclude() call", l.Name)
Expand Down

0 comments on commit f1243fe

Please sign in to comment.