Skip to content

Commit

Permalink
Synthesize fake GOPATH and remove bazel_copy_generated_for_ide.sh
Browse files Browse the repository at this point in the history
We can use rules_go to create a fake symlink farm GOPATH. This can be
set as the GOPATH in IDEs that do not have native support for Bazel,
and we can stop maintaining the bazel_copy_generated_for_ide.sh hack.

The remaining issue is that we still need Go tooling to manage our
go.mod file that serves as the input to Gazelle, so we need to add
replace directives to ensure that Go tools can resolve generated code.

The proper fix for all this is the upcoming native Bazel support in Go:
bazelbuild/rules_go#512

Test Plan:
Ran `bazel build :gopath`, and a wild
`bazel-bin/gopath/src/git.monogon.dev/source/nexantic.git/core/generated/api/schema.pb.go`
appeared.

`scripts/symlink_generated_files.sh` created a valid symlink in core/generated
and `go mod tidy` ran successfully (despite complaining about the symlink).

Running `scripts/gazelle.sh` twice worked.

X-Origin-Diff: phab/D305
GitOrigin-RevId: 0d456bc57d4a2d72e30865ffef777d2f5be5c407
  • Loading branch information
leoluk committed Jan 4, 2020
1 parent a4516f9 commit eff7217
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
11 changes: 10 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "nogo")
load("@io_bazel_rules_go//go:def.bzl", "go_path", "nogo")

# gazelle:prefix git.monogon.dev/source/nexantic.git
# gazelle:exclude core/generated
Expand Down Expand Up @@ -55,3 +55,12 @@ nogo(
"@org_golang_x_tools//go/analysis/passes/unusedresult:go_tool_library",
],
)

# Synthesize a fake GOPATH in bazel-bin/gopath for IDEs without Bazel support
go_path(
name = "gopath",
mode = "link",
deps = [
"//core/cmd/init",
],
)
6 changes: 0 additions & 6 deletions scripts/bazel_copy_generated_for_ide.sh

This file was deleted.

2 changes: 2 additions & 0 deletions scripts/gazelle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# gazelle.sh regenerates BUILD.bazel files for Go source files.
set -euo pipefail

scripts/symlink_generated_files.sh

bazel run //:go mod tidy
bazel run //:gazelle -- update
bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=repositories.bzl%go_repositories -prune=true
10 changes: 10 additions & 0 deletions scripts/symlink_generated_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

create_symlinks() {
local package=$1

rm -rf "$package"
ln -r -s "bazel-bin/gopath/src/git.monogon.dev/source/nexantic.git/$package" "$package"
}

create_symlinks core/generated

0 comments on commit eff7217

Please sign in to comment.