Homebrew / homebrew-core

🍻 Default formulae for the missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
13.77k stars 12.45k forks source link

The system libedit used by python and LLDB is outdated and missing bugfixes #127339

Closed lionel- closed 1 year ago

lionel- commented 1 year ago

brew gist-logs <formula> link OR brew config AND brew doctor output

HOMEBREW_VERSION: 4.0.10-119-g931327d
ORIGIN: https://github.com/Homebrew/brew
HEAD: 931327df1f30a3a5b1aa07657c0d1070e61988f9
Last commit: 2 days ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 6e64abc0cf5efa3f68732d0543333d795dee0717
Core tap last commit: 2 hours ago
Core tap branch: python-fix-libedit
Core tap JSON: 02 Apr 11:50 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_BROWSER: open
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.UbLoCAL2EI/org.xquartz:0
HOMEBREW_EDITOR: emacsclient
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 14.0.0 build 1400
Git: 2.40.0 => /opt/homebrew/bin/git
Curl: 7.85.0 => /usr/bin/curl
macOS: 13.1-arm64
CLT: 14.2.0.0.1.1668646533
Xcode: 14.2
Rosetta 2: false

----
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed kegs have no formulae!
This means they were either deleted or installed manually.
You should find replacements for the following formulae:
  pycparser
  cffi
  szip

Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  ctags
  emscripten@3.1.1
  emacs

Warning: Some taps are not on the default git origin branch and may not receive
updates. If this is a surprise to you, check out the default branch with:
  git -C $(brew --repo lionel/homebrew) checkout 
  git -C $(brew --repo homebrew/core) checkout master

Verification

What were you trying to do (and why)?

Use Python and LLDB inside a shell running within Emacs. Emacs runs such subprocesses inside non-echoing ttys. Since the text is inserted in the "document" before being sent to the process, we don't need the tty to echo the input.

What happened (include all command output)?

The tty settings are unexpectedly changed by python/lldb on startup, which causes the tty to start echoing input:

stty
#> speed 9600 baud;
#> lflags: -echo echoe echoke echoctl
#> oflags: -oxtabs
#> cflags: cs8 -parenb

python3
#> Python 3.11.2 (main, Apr  2 2023, 12:23:07) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
#> Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
#> quit()                            # NOTE: Now echoing

stty
#> stty                              # NOTE: Echo again
#> speed 9600 baud;
#> lflags: echoe echoke echoctl      # NOTE: Missing -echo
#> oflags: -oxtabs
#> cflags: cs8 -parenb

See also https://stackoverflow.com/questions/19246065/python-in-emacs-shell-mode-turns-on-stty-echo-and-breaks-c-d

What did you expect to happen?

The stty settings should not change. There are workarounds in Emacs to deal with echoing ttys but they are not comprehensive across all modules and somewhat ill defined.

This happens because libedit is used in applications like Python and LLDB as a readline replacement. Currently, as is standard, homebrew links to the system library instead of the homebrew version. However the version in macOS hasn't been updated since 2012/09/11 (see https://opensource.apple.com/source/libedit/) and it is missing an important bugfix: https://github.com/NetBSD/src/commit/0aa38cbab4730df863c600ab07029005cf83af4b.

Without this fix, the tty settings are lost each time a subprocess initialises the readline emulation through libedit.

Would it be possible to make an exception for libedit and use the updated homebrew version instead of the old system version throughout homebrew formulas? Here is a diff that fixes the issue for python3:

modified   Formula/python@3.11.rb
@@ -30,10 +30,10 @@ class PythonAT311 < Formula
   depends_on "openssl@1.1"
   depends_on "sqlite"
   depends_on "xz"
+  depends_on "libedit"

   uses_from_macos "bzip2"
   uses_from_macos "expat"
-  uses_from_macos "libedit"
   uses_from_macos "libffi", since: :catalina
   uses_from_macos "libxcrypt"
   uses_from_macos "ncurses"
@@ -173,7 +173,7 @@ class PythonAT311 < Formula
     cflags         = []
     cflags_nodist  = ["-I#{HOMEBREW_PREFIX}/include"]
     ldflags        = []
-    ldflags_nodist = ["-L#{HOMEBREW_PREFIX}/lib", "-Wl,-rpath,#{HOMEBREW_PREFIX}/lib"]
+    ldflags_nodist = ["-L#{Formula["libedit"].opt_lib}", "-L#{HOMEBREW_PREFIX}/lib", "-Wl,-rpath,#{HOMEBREW_PREFIX}/lib"]
     cppflags       = ["-I#{HOMEBREW_PREFIX}/include"]

     if MacOS.sdk_path_if_needed

Happy to send a PR if the fix above makes sense.

Step-by-step reproduction instructions (by running brew commands)

brew install python@3.11
emacs
M-x shell
M-: (setq comint-process-echoes nil)
python3
github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

carlocab commented 1 year ago

Can you reproduce this with Apple-provided Python/LLDB? If so, I suggest reporting it to Apple as well: https://feedbackassistant.apple.com/


Thoughts here, @Homebrew/core?

Personally, I'm not opposed to doing this at some point, but only if multiple users ask for this (which doesn't look to be the case currently). This bug should be reported to Apple too.

lionel- commented 1 year ago

I have reported it to Apple before posting here and the person in the SO post reported it as well.

carlocab commented 1 year ago

Do you have the FB#?

lionel- commented 1 year ago

This is FB12092290

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.