Skip to content

Commit

Permalink
feat: pass-through build config in pipeline (#3444)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Feb 5, 2019
1 parent e0271fc commit 59be834
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
31 changes: 21 additions & 10 deletions kythe/go/serving/pipeline/beam.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ func (c *combineDecorPieces) AddInput(accum *srvpb.FileDecorations, p *ppb.Decor
Anchor: &srvpb.RawAnchor{
StartOffset: ref.Anchor.Span.Start.ByteOffset,
EndOffset: ref.Anchor.Span.End.ByteOffset,

BuildConfiguration: ref.Anchor.BuildConfiguration,
},
Kind: refKind(ref),
Target: kytheuri.ToString(ref.Source),
Expand Down Expand Up @@ -653,6 +655,7 @@ func (k *KytheBeam) References() beam.PCollection {
IncludeFacts: []string{
facts.AnchorStart, facts.AnchorEnd,
facts.SnippetStart, facts.SnippetEnd,
facts.BuildConfig,
},
}, k.nodes))
k.refs = beam.ParDo(s, toRefs, beam.CoGroupByKey(s, k.getFiles(), anchors))
Expand Down Expand Up @@ -741,29 +744,37 @@ func normalizeAnchors(file *srvpb.File, anchor func(**scpb.Node) bool, emit func
func toRawAnchor(n *scpb.Node) (*srvpb.RawAnchor, error) {
var a srvpb.RawAnchor
for _, f := range n.Fact {
i, err := strconv.Atoi(string(f.Value))
if err != nil {
return nil, fmt.Errorf("invalid integer fact value for %q: %v", f.GetKytheName(), err)
}
n := int32(i)

var err error
switch f.GetKytheName() {
case scpb.FactName_BUILD_CONFIG:
a.BuildConfiguration = string(f.Value)
case scpb.FactName_LOC_START:
a.StartOffset = n
a.StartOffset, err = factValueToInt(f)
case scpb.FactName_LOC_END:
a.EndOffset = n
a.EndOffset, err = factValueToInt(f)
case scpb.FactName_SNIPPET_START:
a.SnippetStart = n
a.SnippetStart, err = factValueToInt(f)
case scpb.FactName_SNIPPET_END:
a.SnippetEnd = n
a.SnippetEnd, err = factValueToInt(f)
default:
return nil, fmt.Errorf("unhandled fact: %v", f)
}
if err != nil {
return nil, err
}
}
a.Ticket = kytheuri.ToString(n.Source)
return &a, nil
}

func factValueToInt(f *scpb.Fact) (int32, error) {
i, err := strconv.Atoi(string(f.Value))
if err != nil {
return 0, fmt.Errorf("invalid integer fact value for %q: %v", schema.GetFactName(f), err)
}
return int32(i), nil
}

func moveSourceToKey(n *scpb.Node) (*spb.VName, *scpb.Node) {
return n.Source, &scpb.Node{
Kind: n.Kind,
Expand Down
4 changes: 4 additions & 0 deletions kythe/go/serving/pipeline/beam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func TestReferences(t *testing.T) {
}, {
Name: &scpb.Fact_KytheName{scpb.FactName_LOC_END},
Value: []byte("4"),
}, {
Name: &scpb.Fact_KytheName{scpb.FactName_BUILD_CONFIG},
Value: []byte("test-build-config"),
}},
Edge: []*scpb.Edge{{
Kind: &scpb.Edge_KytheKind{scpb.EdgeKind_REF},
Expand Down Expand Up @@ -102,6 +105,7 @@ func TestReferences(t *testing.T) {
ColumnOffset: 9,
},
},
BuildConfiguration: "test-build-config",
},
}, {
Source: &spb.VName{Signature: "node2"},
Expand Down
2 changes: 2 additions & 0 deletions kythe/go/serving/xrefs/assemble/assemble.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ func ExpandAnchor(anchor *srvpb.RawAnchor, file *srvpb.File, norm *span.Normaliz
Start: p2p(ssp),
End: p2p(sep),
},

BuildConfiguration: anchor.BuildConfiguration,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions kythe/go/util/schema/facts/facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const prefix = "/kythe/" // duplicated to avoid a circular import
const (
AnchorEnd = prefix + "loc/end"
AnchorStart = prefix + "loc/start"
BuildConfig = prefix + "build/config"
Code = prefix + "code"
Complete = prefix + "complete"
ContextURL = prefix + "context/url"
Expand Down

0 comments on commit 59be834

Please sign in to comment.