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

gh-113565: Improve and harden detection of curses dependencies #119816

Merged
merged 21 commits into from
Jul 1, 2024

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented May 31, 2024

@erlend-aasland

This comment was marked as outdated.

configure Outdated Show resolved Hide resolved
@erlend-aasland
Copy link
Contributor Author

If you agree on the overall strategy, I'll continue working on this.

@erlend-aasland
Copy link
Contributor Author

I finally managed to coerce this the way I would like it. Locally on macOS, the SDK supplied curses/panel libs are detected just fine using ./configure without args. The Homebrew supplied curses installation is now correctly identified if I add it to PKG_CONFIG_PATH.

Now, this is a large PR, but the configure.ac change should be as readable as M4 and Autoconf macros get 😄

With this PR we now do:

  1. use pkg-config to check for ncursesw/panelw1
  2. if 1. fails, use pkg-config to check for ncurses/panel
  3. regardless of pkg-config output, search for curses/panel headers, so we're sure we have all defines in pyconfig.h
  4. regardless of pkg-config output, see if libncurses or libncursesw contains the initscr symbol; if it does and pkg-config failed earlier, add the resulting -llib linker option to CURSES_LIBS
  5. ditto for update_panels and PANEL_LIBS
  6. wrap the rest of the curses/panel checks with WITH_SAVE_ENV and make sure we're using updated LIBS and CPPFLAGS for those checks

I believe this is now ready for an initial round of review.

Footnotes

  1. I created the PY_CHECK_CURSES utility macro for this

@erlend-aasland erlend-aasland marked this pull request as ready for review June 2, 2024 12:32
@erlend-aasland
Copy link
Contributor Author

I'm conflicted regarding backporting this change. I think we should consider it for 3.13, but I'm not so sure about 3.12.

@erlend-aasland erlend-aasland changed the title gh-113565: Use pkg-config to detect ncurses[w] and panel[w] gh-113565: Improve and harden detection of curses dependencies Jun 2, 2024
@erlend-aasland erlend-aasland added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 2, 2024
@bedevere-bot

This comment was marked as outdated.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 2, 2024
@erlend-aasland

This comment was marked as outdated.

@vstinner
Copy link
Member

vstinner commented Jun 6, 2024

All buildbot failures are unrelated to this PR: good!

  • AMD64 Arch Linux TraceRefs PR: unrelated. test_import crash, known issue, fixed in the meanwhile.
  • AMD64 Arch Linux Usan PR: unrelated. Objects/object.c:1019:16: runtime error: call to function long_hash through pointer to incorrect function type 'long (*)(struct _object *)'
  • AMD64 Ubuntu NoGIL Refleaks PR: unrelated. timeout.
  • AMD64 Windows10 PR: unrelated. test_launcher failed.
  • AMD64 Windows11 Bigmem PR: unrelated. test_launcher failed.
  • ARM64 Windows Non-Debug PR: unrelated. test_cext and test_launcher failed.
  • ARM64 Windows PR: unrelated. test_launcher failed.
  • x86 Debian Installed with X PR: unrelated. test_ctypes failed.
  • x86 Debian Non-Debug with X PR: unrelated. test_ctypes failed.

@erlend-aasland
Copy link
Contributor Author

All buildbot failures are unrelated to this PR: good!

Yes, and that is expected :) The hard ting with changes like this, is we have to tediously examine all buildbots and verify that the dependency detection works as expected, and examine again that the correct compile and linker flags are used in the build phase.

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

LGTM! (But prefer not to backport as possible, original issue is also classified as the feature not the bug..)

About the backport, I would like to delegate the decision to @ned-deily

@vstinner
Copy link
Member

vstinner commented Jun 9, 2024

LGTM! (But prefer not to backport as possible, original issue is also classified as the feature not the bug..)

Oh same here, I prefer to not backport such change just to limit the risk of regression.

@erlend-aasland
Copy link
Contributor Author

Thanks for the reviews, Donghee and Victor! I still think we should backport :)

@vstinner
Copy link
Member

vstinner commented Jun 10, 2024

I still think we should backport :)

It's up to you if you want to be responsible for potential regression. What are advantages of backporting the change if the current code "just works" on the stable 3.12 branch?

Buildbots only test the most common major platforms. Other platforms such as OpenBSD, NetBSD, AIX, Solaris, HP-UX, and others are not tested.

@erlend-aasland
Copy link
Contributor Author

What are advantages of backporting the change if the current code "just works" on the stable 3.12 branch?

It's a bug-fix; it does not "just work" on 3.12 ;) IMO, the risk of regression is extremely low. This change improves the build system's ability to detect curses dependencies. If dependencies are not detected, the _curses module is simply not built; the build still succeeds. It does not change the behaviour of the _curses module itself.

@erlend-aasland
Copy link
Contributor Author

@ned-deily, friendly ping 🏓

Copy link
Member

@ned-deily ned-deily left a comment

Choose a reason for hiding this comment

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

LGTM, although I limited my review to a non-exhaustive read-through and to testing before and after build configurations on macOS using the current (Sonoma 14.5) release and Command Line Tools with (1) the system-provided ncurses, (2) MacPorts ncurses, (3) Homebrew ncurses, and (4) our Python for macOS installer build. No regressions were noted with or without pkg-config use. I did not test on any other platforms.

FWIW, the PR also eliminates a previously seen compile warning when using either the MacPorts or Homebrew ncurses:

In file included from ./Include/py_curses.h:40:
/opt/homebrew/Cellar/ncurses/6.5/include/ncursesw/ncurses.h:152:9: warning: 'NCURSES_OPAQUE' macro redefined [-Wmacro-redefined]
#define NCURSES_OPAQUE       1
        ^
./Include/py_curses.h:36:9: note: previous definition is here
#define NCURSES_OPAQUE 0

@ned-deily
Copy link
Member

ned-deily commented Jul 1, 2024

WRT backporting, I would like to see this in 3.13; I'm somewhat ambivalent about backporting to 3.12. While it is indeed fixing some somewhat buggy build behavior, it is behavior that has been out there since 3.12.0 (and 3.11?) and presumably most downstream builders of Python 3.12 have figured out how to live with it. If it were a bug that affected all users of Python, that would be one thing, but one that only affects builders and, at that, only those who are concerned about ncurses ... that's a lot of churn in some of our favorite files (like configure.ac and header files). I guess that's a +0 from me for 3.12; I think @Yhg1s needs to call it.

@erlend-aasland
Copy link
Contributor Author

Thank you so much for taking the time to review this huge PR, everyone; highly appreciated!

Regarding other operating systems, I did examine a big chunk of the buildbots and found no regressions. I'll create backports for 3.13 and 3.12, but I'll leave the 3.12 one open for Thomas to decide.

@erlend-aasland erlend-aasland enabled auto-merge (squash) July 1, 2024 07:54
@erlend-aasland erlend-aasland merged commit f80376b into python:main Jul 1, 2024
36 checks passed
@erlend-aasland erlend-aasland deleted the autoconf/curses branch July 1, 2024 08:10
@miss-islington-app

This comment has been minimized.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 1, 2024
…ythonGH-119816)

1. Use pkg-config to check for ncursesw/panelw. If that fails, use
   pkg-config to check for ncurses/panel.
2. Regardless of pkg-config output, search for curses/panel headers, so
   we're sure we have all defines in pyconfig.h.
3. Regardless of pkg-config output, check if libncurses or libncursesw
   contains the 'initscr' symbol; if it does _and_ pkg-config failed
   earlier, add the resulting -llib linker option to CURSES_LIBS.
   Ditto for 'update_panels' and PANEL_LIBS.
4. Wrap the rest of the checks with WITH_SAVE_ENV and make sure we're
   using updated LIBS and CPPFLAGS for those.

Add the PY_CHECK_CURSES convenience macro.
(cherry picked from commit f80376b)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
@miss-islington-app

This comment was marked as outdated.

@bedevere-app
Copy link

bedevere-app bot commented Jul 1, 2024

GH-121202 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jul 1, 2024
erlend-aasland added a commit that referenced this pull request Jul 1, 2024
…GH-119816) (#121202)

1. Use pkg-config to check for ncursesw/panelw. If that fails, use
   pkg-config to check for ncurses/panel.
2. Regardless of pkg-config output, search for curses/panel headers, so
   we're sure we have all defines in pyconfig.h.
3. Regardless of pkg-config output, check if libncurses or libncursesw
   contains the 'initscr' symbol; if it does _and_ pkg-config failed
   earlier, add the resulting -llib linker option to CURSES_LIBS.
   Ditto for 'update_panels' and PANEL_LIBS.
4. Wrap the rest of the checks with WITH_SAVE_ENV and make sure we're
   using updated LIBS and CPPFLAGS for those.

Add the PY_CHECK_CURSES convenience macro.
(cherry picked from commit f80376b)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
@vstinner
Copy link
Member

vstinner commented Jul 1, 2024

Well done @erlend-aasland :-)

@bedevere-app
Copy link

bedevere-app bot commented Jul 1, 2024

GH-121222 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Jul 1, 2024
Akasurde pushed a commit to Akasurde/cpython that referenced this pull request Jul 3, 2024
…ython#119816)

1. Use pkg-config to check for ncursesw/panelw. If that fails, use 
   pkg-config to check for ncurses/panel.
2. Regardless of pkg-config output, search for curses/panel headers, so
   we're sure we have all defines in pyconfig.h.
3. Regardless of pkg-config output, check if libncurses or libncursesw
   contains the 'initscr' symbol; if it does _and_ pkg-config failed
   earlier, add the resulting -llib linker option to CURSES_LIBS.
   Ditto for 'update_panels' and PANEL_LIBS.
4. Wrap the rest of the checks with WITH_SAVE_ENV and make sure we're 
   using updated LIBS and CPPFLAGS for those.

Add the PY_CHECK_CURSES convenience macro.
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
…ython#119816)

1. Use pkg-config to check for ncursesw/panelw. If that fails, use 
   pkg-config to check for ncurses/panel.
2. Regardless of pkg-config output, search for curses/panel headers, so
   we're sure we have all defines in pyconfig.h.
3. Regardless of pkg-config output, check if libncurses or libncursesw
   contains the 'initscr' symbol; if it does _and_ pkg-config failed
   earlier, add the resulting -llib linker option to CURSES_LIBS.
   Ditto for 'update_panels' and PANEL_LIBS.
4. Wrap the rest of the checks with WITH_SAVE_ENV and make sure we're 
   using updated LIBS and CPPFLAGS for those.

Add the PY_CHECK_CURSES convenience macro.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…ython#119816)

1. Use pkg-config to check for ncursesw/panelw. If that fails, use 
   pkg-config to check for ncurses/panel.
2. Regardless of pkg-config output, search for curses/panel headers, so
   we're sure we have all defines in pyconfig.h.
3. Regardless of pkg-config output, check if libncurses or libncursesw
   contains the 'initscr' symbol; if it does _and_ pkg-config failed
   earlier, add the resulting -llib linker option to CURSES_LIBS.
   Ditto for 'update_panels' and PANEL_LIBS.
4. Wrap the rest of the checks with WITH_SAVE_ENV and make sure we're 
   using updated LIBS and CPPFLAGS for those.

Add the PY_CHECK_CURSES convenience macro.
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.

configure prefers system install of ncurses over available pkg-config on macOS
5 participants