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

Explicitly mark non-private APIs. #17128

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ jobs:
- name: Check RuboCop filepaths
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}/Library/Homebrew
run: |
public_apis=$(git grep -l "@api public" -- :^sorbet/ :^vendor/ | wc -l | tr -d ' ')
rubocop_docs=$(yq '.Style/Documentation.Include' .rubocop.yml | wc -l | tr -d ' ')
if [[ public_apis -ne rubocop_docs ]]
then
echo "All public Homebrew APIs should be included in the Style/Documentation RuboCop."
echo "There were ${public_apis} '@api public' lines but ${rubocop_docs} filepaths for the 'Style/Documentation' RuboCop."
echo "Add or remove the filepaths from Library/Homebrew/.rubocop.yml as appropriate."
public_apis="$(git grep -l "@api public" -- :^sorbet/ :^vendor/ | sort)"
rubocop_docs="$(yq '.Style/Documentation.Include[]' .rubocop.yml | sort)"

if [[ "${public_apis}" != "${rubocop_docs}" ]]; then
echo "All public Homebrew APIs should be included in the \`Style/Documentation\` RuboCop."
echo "Add/remove the following paths from \`Library/Homebrew/.rubocop.yml\` as appropriate:"
echo "${public_apis} ${rubocop_docs}" | tr ' ' '\n' | sort | uniq -u

exit 1
fi

Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Style/Documentation:
- utils/shebang.rb
- utils/string_inreplace_extension.rb
- version.rb
- tap.rb

Style/DocumentationMethod:
Include:
Expand Down
32 changes: 27 additions & 5 deletions Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ class Cask
extend APIHashable
include Metadata

attr_reader :token, :sourcefile_path, :source, :config, :default_config, :loader
# The token of this {Cask}.
#
# @api internal
attr_reader :token

# The configuration of this {Cask}.
#
# @api internal
attr_reader :config

attr_reader :sourcefile_path, :source, :default_config, :loader
attr_accessor :download, :allow_reassignment

attr_predicate :loaded_from_api?
Expand Down Expand Up @@ -124,13 +134,21 @@ def timestamped_versions(caskroom_path: self.caskroom_path)
.map { |p| p.split.map(&:to_s) }
end

def full_name
# The fully-qualified token of this {Cask}.
#
# @api internal
def full_token
return token if tap.nil?
return token if tap.core_cask_tap?

"#{tap.name}/#{token}"
end

# Alias for {#full_token}.
#
# @api internal
def full_name = full_token

sig { returns(T::Boolean) }
def installed?
installed_caskfile&.exist? || false
Expand Down Expand Up @@ -226,6 +244,9 @@ def caskroom_path
@caskroom_path ||= Caskroom.path.join(token)
end

# Check if the installed cask is outdated.
#
# @api internal
def outdated?(greedy: false, greedy_latest: false, greedy_auto_updates: false)
!outdated_version(greedy:, greedy_latest:,
greedy_auto_updates:).nil?
Expand Down Expand Up @@ -304,9 +325,10 @@ def populate_from_api!(json_cask)
@ruby_source_checksum = { sha256: ruby_source_sha256 }
end

def to_s
@token
end
# Alias for {#token}.
#
# @api internal
def to_s = token

def inspect
"#<Cask #{token}#{sourcefile_path&.to_s&.prepend(" ")}>"
Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/cask/caskroom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Cask
# Helper functions for interacting with the `Caskroom` directory.
#
# @api private
# @api internal
module Caskroom
sig { returns(Pathname) }
def self.path
Expand Down Expand Up @@ -50,6 +50,9 @@ def self.ensure_caskroom_exists
SystemCommand.run("/usr/bin/chgrp", args: ["admin", path], sudo:)
end

# Get all installed casks.
#
# @api internal
sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) }
def self.casks(config: nil)
tokens.sort.filter_map do |token|
Expand Down
10 changes: 9 additions & 1 deletion Library/Homebrew/cask/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
module Cask
# Configuration for installing casks.
#
# @api private
# @api internal
class Config
DEFAULT_DIRS = {
appdir: "/Applications",
Expand Down Expand Up @@ -88,6 +88,9 @@ def self.canonicalize(config)
end
end

# Get the explicit configuration.
#
# @api internal
sig { returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) }
attr_accessor :explicit

Expand Down Expand Up @@ -184,6 +187,11 @@ def merge(other)
self.class.new(explicit: other.explicit.merge(explicit))
end

# Get explicit configuration as a string.
#
# @api internal
#
# TODO: This is only used by `homebrew/bundle`, so move it there.
sig { returns(String) }
def explicit_s
explicit.map do |key, value|
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/development_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def llvm_clang_build_version
end
end

# Get the GCC version.
#
# @api internal
sig { params(cc: String).returns(Version) }
def gcc_version(cc)
(@gcc_version ||= {}).fetch(cc) do
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Homebrew
# Helper module for querying Homebrew-specific environment variables.
#
# @api private
# @api internal
module EnvConfig
module_function

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require "utils"

# Raised when a command is used wrong.
#
# @api internal
class UsageError < RuntimeError
attr_reader :reason

Expand Down Expand Up @@ -133,6 +135,8 @@ def to_s
end

# Raised when a formula is not available.
#
# @api internal
class FormulaUnavailableError < FormulaOrCaskUnavailableError
attr_accessor :dependent

Expand Down
18 changes: 16 additions & 2 deletions Library/Homebrew/extend/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,42 @@ def oh1(title, truncate: :auto)
puts oh1_title(title, truncate:)
end

# Print a message prefixed with "Warning" (do this rarely).
# Print a warning message.
#
# @api public
def opoo(message)
Tty.with($stderr) do |stderr|
stderr.puts Formatter.warning(message, label: "Warning")
end
end

# Print a message prefixed with "Error".
# Print an error message.
#
# @api public
def onoe(message)
Tty.with($stderr) do |stderr|
stderr.puts Formatter.error(message, label: "Error")
end
end

# Print an error message and fail at the end of the program.
#
# @api public
def ofail(error)
onoe error
Homebrew.failed = true
end

# Print an error message and fail immediately.
#
# @api public
sig { params(error: T.any(String, Exception)).returns(T.noreturn) }
def odie(error)
onoe error
exit 1
end

# Output a deprecation warning/error message.
def odeprecated(method, replacement = nil,
disable: false,
disable_on: nil,
Expand Down Expand Up @@ -254,6 +265,9 @@ def quiet_system(cmd, *args)
end
end

# Find a command.
#
# @api public
def which(cmd, path = ENV.fetch("PATH"))
PATH.new(path).each do |p|
begin
Expand Down