wire: use go/packages for analysis (google/go-cloud#623)
Unfortunately, this does come with a ~4x slowdown to Wire, as it is now pulling source for all transitively depended packages, but not trimming comments or function bodies. This is due to limitations with the ParseFile callback in go/packages. This comes with a single semantic change: when performing analysis, Wire will now evaluate everything with the wireinject build tag. I updated the build tags tests accordingly. Prior to this PR, only the packages directly named by the package patterns would be evaluated with the wireinject build tag. Dependencies would not have the wireinject build tag applied. There isn't a way to selectively apply build tags in go/packages, and there isn't a clear benefit to applying it selectively. Being consistent with other Go tooling provides greater benefit. I deleted the vendoring test, as non-top-level vendoring becomes obsolete with modules. go/packages now parses comments by default, so now the generated code includes comments for non-injector declarations. Fixes google/go-cloud#78
This commit is contained in:
@@ -12,8 +12,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build wireinject
|
||||
//+build !wireinject
|
||||
|
||||
// Package bar includes both wireinject and non-wireinject variants.
|
||||
package bar
|
||||
|
||||
import "github.com/google/go-cloud/wire"
|
||||
@@ -12,9 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build !wireinject
|
||||
//+build wireinject
|
||||
|
||||
// Package bar includes both wireinject and non-wireinject variants.
|
||||
package bar
|
||||
|
||||
import "github.com/google/go-cloud/wire"
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build !wireinject
|
||||
|
||||
// Package bar includes both wireinject and non-wireinject variants.
|
||||
package bar
|
||||
|
||||
import "github.com/google/go-cloud/wire"
|
||||
|
||||
// Set provides a friendly user greeting.
|
||||
var Set = wire.NewSet(wire.Value("Hello, World!"))
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build wireinject
|
||||
|
||||
package bar
|
||||
|
||||
import "github.com/google/go-cloud/wire"
|
||||
|
||||
// Set provides an unfriendly user greeting.
|
||||
var Set = wire.NewSet(wire.Value("Bah humbug! This is the wrong variant!"))
|
||||
@@ -1,17 +0,0 @@
|
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate wire
|
||||
//+build !wireinject
|
||||
|
||||
package main
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func injectedMessage() string {
|
||||
string2 := _wireStringValue
|
||||
return string2
|
||||
}
|
||||
|
||||
var (
|
||||
_wireStringValue = "Hello, World!"
|
||||
)
|
||||
@@ -22,6 +22,7 @@ func main() {
|
||||
fmt.Println(injectedMessage())
|
||||
}
|
||||
|
||||
// provideMessage provides a friendly user greeting.
|
||||
func provideMessage() string {
|
||||
return "Hello, World!"
|
||||
}
|
||||
|
||||
@@ -19,3 +19,8 @@ import "fmt"
|
||||
func main() {
|
||||
fmt.Println(injectedMessage())
|
||||
}
|
||||
|
||||
// provideMessage provides a friendly user greeting.
|
||||
func provideMessage() string {
|
||||
return "Hello, World!"
|
||||
}
|
||||
@@ -17,11 +17,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"example.com/bar"
|
||||
"github.com/google/go-cloud/wire"
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
wire.Build(bar.Set)
|
||||
wire.Build(provideMessage)
|
||||
return ""
|
||||
}
|
||||
@@ -5,13 +5,9 @@
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"example.com/bar"
|
||||
)
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func injectedMessage() string {
|
||||
string2 := bar.ProvideMessage()
|
||||
string2 := provideMessage()
|
||||
return string2
|
||||
}
|
||||
@@ -15,4 +15,7 @@ func injectInterface() Interface {
|
||||
|
||||
// wire.go:
|
||||
|
||||
// Wire tries to disambiguate the variable "select" by prepending
|
||||
// the package name; this package-scoped variable conflicts with that
|
||||
// and forces a different name.
|
||||
var mainSelect = 0
|
||||
|
||||
21
internal/wire/testdata/Vendor/foo/foo.go
vendored
21
internal/wire/testdata/Vendor/foo/foo.go
vendored
@@ -1,21 +0,0 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(injectedMessage())
|
||||
}
|
||||
27
internal/wire/testdata/Vendor/foo/wire.go
vendored
27
internal/wire/testdata/Vendor/foo/wire.go
vendored
@@ -1,27 +0,0 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"example.com/bar"
|
||||
"github.com/google/go-cloud/wire"
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
wire.Build(bar.ProvideMessage)
|
||||
return ""
|
||||
}
|
||||
1
internal/wire/testdata/Vendor/pkg
vendored
1
internal/wire/testdata/Vendor/pkg
vendored
@@ -1 +0,0 @@
|
||||
example.com/foo
|
||||
21
internal/wire/testdata/Vendor/vendor/example.com/bar/bar.go
generated
vendored
21
internal/wire/testdata/Vendor/vendor/example.com/bar/bar.go
generated
vendored
@@ -1,21 +0,0 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package bar is the vendored copy of bar which contains the real provider.
|
||||
package bar
|
||||
|
||||
// ProvideMessage provides a friendly user greeting.
|
||||
func ProvideMessage() string {
|
||||
return "Hello, World!"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
Hello, World!
|
||||
Reference in New Issue
Block a user