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

fix: reshim did not rewrite executable path #1311

Merged
merged 13 commits into from
Dec 20, 2022

Conversation

dylan-chong
Copy link
Contributor

@dylan-chong dylan-chong commented Jul 25, 2022

Summary

Fixes reshimming not working by always recreating the file from scratch.
We grab the existing plugin versions from the existing shim file and squish those into a brand new shim file.
This solves the problem of updating asdf from homebrew causing the executable path to be wrong, and not fixable by asdf reshim

Regenerating the shim file from scratch is much simpler, no additional tests required like #1287.

Fixes: #1115
Fixes: #1231 (dupe)
Fixes: #1286
Makes change in #1287 not needed, although the test is still useful

TLDR for comment section

Read from this comment down #1311 (comment)

Other Information

@dylan-chong dylan-chong requested a review from a team as a code owner July 25, 2022 11:29
@dylan-chong dylan-chong changed the title Fix reshim does not rewrite file Fix: reshim does not rewrite file Jul 25, 2022
@dylan-chong dylan-chong changed the title Fix: reshim does not rewrite file fix: reshim does not rewrite file Jul 25, 2022
@dylan-chong dylan-chong changed the title fix: reshim does not rewrite file fix: reshim did not rewrite file Jul 25, 2022
@alexezio
Copy link
Contributor

hello, @dylan-chong :
What if the execution have more than one shim path?
if we re-generate the reshim file, the shim file will only contains one shim path other than all of their. This will cause issue for origin shim path. could you please run the bats for verify the results?

@dylan-chong
Copy link
Contributor Author

Hey

@alexezio you're right it is breaking some tests.
Why was it implemented as using regex to accumulate data in a file? That gives me the heebie jeebies. Why not take a list of
Also why does the shim have to list the versions of the plugin?

If we could simplify the API such that we remove all shim files and regenerate them all (so asdf reshim takes no arguments) then that would simplify things massively. There would be only one code path:

  1. delete all existing shims
  2. generate shims for all versions of each executable for each plugin

There's no need to keep files around and do complicated regexes on them if we can regenerate them from scratch every time (which is what you have to do when upgrading asdf with homebrew anyway). Unless, there's something I'm missing?

Happy to have a go at implementing this idea if you'd like ^.
Think it'd be a good improvement to make

@alexezio
Copy link
Contributor

alexezio commented Jul 30, 2022

hey dylan @dylan-chong :
In my opinion, asdf is stateless, so the shim file have also saved the program version state. If we regenrate them from scrach, We have no where to fetch version state except the file itself.
although regex is annoying, It can modify the version state without break them(by increment).
I am a newbee for asdf, Maybe there is a better approach to reshim. but for now, I vote for regex...
thanks~

@dylan-chong
Copy link
Contributor Author

dylan-chong commented Jul 30, 2022

@alexezio but you can delete the shim files manually and regenerate the files from scratch? Does this not put the version comments in the file?
Is it not possible to just list all versions of the plugin?

if you would prefer to keep the regex I could have a go at replacing everything except the existing version list using the regex. This would fix the issue in the description.

@dylan-chong
Copy link
Contributor Author

dylan-chong commented Jul 30, 2022

Cc @Stratus3D @jthegedus which option would you prefer:

  1. simplify the reshim API and have the command re-generate all files from scratch [for any given plug-in]. Would need a way to be able to list all versions of the plugin supported by the executable
  2. Replace sed with grep so in the existing function we grab out the existing versions and copy them over into a freshly generated file, which is written over the top. This is less error prone since we can use simple grep patterns and generate most of the file from scratch

IMO 1 is better long term , but requires more work now.

@dylan-chong
Copy link
Contributor Author

The easiest option was to implement no 2 (see above), which I have committed to this branch.

@Stratus3D @jthegedus This is ready to merge

@alexezio This means that the change to the sed pattern in your PR #1287 is not longer required. But it would still be great to merge the test that you wrote in your PR. I have checked and that test passes in this branch, but I don't want to steal your contribution so I'll let you commit that :)

@dylan-chong dylan-chong changed the title fix: reshim did not rewrite file fix: reshim did not rewrite executable path Jul 31, 2022
@jthegedus
Copy link
Contributor

jthegedus commented Dec 12, 2022

I am not sure why the tests didn't run here, but merging master so they can. We have some banned command usage which I believe this solution uses, so might need an update.

#!/usr/bin/env bash
# asdf-plugin: ${plugin_name} ${version}
`sort -u < "$temp_versions_path"`
Copy link
Contributor

Choose a reason for hiding this comment

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

We're already using uniq in the codebase, but not the -u flag on sort. Can we change this to be uniq?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so you mean like cat "$temp_versions_path" | sort | uniq?

@jthegedus
Copy link
Contributor

@Stratus3D looking at our open PRs we have 3 which attempt to resolve this issue. Are you able to check this as it seems to me to be the best option. I am concerned about performance, but here correctness is preferred, we can come back and fix perf.

temp_dir=${TMPDIR:-/tmp}

local temp_versions_path
temp_versions_path=$(mktemp "$temp_dir/asdf-command-reshim-write-shims.XXXXXX")
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure line 91-92 are necessary as mktemp should fallback to TMPDIR and /tmp automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jthegedus, do you have any thoughts since you added this?

Copy link
Contributor

Choose a reason for hiding this comment

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

This seemed fine to me, but after looking at existing use of mktemp this was the outlier, so I changed it to align with the other usages. We can back this out later once we clean up and decide to put this behind a function or something.

lib/commands/reshim.bash Outdated Show resolved Hide resolved
Copy link
Member

@Stratus3D Stratus3D left a comment

Choose a reason for hiding this comment

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

Other than my two comments above this PR looks good to me and I think we should get it merged.

I agree with @dylan-chong that approach #1 is better but this PR should work for now.

@Stratus3D
Copy link
Member

@Stratus3D looking at our open PRs we have 3 which attempt to resolve this issue. Are you able to check this as it seems to me to be the best option. I am concerned about performance, but here correctness is preferred, we can come back and fix perf.

I completely agree. Let's try to get this shipped. I can re-assess performance later if necessary. Thanks @jthegedus !

Copy link
Member

@Stratus3D Stratus3D left a comment

Choose a reason for hiding this comment

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

Approving now as I don't want to hold this up. But I think we should address the TMPDIR issue if we can.

@jthegedus jthegedus merged commit 5af7625 into asdf-vm:master Dec 20, 2022
@dylan-chong dylan-chong deleted the fix-reshim-does-not-rewrite-file branch December 20, 2022 21:27
@jthegedus
Copy link
Contributor

Let's see how it goes 😀

hyperupcall pushed a commit to fox-forks/asdf that referenced this pull request Dec 21, 2022
Co-authored-by: James Hegedus <jthegedus@hey.com>
Fixes asdf-vm#1115
Fixes asdf-vm#1231
Fixes asdf-vm#1286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants