generate.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. //+build ignore
  7. package main
  8. import (
  9. "log"
  10. "os"
  11. "os/exec"
  12. "path/filepath"
  13. )
  14. //go:generate go run scripts/protofmt.go .
  15. // First generate extensions using standard proto compiler.
  16. //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
  17. // Then build our vanity compiler that uses the new extensions
  18. //go:generate go build -o scripts/protoc-gen-gosyncthing scripts/protoc_plugin.go
  19. // Inception, go generate calls the script itself that then deals with generation.
  20. // This is only done because go:generate does not support wildcards in paths.
  21. //go:generate go run generate.go lib/protocol lib/config lib/fs lib/db lib/discover
  22. func main() {
  23. for _, path := range os.Args[1:] {
  24. matches, err := filepath.Glob(filepath.Join(path, "*proto"))
  25. if err != nil {
  26. log.Fatal(err)
  27. }
  28. log.Println(path, "returned:", matches)
  29. args := []string{
  30. "-I", "..",
  31. "-I", ".",
  32. "--plugin=protoc-gen-gosyncthing=scripts/protoc-gen-gosyncthing",
  33. "--gosyncthing_out=paths=source_relative:..",
  34. }
  35. args = append(args, matches...)
  36. cmd := exec.Command("protoc", args...)
  37. cmd.Stdout = os.Stdout
  38. cmd.Stderr = os.Stderr
  39. if err := cmd.Run(); err != nil {
  40. log.Fatal("Failed generating", path)
  41. }
  42. }
  43. }