Skip to content
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

✨ Makefile: handle $GOPATH with a trailing slash #4768

Merged

Conversation

stevekuznetsov
Copy link
Contributor

@stevekuznetsov stevekuznetsov commented Feb 1, 2024

When a $GOPATH contains a trailing slash, the current check for string equality between the repo root and the computed path does not pass, even though it should. Passing both sides of the check through abspath makes this check more robust.

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Checklist:

  • squashed commits
  • includes documentation
  • includes emojis
  • adds unit tests
  • adds or updates e2e tests

Release note:

NONE

When a $GOPATH contains a trailing slash, the current check for string
equality between the repo root and the computed path does not pass, even
though it should. Passing both sides of the check through `abspath`
makes this check more robust.

Signed-off-by: Steve Kuznetsov <[email protected]>
@k8s-ci-robot k8s-ci-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Feb 1, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 1, 2024
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/assign @richardcase @Ankitasw

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 1, 2024
@@ -76,7 +76,7 @@ DOCKER_BUILDKIT=1
export ACK_GINKGO_DEPRECATIONS := 1.16.4

# Set --output-base for conversion-gen if we are not within GOPATH
ifneq ($(abspath $(REPO_ROOT)),$(shell go env GOPATH)/src/sigs.k8s.io/cluster-api-provider-aws)
ifneq ($(abspath $(REPO_ROOT)),$(abspath $(shell go env GOPATH)/src/sigs.k8s.io/cluster-api-provider-aws))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, this seems ok given that go env GOPATH enforces absolute path

Copy link
Contributor Author

@stevekuznetsov stevekuznetsov Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abspath is an idempotent function.

Your concern is that, for some user, this logic would have worked before but will be broken after this change. Let's investigate that.

If the workflow was functional for the user before, we know that this ifneq evaluated to false, or, that $( abspath $(REPO_ROOT)) was equal to the string on the right hand side of the expression.

Therefore, we know that the value on the right hand side of the expression must already be in the output set of abspath.

My change is to run that value through abspath again. Given that abspath is idempotent (running the function on an absolute path returns the input, since it's already an absolute path), it's provably correct here to apply abspath once more - given some user for whom this logic works before my change, it is not possible for the addition of the abspath call to change that.

So, I'd re-word your comment: it does not seem ok, it must logically be ok, and it does not rely on go env GOPATH outputting an absolute path. It is provable regardless of the output that if this check passed before passing the second argument through abspath it must pass after.

@Ankitasw
Copy link
Member

Ankitasw commented Feb 2, 2024

/retest

@nrb
Copy link
Contributor

nrb commented Feb 6, 2024

/lgtm
to me too

@Ankitasw
Copy link
Member

Ankitasw commented Feb 7, 2024

/lgtm

cc @vincepri for final approval based on open comment

@vincepri
Copy link
Member

vincepri commented Feb 7, 2024

thanks @Ankitasw
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 7, 2024
@k8s-ci-robot k8s-ci-robot merged commit faf38c1 into kubernetes-sigs:main Feb 7, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants