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

Add absolute path for lib gm #1363

Merged

Conversation

JonathanLorimer
Copy link
Contributor

@JonathanLorimer JonathanLorimer commented Sep 18, 2021

Description

This is a tiny pr that adds the possibility to provide lib gm via the environment variable $LIB_GM_PATH. This helps me close informalsystems/cosmos.nix#34 by allowing me to wrap the gm executable and provide all the runtime dependencies (namely stoml and sconfig). This wrapping, means that the gm executable is no longer located next to lib-gm, and I don't want to force the user to move lib-gm into their $HOME directory. Therefore I need a third option, to provide an absolute path to lib-gm. I hope that this change isn't too intrusive!

closes #1365


For contributor use:

  • Added a changelog entry, using unclog.
  • If applicable: Unit tests written, added test to CI.
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments.
  • Re-reviewed Files changed in the Github PR explorer.

@adizere
Copy link
Member

adizere commented Sep 20, 2021

Thank you for your contribution Jonathan!

Could you please update gm/changelog.md?

As for reviewing this, I'd like to kindly ask Greg to have a look.

Copy link
Member

@greg-szabo greg-szabo left a comment

Choose a reason for hiding this comment

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

Hi @JonathanLorimer , thanks for your contribution! This is an interesting use-case that I didn't think about. I wonder why you chose LIB_GM_PATH (which fixes the file name to lib-gm) instead of simply LIB_GM (which allows you to override the filename too). Since it reminds me of the LD_LIBRARY_PATH thingies, I'm happy with it. I hope we won't have to add other libraries.

Dissecting bash/sh scripts into readable parts is hard. (and annoying because of all these edge-cases) I'm happy that this code is useful to you and I hope we can keep it up-to-date and useful.

I made one small suggestion to fix an edge-case that can cause an error but apart from that, the code looks good.

SCRIPT_0="${0:-$HOME/.gm/bin/gm}"
export SCRIPT_DIR="${SCRIPT_0%%gm}"
export LOCAL_LIB_GM="${SCRIPT_DIR}lib-gm"
if [ -f "$LOCAL_LIB_GM" ]; then
. "$LOCAL_LIB_GM"
elif [ -f "$HOME/.gm/bin/lib-gm" ]; then
. "$HOME/.gm/bin/lib-gm"
elif [ -f "$LIB_GM_PATH/lib-gm" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

I had a hunch that the impression that HOME is always set (which might not be true) might lead to other similar expectations.

The code looks good, but if lib-gm is not available and LIB_GM_PATH is not set, it will return

./gm: line 14: LIB_GM_PATH: unbound variable

instead of the expected

ERROR: could not find lib-gm, exiting...

It's an easy fix, we just need a default for LIB_GM_PATH. Here's one example:

Suggested change
elif [ -f "$LIB_GM_PATH/lib-gm" ]; then
elif [ -f "${LIB_GM_PATH:-}/lib-gm" ]; then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wow, good catch. I confirmed this fix works and made the changes. In cosmos.nix I am running shellcheck on these scripts and I am surprised this didn't get caught. I guess it isn't always required to default vars in case they are unset? Anyways, glad you spotted this.

scripts/gm/bin/gm Outdated Show resolved Hide resolved
Co-authored-by: Greg Szabo <16846635+greg-szabo@users.noreply.github.com>
Copy link
Member

@greg-szabo greg-szabo left a comment

Choose a reason for hiding this comment

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

Yup, looks good. I'll add the changelog when I'm ready with a new release. This can be merged.

@greg-szabo greg-szabo merged commit 6a5feb3 into informalsystems:master Sep 21, 2021
hu55a1n1 pushed a commit to hu55a1n1/hermes that referenced this pull request Sep 13, 2022
* add absolute path from env var

* testing

* quick fix

* remove echo

* minor bash fix

* Update scripts/gm/bin/gm

Co-authored-by: Greg Szabo <16846635+greg-szabo@users.noreply.github.com>

Co-authored-by: Greg Szabo <16846635+greg-szabo@users.noreply.github.com>
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.

Allow gm-lib path to be set via an environment variable Package sconfig and stoml together with Gaia Manager
3 participants