Skip to content

Commit ac8d799

Browse files
authored
lsif upload: Send indexer version witih upload request (#710)
1 parent 9387b19 commit ac8d799

4 files changed

Lines changed: 31 additions & 17 deletions

File tree

cmd/src/lsif_upload.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ func handleLSIFUpload(args []string) error {
8787

8888
if lsifUploadFlags.json {
8989
serialized, err := json.Marshal(map[string]interface{}{
90-
"repo": lsifUploadFlags.repo,
91-
"commit": lsifUploadFlags.commit,
92-
"root": lsifUploadFlags.root,
93-
"file": lsifUploadFlags.file,
94-
"indexer": lsifUploadFlags.indexer,
95-
"uploadId": uploadID,
96-
"uploadUrl": uploadURL,
90+
"repo": lsifUploadFlags.repo,
91+
"commit": lsifUploadFlags.commit,
92+
"root": lsifUploadFlags.root,
93+
"file": lsifUploadFlags.file,
94+
"indexer": lsifUploadFlags.indexer,
95+
"indexerVersion": lsifUploadFlags.indexerVersion,
96+
"uploadId": uploadID,
97+
"uploadUrl": uploadURL,
9798
})
9899
if err != nil {
99100
return err
@@ -155,6 +156,7 @@ func lsifUploadOptions(out *output.Output) upload.UploadOptions {
155156
Commit: lsifUploadFlags.commit,
156157
Root: lsifUploadFlags.root,
157158
Indexer: lsifUploadFlags.indexer,
159+
IndexerVersion: lsifUploadFlags.indexerVersion,
158160
AssociatedIndexID: associatedIndexID,
159161
},
160162
SourcegraphInstanceOptions: upload.SourcegraphInstanceOptions{
@@ -188,6 +190,7 @@ func printInferredArguments(out *output.Output) {
188190
block.Writef("root: %s", lsifUploadFlags.root)
189191
block.Writef("file: %s", lsifUploadFlags.file)
190192
block.Writef("indexer: %s", lsifUploadFlags.indexer)
193+
block.Writef("indexerVersion: %s", lsifUploadFlags.indexerVersion)
191194
block.Close()
192195
}
193196

cmd/src/lsif_upload_flags.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var lsifUploadFlags struct {
2222
commit string
2323
root string
2424
indexer string
25+
indexerVersion string
2526
associatedIndexID int
2627

2728
// SourcegraphInstanceOptions
@@ -54,6 +55,7 @@ func init() {
5455
lsifUploadFlagSet.StringVar(&lsifUploadFlags.commit, "commit", "", `The 40-character hash of the commit. Defaults to the currently checked-out commit.`)
5556
lsifUploadFlagSet.StringVar(&lsifUploadFlags.root, "root", "", `The path in the repository that matches the LSIF projectRoot (e.g. cmd/project1). Defaults to the directory where the dump file is located.`)
5657
lsifUploadFlagSet.StringVar(&lsifUploadFlags.indexer, "indexer", "", `The name of the indexer that generated the dump. This will override the 'toolInfo.name' field in the metadata vertex of the LSIF dump file. This must be supplied if the indexer does not set this field (in which case the upload will fail with an explicit message).`)
58+
lsifUploadFlagSet.StringVar(&lsifUploadFlags.indexerVersion, "indexerVersion", "", `The version of the indexer that generated the dump. This will override the 'toolInfo.version' field in the metadata vertex of the LSIF dump file. This must be supplied if the indexer does not set this field (in which case the upload will fail with an explicit message).`)
5759
lsifUploadFlagSet.IntVar(&lsifUploadFlags.associatedIndexID, "associated-index-id", -1, "ID of the associated index record for this upload. For internal use only.")
5860

5961
// SourcegraphInstanceOptions
@@ -131,6 +133,10 @@ func inferMissingLSIFUploadFlags() (inferErrors []argumentInferenceError) {
131133
inferErrors = append(inferErrors, argumentInferenceError{"file", err})
132134
}
133135

136+
indexerName, indexerVersion, readIndexerNameAndVersionErr := readIndexerNameAndVersion()
137+
getIndexerName := func() (string, error) { return indexerName, readIndexerNameAndVersionErr }
138+
getIndexerVersion := func() (string, error) { return indexerVersion, readIndexerNameAndVersionErr }
139+
134140
if err := inferUnsetFlag("repo", &lsifUploadFlags.repo, codeintel.InferRepo); err != nil {
135141
inferErrors = append(inferErrors, *err)
136142
}
@@ -140,7 +146,10 @@ func inferMissingLSIFUploadFlags() (inferErrors []argumentInferenceError) {
140146
if err := inferUnsetFlag("root", &lsifUploadFlags.root, inferIndexRoot); err != nil {
141147
inferErrors = append(inferErrors, *err)
142148
}
143-
if err := inferUnsetFlag("indexer", &lsifUploadFlags.indexer, readIndexerName); err != nil {
149+
if err := inferUnsetFlag("indexer", &lsifUploadFlags.indexer, getIndexerName); err != nil {
150+
inferErrors = append(inferErrors, *err)
151+
}
152+
if err := inferUnsetFlag("indexerVersion", &lsifUploadFlags.indexerVersion, getIndexerVersion); err != nil {
144153
inferErrors = append(inferErrors, *err)
145154
}
146155

@@ -187,17 +196,18 @@ func inferIndexRoot() (string, error) {
187196
return codeintel.InferRoot(lsifUploadFlags.file)
188197
}
189198

190-
// readIndexerName returns the indexer name read from the configured index file.
199+
// readIndexerNameAndVersion returns the indexer name and version values read from the
200+
// toolInfo value in the configured index file.
191201
//
192202
// Note: This function must not be called before lsifUploadFlagSet.Parse.
193-
func readIndexerName() (string, error) {
203+
func readIndexerNameAndVersion() (string, string, error) {
194204
file, err := os.Open(lsifUploadFlags.file)
195205
if err != nil {
196-
return "", err
206+
return "", "", err
197207
}
198208
defer file.Close()
199209

200-
return upload.ReadIndexerName(file)
210+
return upload.ReadIndexerNameAndVersion(file)
201211
}
202212

203213
// validateLSIFUploadFlags returns an error if any of the parsed flag values are illegal.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
2020
github.com/sourcegraph/go-diff v0.6.1
2121
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf
22-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220218193119-f6123c1144b4
22+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220314135113-5b7b17c7f27a
2323
github.com/stretchr/testify v1.7.0
2424
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f
2525
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
@@ -56,7 +56,7 @@ require (
5656
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
5757
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
5858
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
59-
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
59+
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
6060
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
6161
gopkg.in/yaml.v2 v2.4.0 // indirect
6262
)

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ github.com/sourcegraph/go-diff v0.6.1 h1:hmA1LzxW0n1c3Q4YbrFgg4P99GSnebYa3x8gr0H
292292
github.com/sourcegraph/go-diff v0.6.1/go.mod h1:iBszgVvyxdc8SFZ7gm69go2KDdt3ag071iBaWPF6cjs=
293293
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf h1:oAdWFqhStsWiiMP/vkkHiMXqFXzl1XfUNOdxKJbd6bI=
294294
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf/go.mod h1:ppFaPm6kpcHnZGqQTFhUIAQRIEhdQDWP1PCv4/ON354=
295-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220218193119-f6123c1144b4 h1:QOdM6vg4+Co8p0OEQtRzOcyxmN4+Ib8FrsSj2/LLzk4=
296-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220218193119-f6123c1144b4/go.mod h1:6/o2uP/pgAIyAZWqHeZF4J9F8rfWvkU3BRqVLWpLwTA=
295+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220314135113-5b7b17c7f27a h1:hVZHXDc5i39zda7BFVaGqUBfk7S5KLTiyaScR+MsjiI=
296+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220314135113-5b7b17c7f27a/go.mod h1:6/o2uP/pgAIyAZWqHeZF4J9F8rfWvkU3BRqVLWpLwTA=
297297
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 h1:z/MpntplPaW6QW95pzcAR/72Z5TWDyDnSo0EOcyij9o=
298298
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
299299
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
@@ -423,8 +423,9 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc
423423
golang.org/x/sys v0.0.0-20211102192858-4dd72447c267/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
424424
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
425425
golang.org/x/sys v0.0.0-20211213223007-03aa0b5f6827/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
426-
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
427426
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
427+
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
428+
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
428429
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
429430
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
430431
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

0 commit comments

Comments
 (0)