29 Commits

Author SHA1 Message Date
Issy Long
45978435e7
rubocop: Use Sorbet/StrictSigil as it's better than comments
- Previously I thought that comments were fine to discourage people from
  wasting their time trying to bump things that used `undef` that Sorbet
  didn't support. But RuboCop is better at this since it'll complain if
  the comments are unnecessary.

- Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501.

- I've gone for a mixture of `rubocop:disable` for the files that can't
  be `typed: strict` (use of undef, required before everything else, etc)
  and `rubocop:todo` for everything else that should be tried to make
  strictly typed. There's no functional difference between the two as
  `rubocop:todo` is `rubocop:disable` with a different name.

- And I entirely disabled the cop for the docs/ directory since
  `typed: strict` isn't going to gain us anything for some Markdown
  linting config files.

- This means that now it's easier to track what needs to be done rather
  than relying on checklists of files in our big Sorbet issue:

```shell
$ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l
    268
```

- And this is confirmed working for new files:

```shell
$ git status
On branch use-rubocop-for-sorbet-strict-sigils
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        Library/Homebrew/bad.rb
        Library/Homebrew/good.rb

nothing added to commit but untracked files present (use "git add" to track)

$ brew style
Offenses:

bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true.
^^^^^^^^^^^^^

1340 files inspected, 1 offense detected
```
2024-08-12 15:24:27 +01:00
Ryan Rotter
e8c71646c1 description cache invalid if updated w/o EVAL_ALL
When updating description cache, if eval_all not set, clear cache rather
than leaving it out of date.

This fixes an issue where, if a user sets `--eval-all` on the command
line to run description searches, but HOMEBREW_EVAL_ALL isn't set in the
environment the cache is never updated.
2024-07-01 15:18:28 -04:00
EricFromCanada
216a045b36
rubydoc: fixes for output 2022-11-11 16:16:54 -05:00
Mike McQuaid
4c1b2630dc
Fix sorbet errors. 2020-12-28 13:34:07 +00:00
EricFromCanada
3768b7a6e9 apidoc: update comment wording, punctuation, formatting 2020-11-06 00:21:02 -05:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Mike McQuaid
3d436d3664 Improve linkage cache linkage_cache_performance
- Use reference counting so nested `CacheStoreDatabase.use` share the
  same underlying database (rather than rereading it every time).
- Only write out the cache database file when it has changed.
- Cleanup cache database entries on formula or full `brew cleanup`.

Fixes #8690
2020-09-11 12:57:15 +01:00
Mike McQuaid
36dbad3922
Add frozen_string_literal to all files. 2019-04-20 13:27:36 +09:00
Mike McQuaid
e095da4d01
rubocop: enable Layout/EmptyLineAfterGuardClause. 2019-02-21 12:55:49 +00:00
EricFromCanada
20167e5f1b Adjust comments to tidy API docs output. 2018-10-18 21:42:43 -04:00
Markus Reiter
afb75a67b1 Ensure cache directory for CacheStoreDatabase exists. 2018-10-16 11:16:17 +02:00
Mike McQuaid
fe6b78a3f3
Use cache_store for descriptions
This makes use of both the existing interfaces and could use the
existing cache file but we'll create a new one and cleanup the old one
to avoid issues and use a more consistent name.
2018-10-13 08:22:52 -07:00
Mike McQuaid
8b5f64881c
cache_store: use JSON.
After all our recent troubles with DBM I figured I'd benchmark the
performance of DBM vs. JSON. At read time (what we care more about) the
performance is pretty much identical and JSON is only 1.5x slower at
write time. This seems worth it for the reliability increases to avoid
messing with unreliable native code.
2018-09-25 21:07:01 +01:00
Mike McQuaid
5506dc22bd
cache_store: check DBM values size.
This seems to reproduce more crashes (and therefore avoid them).
2018-09-25 19:59:12 +01:00
Mike McQuaid
9a4b54f85d
Remove dbm_test_read analytics.
This can now be removed because my paranoia was unjustified and it's
successful 99.93% of the time.
2018-09-25 09:56:13 +01:00
Mike McQuaid
752714b71c
cache_store: add dbm_test_read analytics. 2018-09-21 14:14:51 +01:00
Mike McQuaid
7eb4b92d30
cache_store: handle missing process.
If we try to kill the process but it's already dead just ignore it.
2018-09-21 14:09:57 +01:00
Mike McQuaid
a11fe57cd2
cache_store: handle corrupt DBM database.
When the DBM database cannot be read by the current version of Ruby's
DBM library (due to corruption or another incompatibility) it segfaults
or freezes which takes down the entire Homebrew Ruby process.

This isn't desirable so instead perform a shell out with the Homebrew
Ruby to see if it can read the DBM database before we try to use the
information. If this hangs or crashes: silently delete the database and
recreate it.
2018-09-20 10:57:27 +01:00
Markus Reiter
e9b9ea49a1 Update to RuboCop 0.59.1. 2018-09-17 03:45:59 +02:00
Mike McQuaid
512073ad38 cache_store: create HOMEBREW_CACHE when needed.
Fixes #4366.
2018-06-21 13:59:07 +01:00
Mike McQuaid
44f5d3ec79 Refactor cache store code. 2018-05-22 14:46:14 +01:00
Andrew R. McBurney
360a301503 Fix file path issue caused by dbm implicitly appending .db to end of file path provided. 2018-05-21 12:27:53 -04:00
Andrew R. McBurney
e93e8f3266 Lazily load db of type DBM instance variable for DatabaseCache so the corresponding database file isn't created in the .use block for a DatabaseCache. 2018-05-18 16:37:01 -04:00
Andrew R. McBurney
cd6f89ca76 Made DatabaseCache.new private, and changes instances in code that call it to use DatabaseCache.use instead. 2018-05-18 10:06:30 -04:00
Andrew R. McBurney
ddd2ec05d8 Added static use method for DatabaseCache. 2018-05-17 16:56:59 -04:00
Andrew R. McBurney
17f484b0ae Set the return_value from the initialize block in the DatabaseCache. 2018-05-15 13:15:30 -04:00
AndrewMcBurney
2c7ae2544b Updated documentation for cache_store. 2018-03-06 13:39:34 -05:00
AndrewMcBurney
c5a6724c5c WIP 2018-03-06 11:42:45 -05:00
AndrewMcBurney
d7765dd223 Separated os/mac/cache_store.rb into cache_store.rb and os/mac/linkage_cache_store.rb. 2018-02-28 10:39:15 -05:00