internal: reintroduce legacy appengine build constraints (#3838)
This commit is contained in:
Родитель
44d73dff99
Коммит
ff1fc890e4
|
@ -1,3 +1,5 @@
|
|||
// +build !appengine
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
|
|
|
@ -37,6 +37,6 @@ type SocketOptionData struct {
|
|||
// Windows OS doesn't support Socket Option
|
||||
func (s *SocketOptionData) Getsockopt(fd uintptr) {
|
||||
once.Do(func() {
|
||||
logger.Warning("Channelz: socket options are not supported on non-linux os.")
|
||||
logger.Warning("Channelz: socket options are not supported on non-linux os and appengine.")
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// +build linux
|
||||
// +build linux,!appengine
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// +build linux
|
||||
// +build linux,!appengine
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build !appengine
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2020 gRPC authors.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build !appengine
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build !appengine
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build !appengine
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 gRPC authors.
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
// +build appengine
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 gRPC 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
|
||||
*
|
||||
* http://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 buffer
|
||||
|
||||
// CircularBuffer is a no-op implementation for appengine builds.
|
||||
//
|
||||
// Appengine does not support stats because of lack of the support for unsafe
|
||||
// pointers, which are necessary to efficiently store and retrieve things into
|
||||
// and from a circular buffer. As a result, Push does not do anything and Drain
|
||||
// returns an empty slice.
|
||||
type CircularBuffer struct{}
|
||||
|
||||
// NewCircularBuffer returns a no-op for appengine builds.
|
||||
func NewCircularBuffer(size uint32) (*CircularBuffer, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Push returns a no-op for appengine builds.
|
||||
func (cb *CircularBuffer) Push(x interface{}) {
|
||||
}
|
||||
|
||||
// Drain returns a no-op for appengine builds.
|
||||
func (cb *CircularBuffer) Drain() []interface{} {
|
||||
return nil
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
// +build !appengine
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 gRPC authors.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build !appengine
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
|
|
|
@ -35,40 +35,40 @@ var logger = grpclog.Component("core")
|
|||
|
||||
func log() {
|
||||
once.Do(func() {
|
||||
logger.Info("CPU time info is unavailable on non-linux environment.")
|
||||
logger.Info("CPU time info is unavailable on non-linux or appengine environment.")
|
||||
})
|
||||
}
|
||||
|
||||
// GetCPUTime returns the how much CPU time has passed since the start of this process.
|
||||
// It always returns 0 under non-linux environment.
|
||||
// It always returns 0 under non-linux or appengine environment.
|
||||
func GetCPUTime() int64 {
|
||||
log()
|
||||
return 0
|
||||
}
|
||||
|
||||
// Rusage is an empty struct under non-linux environment.
|
||||
// Rusage is an empty struct under non-linux or appengine environment.
|
||||
type Rusage struct{}
|
||||
|
||||
// GetRusage is a no-op function under non-linux environment.
|
||||
// GetRusage is a no-op function under non-linux or appengine environment.
|
||||
func GetRusage() (rusage *Rusage) {
|
||||
log()
|
||||
return nil
|
||||
}
|
||||
|
||||
// CPUTimeDiff returns the differences of user CPU time and system CPU time used
|
||||
// between two Rusage structs. It a no-op function for non-linux environment.
|
||||
// between two Rusage structs. It a no-op function for non-linux or appengine environment.
|
||||
func CPUTimeDiff(first *Rusage, latest *Rusage) (float64, float64) {
|
||||
log()
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
// SetTCPUserTimeout is a no-op function under non-linux environments
|
||||
// SetTCPUserTimeout is a no-op function under non-linux or appengine environments
|
||||
func SetTCPUserTimeout(conn net.Conn, timeout time.Duration) error {
|
||||
log()
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTCPUserTimeout is a no-op function under non-linux environments
|
||||
// GetTCPUserTimeout is a no-op function under non-linux or appengine environments
|
||||
// a negative return value indicates the operation is not supported
|
||||
func GetTCPUserTimeout(conn net.Conn) (int, error) {
|
||||
log()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// +build linux
|
||||
// +build linux,!appengine
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC 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
|
||||
*
|
||||
* http://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.
|
||||
*
|
||||
*/
|
||||
|
||||
// vet checks whether files that are supposed to be built on appengine running
|
||||
// Go 1.10 or earlier import an unsupported package (e.g. "unsafe", "syscall").
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/build"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fail := false
|
||||
b := build.Default
|
||||
b.BuildTags = []string{"appengine", "appenginevm"}
|
||||
argsWithoutProg := os.Args[1:]
|
||||
for _, dir := range argsWithoutProg {
|
||||
p, err := b.Import(".", dir, 0)
|
||||
if _, ok := err.(*build.NoGoError); ok {
|
||||
continue
|
||||
} else if err != nil {
|
||||
fmt.Printf("build.Import failed due to %v\n", err)
|
||||
fail = true
|
||||
continue
|
||||
}
|
||||
for _, pkg := range p.Imports {
|
||||
if pkg == "syscall" || pkg == "unsafe" {
|
||||
fmt.Printf("Package %s/%s importing %s package without appengine build tag is NOT ALLOWED!\n", p.Dir, p.Name, pkg)
|
||||
fail = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if fail {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
4
vet.sh
4
vet.sh
|
@ -92,6 +92,10 @@ not git grep "\(import \|^\s*\)\"github.com/golang/protobuf/ptypes/" -- "*.go"
|
|||
# - Ensure all xds proto imports are renamed to *pb or *grpc.
|
||||
git grep '"github.com/envoyproxy/go-control-plane/envoy' -- '*.go' ':(exclude)*.pb.go' | not grep -v 'pb "\|grpc "'
|
||||
|
||||
# - Check imports that are illegal in appengine (until Go 1.11).
|
||||
# TODO: Remove when we drop Go 1.10 support
|
||||
go list -f {{.Dir}} ./... | xargs go run test/go_vet/vet.go
|
||||
|
||||
# - gofmt, goimports, golint (with exceptions for generated code), go vet.
|
||||
gofmt -s -d -l . 2>&1 | fail_on_output
|
||||
goimports -l . 2>&1 | not grep -vE "\.pb\.go"
|
||||
|
|
Загрузка…
Ссылка в новой задаче