[cproto] Put -proto-path last in --proto_path passed to protoc.

When using cproto with Go modules, it builds a staging directory
with Go modules symlinked into directories based on their module
names, e.g. "infra" becomes "<staging>/infra" and
"go.chromium.org/luci" becomes "<staging>/go.chromium.org/luci",
where "<staging>" is some temp directory.

It then calls protoc as

    protoc --proto_path <staging> ... <staging>/some/file.proto

That way proto files can maintain the illusion they live in a single
source tree (like they did in the GOPATH mode).

Now there's a problem: this staging tree contains only real Go
modules. This doesn't work for go.chromium.org/chromiumos/config
protos: they aren't actually in a Go module. They just happened to
be under GOPATH when GOPATH existed.

There's a known solution for telling protoc about such out-of-tree
files: --proto_path (which cproto exposes as -proto-path flag).

Due to how our Go modules and git checkouts laid out on disk,
`--proto_path` needed to pick up go.chromium.org/chromiumos/config
protos happens to match former GOPATH (this is not surprising,
considering we migrated to Go modules without moving any files).

In particular, when such --proto_path is passed to protoc, the call
looks like:

    protoc \
        --proto_path <former_root> \
        --proto_path <staging> \
        <staging>/some/file.proto

Again, due to how our checkouts laid out, <staging>/some/file.proto
and <former_root>/some/file.proto are actually the exact same file
(<staging> was meant to emulate former GOPATH layout after all).

To derive proto file names for the proto registry, protoc calculates
relative path from <staging>/some/file.proto to *any* of
`--proto_path`. And it appears it is getting confused when it finds
the input file in another (non <staging>) --proto_path if this path
precedes <staging>:

  <staging>/infra/tools/dirmd/proto/chromeos/chromeos.proto: Input is
  shadowed in the --proto_path by
  "<former_root>/infra/tools/dirmd/proto/chromeos/chromeos.proto".
  Either use the latter file as your input or reorder the
  --proto_path so that the former file's location comes first.

This CL makes sure protoc is called like:

    protoc \
        --proto_path <staging> \
        --proto_path <former_root> \
        <staging>/some/file.proto

It makes protoc happy.

R=chanli@chromium.org

Change-Id: Ifabfb32d77d84b769ce8b72309ed3227f8276025
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/3449095
Reviewed-by: Chan Li <chanli@chromium.org>
Commit-Queue: Vadim Shtayura <vadimsh@chromium.org>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
1 file changed
tree: 2ae62e6368a1c48c07d83018968a9d2093a93e0f
  1. appengine/
  2. auth/
  3. auth_service/
  4. build/
  5. buildbucket/
  6. casviewer/
  7. cipd/
  8. client/
  9. cmdrunner/
  10. common/
  11. config/
  12. cv/
  13. dm/
  14. examples/
  15. gae/
  16. gce/
  17. grpc/
  18. hacks/
  19. hardcoded/
  20. led/
  21. logdog/
  22. luci_notify/
  23. lucicfg/
  24. lucictx/
  25. luciexe/
  26. machine-db/
  27. mailer/
  28. milo/
  29. mmutex/
  30. resultdb/
  31. scheduler/
  32. scripts/
  33. server/
  34. starlark/
  35. swarming/
  36. tokenserver/
  37. tools/
  38. tumble/
  39. vpython/
  40. web/
  41. .gitallowed
  42. .gitattributes
  43. .golangci.yml
  44. AUTHORS
  45. codereview.settings
  46. CONTRIBUTING.md
  47. CONTRIBUTORS
  48. go.mod
  49. go.sum
  50. LICENSE
  51. OWNERS
  52. PRESUBMIT.py
  53. README.md
  54. tools.go
  55. WATCHLISTS
README.md

luci-go: LUCI services and tools in Go

GoDoc

Installing

LUCI Go code is meant to be worked on from an Chromium infra.git checkout, which enforces packages versions and Go toolchain version. First get fetch via depot_tools.git then run:

fetch infra
cd infra/go
eval `./env.py`
cd src/go.chromium.org/luci

Contributing

Contributing uses the same flow as Chromium contributions.