-
Notifications
You must be signed in to change notification settings - Fork 38.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prune Bazel build files from imported go deps and update to gazelle 0.10.1 #61575
prune Bazel build files from imported go deps and update to gazelle 0.10.1 #61575
Conversation
e28319c
to
9d686e2
Compare
@@ -1976,6 +1976,7 @@ | |||
}, | |||
{ | |||
"ImportPath": "github.com/inconshreveable/mousetrap", | |||
"Comment": "v1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that it's adding these back in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️ who even understands godep?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:left-shark:
# Assume that anything imported through godep doesn't need Bazel to build. | ||
# Prune out any Bazel build files, since these can break the build due to | ||
# missing dependencies that aren't included by godep. | ||
find vendor/ -type f \( -name BUILD -o -name BUILD.bazel -o -name WORKSPACE \) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this logic make more sense as part of hack/update-bazel.sh
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but I didn't want to unnecessarily recreate these files all the time, just only when we're actually updating vendor/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought is, if we're calling hack/update-bazel.sh
for some reason, we are specifically saying we want to update the bazel files. Is there a large performance difference between updating without deleting, vs deleting?
I also wonder if there's some weird situation we could get into where a build file is updated in some other way, and starts failing the verify-bazel step because of the way it recreates in a temp folder.
I'm not stuck on it, but part of me thinks if you're we're gonna blow them away at all, just blow them all away every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the other reason not to do this is that kazel
prints out every time it updates a file, which it'll do every time these are recreated, even though there will likely be no diff.
/retest |
1 similar comment
/retest |
hack/update-bazel.sh
Outdated
( | ||
# gazelle needs to run from the real ${KUBE_ROOT}, as otherwise its symlink | ||
# following logic can get confused. | ||
cd "${KUBE_ROOT}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand this - under what circumstances is it not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recent functionality in gazelle causes it to follow symlinks, but only if they're outside the repo root.
if you run hack/run-in-gopath.sh hack/update-bazel.sh
, gazelle ends up running inside _output/local/go/src/k8s.io/kubernetes
. gazelle doesn't currently resolve the repo root to an absolute path, so its check to verify that the symlink is out-of-repo fails (since it resolves symlinks its considering to their absolute path).
For example, consider vendor/k8s.io/apimachinery
, which points to ../../staging/src/k8s.io/apimachinery
.
When run in the real $KUBE_ROOT
, gazelle detects the repo root as $HOME/go/src/k8s.io/kubernetes
and the endpoint of this symlink as $HOME/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery
. Since that's within the repo, it doesn't follow the symlink.
When run through hack/run-in-gopath.sh
, gazelle detects the repo root as $HOME/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes
, but still resolves the endpoint of the vendor symlink as $HOME/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery
. It considers this as out-of-repo and thus follows the symlink, erroneously.
I tried passing -repo_root ${KUBE_ROOT}
instead of the chdir, but this was causing different problems in vendor/ that I haven't yet figured out.
I also have refrained from changing the cwd for kazel
, since kazel
will blow up if it's not run from a valid GOPATH.
LGTM, just one Q |
/retest |
1 similar comment
/retest |
/lgtm |
recent functionality in gazelle causes it to follow symlinks, but only if
they're outside the repo root.
How does it calculate repo root?
if you run hack/run-in-gopath.sh hack/update-bazel.sh, gazelle ends up
running inside _output/local/go/src/k8s.io/kubernetes. gazelle doesn't
currently resolve the repo root to an absolute path, so its check to verify
that the symlink is out-of-repo fails (since it resolves symlinks its
considering to their absolute path).
This sounds incredibly broken and fragile. If it needs to do anything like
this, it should probably canonicalize the path, resolve symlinks, etc.
`pwd -P`
For example, consider vendor/k8s.io/apimachinery, which points to
../../staging/src/k8s.io/apimachinery.
When run in the real $KUBE_ROOT, gazelle detects the repo root as
$HOME/go/src/k8s.io/kubernetes and the endpoint of this symlink as
$HOME/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery. Since
that's within the repo, it doesn't follow the symlink.
When run through hack/run-in-gopath.sh, gazelle detects the repo root as
$HOME/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes, but
still resolves the endpoint of the vendor symlink as $HOME/go/src/
k8s.io/kubernetes/staging/src/k8s.io/apimachinery. It considers this as
out-of-repo and thus follows the symlink, erroneously.
Did you file a bug against gazelle? This is broken.
|
I'm happy of you just leave a TODO with a bug link to a bug against gazelle.
…On Fri, Mar 23, 2018 at 3:02 PM Tim Hockin ***@***.***> wrote:
> recent functionality in gazelle causes it to follow symlinks, but only if
they're outside the repo root.
How does it calculate repo root?
> if you run hack/run-in-gopath.sh hack/update-bazel.sh, gazelle ends up
running inside _output/local/go/src/k8s.io/kubernetes. gazelle doesn't
currently resolve the repo root to an absolute path, so its check to verify
that the symlink is out-of-repo fails (since it resolves symlinks its
considering to their absolute path).
This sounds incredibly broken and fragile. If it needs to do anything like
this, it should probably canonicalize the path, resolve symlinks, etc.
`pwd -P`
> For example, consider vendor/k8s.io/apimachinery, which points to
../../staging/src/k8s.io/apimachinery.
> When run in the real $KUBE_ROOT, gazelle detects the repo root as
$HOME/go/src/k8s.io/kubernetes and the endpoint of this symlink as
$HOME/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery. Since
that's within the repo, it doesn't follow the symlink.
> When run through hack/run-in-gopath.sh, gazelle detects the repo root as
$HOME/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes, but
still resolves the endpoint of the vendor symlink as $HOME/go/src/
k8s.io/kubernetes/staging/src/k8s.io/apimachinery. It considers this as
out-of-repo and thus follows the symlink, erroneously.
Did you file a bug against gazelle? This is broken.
|
I agree that it's fragile. I'm discussing this with @jayconrod out-of-band to confirm that it's a bug in gazelle (I'm pretty sure it is). |
It looks like this was just fixed in bazelbuild/bazel-gazelle#166. Updating to a newer gazelle causes more churn in some of the build files due to bazelbuild/bazel-gazelle#148, and it probably also requires updating rules_go. I'm tempted to just leave a comment here pointing at bazelbuild/bazel-gazelle#166 and then plan to update this soon and remove the workaround, rather than bumping everything now. WDYT @thockin? |
/hold |
@ixdy I'll cherry-pick that fix back to Gazelle 0.10 and tag 0.10.1. Gazelle at tip will require a newer version of rules_go. In particular, bazelbuild/bazel-gazelle#148 generates |
yeah, I was just about to comment that I tried updating to gazelle HEAD, and it complained that we're actually not using 0.10.0 right now, but rather 6 commits past it; we're using this version because we needed buildtools to be vendored. |
though: this PR will unblock #57600, which will allow us to vendor gazelle and buildtools ourselves. at that point, it won't matter whether the version of gazelle we're using vendors buildtools or not. |
In Gazelle 0.10.1, I'll include changes that vendor buildtools on our side, so you may not need to vendor it yourself unless you have a separate dependency. |
Gazelle 0.10.1 is ready. |
9d686e2
to
f7ec474
Compare
/hold cancel Updated to gazelle 0.10.1. Removed the chdir workaround; confirmed that we still get the same results via |
@ixdy do we need the |
nope; it'll auto-detect it based on the presence of the |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cblecker, ixdy The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Automatic merge from submit-queue (batch tested with PRs 61546, 61038, 61575, 60779, 61496). If you want to cherry-pick this change to another branch, please follow the instructions here. |
…57600-#62499-upstream-release-1.10 Automatic merge from submit-queue. Automated cherry pick of #61575: Remove all upstream BUILD, BUILD.bazel, and WORKSPACE #57600: Vendor gazelle #62499: Update kazel to include openapi tag detection fix Cherry pick of #61575 #57600 #62499 on release-1.10. #61575: Remove all upstream BUILD, BUILD.bazel, and WORKSPACE #57600: Vendor gazelle #62499: Update kazel to include openapi tag detection fix This is an alternative to #64928, and would fix #64925. We can't just cherry-pick #57600, since there was a prerequisite PR and a fixup PR afterwards.
What this PR does / why we need it: updates the
hack/godep-save.sh
script to prune any importedBUILD
,BUILD.bazel
, orWORKSPACE
files.We assume anything imported through godep doesn't need Bazel, but a Bazel-enabled Go project may include
BUILD
files with missing dependencies not imported by godep. To prevent this from breaking the Bazel build, remove these. (Gazelle will then regenerate theBUILD
files based on the go build metadata.)Additionally, there seems to be a bug in gazelle where it follows the
vendor/k8s.io
staging symlinks only when run throughhack/run-in-gopath.sh
. Updating to gazelle 0.10.1 fixes this bug.A similar PR was recently merged in kubernetes/test-infra: kubernetes/test-infra#7366
Release note:
/assign @thockin
cc @jayconrod