362 Commits

Author SHA1 Message Date
Mike McQuaid
41bf51e211
brew.sh: avoid shelling out when possible. 2024-05-14 15:46:33 +09:00
Mike McQuaid
2b363b904c
brew.sh: cache HOMEBREW_VERSION on disk.
This is a (relatively, for this Bash script) expensive operation that
can be trivially cached so: let's do so.

Speedup on my machine:

```
$ hyperfine "brew --version" "HOMEBREW_VERSION_CACHE=1 brew --version"
Benchmark 1: brew --version
  Time (mean ± σ):     173.4 ms ±   5.1 ms    [User: 28.7 ms, System: 67.0 ms]
  Range (min … max):   167.3 ms … 182.9 ms    15 runs

Benchmark 2: HOMEBREW_VERSION_CACHE=1 brew --version
  Time (mean ± σ):     145.9 ms ±   4.0 ms    [User: 22.4 ms, System: 33.9 ms]
  Range (min … max):   140.0 ms … 154.5 ms    17 runs

Summary
  HOMEBREW_VERSION_CACHE=1 brew --version ran
    1.19 ± 0.05 times faster than brew --version
```

Co-authored-by: Bo Anderson <mail@boanderson.me>
2024-05-14 15:46:32 +09:00
Mike McQuaid
7a61b03e72
brew.sh: shift -v to the end of the parameter list earlier.
Fixes #17240
2024-05-07 08:57:57 +01:00
Mike McQuaid
b5b37d8c80
Merge pull request #17204 from Homebrew/ruby_scripts_to_utils_files
Library/Homebrew: move stdin ruby scripts to files under `utils`.
2024-05-02 10:44:00 +01:00
Mike McQuaid
bc0f5ee62a
Library/Homebrew: move stdin ruby scripts to files under utils.
This avoids can avoid UID/EUID related issues with Ruby scripts passed
over `stdin` clashing with Ruby security features.

It's also just a bit nicer to have Ruby scripts in files instead.

While we're here:
- refactor some shared logic into a new `setup-gem-home-bundle-gemfile`
  function in `ruby.sh`
- do some general cleanup of `lock.sh`
- prioritise `flock` over `python` in `lock.sh`
2024-05-02 10:33:42 +01:00
Markus Reiter
caf87c0336
Warn about undocumented non-private APIs. 2024-05-01 11:35:20 +02:00
Mike McQuaid
de8266b4bc
brew.sh: fix argument handling for a few commands.
These need moved to the later `case` because they optionally take
arguments.
2024-04-30 16:58:11 +01:00
Mike McQuaid
97ad3567d1
Optimise more command handling/speed
- in `brew.sh` split the `case` into those cases that take a single or
  no arguments and those that take multiple arguments or handle
  multiple commands. This considerably speeds up the
  `brew shellenv bash` case that wasn't being handled here before.
- add `setup-ruby` to the list of commands that can be called quickly
  by `brew.sh` without additional setup. This speeds up the
  `brew setup-ruby` no-op case by ~10x.
- add a parameter to `setup-ruby` to avoid running Bundler if the
  command doesn't need it. This makes many more cases for
  `brew setup-ruby` to be no-op cases.
- Remove the (now) unused `HOMEBREW_RUBY3` check in `setup-ruby`.
- Improve argument handling in `command_path.sh` to allow it to be
  used as a function in `setup-ruby.sh`.
- Add a new RuboCop to check usage of `install_bundler_gems!` is only
  inside `dev-cmd` (or a few other acceptable places).
- Use new `processed_source.file_path` API in `formula_cop.rb`
2024-04-30 12:48:29 +01:00
Mike McQuaid
4ffcd8a110
Various improvements for brew command
- Add a (large) speedup by moving some logic to Bash for the typical
  case of a normal or dev-cmd, Bash or Ruby command.
- Make `brew command` a non-developer command, I don't think it makes
  sense to consider it something needed for developing Homebrew.
- Update the manpage/tests/RBI accordingly.

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
2024-04-30 11:38:19 +01:00
Mike McQuaid
ef49b5a537
brew.sh: auto-update 3rd-party taps more often.
When doing an `install`, `outdated` or `upgrade` and referring to a
formula or cask in a specific tap: you probably want to get the latest
version of that formula/cask more often than the default 1 or 24 hours.

Let's check for arguments for these commands that look appropriate and
auto-update every 5 minutes in that case.
2024-04-29 17:42:51 +01:00
Bo Anderson
636d883008
Support bash in privileged mode 2024-03-27 04:40:44 +00:00
Bo Anderson
7921e8a67d
brew.sh: fix autoupdate not working correctly for bump commands 2024-03-14 03:47:01 +00:00
Mike McQuaid
9ac31827a0
Various brew update behaviour improvements
- Output a message every time auto-update is run rather than a 3 second
  timer. This makes it more obvious that Homebrew isn't just sitting
  doing nothing for 2.9 seconds.
- Output a message when running `brew update` so Homebrew doesn't just
  sit there silently doing nothing.
- Update all taps when `brew update` is run, not just those hosted on
  GitHub. This makes it more obvious that people don't need to explictly
  run `brew update` "just in case".
- As a result of this, remove `brew tap --force-auto-update` as it's no
  longer necessary.
2024-03-08 16:21:09 +00:00
Bo Anderson
58874de60b
Generalise internal cross-image handling 2024-02-22 17:25:20 +00:00
Mike McQuaid
f404aafe56
brew: clarify which user needs to be able to read the working directory.
Otherwise, in multi-user environments, it can be ambiguous.
2024-01-11 12:24:04 +00:00
Mike McQuaid
abc1d14807
Improve working directory error messages
- Check for directory existing and directory being readable separately
  and print appropriate messages for each
- Make error messages more consistent
2024-01-10 17:21:57 +00:00
Bo Anderson
89531e9ff3
Update all dependencies 2023-12-15 16:24:46 +00:00
Bo Anderson
688d87e839
Remove Ruby 2.6 & macOS system Ruby support code 2023-12-12 03:44:31 +00:00
Bo Anderson
987ebe3d6d
Require Ruby 3.1 2023-12-05 02:31:08 +00:00
Bo Anderson
e19c3e1f13
Unset HOMEBREW_RUBY3 after updates 2023-12-01 13:44:33 +00:00
Bo Anderson
d68e3e563e
Merge pull request #16268 from Bo98/ruby3-for-all
Enable Ruby 3 for all users
2023-11-30 14:27:59 +00:00
Mike McQuaid
e3d1996a43
brew.sh: bump unknown HOMEBREW_VERSION. 2023-11-30 11:44:10 +00:00
Bo Anderson
489879ff72
Enable Ruby 3 for all users 2023-11-29 15:30:17 +00:00
Bo Anderson
2658f4467f
brew.sh: always run test-bot under Ruby 3 2023-11-24 14:19:32 +00:00
Bo Anderson
6502524456
brew.sh: set HOMEBREW_RUBY3 earlier 2023-11-22 00:51:43 +00:00
Bo Anderson
559336c771
Enable Ruby 3 for HOMEBREW_DEVELOPER 2023-11-20 20:04:18 +00:00
Bo Anderson
386fd0548a
Support system Ruby 3 on Linux 2023-11-07 19:27:30 +00:00
apainintheneck
e1dda872c3 use XDG_CACHE_HOME on Linux
This variable was getting filtered out before so it wasn't possible
for us to use it as the default for HOMEBREW_DEFAULT_CACHE
and HOMEBREW_DEFAULT_LOGS.
2023-10-28 19:10:20 -07:00
Mike McQuaid
9ee15e02a3
workflows/pkg-installer: fix filename.
This intermediate state got missed during a previous refactoring PR.
2023-10-04 15:34:04 +01:00
Mike McQuaid
c95a26b917
Improve building Homebrew*.pkg
- split jobs into build/test/deploy
- test package on both macOS Intel and Apple Silicon
- cleanup some argument handling
- use `HOMEBREW_MACOS_OLDEST_SUPPORTED` naming to be consistent with
  `brew.sh`
- note in `brew.sh` that `Distribution.xml` also needs updated (and do
  so)
- various other little bits of style cleanup
2023-10-04 10:18:27 +01:00
Mike McQuaid
def7ab4103
brew.sh: improve/add comment for supported macOSs. 2023-10-02 16:41:51 +01:00
Francois-Xavier Coudert
c3a2c40aa8 Make Sonoma supported 2023-09-24 11:12:05 +02:00
Mike McQuaid
8775465872
Enable Sorbet after running a developer command
We have no commands with Sorbet disabled and have had Sorbet enabled
for developers for a decent amount of time. As a result, we can enable
it for everyone who has run a developer command.

This also allows a bunch of `raise TypeError`s to be removed in favour
of relying on Sorbet here instead.
2023-09-02 08:39:28 -04:00
Branch Vincent
a75568147e
brew.sh: disable shellcheck warning 2023-08-26 12:48:30 +01:00
Mike McQuaid
6335728b61
brew.sh: fix shellcheck warning.
Fixes #15876.
2023-08-16 12:01:25 +01:00
Mike McQuaid
1481eac57c
brew.sh: don't set HOMEBREW_NO_INSTALL_FROM_API automatically.
My understanding is that now https://github.com/Homebrew/brew/pull/15778
has been merged this should now work fine on both older macOS versions
and non-default prefixes so let's try this again.
2023-08-15 11:42:02 +01:00
Mike McQuaid
389bcf4eb4
Merge pull request #15781 from MikeMcQuaid/post_install_improvements_fixes
post_install: improvements and fixes.
2023-07-28 12:06:05 +01:00
Mike McQuaid
7801878c74
post_install: improvements and fixes.
- warn if running `brew postinstall` explicitly and there's no
  `post_install` defined in the formula
- add a `post_install` alias for `brew postinstall` to make life
  easier for those jumping between `postinstall` and `post_install` in
  e.g. Homebrew development
- refactor `post_install` formula path logic into a new method for
  improved readability
- handle the JSON API `post_install` formula path case
2023-07-28 11:26:09 +01:00
Mike McQuaid
2c300cfbe9
brew update core/homebrew-cask taps properly
The existing logic in `update.sh` was both a bit hard to follow and
had some edge cases. Fix this up for improving #15775.
2023-07-28 10:13:57 +01:00
Mike McQuaid
21d8f82056
Add/use HOMEBREW_INSTALL_FROM_API_UNSUPPORTED
When we're automatically setting `HOMEBREW_NO_INSTALL_FROM_API`
when on an old macOS version or with a non-default prefix (e.g. cases
where you're going to be mostly building from source).

My initial plan was to set
`HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API` in these cases but
it's used differently enough it made sense to add another internal
variable instead: `HOMEBREW_INSTALL_FROM_API_UNSUPPORTED`.

At the moment this is only used to avoid printing the "You have set
`HOMEBREW_NO_INSTALL_FROM_API`" message inside `brew update` but may
make sense to use in other places over time.

Ideally, we'll get rid of these automatic sets of
`HOMEBREW_NO_INSTALL_FROM_API` and perhaps even the variable entirely.
2023-07-27 12:36:54 +01:00
Carlo Cabrera
e576fe0062
Revert "brew.sh: don't set HOMEBREW_NO_INSTALL_FROM_API automatically."
https://github.com/Homebrew/brew/pull/15765#issuecomment-1652856355

This reverts commit d9bc51f8171b49486a871a8bb12a2629df28a519.
2023-07-27 11:35:37 +08:00
Mike McQuaid
d9bc51f817
brew.sh: don't set HOMEBREW_NO_INSTALL_FROM_API automatically.
My understanding from conversations with Bo98 is that this should now
work fine on both older macOS versions and non-default prefixes.

Similarly, it's super confusing when this is set automatically and you
can't figure out why...
2023-07-26 15:36:04 +01:00
Mike McQuaid
cf65176853
Update Library/Homebrew/brew.sh 2023-07-21 11:46:04 +01:00
Mike McQuaid
0ae98a8a09
Enable HOMEBREW_SORBET_RUNTIME (sometimes)
Reverts #15385 with some tweaks.
2023-07-18 13:17:54 +01:00
Michka Popoff
518fb43112
Merge pull request #15656 from osalbahr/silverbrew
Feature: support symlinked /home
2023-07-15 13:45:07 +02:00
Sean Molenaar
7f55ee4494
Update Library/Homebrew/brew.sh 2023-07-12 10:59:57 +02:00
Sean Molenaar
ac78a4b512
Update Library/Homebrew/brew.sh 2023-07-12 10:55:52 +02:00
Sean Molenaar
2b83895d73
brew.sh: record OS version for non-debian linux 2023-07-12 10:51:25 +02:00
Osama Albahrani
64b6479100 brew.sh: fix HOMEBREW_PREFIX if /home is a symlink
Correct `HOMEBREW_PREFIX`, and its only dependent up to that point, `HOMEBREW_REPOSITORY`, if the defaults contain symlinks. For example:
```console
$ realpath /home/linuxbrew/.linuxbrew
/var/home/linuxbrew/.linuxbrew
$ ls -ld /home
lrwxrwxrwx. 4 root root 8 Jun 29 22:29 /home -> var/home
```
I was hoping to correct `HOMEBREW_PREFIX` from the start (in `bin/brew`), but the default prefixes are in `brew.sh`. See #15656 for a discussion on this middleground solution.

Co-Authored-By: rohanssrao <17805516+rohanssrao@users.noreply.github.com>
Co-Authored-By: Bo Anderson <mail@boanderson.me>
2023-07-09 18:33:31 -04:00
Osama Albahrani
287a359a74 brew.sh: set HOMEBREW_CELLAR after default prefix
Fixes #14557. This allows correcting the prefix variables first. See #15656.

Co-Authored-By: rohanssrao <17805516+rohanssrao@users.noreply.github.com>
2023-07-09 18:33:04 -04:00