You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

54 lines
1.4 KiB

  1. /*
  2. *
  3. * Copyright 2018 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. // vet checks whether files that are supposed to be built on appengine running
  19. // Go 1.10 or earlier import an unsupported package (e.g. "unsafe", "syscall").
  20. package main
  21. import (
  22. "fmt"
  23. "go/build"
  24. "os"
  25. )
  26. func main() {
  27. fail := false
  28. b := build.Default
  29. b.BuildTags = []string{"appengine", "appenginevm"}
  30. argsWithoutProg := os.Args[1:]
  31. for _, dir := range argsWithoutProg {
  32. p, err := b.Import(".", dir, 0)
  33. if _, ok := err.(*build.NoGoError); ok {
  34. continue
  35. } else if err != nil {
  36. fmt.Printf("build.Import failed due to %v\n", err)
  37. fail = true
  38. continue
  39. }
  40. for _, pkg := range p.Imports {
  41. if pkg == "syscall" || pkg == "unsafe" {
  42. fmt.Printf("Package %s/%s importing %s package without appengine build tag is NOT ALLOWED!\n", p.Dir, p.Name, pkg)
  43. fail = true
  44. }
  45. }
  46. }
  47. if fail {
  48. os.Exit(1)
  49. }
  50. }