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 macOS support to build script #14

Merged
merged 2 commits into from
Oct 11, 2022
Merged

Conversation

alexjurkiewicz
Copy link
Contributor

macOS bundles BSD readlink, which doesn't support -f (or any
equivalent). Instead, use stat (again, the BSD version) as a partial
replacement -- it will canonicalise symlinks.

You also can't strip ELF binaries on macOS, since the bundled strip only
supports Mach-O format.

@uablrek
Copy link
Contributor

uablrek commented Mar 14, 2022

Thanks for your contribution.

I don't like [ in scripts. Unix shell scripts are closer to a functional language regarding conditionals and using [ (which is a built-in alias for test) encourage the imperative programming style. Note for instance that the man page doesn't mention "condition" or "expresstion" when describing if (from man bash);

       if list; then list; [ elif list; then list; ] ... [ else list; ] fi

A very common misuse (which I find very annoying) is constructs like;

  grep -q pattern some/file
  if [ $? -eq 0 ]; then
    echo "Found"
...

@alexjurkiewicz
Copy link
Contributor Author

alexjurkiewicz commented Oct 11, 2022 via email

@uablrek
Copy link
Contributor

uablrek commented Oct 11, 2022

Make the suggested upates, squash and force-push.

@alexjurkiewicz
Copy link
Contributor Author

Perhaps I'm not as smart as you, because I don't understand what your suggested updates are. I understand you "don't like [ in scripts", but not what approach you prefer.

build.sh Outdated
Comment on lines 10 to 14
dir=$(dirname $0)
if [ "$(uname)" = Darwin ] ; then
if [ -s "$dir" ]; then
dir=$(stat -f%Y "$0")
fi
else
dir=$(readlink -f "$dir")
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the [ and replace with test. Like;

if test  "$(uname)" = Darwin  ; then
	test -s "$dir" && dir=$(stat -f%Y "$0")
else
	dir=$(readlink -f "$dir")
fi

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to use the safer;

if uname | grep -qi Darwin  ; then
...

This illustrates my aversion to [, one tend to forget that the "thing" after if is not an expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

build.sh Outdated
Comment on lines 58 to 62
if [ "$(uname)" = Darwin ] ; then
log "Not stripping image/kahttp: not supported on macOS"
else
strip image/kahttp
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with;

test "$(uname)" != Darwin && strip image/kahttp

Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above;

uname | grep -qi darwin || strip image/kahttp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@uablrek
Copy link
Contributor

uablrek commented Oct 11, 2022

My bad, sorry. I had started a review and made suggestions but was unaware that the suggestion was not visible to you unless I press a (somewhat hidden) "Submit" button. I hope you see them now.

@uablrek
Copy link
Contributor

uablrek commented Oct 11, 2022

And my apologize again for answer in #14 (comment). I thought my suggestions were visible.

macOS bundles BSD readlink, which doesn't support -f (or any
equivalent). Instead, use stat (again, the BSD version) as a partial
replacement -- it will canonicalise symlinks.

You also can't strip ELF binaries on macOS, since the bundled strip only
supports Mach-O format.
@alexjurkiewicz
Copy link
Contributor Author

All good. Updated as requested.

@uablrek uablrek merged commit 5ef0c10 into Nordix:master Oct 11, 2022
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.

2 participants