generate.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2020 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. //go:build ignore
  7. // +build ignore
  8. package main
  9. import (
  10. "log"
  11. "os"
  12. "os/exec"
  13. "path/filepath"
  14. )
  15. //go:generate go run scripts/protofmt.go .
  16. // First generate extensions using standard proto compiler.
  17. //go:generate protoc -I ../ -I . --gogofast_out=Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor,paths=source_relative:ext ext.proto
  18. // Then build our vanity compiler that uses the new extensions
  19. //go:generate go build -o scripts/protoc-gen-gosyncthing scripts/protoc_plugin.go
  20. // Inception, go generate calls the script itself that then deals with generation.
  21. // This is only done because go:generate does not support wildcards in paths.
  22. //go:generate go run generate.go lib/protocol lib/config lib/fs lib/db lib/discover
  23. func main() {
  24. for _, path := range os.Args[1:] {
  25. matches, err := filepath.Glob(filepath.Join(path, "*proto"))
  26. if err != nil {
  27. log.Fatal(err)
  28. }
  29. log.Println(path, "returned:", matches)
  30. args := []string{
  31. "-I", "..",
  32. "-I", ".",
  33. "--plugin=protoc-gen-gosyncthing=scripts/protoc-gen-gosyncthing",
  34. "--gosyncthing_out=paths=source_relative:..",
  35. }
  36. args = append(args, matches...)
  37. cmd := exec.Command("protoc", args...)
  38. cmd.Stdout = os.Stdout
  39. cmd.Stderr = os.Stderr
  40. if err := cmd.Run(); err != nil {
  41. log.Fatal("Failed generating", path)
  42. }
  43. }
  44. }