Skip to content

Commit

Permalink
Conform with OSS golang expectations
Browse files Browse the repository at this point in the history
This looks like a huge change, but I promise it's quite simple. In fact
it's so simple that I was able to sync it with several days of commit
from your mainline repo and only had one merge conflict (`server/BUILD`,
which I replaced entirely) + updating the new imports you had made to
point at their new path. I promise this won't negatively impact your
productivity.

If a file previously was declaring a unique package, put it under the
equivalent path. For example:

`server/backends/cachedb.go` was creating a package
`github.com/buildbuddy-io/buildbuddy/cachedb`, so I simply moved it to
the directory that would be associated with it.

Additionally, I manually mapped the `go_proto_library`s in `/proto` to
have an `importpath` that was relative to the repo root
(`github.com/buildbuddy-io/buildbuddy`). This means that Gazelle knows
about the existance of these proto files and can automatically add
dependencies on them.

Why is this worth merging?

 * You will now be able to get the beautiful godoc.org docs when you're
   working on your project.
 * I made Gazelle work, so now you'll no longer have to manually update
   your build files.
 * You will also be able to use more of the go ecosystem around linting,
   code fixes (eg), and more!
 * Having code that uses the standard tools decreases the burden on
   external contributors to your project (like me) who would be
   delighted to pitch in and fix issues here and there. After all, this
   is the whole reason to do open source, right?

But isn't `go_default_library` ugly?

 * Yes, yes it is. It's also a hack that has been in place in `rules_go`
   for a while that is not beloved by the maintainer. In the olden days
   of rules_go, before there was even a Gazelle, the package name was
   inferred from the path to the file. You would declare your repo root
   when you loaded rules_go in your WORKSPACE. This, over time, was
   deemed to be insufficiently flexible for open-source where you can't
   make modifications in a `third_party` context. They have a different,
   now deprecated system called `vendors` that behaves similarly, but
   differently enough that it caused problems.  In order to address
   this, `importpath` was added as a stopgap to allow the file path and
   the `importpath` to be inconsistent. Then there was an issue around
   creating crosscompilation targets for linux from osx. This issue has
   since been resolved in the master for rules_go using transitions, and
   as of the next release of rules_go.

   Fixing `go_default_library` is now just a matter of someone going
   into gazelle and updating it to have a flag to select naming things
   name things `go_default_library` or the directory that contains them.
   I think that is probably something I'm going to do in the near
   future.

Testing strategy:

I've ensured that the entire repo is able to build/test completely. Note
that there are no tests checked into this repo, so the `bazel test`
returns failure. The `bazel build` was successful, however.

```
$ bazelisk test //...
INFO: Invocation ID: e4f2626b-88ef-4e32-a52c-1c0bdbe10780
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/e4f2626b-88ef-4e32-a52c-1c0bdbe10780
WARNING: Streamed test output requested. All tests will be run locally, without sharding, one at a time
INFO: Analyzed 117 targets (0 packages loaded, 0 targets configured).
INFO: Found 117 targets and 0 test targets...
INFO: Elapsed time: 0.262s, Critical Path: 0.00s
INFO: 0 processes.
ERROR: No test targets were found, yet testing was requested
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/e4f2626b-88ef-4e32-a52c-1c0bdbe10780
INFO: Build completed successfully, 1 total action
$ bazelisk build //...
INFO: Invocation ID: d1abc034-6186-4f9c-9b0a-0763c3725dc3
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/d1abc034-6186-4f9c-9b0a-0763c3725dc3
INFO: Build option --test_sharding_strategy has changed, discarding analysis cache.
INFO: Analyzed 117 targets (0 packages loaded, 16507 targets configured).
INFO: Found 117 targets...
INFO: Elapsed time: 1.096s, Critical Path: 0.07s
INFO: 0 processes.
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/d1abc034-6186-4f9c-9b0a-0763c3725dc3
INFO: Build completed successfully, 1 total action
```

Fixed: buildbuddy-io#16
  • Loading branch information
Andrew Allen committed May 6, 2020
1 parent 58eeeb6 commit 59bee52
Show file tree
Hide file tree
Showing 89 changed files with 647 additions and 615 deletions.
6 changes: 5 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package(default_visibility = ["//visibility:public"])

load("@bazel_gazelle//:def.bzl", "gazelle")

# gazelle:prefix github.com/tryflame/buildbuddy
# Ignore the node_modules dir
# gazelle:exclude node_modules
# Prefer generated BUILD files to be called BUILD over BUILD.bazel
# gazelle:build_file_name BUILD,BUILD.bazel
# gazelle:prefix github.com/buildbuddy-io/buildbuddy
gazelle(name = "gazelle")

exports_files([
Expand Down
44 changes: 23 additions & 21 deletions proto/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("//rules:typescript_proto_library.bzl", "ts_proto_library")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -70,13 +69,13 @@ proto_library(

go_proto_library(
name = "build_status_go_proto",
importpath = "proto/build_status",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/build_status",
proto = ":build_status_proto",
)

go_proto_library(
name = "build_events_go_proto",
importpath = "proto/build_events",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/build_events",
proto = ":build_events_proto",
deps = [
":build_status_go_proto",
Expand All @@ -85,7 +84,7 @@ go_proto_library(

go_proto_library(
name = "config_go_proto",
importpath = "proto/config",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/config",
proto = ":config_proto",
)

Expand Down Expand Up @@ -170,9 +169,10 @@ proto_library(

# Go proto rules below here

go_grpc_library(
go_proto_library(
name = "publish_build_event_go_proto",
importpath = "proto/publish_build_event",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/buildbuddy-io/buildbuddy/proto/publish_build_event",
proto = ":publish_build_event_proto",
deps = [
":build_events_go_proto",
Expand All @@ -182,7 +182,7 @@ go_grpc_library(

go_proto_library(
name = "build_event_stream_go_proto",
importpath = "proto/build_event_stream",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/build_event_stream",
proto = ":build_event_stream_proto",
deps = [
":command_line_go_proto",
Expand All @@ -192,13 +192,13 @@ go_proto_library(

go_proto_library(
name = "invocation_policy_go_proto",
importpath = "proto/blaze.invocation_policy",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/blaze.invocation_policy",
proto = ":invocation_policy_proto",
)

go_proto_library(
name = "command_line_go_proto",
importpath = "proto/command_line",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/command_line",
proto = ":command_line_proto",
deps = [
":option_filters_go_proto",
Expand All @@ -207,13 +207,13 @@ go_proto_library(

go_proto_library(
name = "option_filters_go_proto",
importpath = "proto/options",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/options",
proto = ":option_filters_proto",
)

go_proto_library(
name = "invocation_go_proto",
importpath = "proto/invocation",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/invocation",
proto = ":invocation_proto",
deps = [
":build_event_stream_go_proto",
Expand All @@ -222,9 +222,10 @@ go_proto_library(
],
)

go_grpc_library(
go_proto_library(
name = "buildbuddy_service_go_proto",
importpath = "proto/buildbuddy_service",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/buildbuddy-io/buildbuddy/proto/buildbuddy_service",
proto = ":buildbuddy_service_proto",
deps = [
":bazel_config_go_proto",
Expand All @@ -235,13 +236,13 @@ go_grpc_library(

go_proto_library(
name = "semver_go_proto",
importpath = "proto/semver",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/semver",
proto = ":semver_proto",
)

go_proto_library(
name = "user_go_proto",
importpath = "proto/user",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/user",
proto = ":user_proto",
deps = [
":group_go_proto",
Expand All @@ -250,13 +251,13 @@ go_proto_library(

go_proto_library(
name = "group_go_proto",
importpath = "proto/group",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/group",
proto = ":group_proto",
)

go_proto_library(
name = "context_go_proto",
importpath = "proto/context",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/context",
proto = ":context_proto",
deps = [
":user_go_proto",
Expand All @@ -265,16 +266,17 @@ go_proto_library(

go_proto_library(
name = "bazel_config_go_proto",
importpath = "proto/bazel_config",
importpath = "github.com/buildbuddy-io/buildbuddy/proto/bazel_config",
proto = ":bazel_config_proto",
deps = [
":context_go_proto",
],
)

go_grpc_library(
go_proto_library(
name = "remote_execution_go_proto",
importpath = "proto/remote_execution",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/buildbuddy-io/buildbuddy/proto/remote_execution",
proto = ":remote_execution_proto",
deps = [
":semver_go_proto",
Expand Down
Loading

0 comments on commit 59bee52

Please sign in to comment.