Skip to content

Commit 14f45f2

Browse files
authoredSep 12, 2022
schemas/cleanup: replace vsfsgen w/ Go stdlib's embed (hashicorp#1070)
1 parent b60c8d0 commit 14f45f2

File tree

4 files changed

+10
-33
lines changed

4 files changed

+10
-33
lines changed
 

Diff for: ‎go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ require (
2525
github.com/mitchellh/mapstructure v1.5.0
2626
github.com/otiai10/copy v1.7.0
2727
github.com/pmezard/go-difflib v1.0.0
28-
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
2928
github.com/stretchr/testify v1.8.0
3029
github.com/vektra/mockery/v2 v2.14.0
3130
github.com/zclconf/go-cty v1.11.0
@@ -76,7 +75,6 @@ require (
7675
github.com/rivo/uniseg v0.2.0 // indirect
7776
github.com/rs/zerolog v1.27.0 // indirect
7877
github.com/shopspring/decimal v1.2.0 // indirect
79-
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
8078
github.com/sourcegraph/run v0.9.0 // indirect
8179
github.com/spf13/afero v1.8.2 // indirect
8280
github.com/spf13/cast v1.5.0 // indirect

Diff for: ‎go.sum

-4
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,6 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX
339339
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
340340
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
341341
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
342-
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
343-
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
344-
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU=
345-
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
346342
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
347343
github.com/sourcegraph/run v0.9.0 h1:mj4pwBqCB+5qEaTp+rhauh5ubYI8n/icOkeiLTCT9Xg=
348344
github.com/sourcegraph/run v0.9.0/go.mod h1:j6Do38ccF+w/rSWgOuu4Ou/eOIDiU6pC87BZmq0DXDY=

Diff for: ‎internal/schemas/gen/gen.go

+1-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/hashicorp/hc-install/src"
2525
"github.com/hashicorp/terraform-exec/tfexec"
2626
"github.com/hashicorp/terraform-ls/internal/schemas"
27-
"github.com/shurcooL/vfsgen"
2827
)
2928

3029
const terraformBlock = `terraform {
@@ -138,7 +137,6 @@ func gen() error {
138137
if err != nil {
139138
return err
140139
}
141-
fs := http.Dir("data")
142140

143141
coreVersion, providerVersions, err := tf.Version(ctx, true)
144142
if err != nil {
@@ -175,17 +173,7 @@ func gen() error {
175173
}
176174

177175
log.Println("writing schemas to file")
178-
err = json.NewEncoder(schemasFile).Encode(ps)
179-
if err != nil {
180-
return err
181-
}
182-
183-
log.Println("generating embedded go file")
184-
return vfsgen.Generate(fs, vfsgen.Options{
185-
Filename: "schemas_gen.go",
186-
PackageName: "schemas",
187-
VariableName: "files",
188-
})
176+
return json.NewEncoder(schemasFile).Encode(ps)
189177
}
190178

191179
func stringifyProviderVersions(m map[string]*version.Version) map[string]string {

Diff for: ‎internal/schemas/schemas_preloadschema.go

+9-14
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
package schemas
55

66
import (
7+
_ "embed"
78
"encoding/json"
89
"sync"
910

1011
"github.com/hashicorp/go-version"
1112
tfjson "github.com/hashicorp/terraform-json"
1213
)
1314

15+
//go:embed data/schemas.json
16+
var schemasJsonBytes []byte
17+
18+
//go:embed data/versions.json
19+
var versionsJsonBytes []byte
20+
1421
var (
1522
_preloadedProviderSchemas *tfjson.ProviderSchemas
1623
_preloadedVersionOutput VersionOutput
@@ -20,23 +27,11 @@ var (
2027

2128
func PreloadedProviderSchemas() (*tfjson.ProviderSchemas, VersionOutput, error) {
2229
_preloadedProviderSchemasOnce.Do(func() {
23-
schemasFile, fErr := files.Open("schemas.json")
24-
if fErr != nil {
25-
_preloadedProviderSchemasErr = fErr
26-
return
27-
}
28-
2930
_preloadedProviderSchemas = &tfjson.ProviderSchemas{}
30-
_preloadedProviderSchemasErr = json.NewDecoder(schemasFile).Decode(_preloadedProviderSchemas)
31-
32-
versionFile, fErr := files.Open("versions.json")
33-
if fErr != nil {
34-
_preloadedProviderSchemasErr = fErr
35-
return
36-
}
31+
_preloadedProviderSchemasErr = json.Unmarshal(schemasJsonBytes, _preloadedProviderSchemas)
3732

3833
output := &RawVersionOutput{}
39-
err := json.NewDecoder(versionFile).Decode(output)
34+
err := json.Unmarshal(versionsJsonBytes, output)
4035
if err != nil {
4136
_preloadedProviderSchemasErr = err
4237
return

0 commit comments

Comments
 (0)
Please sign in to comment.