Skip to content

fix(stm32cubeprog): harden getopt support on MacOS#120

Merged
fpistm merged 1 commit into
stm32duino:mainfrom
fpistm:mac_getopt_issue
Jul 22, 2026
Merged

fix(stm32cubeprog): harden getopt support on MacOS#120
fpistm merged 1 commit into
stm32duino:mainfrom
fpistm:mac_getopt_issue

Conversation

@fpistm

@fpistm fpistm commented Jul 22, 2026

Copy link
Copy Markdown
Member
  • brew prefix usage
  • MacPorts support

Fixes #115.
Supersede #113.

@ndoo if you can test it will be fine.

@fpistm fpistm added this to the 2.4.1/2.5.0 milestone Jul 22, 2026
@fpistm fpistm added enhancement New feature or request fix 🩹 Bug fix labels Jul 22, 2026
@fpistm
fpistm requested a review from Copilot July 22, 2026 12:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates stm32CubeProg.sh to improve macOS robustness around GNU getopt availability, aiming to support both Homebrew (including non-default prefixes) and MacPorts installs so the script can reliably accept long options when GNU getopt is present.

Changes:

  • Adds macOS (Darwin) logic to detect GNU vs BSD getopt and to extend PATH for Homebrew/MacPorts installs.
  • Switches argument parsing to use long options only when GNU getopt is available, otherwise falls back to short-option parsing with warnings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stm32CubeProg.sh
Comment thread stm32CubeProg.sh Outdated
Comment thread stm32CubeProg.sh Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

stm32CubeProg.sh:101

  • GNU getopt detection is inverted: getopt --test returns exit code 4 on GNU getopt (and errors on BSD getopt), so if ! getopt --test; then GNU_GETOPT="y" will incorrectly mark BSD getopt as GNU, causing the script to run GNU-style long-option parsing on macOS and fail. Check explicitly for exit status 4 instead.
    if command -v getopt >/dev/null 2>&1; then
      if ! getopt --test 2>/dev/null; then
        GNU_GETOPT="y"
      fi
    fi

stm32CubeProg.sh:109

  • Homebrew GNU getopt lookup is checking ${BREW_PREFIX}/bin/getopt, but gnu-getopt is keg-only by default and typically lives under ${BREW_PREFIX}/opt/gnu-getopt/bin/getopt. With a non-default Homebrew prefix, this check will usually miss GNU getopt and the later hardcoded /usr/local//opt/homebrew fallbacks won't apply, so long options remain broken.
        BREW_PREFIX=$(brew --prefix)
        # Only check in bin as brew symlinks its files into the prefix,
        if command -v "${BREW_PREFIX}/bin/getopt" >/dev/null 2>&1; then
          export PATH="${BREW_PREFIX}/bin":"$PATH"
          GNU_GETOPT="y"

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread stm32CubeProg.sh Outdated
Comment thread stm32CubeProg.sh Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

stm32CubeProg.sh:90

  • Homebrew getopt detection stops after checking "${BREW_PREFIX}/bin/getopt" even when that binary exists but is not GNU (e.g., a non-GNU getopt wrapper). In that case the script never falls back to checking the typical keg-only path "${BREW_PREFIX}/opt/gnu-getopt/bin/getopt". Consider (1) quoting the brew prefix assignment and (2) only short-circuiting to the next candidate if the first candidate fails the GNU "--test" check.
          BREW_PREFIX=$(brew --prefix)
          if command -v "${BREW_PREFIX}/bin/getopt" >/dev/null 2>&1; then
            "${BREW_PREFIX}"/bin/getopt --test >/dev/null 2>&1

- brew prefix usage
- MacPorts support

Fixes stm32duino#115

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread stm32CubeProg.sh
@fpistm
fpistm merged commit 58794f6 into stm32duino:main Jul 22, 2026
@fpistm
fpistm deleted the mac_getopt_issue branch July 22, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fix 🩹 Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stm32CubeProg.sh: missing MacPorts getopt support

2 participants