Repository: kythe/kythe
Pull request #5481 (2022-12-20 17:19:11)

feat(indexing): allow an AnalysisResult return from the driver


Patch:
diff --git a/kythe/go/platform/analysis/analysis.go b/kythe/go/platform/analysis/analysis.go
index 39ff2c8b4..f6b0d3553 100644
--- a/kythe/go/platform/analysis/analysis.go
+++ b/kythe/go/platform/analysis/analysis.go
@@ -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
diff --git a/kythe/go/platform/analysis/driver/driver.go b/kythe/go/platform/analysis/driver/driver.go
index 48f9769af..3062655e7 100644
--- a/kythe/go/platform/analysis/driver/driver.go
+++ b/kythe/go/platform/analysis/driver/driver.go
@@ -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
 }


Test patch:
diff --git a/kythe/go/platform/analysis/driver/driver_test.go b/kythe/go/platform/analysis/driver/driver_test.go
index 0f2463acc..7098f6f47 100644
--- a/kythe/go/platform/analysis/driver/driver_test.go
+++ b/kythe/go/platform/analysis/driver/driver_test.go
@@ -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
 
@@ -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)
@@ -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) {
@@ -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.