Skip to content

Commit

Permalink
feat(indexing): allow an AnalysisResult return from the driver (#5481)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Dec 20, 2022
1 parent 6f17a71 commit 872432a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion kythe/go/platform/analysis/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type CompilationAnalyzer interface {
// Analyze calls f on each analysis output resulting from the analysis of the
// given apb.CompilationUnit. If f returns an error, f is no longer called
// and Analyze returns with the same error.
Analyze(ctx context.Context, req *apb.AnalysisRequest, f OutputFunc) error
Analyze(ctx context.Context, req *apb.AnalysisRequest, f OutputFunc) (*apb.AnalysisResult, error)
}

// EntryOutput returns an OutputFunc that unmarshals each output's value as an
Expand Down
3 changes: 2 additions & 1 deletion kythe/go/platform/analysis/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ func (d *Driver) runAnalysis(ctx context.Context, cu Compilation) error {
ctx, cancel = context.WithTimeout(ctx, d.AnalysisOptions.Timeout)
defer cancel()
}
return d.Analyzer.Analyze(ctx, &apb.AnalysisRequest{
_, err := d.Analyzer.Analyze(ctx, &apb.AnalysisRequest{
Compilation: cu.Unit,
FileDataService: d.FileDataService,
Revision: cu.Revision,
BuildId: cu.BuildID,
}, d.writeOutput)
return err
}
17 changes: 9 additions & 8 deletions kythe/go/platform/analysis/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ type mock struct {

idx int

Compilations []Compilation
Outputs []*apb.AnalysisOutput
AnalyzeError error
OutputError error
Compilations []Compilation
Outputs []*apb.AnalysisOutput
AnalysisResult *apb.AnalysisResult
AnalyzeError error
OutputError error

AnalysisDuration time.Duration

Expand All @@ -66,7 +67,7 @@ func (m *mock) out() analysis.OutputFunc {
const buildID = "aabbcc"

// Analyze implements the analysis.CompilationAnalyzer interface.
func (m *mock) Analyze(ctx context.Context, req *apb.AnalysisRequest, out analysis.OutputFunc) error {
func (m *mock) Analyze(ctx context.Context, req *apb.AnalysisRequest, out analysis.OutputFunc) (*apb.AnalysisResult, error) {
if m.AnalysisDuration != 0 {
log.Printf("Waiting %s for analysis request", m.AnalysisDuration)
time.Sleep(m.AnalysisDuration)
Expand All @@ -76,7 +77,7 @@ func (m *mock) Analyze(ctx context.Context, req *apb.AnalysisRequest, out analys
for _, o := range m.Outputs {
if err := out(ctx, o); err != m.OutputError {
m.t.Errorf("Expected OutputFunc error: %v; found: %v", m.OutputError, err)
return err
return nil, err
}
}
if m.OutputIndex != len(m.Outputs) {
Expand All @@ -86,9 +87,9 @@ func (m *mock) Analyze(ctx context.Context, req *apb.AnalysisRequest, out analys
m.t.Errorf("Missing build ID")
}
if err := ctx.Err(); err != nil {
return err
return m.AnalysisResult, err
}
return m.AnalyzeError
return m.AnalysisResult, m.AnalyzeError
}

// Next implements the Queue interface.
Expand Down

0 comments on commit 872432a

Please sign in to comment.