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: don't override existing ASDF_DIR #1008

Merged
merged 1 commit into from Nov 2, 2021
Merged

fix: don't override existing ASDF_DIR #1008

merged 1 commit into from Nov 2, 2021

Conversation

ericbn
Copy link
Contributor

@ericbn ericbn commented Jul 23, 2021

Summary

Allow users to define their own value of ASDF_DIR before sourcing asdf.sh, e.g. when it was installed with homebrew.

For example, I can use this in my shell startup script:

ASDF_DIR=/usr/local/opt/asdf
source "$ASDF_DIR/asdf.sh"

Also, similar test for [ -z "$ASDF_DIR" ] is already being done in lib/utils.bash.

Other Information

Also unset locally used variables at the end.

@ericbn ericbn requested a review from a team as a code owner July 23, 2021 22:48
@ericbn ericbn changed the title Don't override existing ASDF_DIR fix: don't override existing ASDF_DIR Jul 23, 2021
allowing users to define its value, e.g. when installed with homebrew.

Also unset locally used variables at the end.
@jthegedus
Copy link
Contributor

@ericbn is this related to or independent of Homebrew/homebrew-core#81664?

@ericbn
Copy link
Contributor Author

ericbn commented Jul 24, 2021

Hi @jthegedus. The changes here still don't fix the problems I've raised in that PR in homebrew-core. So, still unrelated in this sense.

@ericbn
Copy link
Contributor Author

ericbn commented Jul 26, 2021

@jthegedus this change allows users to set ASDF_DIR before sourcing asdf.sh, as this is one of the environment variables mentioned in https://asdf-vm.com/manage/configuration.html#environment-variables

@jthegedus
Copy link
Contributor

@Stratus3D this change looks good to me. What are your thoughts?

@@ -21,6 +21,9 @@ setup() {
mkdir -p $CHILD_DIR

cd $PROJECT_DIR

# asdf lib needed to run asdf.sh
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
Copy link
Contributor

Choose a reason for hiding this comment

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

Do the tests fail without this change? Which new codepath requires this as I don't see any test changes.

Copy link
Contributor Author

@ericbn ericbn Jul 30, 2021

Choose a reason for hiding this comment

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

Yes, tests fail without this change because setup_asdf_dir creates an "empty" ASDF_DIR. It's more like a valid ASDF_DATA_DIR than a valid ASDF_DIR, because the {bin,lib} files are not there. Since with this change the asdf.sh will respect any previously set ASDF_DIR variable, that ASDF_DIR will be used, and the tests fail.

Maybe we should move this cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/ (which is repeated may times after calling setup_asdf_dir in individual tests) to setup_asdf_dir, so this function guarantees that a complete ASDF_DIR was created. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understand after looking through some code. setup_asdf_dir makes sense, but I question why it would be needed even after your change. As I understand, it will not overwrite ASDF_DIR if it is already set. ASDF_DIR is set during the setup_asdf_dir func, so why would these version_commands.bats tests start to fail?

I would expect your change in asdf.sh to only affect tests in asdf_sh.bats, but I don't think there's a test case for this scenarion, so a test should be added there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The version_commands.bats tests fail because:

  1. They call setup_asdf_dir in the setup step.
    1. setup_asdf_dir creates a temp directory with no bin or lib files
    2. and sets the ASDF_DIR env variable to be the path to that directory.
  2. The tests call . $(dirname "$BATS_TEST_DIRNAME")/asdf.sh.
  3. asdf.sh will use the value of the existing ASDF_DIR env variable, that was set by setup_asdf_dir
  4. and fail because there's no lib/asdf.sh file in that ASDF_DIR.

This is what I've mentioned in my previous comments, and that's why I've said that "setup_asdf_dir creates an 'empty' ASDF_DIR", and suggested that it should guarantee that the ASDF_DIR it creates is complete.

@ericbn
Copy link
Contributor Author

ericbn commented Jul 30, 2021

I don't know any fish scripting, but if you agree with this change, maybe the same should be applied to the asdf.fish script, for symmetry.

Copy link

@KlausEverWalkingDev KlausEverWalkingDev left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

@jthegedus jthegedus merged commit 73efc9f into asdf-vm:master Nov 2, 2021
@n-rodriguez
Copy link

n-rodriguez commented Nov 4, 2021

It seems that this change breaks something : https://github.com/jbox-web/asdf-squarectl/actions

@ericbn ericbn deleted the dont_override_existing_ASDF_DIR branch November 4, 2021 23:33
@ericbn
Copy link
Contributor Author

ericbn commented Nov 4, 2021

@n-rodriguez, this works for me:

unset ASDF_DIR
git clone --depth 1 --branch master https://github.com/asdf-vm/asdf.git /tmp/.asdf
/tmp/.asdf/bin/asdf plugin-test squarectl https://github.com/jbox-web/asdf-squarectl --asdf-tool-version latest --asdf-plugin-gitref 9967cd047af5fcd74e926bb1abf6d4aecffd90ec squarectl --version

Maybe you already have ASDF_DIR set to something else before running .asdf/bin/asdf...

@Stratus3D
Copy link
Member

@n-rodriguez did you figure out what your issue was? I don't see any failures for your CI action.

@n-rodriguez
Copy link

@Stratus3D sorry I did some clean but I triggered one for you : https://github.com/jbox-web/asdf-squarectl/actions/runs/1426185845

@n-rodriguez
Copy link

n-rodriguez commented Nov 5, 2021

Actually I can't really tell if it's related. The only thing is synchronicity of events (and the git history ^^)

Everything was green for 10 days : https://github.com/jbox-web/asdf-squarectl/actions

And then 2 commits appear : https://github.com/asdf-vm/asdf/commits/master (2021-11-02)

And then I realize it might be due to 69ff2d0

But one of them break something. Thank you! (and sorry for the noise)

@Stratus3D
Copy link
Member

Stratus3D commented Nov 5, 2021

I'm pretty sure it is due to 69ff2d0. See our discussion here: #1078 and here: #1083, and here: #1084. Please follow those issues for the resolution of this. Your issue is not caused by this PR.

joehorsnell added a commit to joehorsnell/asdf that referenced this pull request Jan 13, 2022
`asdf` [v0.9.0][1] included a [bug fix][2] to not override an existing ASDF_DIR.

However, if `ASDF_DIR` is not set at all, then this causes an error when using bash `set -u`, or
`set -o nounset` - see [here][3] for additional info.

[1]: https://github.com/asdf-vm/asdf/releases/tag/v0.9.0
[2]: asdf-vm#1008
[3]: https://mywiki.wooledge.org/BashFAQ/112
joehorsnell added a commit to joehorsnell/asdf that referenced this pull request Jan 14, 2022
`asdf` [v0.9.0][1] included a [bug fix][2] to not override an existing ASDF_DIR.

However, if `ASDF_DIR` is not set at all, then this causes an error when using bash `set -u`, or
`set -o nounset` - see [here][3] for additional info.

[1]: https://github.com/asdf-vm/asdf/releases/tag/v0.9.0
[2]: asdf-vm#1008
[3]: https://mywiki.wooledge.org/BashFAQ/112
Stratus3D pushed a commit that referenced this pull request Jan 19, 2022
`asdf` [v0.9.0][1] included a [bug fix][2] to not override an existing ASDF_DIR.

However, if `ASDF_DIR` is not set at all, then this causes an error when using bash `set -u`, or
`set -o nounset` - see [here][3] for additional info.

[1]: https://github.com/asdf-vm/asdf/releases/tag/v0.9.0
[2]: #1008
[3]: https://mywiki.wooledge.org/BashFAQ/112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants