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

Alias gnu commands for homebrew packaging #172

Merged
merged 3 commits into from Apr 5, 2024

Conversation

LecrisUT
Copy link
Contributor

@LecrisUT LecrisUT commented Mar 22, 2024

Addressing the packaging issue in: Homebrew/homebrew-core#164352 (comment)

  • Alias getopt to GETOPT_CMD
  • Alias readlink to READLINK_CMD
  • Add a makefile interface to sed these functions. I am not proficient in writing Makefiles manually, can someone help for this?

Hopefully the CI can catch any issues with aliasing

Depends-on: #171
Homebrew runner: LecrisUT/homebrew-tmt#1 (I'll try to keep it in sync with this PR)

src/storage.sh Outdated Show resolved Hide resolved
src/beakerlib.sh Outdated
Comment on lines 34 to 38

# Command aliases for compatibilities
declare READLINK_CMD="readlink"

Copy link
Member

@sopos sopos Mar 22, 2024

Choose a reason for hiding this comment

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

It should be enough to move all the *_CMD variable definitions here. The individual definitions on other scripts should not be necessary unless someone would like to use them separately which is not expected.

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 all scripts source beakerlib.sh? Is it done recursively like the user's test.sh -> beakerlib.sh -> logging.sh -> beakerlib.sh? Or is it that the individual .sh scripts will not work without *_CMD having been defined beforehand?

What about unit-tests, no need for anything special there as well?

Copy link
Member

Choose a reason for hiding this comment

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

So all scripts source beakerlib.sh? Is it done recursively like the user's test.sh -> beakerlib.sh -> logging.sh -> beakerlib.sh? Or is it that the individual .sh scripts will not work without *_CMD having been defined beforehand?

No, the test sources beakerlib.sh which would define the variables so the other scripts, which are sourced by the beakerlib.sh, will have it available because they run in the same scope/namespace as they are just sourced, not executed. The individual sub-scripts, e.g. infrastructure.sh should not be sourced directly.

What about unit-tests, no need for anything special there as well?

I'm wondering how it could be tested differently than just calling some of the affected functions.. The only way I can imagine is be to provide a custom bash function/script as a wrapper which would e.g. echo some additional text which could be caught for an assert. Something like getopt_test() {echo "a getopt wrapper" >&2; getopt "$@"; } GETOPT_CMD='getopt_test'; rlHash 'test'; and then check the "a getopt wrapper" was logged on an error log level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking more on the lines of if the unit tests will still work, i.e. do those tests source beakerlib.sh or infrastructure.sh directly. If the later, we might need to add a declare in those places as well.

For writing the unit test for getopt_test, I am not sure I follow. That would depend on if beakerlib.sh is sourced, and if we can avoid the whole thing not breaking down if we re-define GETOPT_CMD.

src/beakerlib.sh Outdated Show resolved Hide resolved
@LecrisUT
Copy link
Contributor Author

The only part left is to write the Makefile interface to sed replace beakerlib.sh.

I am not proficient with make enough to figure how to add a ifdef instructions, but the sed part is pretty straightforward:

$ sed -i "s/declare -r __INTERNAL_GETOPT_CMD=\"getopt\"/declare -r __INTERNAL_GETOPT_CMD=\"${GETOPT_CMD}\"/" src/beakerlib.sh
$ sed -i "s/declare -r __INTERNAL_READLINK_CMD=\"readlink\"/declare -r __INTERNAL_READLINK_CMD=\"${READLINK_CMD}\"/" src/beakerlib.sh

@LecrisUT LecrisUT marked this pull request as ready for review April 2, 2024 12:02
@LecrisUT
Copy link
Contributor Author

LecrisUT commented Apr 2, 2024

In order to move this along, I added a naive implementation with 5d39fc9. Feel free to review it.

Edit: Finally got it working with homebrew as well https://github.com/LecrisUT/homebrew-tmt/actions/runs/8523574505/job/23346138439?pr=1

@LecrisUT LecrisUT force-pushed the fix/macos branch 2 times, most recently from 2b1a3f2 to c423866 Compare April 2, 2024 13:14
src/Makefile Outdated Show resolved Hide resolved
src/Makefile Outdated Show resolved Hide resolved
This is to allow replacing the `getopt` command with a full path alias, e.g. for homebrew

Signed-off-by: Cristian Le <[email protected]>
See the previous commit on `getopt`

Signed-off-by: Cristian Le <[email protected]>
Signed-off-by: Cristian Le <[email protected]>
@sopos sopos merged commit ee4c5d0 into beakerlib:master Apr 5, 2024
16 checks passed
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

2 participants