Module: Homebrew
- Extended by:
- Context, DependenciesHelpers, FileUtils, Fetch, Install, Search
- Defined in:
- Library/Homebrew/fetch.rb,
Library/Homebrew/help.rb,
Library/Homebrew/style.rb,
Library/Homebrew/utils.rb,
Library/Homebrew/global.rb,
Library/Homebrew/search.rb,
Library/Homebrew/unlink.rb,
Library/Homebrew/cleanup.rb,
Library/Homebrew/cmd/log.rb,
Library/Homebrew/cmd/pin.rb,
Library/Homebrew/cmd/tap.rb,
Library/Homebrew/install.rb,
Library/Homebrew/upgrade.rb,
Library/Homebrew/cli/args.rb,
Library/Homebrew/cmd/cask.rb,
Library/Homebrew/cmd/deps.rb,
Library/Homebrew/cmd/desc.rb,
Library/Homebrew/cmd/help.rb,
Library/Homebrew/cmd/home.rb,
Library/Homebrew/cmd/info.rb,
Library/Homebrew/cmd/link.rb,
Library/Homebrew/cmd/list.rb,
Library/Homebrew/cmd/uses.rb,
Library/Homebrew/cmd/--env.rb,
Library/Homebrew/cmd/fetch.rb,
Library/Homebrew/cmd/unpin.rb,
Library/Homebrew/cmd/untap.rb,
Library/Homebrew/reinstall.rb,
Library/Homebrew/cli/parser.rb,
Library/Homebrew/cmd/config.rb,
Library/Homebrew/cmd/doctor.rb,
Library/Homebrew/cmd/leaves.rb,
Library/Homebrew/cmd/search.rb,
Library/Homebrew/cmd/switch.rb,
Library/Homebrew/cmd/unlink.rb,
Library/Homebrew/dev-cmd/sh.rb,
Library/Homebrew/diagnostic.rb,
Library/Homebrew/env_config.rb,
Library/Homebrew/utils/gems.rb,
Library/Homebrew/cmd/--cache.rb,
Library/Homebrew/cmd/cleanup.rb,
Library/Homebrew/cmd/install.rb,
Library/Homebrew/cmd/migrate.rb,
Library/Homebrew/cmd/missing.rb,
Library/Homebrew/cmd/options.rb,
Library/Homebrew/cmd/readall.rb,
Library/Homebrew/cmd/upgrade.rb,
Library/Homebrew/dev-cmd/cat.rb,
Library/Homebrew/dev-cmd/diy.rb,
Library/Homebrew/dev-cmd/irb.rb,
Library/Homebrew/dev-cmd/man.rb,
Library/Homebrew/cmd/--cellar.rb,
Library/Homebrew/cmd/--prefix.rb,
Library/Homebrew/cmd/commands.rb,
Library/Homebrew/cmd/outdated.rb,
Library/Homebrew/cmd/tap-info.rb,
Library/Homebrew/dev-cmd/bump.rb,
Library/Homebrew/dev-cmd/edit.rb,
Library/Homebrew/dev-cmd/prof.rb,
Library/Homebrew/dev-cmd/pull.rb,
Library/Homebrew/dev-cmd/ruby.rb,
Library/Homebrew/dev-cmd/test.rb,
Library/Homebrew/cmd/--version.rb,
Library/Homebrew/cmd/analytics.rb,
Library/Homebrew/cmd/gist-logs.rb,
Library/Homebrew/cmd/reinstall.rb,
Library/Homebrew/cmd/uninstall.rb,
Library/Homebrew/dev-cmd/audit.rb,
Library/Homebrew/dev-cmd/style.rb,
Library/Homebrew/dev-cmd/tests.rb,
Library/Homebrew/cli/named_args.rb,
Library/Homebrew/cmd/--caskroom.rb,
Library/Homebrew/dev-cmd/bottle.rb,
Library/Homebrew/dev-cmd/create.rb,
Library/Homebrew/dev-cmd/mirror.rb,
Library/Homebrew/dev-cmd/unpack.rb,
Library/Homebrew/cmd/postinstall.rb,
Library/Homebrew/dev-cmd/command.rb,
Library/Homebrew/dev-cmd/extract.rb,
Library/Homebrew/dev-cmd/formula.rb,
Library/Homebrew/dev-cmd/linkage.rb,
Library/Homebrew/dev-cmd/pr-pull.rb,
Library/Homebrew/dev-cmd/tap-new.rb,
Library/Homebrew/formula_creator.rb,
Library/Homebrew/missing_formula.rb,
Library/Homebrew/os/linux/global.rb,
Library/Homebrew/cmd/--repository.rb,
Library/Homebrew/dev-cmd/sponsors.rb,
Library/Homebrew/cmd/update-report.rb,
Library/Homebrew/dev-cmd/livecheck.rb,
Library/Homebrew/dev-cmd/pr-upload.rb,
Library/Homebrew/dev-cmd/typecheck.rb,
Library/Homebrew/formula_free_port.rb,
Library/Homebrew/dev-cmd/pr-publish.rb,
Library/Homebrew/formula_assertions.rb,
Library/Homebrew/livecheck/strategy.rb,
Library/Homebrew/dev-cmd/update-test.rb,
Library/Homebrew/dev-cmd/vendor-gems.rb,
Library/Homebrew/livecheck/livecheck.rb,
Library/Homebrew/dev-cmd/bump-cask-pr.rb,
Library/Homebrew/dev-cmd/pr-automerge.rb,
Library/Homebrew/extend/os/mac/search.rb,
Library/Homebrew/dev-cmd/bump-revision.rb,
Library/Homebrew/dev-cmd/release-notes.rb,
Library/Homebrew/livecheck/strategy/git.rb,
Library/Homebrew/livecheck/strategy/gnu.rb,
Library/Homebrew/livecheck/strategy/npm.rb,
Library/Homebrew/dev-cmd/bump-formula-pr.rb,
Library/Homebrew/extend/os/linux/install.rb,
Library/Homebrew/livecheck/strategy/pypi.rb,
Library/Homebrew/livecheck/strategy/xorg.rb,
Library/Homebrew/extend/os/mac/diagnostic.rb,
Library/Homebrew/livecheck/strategy/gnome.rb,
Library/Homebrew/livecheck/strategy/apache.rb,
Library/Homebrew/extend/os/linux/diagnostic.rb,
Library/Homebrew/livecheck/strategy/hackage.rb,
Library/Homebrew/dev-cmd/update-license-data.rb,
Library/Homebrew/dev-cmd/install-bundler-gems.rb,
Library/Homebrew/livecheck/strategy/bitbucket.rb,
Library/Homebrew/livecheck/strategy/launchpad.rb,
Library/Homebrew/dev-cmd/dispatch-build-bottle.rb,
Library/Homebrew/extend/os/mac/missing_formula.rb,
Library/Homebrew/livecheck/strategy/page_match.rb,
Library/Homebrew/livecheck/strategy/sourceforge.rb,
Library/Homebrew/dev-cmd/update-python-resources.rb
Overview
typed: false frozen_string_literal: true
Defined Under Namespace
Modules: Assertions, CLI, Diagnostic, EnvConfig, Fetch, FreePort, Help, Install, Livecheck, MissingFormula, Search, Style, Unlink, Upgrade Classes: Cleanup, DependentsMessage, DeveloperDependentsMessage, FormulaAuditor, FormulaCreator, FormulaText, NondeveloperDependentsMessage, ResourceAuditor
Constant Summary collapse
- DEFAULT_CELLAR =
"#{DEFAULT_PREFIX}/Cellar"
- DEFAULT_REPOSITORY =
"#{DEFAULT_PREFIX}/Homebrew"
- VALID_DAYS =
%w[30 90 365].freeze
- VALID_FORMULA_CATEGORIES =
%w[install install-on-request build-error].freeze
- VALID_CATEGORIES =
(VALID_FORMULA_CATEGORIES + %w[cask-install os-version]).freeze
- UNBREWED_EXCLUDE_FILES =
%w[.DS_Store].freeze
- UNBREWED_EXCLUDE_PATHS =
%w[ */.keepme .github/* bin/brew completions/zsh/_brew docs/* lib/gdk-pixbuf-2.0/* lib/gio/* lib/node_modules/* lib/python[23].[0-9]/* lib/pypy/* lib/pypy3/* lib/ruby/gems/[12].* lib/ruby/site_ruby/[12].* lib/ruby/vendor_ruby/[12].* manpages/brew.1 share/pypy/* share/pypy3/* share/info/dir share/man/whatis ].freeze
- PACKAGE_MANAGERS =
{ macports: ->(query) { "https://www.macports.org/ports.php?by=name&substr=#{query}" }, fink: ->(query) { "https://pdb.finkproject.org/pdb/browse.php?summary=#{query}" }, opensuse: ->(query) { "https://software.opensuse.org/search?q=#{query}" }, fedora: ->(query) { "https://apps.fedoraproject.org/packages/s/#{query}" }, debian: lambda { |query| "https://packages.debian.org/search?keywords=#{query}&searchon=names&suite=all§ion=all" }, ubuntu: lambda { |query| "https://packages.ubuntu.com/search?keywords=#{query}&searchon=names&suite=all§ion=all" }, }.freeze
- HOMEBREW_BUNDLER_VERSION =
Keep in sync with the
Gemfile.lock
's BUNDLED WITH. "1.17.3"
- SOURCE_PATH =
(HOMEBREW_LIBRARY_PATH/"manpages").freeze
- TARGET_MAN_PATH =
(HOMEBREW_REPOSITORY/"manpages").freeze
- TARGET_DOC_PATH =
(HOMEBREW_REPOSITORY/"docs").freeze
- WATCHLIST_PATH =
( ENV["HOMEBREW_LIVECHECK_WATCHLIST"] || "#{Dir.home}/.brew_livecheck_watchlist" ).freeze
Class Attribute Summary collapse
- .args ⇒ Object
-
.auditing ⇒ Object
writeonly
Sets the attribute auditing.
-
.failed ⇒ Object
writeonly
Sets the attribute failed.
-
.raise_deprecation_exceptions ⇒ Object
writeonly
Sets the attribute raise_deprecation_exceptions.
Class Method Summary collapse
- .__cache ⇒ Object
- .__cache_args ⇒ Object
- .__caskroom ⇒ Object
- .__caskroom_args ⇒ Object
- .__cellar ⇒ Object
- .__cellar_args ⇒ Object
- .__env ⇒ Object
- .__env_args ⇒ Object
- .__gets ⇒ Object
- .__prefix ⇒ Object
- .__prefix_args ⇒ Object
- .__repository ⇒ Object
- .__repository_args ⇒ Object
- .__version ⇒ Object
- .__version_args ⇒ Object
- ._system(cmd, *args, **options) ⇒ Object
- .alias_update_pair(formula, new_formula_version) ⇒ Object
- .analytics ⇒ Object
- .analytics_args ⇒ Object
- .audit ⇒ Object
- .audit_args ⇒ Object
- .auditing? ⇒ Boolean
- .autosquash!(original_commit, path: ".", reason: "", verbose: false, resolve: false) ⇒ Object
- .backup(keg) ⇒ Object
- .backup_path(path) ⇒ Object
- .bottle ⇒ Object
- .bottle_args ⇒ Object
- .bottle_formula(f, args:) ⇒ Object
- .bottle_output(bottle) ⇒ Object
- .brief_build_info(f, with_hostname:) ⇒ Object
- .build_man_page(quiet:) ⇒ Object
- .bump ⇒ Object
- .bump_args ⇒ Object
- .bump_cask_pr ⇒ Object
- .bump_cask_pr_args ⇒ Object
- .bump_formula_pr ⇒ Object
- .bump_formula_pr_args ⇒ Object
- .bump_revision ⇒ Object
- .bump_revision_args ⇒ Object
- .cask ⇒ Object
- .cask_args ⇒ Object
- .cat ⇒ Object
- .cat_args ⇒ Object
- .changed_formulae(tap, original_commit) ⇒ Object
- .check_bottled_formulae(bottles_hash) ⇒ Object
- .check_closed_pull_requests(formula, tap_full_name, args:, version: nil, url: nil, tag: nil) ⇒ Object
- .check_for_dependents(kegs, named_args: []) ⇒ Object
- .check_for_mirrors(formula, old_mirrors, new_mirrors, args:) ⇒ Object
- .check_open_pull_requests(formula, tap_full_name, args:) ⇒ Object
- .cherry_pick_pr!(user, repo, pr, args:, path: ".") ⇒ Object
- .cleanup ⇒ Object
- .cleanup_args ⇒ Object
- .cmd_comment_manpage_lines(cmd_path) ⇒ Object
- .cmd_comment_options(cmd_path) ⇒ Object
- .cmd_parser_manpage_lines(cmd_parser) ⇒ Object
- .command ⇒ Object
- .command_args ⇒ Object
- .commands ⇒ Object
- .commands_args ⇒ Object
- .condense_requirements(deps, args:) ⇒ Object
- .config ⇒ Object
- .config_args ⇒ Object
- .convert_man_page(markup, target, preserve_date:) ⇒ Object
-
.create ⇒ Object
Create a formula from a tarball URL.
- .create_args ⇒ Object
- .create_gist(files, description, private:) ⇒ Object
- .create_issue(repo, title, body) ⇒ Object
- .decorate_dependencies(dependencies) ⇒ Object
- .decorate_requirements(requirements) ⇒ Object
- .default_prefix?(prefix = HOMEBREW_PREFIX) ⇒ Boolean
- .dep_display_name(dep, args:) ⇒ Object
- .dep_display_s(dep) ⇒ Object
- .deps ⇒ Object
- .deps_args ⇒ Object
- .deps_for_dependent(d, args:, recursive: false) ⇒ Object
- .deps_for_dependents(dependents, args:, recursive: false, &block) ⇒ Object
- .desc ⇒ Object
- .desc_args ⇒ Object
- .detect_name(path, version) ⇒ Object
- .detect_version(path) ⇒ Object
- .determine_bump_subject(old_contents, new_contents, formula_path, reason: nil) ⇒ Object
- .determine_formula_from_url(url) ⇒ Object
- .determine_mirror(url) ⇒ Object
- .dispatch_build_bottle ⇒ Object
- .dispatch_build_bottle_args ⇒ Object
- .display(formulae) ⇒ Object
- .diy ⇒ Object
- .diy_args ⇒ Object
- .doctor ⇒ Object
- .doctor_args ⇒ Object
- .download_artifact(url, dir, pr) ⇒ Object
- .edit ⇒ Object
- .edit_args ⇒ Object
- .ensure_relocation_formulae_installed! ⇒ Object
- .env_vars_manpage ⇒ Object
- .extract ⇒ Object
- .extract_args ⇒ Object
- .failed? ⇒ Boolean
- .fetch ⇒ Object
- .fetch_args ⇒ Object
- .fetch_fetchable(f, args:) ⇒ Object
- .fetch_formula(f, args:) ⇒ Object
- .fetch_patch(p, args:) ⇒ Object
- .fetch_resource(formula, new_version, url, **specs) ⇒ Object
- .filtered_list(args:) ⇒ Object
- .find_in_path(executable) ⇒ Object
- .force_auto_update?(args:) ⇒ Boolean
- .format_long_opt(opt) ⇒ Object
- .format_problem(message, location) ⇒ Object
- .format_problem_lines(problems) ⇒ Object
- .format_short_opt(opt) ⇒ Object
- .format_usage_banner(usage_banner) ⇒ Object
- .formula ⇒ Object
- .formula_args ⇒ Object
- .formula_version(formula, spec, contents = nil) ⇒ Object
- .formulae_need_bottles?(tap, original_commit, args:) ⇒ Boolean
- .gem_user_bindir ⇒ Object
- .generate_cmd_manpages(cmd_paths) ⇒ Object
- .generate_option_doc(short, long, desc) ⇒ Object
- .gist_logs ⇒ Object
- .gist_logs_args ⇒ Object
- .gistify_logs(f, args:) ⇒ Object
- .git_log(cd_dir, path = nil, tap = nil, args:) ⇒ Object
- .github_info(f) ⇒ Object
- .github_releases?(bottles_hash) ⇒ Boolean
- .github_remote_path(remote, path) ⇒ Object
- .global_cask_options_manpage ⇒ Object
- .global_options_manpage ⇒ Object
- .handle_unsatisfied_dependents(kegs_by_rack, ignore_dependencies: false, named_args: []) ⇒ Object
- .home ⇒ Object
- .home_args ⇒ Object
- .info ⇒ Object
- .info_args ⇒ Object
- .info_cask(cask, args:) ⇒ Object
- .info_formula(f, args:) ⇒ Object
-
.inject_dump_stats!(the_module, pattern) ⇒ Object
rubocop:disable Style/GlobalVars.
- .install ⇒ Object
- .install_args ⇒ Object
- .install_bundler! ⇒ Object
- .install_bundler_gems ⇒ Object
- .install_bundler_gems! ⇒ Object
- .install_bundler_gems_args ⇒ Object
- .install_core_tap_if_necessary ⇒ Object
- .install_formula(f, args:) ⇒ Object
- .install_gem!(name, version: nil, setup_gem_environment: true) ⇒ Object
- .install_gem_setup_path!(name, version: nil, executable: name, setup_gem_environment: true) ⇒ Object
- .intersection_of_dependents(use_runtime_dependents, used_formulae, args:) ⇒ Object
- .irb ⇒ Object
- .irb_args ⇒ Object
- .json_info(formulae_or_casks, args:) ⇒ Object
- .json_version(version) ⇒ Object
- .keg_contain?(string, keg, ignores, formula_and_runtime_deps_names = nil, args:) ⇒ Boolean
- .keg_contain_absolute_symlink_starting_with?(string, keg, args:) ⇒ Boolean
- .leaves ⇒ Object
- .leaves_args ⇒ Object
- .link ⇒ Object
- .link_args ⇒ Object
- .link_completions_manpages_and_docs(repository = HOMEBREW_REPOSITORY) ⇒ Object
- .linkage ⇒ Object
- .linkage_args ⇒ Object
- .list ⇒ Object
- .list_args ⇒ Object
- .list_casks(args:) ⇒ Object
- .list_unbrewed ⇒ Object
- .livecheck ⇒ Object
- .livecheck_args ⇒ Object
- .load_logs(dir) ⇒ Object
- .log ⇒ Object
- .log_args ⇒ Object
- .login! ⇒ Object
- .man ⇒ Object
- .man_args ⇒ Object
- .merge(args:) ⇒ Object
- .messages ⇒ Object
- .migrate ⇒ Object
- .migrate_args ⇒ Object
- .mirror ⇒ Object
- .mirror_args ⇒ Object
- .mirror_formulae(tap, original_commit, org:, repo:, args:, publish: true) ⇒ Object
- .missing ⇒ Object
- .missing_args ⇒ Object
- .name_of(formula_or_cask) ⇒ Object
-
.noecho_gets ⇒ Object
Causes some terminals to display secure password entry indicators.
- .odie_if_defined(message) ⇒ Object
- .ohai_if_defined(message) ⇒ Object
- .options ⇒ Object
- .options_args ⇒ Object
- .outdated ⇒ Object
- .outdated_args ⇒ Object
- .outdated_casks(args:) ⇒ Object
- .outdated_formulae(args:) ⇒ Object
- .outdated_formulae_casks(args:) ⇒ Object
- .pin ⇒ Object
- .pin_args ⇒ Object
- .postinstall ⇒ Object
- .postinstall_args ⇒ Object
- .pr_automerge ⇒ Object
- .pr_automerge_args ⇒ Object
- .pr_publish ⇒ Object
- .pr_publish_args ⇒ Object
- .pr_pull ⇒ Object
- .pr_pull_args ⇒ Object
- .pr_upload ⇒ Object
- .pr_upload_args ⇒ Object
- .print_analytics(args:) ⇒ Object
- .print_cask_cache(cask) ⇒ Object
- .print_formula_cache(formula, args:) ⇒ Object
- .print_info(args:) ⇒ Object
- .print_json(args:) ⇒ Object
- .print_outdated(formulae_or_casks, args:) ⇒ Object
- .print_tap_info(taps) ⇒ Object
- .print_tap_json(taps) ⇒ Object
- .prof ⇒ Object
- .prof_args ⇒ Object
- .pull ⇒ Object
- .pull_args ⇒ Object
- .puts_deps(dependents, args:, recursive: false) ⇒ Object
- .puts_deps_tree(dependents, args:, recursive: false) ⇒ Object
- .puts_keg_only_path_message(keg) ⇒ Object
- .puts_options(formulae, args:) ⇒ Object
- .raise_deprecation_exceptions? ⇒ Boolean
- .readall ⇒ Object
- .readall_args ⇒ Object
- .recursive_deps_tree(f, prefix, recursive, args:) ⇒ Object
- .regenerate_man_pages(preserve_date:, quiet:) ⇒ Object
- .reinstall ⇒ Object
- .reinstall_args ⇒ Object
- .reinstall_formula(f, args:, build_from_source: false) ⇒ Object
- .release_notes ⇒ Object
- .release_notes_args ⇒ Object
- .restore_backup(keg, keg_was_linked, verbose:) ⇒ Object
- .retry_fetch?(f, args:) ⇒ Boolean
- .retry_test?(f, args:) ⇒ Boolean
-
.reword_formula_commit(commit, file, reason: "", verbose: false, resolve: false, path: ".") ⇒ Object
Cherry picks a single commit that modifies a single file.
- .rm_pin(rack) ⇒ Object
- .ruby ⇒ Object
- .ruby_args ⇒ Object
- .ruby_bindir ⇒ Object
- .run_audit(formula, alias_rename, old_contents, args:) ⇒ Object
- .run_cask_audit(cask, old_contents, args:) ⇒ Object
- .run_cask_style(cask, old_contents, args:) ⇒ Object
- .search ⇒ Object
- .search_args ⇒ Object
- .select_outdated(formulae_or_casks, args:) ⇒ Object
- .select_used_dependents(dependents, used_formulae, recursive, includes, ignores) ⇒ Object
-
.separate_commit_message(message) ⇒ Object
Separates a commit message into subject, body, and trailers.
- .setup_gem_environment!(gem_home: nil, gem_bindir: nil) ⇒ Object
- .sh ⇒ Object
- .sh_args ⇒ Object
- .shorten_revision(revision) ⇒ Object
- .signoff!(path, pr: nil, dry_run: false) ⇒ Object
- .sort_key_for_path(path) ⇒ Object
- .sorted_dependents(formulae_or_casks) ⇒ Object
- .sponsors ⇒ Object
- .sponsors_args ⇒ Object
-
.squash_formula_commits(commits, file, reason: "", verbose: false, resolve: false, path: ".") ⇒ Object
Cherry picks multiple commits that each modify a single file.
- .style ⇒ Object
- .style_args ⇒ Object
- .sudo_purge ⇒ Object
- .switch ⇒ Object
- .switch_args ⇒ Object
- .system(cmd, *args, **options) ⇒ Object
- .tap ⇒ Object
- .tap_args ⇒ Object
- .tap_info ⇒ Object
- .tap_info_args ⇒ Object
- .tap_new ⇒ Object
- .tap_new_args ⇒ Object
- .target_path_to_format(target) ⇒ Object
- .test ⇒ Object
- .test_args ⇒ Object
- .tests ⇒ Object
- .tests_args ⇒ Object
- .typecheck ⇒ Object
- .typecheck_args ⇒ Object
- .uninstall ⇒ Object
- .uninstall_args ⇒ Object
- .unlink ⇒ Object
- .unlink_args ⇒ Object
- .unpack ⇒ Object
- .unpack_args ⇒ Object
- .unpin ⇒ Object
- .unpin_args ⇒ Object
- .untap ⇒ Object
- .untap_args ⇒ Object
- .up_to_date?(package) ⇒ Boolean
- .update_license_data ⇒ Object
- .update_license_data_args ⇒ Object
- .update_preinstall_header(args:) ⇒ Object
- .update_python_resources ⇒ Object
- .update_python_resources_args ⇒ Object
- .update_report ⇒ Object
- .update_report_args ⇒ Object
- .update_test ⇒ Object
- .update_test_args ⇒ Object
- .upgrade ⇒ Object
- .upgrade_args ⇒ Object
- .upgrade_outdated_casks(casks, args:) ⇒ Object
- .upgrade_outdated_formulae(formulae, args:) ⇒ Object
- .use_correct_linux_tap(formula, args:) ⇒ Object
- .uses ⇒ Object
- .uses_args ⇒ Object
- .validate_formula(formula_name) ⇒ Object
- .vendor_gems ⇒ Object
- .vendor_gems_args ⇒ Object
- .verbose? ⇒ Boolean
- .write_path(tap, filename, content) ⇒ Object
Instance Method Summary collapse
Methods included from Install
generic_perform_preinstall_checks, perform_build_from_source_checks, perform_preinstall_checks
Methods included from Fetch
Methods included from Search
query_regexp, search_casks, search_descriptions, search_formulae, search_taps
Methods included from DependenciesHelpers
args_includes_ignores, dependents, recursive_includes, reject_ignores
Methods included from Context
current, current=, debug?, quiet?, with_context
Class Attribute Details
.args ⇒ Object
96 97 98 |
# File 'Library/Homebrew/global.rb', line 96 def args @args ||= CLI::Args.new end |
.auditing=(value) ⇒ Object (writeonly)
Sets the attribute auditing
85 86 87 |
# File 'Library/Homebrew/global.rb', line 85 def auditing=(value) @auditing = value end |
.failed=(value) ⇒ Object (writeonly)
Sets the attribute failed
85 86 87 |
# File 'Library/Homebrew/global.rb', line 85 def failed=(value) @failed = value end |
.raise_deprecation_exceptions=(value) ⇒ Object (writeonly)
Sets the attribute raise_deprecation_exceptions
85 86 87 |
# File 'Library/Homebrew/global.rb', line 85 def raise_deprecation_exceptions=(value) @raise_deprecation_exceptions = value end |
Class Method Details
.__cache ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'Library/Homebrew/cmd/--cache.rb', line 35 def __cache args = __cache_args.parse if args.no_named? puts HOMEBREW_CACHE return end formulae_or_casks = if args.formula? args.named.to_formulae elsif args.cask? args.named.to_casks else args.named.to_formulae_and_casks end formulae_or_casks.each do |formula_or_cask| if formula_or_cask.is_a? Formula print_formula_cache formula_or_cask, args: args else print_cask_cache formula_or_cask end end end |
.__cache_args ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'Library/Homebrew/cmd/--cache.rb', line 13 def __cache_args Homebrew::CLI::Parser.new do <<~EOS `--cache` [<options>] [<formula|cask>] Display Homebrew's download cache. See also `HOMEBREW_CACHE`. If <formula> is provided, display the file or directory used to cache <formula>. EOS switch "-s", "--build-from-source", description: "Show the cache file used when building from source." switch "--force-bottle", description: "Show the cache file used when pouring a bottle." switch "--formula", description: "Only show cache files for formulae." switch "--cask", description: "Only show cache files for casks." conflicts "--build-from-source", "--force-bottle" conflicts "--formula", "--cask" end end |
.__caskroom ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'Library/Homebrew/cmd/--caskroom.rb', line 20 def __caskroom args = __caskroom_args.parse if args.named.to_casks.blank? puts Cask::Caskroom.path else args.named.to_casks.each do |cask| puts "#{Cask::Caskroom.path}/#{cask.token}" end end end |
.__caskroom_args ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'Library/Homebrew/cmd/--caskroom.rb', line 7 def __caskroom_args Homebrew::CLI::Parser.new do <<~EOS `--caskroom` [<cask>] Display Homebrew's Caskroom path. If <cask> is provided, display the location in the Caskroom where <cask> would be installed, without any sort of versioned directory as the last path. EOS end end |
.__cellar ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'Library/Homebrew/cmd/--cellar.rb', line 23 def __cellar args = __cellar_args.parse if args.no_named? puts HOMEBREW_CELLAR else puts args.named.to_resolved_formulae.map(&:rack) end end |
.__cellar_args ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'Library/Homebrew/cmd/--cellar.rb', line 9 def __cellar_args Homebrew::CLI::Parser.new do <<~EOS `--cellar` [<formula>] Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if that directory doesn't exist, `$(brew --repository)/Cellar`. If <formula> is provided, display the location in the Cellar where <formula> would be installed, without any sort of versioned directory as the last path. EOS end end |
.__env ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'Library/Homebrew/cmd/--env.rb', line 30 def __env args = __env_args.parse ENV.activate_extensions!(env: args.env) ENV.deps = args.named.to_formulae if superenv?(args.env) ENV.setup_build_environment shell = if args.plain? nil elsif args.shell.nil? :bash unless $stdout.tty? elsif args.shell == "auto" Utils::Shell.parent || Utils::Shell.preferred elsif args.shell Utils::Shell.from_path(args.shell) end env_keys = BuildEnvironment.keys(ENV) if shell.nil? BuildEnvironment.dump ENV else env_keys.each do |key| puts Utils::Shell.export_value(key, ENV[key], shell) end end end |
.__env_args ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'Library/Homebrew/cmd/--env.rb', line 12 def __env_args Homebrew::CLI::Parser.new do <<~EOS `--env` [<options>] [<formula>] Summarise Homebrew's build environment as a plain list. If the command's output is sent through a pipe and no shell is specified, the list is formatted for export to `bash`(1) unless `--plain` is passed. EOS flag "--shell=", description: "Generate a list of environment variables for the specified shell, " \ "or `--shell=auto` to detect the current shell." switch "--plain", description: "Generate plain output even when piped." end end |
.__gets ⇒ Object
147 148 149 150 |
# File 'Library/Homebrew/dev-cmd/create.rb', line 147 def __gets gots = $stdin.gets.chomp gots.empty? ? nil : gots end |
.__prefix ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'Library/Homebrew/cmd/--prefix.rb', line 23 def __prefix args = __prefix_args.parse if args.no_named? puts HOMEBREW_PREFIX else puts args.named.to_resolved_formulae.map { |f| f.opt_prefix.exist? ? f.opt_prefix : f.latest_installed_prefix } end end |
.__prefix_args ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'Library/Homebrew/cmd/--prefix.rb', line 9 def __prefix_args Homebrew::CLI::Parser.new do <<~EOS `--prefix` [<formula>] Display Homebrew's install path. *Default:* `/usr/local` on macOS and `/home/linuxbrew/.linuxbrew` on Linux. If <formula> is provided, display the location in the Cellar where <formula> is or would be installed. EOS end end |
.__repository ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'Library/Homebrew/cmd/--repository.rb', line 21 def __repository args = __repository_args.parse if args.no_named? puts HOMEBREW_REPOSITORY else puts args.named.map { |tap| Tap.fetch(tap).path } end end |
.__repository_args ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'Library/Homebrew/cmd/--repository.rb', line 9 def __repository_args Homebrew::CLI::Parser.new do <<~EOS `--repository`, `--repo` [<user>`/`<repo>] Display where Homebrew's `.git` directory is located. If <user>`/`<repo> are provided, display where tap <user>`/`<repo>'s directory is located. EOS end end |
.__version ⇒ Object
21 22 23 24 25 26 27 |
# File 'Library/Homebrew/cmd/--version.rb', line 21 def __version __version_args.parse puts "Homebrew #{HOMEBREW_VERSION}" puts "#{CoreTap.instance.full_name} #{CoreTap.instance.version_string}" puts "#{Tap.default_cask_tap.full_name} #{Tap.default_cask_tap.version_string}" if Tap.default_cask_tap.installed? end |
.__version_args ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'Library/Homebrew/cmd/--version.rb', line 9 def __version_args Homebrew::CLI::Parser.new do <<~EOS `--version` Print the version numbers of Homebrew, Homebrew/homebrew-core and Homebrew/homebrew-cask (if tapped) to standard output. EOS max_named 0 end end |
._system(cmd, *args, **options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'Library/Homebrew/utils.rb', line 26 def _system(cmd, *args, **) pid = fork do yield if block_given? args.map!(&:to_s) begin exec(cmd, *args, **) rescue nil end exit! 1 # never gets here unless exec failed end Process.wait(pid) $CHILD_STATUS.success? end |
.alias_update_pair(formula, new_formula_version) ⇒ Object
446 447 448 449 450 451 452 453 454 455 456 |
# File 'Library/Homebrew/dev-cmd/bump-formula-pr.rb', line 446 def alias_update_pair(formula, new_formula_version) versioned_alias = formula.aliases.grep(/^.*@\d+(\.\d+)?$/).first return if versioned_alias.nil? name, old_alias_version = versioned_alias.split("@") new_alias_regex = (old_alias_version.split(".").length == 1) ? /^\d+/ : /^\d+\.\d+/ new_alias_version, = *new_formula_version.to_s.match(new_alias_regex) return if Version.create(new_alias_version) <= Version.create(old_alias_version) [versioned_alias, "#{name}@#{new_alias_version}"] end |
.analytics ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'Library/Homebrew/cmd/analytics.rb', line 30 def analytics args = analytics_args.parse case args.named.first when nil, "state" if Utils::Analytics.disabled? puts "Analytics are disabled." else puts "Analytics are enabled." puts "UUID: #{Utils::Analytics.uuid}" if Utils::Analytics.uuid.present? end when "on" Utils::Analytics.enable! when "off" Utils::Analytics.disable! when "regenerate-uuid" Utils::Analytics.regenerate_uuid! else raise UsageError, "unknown subcommand: #{args.named.first}" end end |
.analytics_args ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'Library/Homebrew/cmd/analytics.rb', line 9 def analytics_args Homebrew::CLI::Parser.new do <<~EOS `analytics` [<subcommand>] Control Homebrew's anonymous aggregate user behaviour analytics. Read more at <https://docs.brew.sh/Analytics>. `brew analytics` [`state`]: Display the current state of Homebrew's analytics. `brew analytics` [`on`|`off`]: Turn Homebrew's analytics on or off respectively. `brew analytics regenerate-uuid`: Regenerate the UUID used for Homebrew's analytics. EOS max_named 1 end end |
.audit ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'Library/Homebrew/dev-cmd/audit.rb', line 79 def audit args = audit_args.parse Homebrew.auditing = true inject_dump_stats!(FormulaAuditor, /^audit_/) if args.audit_debug? formula_count = 0 problem_count = 0 corrected_problem_count = 0 new_formula_problem_count = 0 new_formula = args.new_formula? strict = new_formula || args.strict? online = new_formula || args.online? git = args.git? skip_style = args.skip_style? || args.no_named? || args.tap ENV.activate_extensions! ENV.setup_build_environment audit_formulae = if args.tap Tap.fetch(args.tap).formula_names.map { |name| Formula[name] } elsif args.no_named? Formula else args.named.to_resolved_formulae end style_files = args.named.to_formulae_paths unless skip_style only_cops = args.only_cops except_cops = args.except_cops = { fix: args.fix?, debug: args.debug?, verbose: args.verbose? } if only_cops [:only_cops] = only_cops elsif args.new_formula? nil elsif except_cops [:except_cops] = except_cops elsif !strict [:except_cops] = [:FormulaAuditStrict] end # Check style in a single batch run up front for performance style_offenses = Style.check_style_json(style_files, ) if style_files # load licenses spdx_license_data = SPDX.license_data spdx_exception_data = SPDX.exception_data new_formula_problem_lines = [] audit_formulae.sort.each do |f| only = only_cops ? ["style"] : args.only = { new_formula: new_formula, strict: strict, online: online, git: git, only: only, except: args.except, spdx_license_data: spdx_license_data, spdx_exception_data: spdx_exception_data, } [:style_offenses] = style_offenses.for_path(f.path) if style_offenses [:display_cop_names] = args.display_cop_names? [:build_stable] = args.build_stable? fa = FormulaAuditor.new(f, ) fa.audit next if fa.problems.empty? && fa.new_formula_problems.empty? formula_count += 1 problem_count += fa.problems.size problem_lines = format_problem_lines(fa.problems) corrected_problem_count = [:style_offenses].count(&:corrected?) if [:style_offenses] new_formula_problem_lines = format_problem_lines(fa.new_formula_problems) if args.display_filename? puts problem_lines.map { |s| "#{f.path}: #{s}" } else puts "#{f.full_name}:", problem_lines.map { |s| " #{s}" } end next unless ENV["GITHUB_ACTIONS"] (fa.problems + fa.new_formula_problems).each do |message:, location:| annotation = GitHub::Actions::Annotation.new( :error, , file: f.path, line: location&.line, column: location&.column ) puts annotation if annotation.relevant? end end new_formula_problem_count += new_formula_problem_lines.size puts new_formula_problem_lines.map { |s| " #{s}" } total_problems_count = problem_count + new_formula_problem_count problem_plural = "#{total_problems_count} #{"problem".pluralize(total_problems_count)}" formula_plural = "#{formula_count} #{"formula".pluralize(formula_count)}" corrected_problem_plural = "#{corrected_problem_count} #{"problem".pluralize(corrected_problem_count)}" errors_summary = "#{problem_plural} in #{formula_plural} detected" errors_summary += ", #{corrected_problem_plural} corrected" if corrected_problem_count.positive? ofail errors_summary if problem_count.positive? || new_formula_problem_count.positive? end |
.audit_args ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'Library/Homebrew/dev-cmd/audit.rb', line 23 def audit_args Homebrew::CLI::Parser.new do <<~EOS `audit` [<options>] [<formula>] Check <formula> for Homebrew coding style violations. This should be run before submitting a new formula. If no <formula> are provided, check all locally available formulae and skip style checks. Will exit with a non-zero status if any errors are found. EOS switch "--strict", description: "Run additional, stricter style checks." switch "--git", description: "Run additional, slower style checks that navigate the Git repository." switch "--online", description: "Run additional, slower style checks that require a network connection." switch "--new-formula", description: "Run various additional style checks to determine if a new formula is eligible "\ "for Homebrew. This should be used when creating new formula and implies "\ "`--strict` and `--online`." flag "--tap=", description: "Check the formulae within the given tap, specified as <user>`/`<repo>." switch "--fix", description: "Fix style violations automatically using RuboCop's auto-correct feature." switch "--display-cop-names", description: "Include the RuboCop cop name for each violation in the output." switch "--display-filename", description: "Prefix every line of output with the file or formula name being audited, to "\ "make output easy to grep." switch "--skip-style", description: "Skip running non-RuboCop style checks. Useful if you plan on running "\ "`brew style` separately. Default unless a formula is specified by name" switch "-D", "--audit-debug", description: "Enable debugging and profiling of audit methods." comma_array "--only", description: "Specify a comma-separated <method> list to only run the methods named "\ "`audit_`<method>." comma_array "--except", description: "Specify a comma-separated <method> list to skip running the methods named "\ "`audit_`<method>." comma_array "--only-cops", description: "Specify a comma-separated <cops> list to check for violations of only the listed "\ "RuboCop cops." comma_array "--except-cops", description: "Specify a comma-separated <cops> list to skip checking for violations of the listed "\ "RuboCop cops." conflicts "--only", "--except" conflicts "--only-cops", "--except-cops", "--strict" conflicts "--only-cops", "--except-cops", "--only" conflicts "--display-cop-names", "--skip-style" conflicts "--display-cop-names", "--only-cops" conflicts "--display-cop-names", "--except-cops" end end |
.auditing? ⇒ Boolean
108 109 110 |
# File 'Library/Homebrew/global.rb', line 108 def auditing? @auditing == true end |
.autosquash!(original_commit, path: ".", reason: "", verbose: false, resolve: false) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'Library/Homebrew/dev-cmd/pr-pull.rb', line 204 def autosquash!(original_commit, path: ".", reason: "", verbose: false, resolve: false) original_head = Utils.safe_popen_read("git", "-C", path, "rev-parse", "HEAD").strip commits = Utils.safe_popen_read("git", "-C", path, "rev-list", "--reverse", "#{original_commit}..HEAD").lines.map(&:strip) # Generate a bidirectional mapping of commits <=> formula files. files_to_commits = {} commits_to_files = commits.map do |commit| files = Utils.safe_popen_read("git", "-C", path, "diff-tree", "--diff-filter=AMD", "-r", "--name-only", "#{commit}^", commit).lines.map(&:strip) files.each do |file| files_to_commits[file] ||= [] files_to_commits[file] << commit next if %r{^Formula/.*\.rb$}.match?(file) odie <<~EOS Autosquash can't squash commits that modify non-formula files. File: #{file} Commit: #{commit} EOS end [commit, files] end.to_h # Reset to state before cherry-picking. safe_system "git", "-C", path, "reset", "--hard", original_commit # Iterate over every commit in the pull request series, but if we have to squash # multiple commits into one, ensure that we skip over commits we've already squashed. processed_commits = [] commits.each do |commit| next if processed_commits.include? commit files = commits_to_files[commit] if files.length == 1 && files_to_commits[files.first].length == 1 # If there's a 1:1 mapping of commits to files, just cherry pick and (maybe) reword. reword_formula_commit(commit, files.first, path: path, reason: reason, verbose: verbose, resolve: resolve) processed_commits << commit elsif files.length == 1 && files_to_commits[files.first].length > 1 # If multiple commits modify a single file, squash them down into a single commit. file = files.first commits = files_to_commits[file] squash_formula_commits(commits, file, path: path, reason: reason, verbose: verbose, resolve: resolve) processed_commits += commits else # We can't split commits (yet) so just raise an error. odie <<~EOS Autosquash can't split commits that modify multiple files. Commit: #{commit} Files: #{files.join " "} EOS end end rescue opoo "Autosquash encountered an error; resetting to original cherry-picked state at #{original_head}" system "git", "-C", path, "reset", "--hard", original_head system "git", "-C", path, "cherry-pick", "--abort" raise end |
.backup(keg) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'Library/Homebrew/reinstall.rb', line 68 def backup(keg) keg.unlink begin keg.rename backup_path(keg) rescue Errno::EACCES, Errno::ENOTEMPTY odie <<~EOS Could not rename #{keg.name} keg! Check/fix its permissions: sudo chown -R $(whoami) #{keg} EOS end end |
.backup_path(path) ⇒ Object
91 92 93 |
# File 'Library/Homebrew/reinstall.rb', line 91 def backup_path(path) Pathname.new "#{path}.reinstall" end |
.bottle ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'Library/Homebrew/dev-cmd/bottle.rb', line 86 def bottle args = bottle_args.parse return merge(args: args) if args.merge? ensure_relocation_formulae_installed! unless args.skip_relocation? args.named.to_resolved_formulae.each do |f| bottle_formula f, args: args end end |
.bottle_args ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'Library/Homebrew/dev-cmd/bottle.rb', line 43 def bottle_args Homebrew::CLI::Parser.new do <<~EOS `bottle` [<options>] <formula> Generate a bottle (binary package) from a formula that was installed with `--build-bottle`. If the formula specifies a rebuild version, it will be incremented in the generated DSL. Passing `--keep-old` will attempt to keep it at its original value, while `--no-rebuild` will remove it. EOS switch "--skip-relocation", description: "Do not check if the bottle can be marked as relocatable." switch "--force-core-tap", description: "Build a bottle even if <formula> is not in `homebrew/core` or any installed taps." switch "--no-rebuild", description: "If the formula specifies a rebuild version, remove it from the generated DSL." switch "--keep-old", description: "If the formula specifies a rebuild version, attempt to preserve its value in the "\ "generated DSL." switch "--json", description: "Write bottle information to a JSON file, which can be used as the value for "\ "`--merge`." switch "--merge", description: "Generate an updated bottle block for a formula and optionally merge it into the "\ "formula file. Instead of a formula name, requires the path to a JSON file generated with "\ "`brew bottle --json` <formula>." switch "--write", depends_on: "--merge", description: "Write changes to the formula file. A new commit will be generated unless "\ "`--no-commit` is passed." switch "--no-commit", depends_on: "--write", description: "When passed with `--write`, a new commit will not generated after writing changes "\ "to the formula file." flag "--root-url=", description: "Use the specified <URL> as the root of the bottle's URL instead of Homebrew's default." conflicts "--no-rebuild", "--keep-old" min_named 1 end end |
.bottle_formula(f, args:) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'Library/Homebrew/dev-cmd/bottle.rb', line 212 def bottle_formula(f, args:) return ofail "Formula not installed or up-to-date: #{f.full_name}" unless f.latest_version_installed? unless tap = f.tap return ofail "Formula not from core or any installed taps: #{f.full_name}" unless args.force_core_tap? tap = CoreTap.instance end if f.bottle_disabled? ofail "Formula has disabled bottle: #{f.full_name}" puts f.bottle_disable_reason return end return ofail "Formula was not installed with --build-bottle: #{f.full_name}" unless Utils::Bottles.built_as? f return ofail "Formula has no stable version: #{f.full_name}" unless f.stable if args.no_rebuild? || !f.tap rebuild = 0 elsif args.keep_old? rebuild = f.bottle_specification.rebuild else ohai "Determining #{f.full_name} bottle rebuild..." versions = FormulaVersions.new(f) rebuilds = versions.bottle_version_map("origin/master")[f.pkg_version] rebuilds.pop if rebuilds.last.to_i.positive? rebuild = rebuilds.empty? ? 0 : rebuilds.max.to_i + 1 end filename = Bottle::Filename.create(f, Utils::Bottles.tag, rebuild) bottle_path = Pathname.pwd/filename tar_filename = filename.to_s.sub(/.gz$/, "") tar_path = Pathname.pwd/tar_filename prefix = HOMEBREW_PREFIX.to_s repository = HOMEBREW_REPOSITORY.to_s cellar = HOMEBREW_CELLAR.to_s ohai "Bottling #{filename}..." formula_and_runtime_deps_names = [f.name] + f.runtime_dependencies.map(&:name) keg = Keg.new(f.prefix) relocatable = false skip_relocation = false keg.lock do original_tab = nil changed_files = nil begin keg.delete_pyc_files! changed_files = keg.replace_locations_with_placeholders unless args.skip_relocation? Formula.clear_cache Keg.clear_cache Tab.clear_cache tab = Tab.for_keg(keg) original_tab = tab.dup tab.poured_from_bottle = false tab.HEAD = nil tab.time = nil tab.changed_files = changed_files tab.write keg.find do |file| if file.symlink? File.lutime(tab.source_modified_time, tab.source_modified_time, file) else file.utime(tab.source_modified_time, tab.source_modified_time) end end cd cellar do sudo_purge safe_system "tar", "cf", tar_path, "#{f.name}/#{f.pkg_version}" sudo_purge tar_path.utime(tab.source_modified_time, tab.source_modified_time) relocatable_tar_path = "#{f}-bottle.tar" mv tar_path, relocatable_tar_path # Use gzip, faster to compress than bzip2, faster to uncompress than bzip2 # or an uncompressed tarball (and more bandwidth friendly). safe_system "gzip", "-f", relocatable_tar_path sudo_purge mv "#{relocatable_tar_path}.gz", bottle_path end ohai "Detecting if #{filename} is relocatable..." if bottle_path.size > 1 * 1024 * 1024 prefix_check = if Homebrew.default_prefix?(prefix) File.join(prefix, "opt") else prefix end # Ignore matches to source code, which is not required at run time. # These matches may be caused by debugging symbols. ignores = [%r{/include/|\.(c|cc|cpp|h|hpp)$}] any_go_deps = f.deps.any? do |dep| dep.name =~ Version.formula_optionally_versioned_regex(:go) end if any_go_deps go_regex = Version.formula_optionally_versioned_regex(:go, full: false) ignores << %r{#{Regexp.escape(HOMEBREW_CELLAR)}/#{go_regex}/[\d.]+/libexec} end relocatable = true if args.skip_relocation? skip_relocation = true else relocatable = false if keg_contain?(prefix_check, keg, ignores, formula_and_runtime_deps_names, args: args) relocatable = false if keg_contain?(repository, keg, ignores, args: args) relocatable = false if keg_contain?(cellar, keg, ignores, formula_and_runtime_deps_names, args: args) if prefix != prefix_check relocatable = false if keg_contain_absolute_symlink_starting_with?(prefix, keg, args: args) relocatable = false if keg_contain?("#{prefix}/etc", keg, ignores, args: args) relocatable = false if keg_contain?("#{prefix}/var", keg, ignores, args: args) relocatable = false if keg_contain?("#{prefix}/share/vim", keg, ignores, args: args) end skip_relocation = relocatable && !keg.require_relocation? end puts if !relocatable && args.verbose? rescue Interrupt ignore_interrupts { bottle_path.unlink if bottle_path.exist? } raise ensure ignore_interrupts do original_tab&.write keg.replace_placeholders_with_locations changed_files unless args.skip_relocation? end end end root_url = args.root_url bottle = BottleSpecification.new bottle.tap = tap bottle.root_url(root_url) if root_url if relocatable if skip_relocation bottle.cellar :any_skip_relocation else bottle.cellar :any end else bottle.cellar cellar bottle.prefix prefix end bottle.rebuild rebuild sha256 = bottle_path.sha256 bottle.sha256 sha256 => Utils::Bottles.tag old_spec = f.bottle_specification if args.keep_old? && !old_spec.checksums.empty? mismatches = [:root_url, :prefix, :cellar, :rebuild].reject do |key| old_spec.send(key) == bottle.send(key) end if (old_spec.cellar == :any && bottle.cellar == :any_skip_relocation) || (old_spec.cellar == cellar && [:any, :any_skip_relocation].include?(bottle.cellar)) mismatches.delete(:cellar) bottle.cellar old_spec.cellar end unless mismatches.empty? bottle_path.unlink if bottle_path.exist? mismatches.map! do |key| old_value = old_spec.send(key).inspect value = bottle.send(key).inspect "#{key}: old: #{old_value}, new: #{value}" end odie <<~EOS --keep-old was passed but there are changes in: #{mismatches.join("\n")} EOS end end output = bottle_output bottle puts "./#{filename}" puts output return unless args.json? json = { f.full_name => { "formula" => { "pkg_version" => f.pkg_version.to_s, "path" => f.path.to_s.delete_prefix("#{HOMEBREW_REPOSITORY}/"), }, "bottle" => { "root_url" => bottle.root_url, "prefix" => bottle.prefix, "cellar" => bottle.cellar.to_s, "rebuild" => bottle.rebuild, "tags" => { Utils::Bottles.tag.to_s => { "filename" => filename.bintray, "local_filename" => filename.to_s, "sha256" => sha256, }, }, }, "bintray" => { "package" => Utils::Bottles::Bintray.package(f.name), "repository" => Utils::Bottles::Bintray.repository(tap), }, }, } File.open(filename.json, "w") do |file| file.write JSON.generate json end end |
.bottle_output(bottle) ⇒ Object
201 202 203 204 |
# File 'Library/Homebrew/dev-cmd/bottle.rb', line 201 def bottle_output(bottle) erb = ERB.new BOTTLE_ERB erb.result(bottle.instance_eval { binding }).gsub(/^\s*$\n/, "") end |
.brief_build_info(f, with_hostname:) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'Library/Homebrew/cmd/gist-logs.rb', line 81 def brief_build_info(f, with_hostname:) build_time_str = f.logs.ctime.strftime("%Y-%m-%d %H:%M:%S") s = +<<~EOS Homebrew build logs for #{f.full_name} on #{OS_VERSION} EOS if with_hostname hostname = Socket.gethostname s << "Host: #{hostname}\n" end s << "Build date: #{build_time_str}\n" s.freeze end |
.build_man_page(quiet:) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 62 def build_man_page(quiet:) template = (SOURCE_PATH/"brew.1.md.erb").read variables = OpenStruct.new variables[:commands] = generate_cmd_manpages(Commands.internal_commands_paths) variables[:developer_commands] = generate_cmd_manpages(Commands.internal_developer_commands_paths) variables[:official_external_commands] = generate_cmd_manpages(Commands.official_external_commands_paths(quiet: quiet)) variables[:global_cask_options] = variables[:global_options] = variables[:environment_variables] = env_vars_manpage readme = HOMEBREW_REPOSITORY/"README.md" variables[:lead] = readme.read[/(Homebrew's \[Project Leader.*\.)/, 1] .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') variables[:plc] = readme.read[/(Homebrew's \[Project Leadership Committee.*\.)/, 1] .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') variables[:tsc] = readme.read[/(Homebrew's \[Technical Steering Committee.*\.)/, 1] .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') variables[:linux] = readme.read[%r{(Homebrew/brew's Linux maintainers .*\.)}, 1] .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') variables[:maintainers] = readme.read[/(Homebrew's other current maintainers .*\.)/, 1] .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') variables[:alumni] = readme.read[/(Former maintainers .*\.)/, 1] .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') ERB.new(template, trim_mode: ">").result(variables.instance_eval { binding }) end |
.bump ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'Library/Homebrew/dev-cmd/bump.rb', line 24 def bump args = bump_args.parse requested_formulae = args.named.to_formulae.map(&:name) if args.named.to_formulae.present? requested_limit = args.limit.to_i if args.limit.present? repology_data = if requested_formulae response = {} requested_formulae.each do |formula| raise FormulaUnavailableError, formula unless validate_formula(formula) package_data = Repology.single_package_query(formula) response[package_data.keys.first] = package_data.values.first if package_data end response else Repology.parse_api_response(requested_limit) end validated_formulae = {} validated_formulae = Repology.validate_and_format_packages(repology_data, requested_limit) if repology_data if requested_formulae repology_excluded_formulae = requested_formulae.reject do |formula| repology_data[formula] end formulae = {} repology_excluded_formulae.each do |formula| formulae[formula] = Repology.format_package(formula, nil) end formulae.each { |formula, data| validated_formulae[formula] = data } end display(validated_formulae) end |
.bump_args ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'Library/Homebrew/dev-cmd/bump.rb', line 9 def bump_args Homebrew::CLI::Parser.new do <<~EOS `bump` [<options>] [<formula>] Display out-of-date brew formulae and the latest version available. Also displays whether a pull request has been opened with the URL. EOS flag "--limit=", description: "Limit number of package results returned." switch :verbose switch :debug end end |
.bump_cask_pr ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'Library/Homebrew/dev-cmd/bump-cask-pr.rb', line 56 def bump_cask_pr args = bump_cask_pr_args.parse # As this command is simplifying user-run commands then let's just use a # user path, too. ENV["PATH"] = ENV["HOMEBREW_PATH"] # Use the user's browser, too. ENV["BROWSER"] = Homebrew::EnvConfig.browser cask = args.named.to_casks.first new_version = args.version new_version = "latest" if new_version == ":latest" new_version = Cask::DSL::Version.new(new_version) new_base_url = args.url new_hash = args.sha256 old_version = cask.version old_hash = cask.sha256 tap_full_name = cask.tap&.full_name origin_branch = Utils::Git.origin_branch(cask.tap.path) if cask.tap origin_branch ||= "origin/master" previous_branch = "-" check_open_pull_requests(cask, tap_full_name, args: args) odie "#{cask}: no --version= argument specified!" if new_version.empty? check_closed_pull_requests(cask, tap_full_name, version: new_version, args: args) unless new_version.latest? if new_version == old_version odie <<~EOS You need to bump this cask manually since the new version and old version are both #{new_version}. EOS elsif old_version.latest? opoo "No --url= argument specified!" unless new_base_url elsif new_version.latest? opoo "Ignoring specified --sha256= argument." if new_hash elsif Version.new(new_version) < Version.new(old_version) odie <<~EOS You need to bump this cask manually since changing the version from #{old_version} to #{new_version} would be a downgrade. EOS end old_contents = File.read(cask.sourcefile_path) replacement_pairs = [] replacement_pairs << if old_version.latest? [ "version :latest", "version \"#{new_version}\"", ] elsif new_version.latest? [ "version \"#{old_version}\"", "version :latest", ] else [ old_version, new_version, ] end if new_base_url.present? m = /^ +url "(.+?)"\n/m.match(old_contents) odie "Could not find old URL in cask!" if m.nil? old_base_url = m.captures.first replacement_pairs << [ /#{Regexp.escape(old_base_url)}/, new_base_url, ] end if !new_version.latest? && (new_hash.nil? || cask.languages.present?) tmp_contents = Utils::Inreplace.inreplace_pairs(cask.sourcefile_path, replacement_pairs.uniq.compact, read_only_run: true, silent: true) tmp_cask = Cask::CaskLoader.load(tmp_contents) tmp_url = tmp_cask.url.to_s if new_hash.nil? resource_path = fetch_resource(cask, new_version, tmp_url) Utils::Tar.validate_file(resource_path) new_hash = resource_path.sha256 end cask.languages.each do |language| next if language == cask.language tmp_cask.config.languages = [language] lang_cask = Cask::CaskLoader.load(tmp_contents) lang_url = lang_cask.url.to_s lang_old_hash = lang_cask.sha256 resource_path = fetch_resource(cask, new_version, lang_url) Utils::Tar.validate_file(resource_path) lang_new_hash = resource_path.sha256 replacement_pairs << [ lang_old_hash, lang_new_hash, ] end end replacement_pairs << if old_version.latest? [ "sha256 :no_check", "sha256 \"#{new_hash}\"", ] elsif new_version.latest? [ "sha256 \"#{old_hash}\"", "sha256 :no_check", ] else [ old_hash, new_hash, ] end Utils::Inreplace.inreplace_pairs(cask.sourcefile_path, replacement_pairs.uniq.compact, read_only_run: args.dry_run?, silent: args.quiet?) run_cask_audit(cask, old_contents, args: args) run_cask_style(cask, old_contents, args: args) pr_info = { sourcefile_path: cask.sourcefile_path, old_contents: old_contents, origin_branch: origin_branch, branch_name: "bump-#{cask.token}-#{new_version.tr(",:", "-")}", commit_message: "Update #{cask.token} from #{old_version} to #{new_version}", previous_branch: previous_branch, tap: cask.tap, tap_full_name: tap_full_name, pr_message: "Created with `brew bump-cask-pr`.", } GitHub.create_bump_pr(pr_info, args: args) end |
.bump_cask_pr_args ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'Library/Homebrew/dev-cmd/bump-cask-pr.rb', line 11 def bump_cask_pr_args Homebrew::CLI::Parser.new do <<~EOS `bump-cask-pr` [<options>] [<cask>] Create a pull request to update <cask> with a new version. A best effort to determine the <SHA-256> will be made if the value is not supplied by the user. EOS switch "-n", "--dry-run", description: "Print what would be done rather than doing it." switch "--write", description: "Make the expected file modifications without taking any Git actions." switch "--commit", depends_on: "--write", description: "When passed with `--write`, generate a new commit after writing changes "\ "to the cask file." switch "--no-audit", description: "Don't run `brew cask audit` before opening the PR." switch "--online", description: "Run `brew cask audit --online` before opening the PR." switch "--no-style", description: "Don't run `brew cask style --fix` before opening the PR." switch "--no-browse", description: "Print the pull request URL instead of opening in a browser." switch "--no-fork", description: "Don't try to fork the repository." flag "--version=", description: "Specify the new <version> for the cask." flag "--message=", description: "Append <message> to the default pull request message." flag "--url=", description: "Specify the <URL> for the new download." flag "--sha256=", description: "Specify the <SHA-256> checksum of the new download." switch "-f", "--force", description: "Ignore duplicate open PRs." conflicts "--dry-run", "--write" conflicts "--no-audit", "--online" named 1 end end |
.bump_formula_pr ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'Library/Homebrew/dev-cmd/bump-formula-pr.rb', line 124 def bump_formula_pr args = bump_formula_pr_args.parse # As this command is simplifying user-run commands then let's just use a # user path, too. ENV["PATH"] = ENV["HOMEBREW_PATH"] # Use the user's browser, too. ENV["BROWSER"] = Homebrew::EnvConfig.browser formula = args.named.to_formulae.first new_url = args.url formula ||= determine_formula_from_url(new_url) if new_url raise FormulaUnspecifiedError unless formula odie "This formula is disabled!" if formula.disabled? tap_full_name, origin_branch, previous_branch = use_correct_linux_tap(formula, args: args) check_open_pull_requests(formula, tap_full_name, args: args) new_version = args.version check_closed_pull_requests(formula, tap_full_name, version: new_version, args: args) if new_version opoo "This formula has patches that may be resolved upstream." if formula.patchlist.present? if formula.resources.any? { |resource| !resource.name.start_with?("homebrew-") } opoo "This formula has resources that may need to be updated." end requested_spec = :stable formula_spec = formula.stable odie "#{formula}: no #{requested_spec} specification found!" unless formula_spec old_mirrors = formula_spec.mirrors new_mirrors ||= args.mirror new_mirror ||= determine_mirror(new_url) new_mirrors ||= [new_mirror] unless new_mirror.nil? check_for_mirrors(formula, old_mirrors, new_mirrors, args: args) if new_url hash_type, old_hash = if (checksum = formula_spec.checksum) [checksum.hash_type, checksum.hexdigest] end new_hash = args[hash_type] if hash_type new_tag = args.tag new_revision = args.revision old_url = formula_spec.url old_tag = formula_spec.specs[:tag] old_formula_version = formula_version(formula, requested_spec) old_version = old_formula_version.to_s forced_version = new_version.present? new_url_hash = if new_url && new_hash check_closed_pull_requests(formula, tap_full_name, url: new_url, args: args) unless new_version true elsif new_tag && new_revision check_closed_pull_requests(formula, tap_full_name, url: old_url, tag: new_tag, args: args) unless new_version false elsif !hash_type odie "#{formula}: no --tag= or --version= argument specified!" if !new_tag && !new_version new_tag ||= old_tag.gsub(old_version, new_version) if new_tag == old_tag odie <<~EOS You need to bump this formula manually since the new tag and old tag are both #{new_tag}. EOS end check_closed_pull_requests(formula, tap_full_name, url: old_url, tag: new_tag, args: args) unless new_version resource_path, forced_version = fetch_resource(formula, new_version, old_url, tag: new_tag) new_revision = Utils.popen_read("git -C \"#{resource_path}\" rev-parse -q --verify HEAD") new_revision = new_revision.strip false elsif !new_url && !new_version odie "#{formula}: no --url= or --version= argument specified!" else new_url ||= PyPI.update_pypi_url(old_url, new_version) unless new_url new_url = old_url.gsub(old_version, new_version) if !new_mirrors && !old_mirrors.empty? new_mirrors = old_mirrors.map do |old_mirror| old_mirror.gsub(old_version, new_version) end end end if new_url == old_url odie <<~EOS You need to bump this formula manually since the new URL and old URL are both: #{new_url} EOS end check_closed_pull_requests(formula, tap_full_name, url: new_url, args: args) unless new_version resource_path, forced_version = fetch_resource(formula, new_version, new_url) Utils::Tar.validate_file(resource_path) new_hash = resource_path.sha256 end replacement_pairs = [] if requested_spec == :stable && formula.revision.nonzero? replacement_pairs << [ /^ revision \d+\n(\n( head "))?/m, "\\2", ] end replacement_pairs += formula_spec.mirrors.map do |mirror| [ / +mirror "#{Regexp.escape(mirror)}"\n/m, "", ] end replacement_pairs += if new_url_hash [ [ /#{Regexp.escape(formula_spec.url)}/, new_url, ], [ old_hash, new_hash, ], ] else [ [ formula_spec.specs[:tag], new_tag, ], [ formula_spec.specs[:revision], new_revision, ], ] end old_contents = File.read(formula.path) unless args.dry_run? if new_mirrors replacement_pairs << [ /^( +)(url "#{Regexp.escape(new_url)}"\n)/m, "\\1\\2\\1mirror \"#{new_mirrors.join("\"\n\\1mirror \"")}\"\n", ] end # When bumping a linux-only formula, one needs to also delete the # sha256 linux bottle line if it exists. That's because of running # test-bot with --keep-old option in linuxbrew-core. formula_contents = formula.path.read if formula_contents.include?("depends_on :linux") && formula_contents.include?("=> :x86_64_linux") replacement_pairs << [ /^ sha256 ".+" => :x86_64_linux\n/m, "\\2", ] end if forced_version && new_version != "0" replacement_pairs << if File.read(formula.path).include?("version \"#{old_formula_version}\"") [ old_formula_version.to_s, new_version, ] elsif new_mirrors [ /^( +)(mirror "#{Regexp.escape(new_mirrors.last)}"\n)/m, "\\1\\2\\1version \"#{new_version}\"\n", ] elsif new_url [ /^( +)(url "#{Regexp.escape(new_url)}"\n)/m, "\\1\\2\\1version \"#{new_version}\"\n", ] elsif new_revision [ /^( {2})( +)(:revision => "#{new_revision}"\n)/m, "\\1\\2\\3\\1version \"#{new_version}\"\n", ] end elsif forced_version && new_version == "0" replacement_pairs << [ /^ version "[\w.\-+]+"\n/m, "", ] end new_contents = Utils::Inreplace.inreplace_pairs(formula.path, replacement_pairs.uniq.compact, read_only_run: args.dry_run?, silent: args.quiet?) new_formula_version = formula_version(formula, requested_spec, new_contents) if new_formula_version < old_formula_version formula.path.atomic_write(old_contents) unless args.dry_run? odie <<~EOS You need to bump this formula manually since changing the version from #{old_formula_version} to #{new_formula_version} would be a downgrade. EOS elsif new_formula_version == old_formula_version formula.path.atomic_write(old_contents) unless args.dry_run? odie <<~EOS You need to bump this formula manually since the new version and old version are both #{new_formula_version}. EOS end alias_rename = alias_update_pair(formula, new_formula_version) if alias_rename.present? ohai "renaming alias #{alias_rename.first} to #{alias_rename.last}" alias_rename.map! { |a| formula.tap.alias_dir/a } end unless args.dry_run? resources_checked = PyPI.update_python_resources! formula, new_formula_version, silent: args.quiet?, ignore_non_pypi_packages: true end run_audit(formula, alias_rename, old_contents, args: args) = "Created with `brew bump-formula-pr`." if resources_checked.nil? && formula.resources.any? { |resource| !resource.name.start_with?("homebrew-") } += <<~EOS `resource` blocks may require updates. EOS end pr_info = { sourcefile_path: formula.path, old_contents: old_contents, additional_files: alias_rename, origin_branch: origin_branch, branch_name: "bump-#{formula.name}-#{new_formula_version}", commit_message: "#{formula.name} #{new_formula_version}", previous_branch: previous_branch, tap: formula.tap, tap_full_name: tap_full_name, pr_message: , } GitHub.create_bump_pr(pr_info, args: args) end |
.bump_formula_pr_args ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'Library/Homebrew/dev-cmd/bump-formula-pr.rb', line 12 def bump_formula_pr_args Homebrew::CLI::Parser.new do <<~EOS `bump-formula-pr` [<options>] [<formula>] Create a pull request to update <formula> with a new URL or a new tag. If a <URL> is specified, the <SHA-256> checksum of the new download should also be specified. A best effort to determine the <SHA-256> and <formula> name will be made if either or both values are not supplied by the user. If a <tag> is specified, the Git commit <revision> corresponding to that tag should also be specified. A best effort to determine the <revision> will be made if the value is not supplied by the user. If a <version> is specified, a best effort to determine the <URL> and <SHA-256> or the <tag> and <revision> will be made if both values are not supplied by the user. *Note:* this command cannot be used to transition a formula from a URL-and-SHA-256 style specification into a tag-and-revision style specification, nor vice versa. It must use whichever style specification the formula already uses. EOS switch "-n", "--dry-run", description: "Print what would be done rather than doing it." switch "--write", description: "Make the expected file modifications without taking any Git actions." switch "--commit", depends_on: "--write", description: "When passed with `--write`, generate a new commit after writing changes "\ "to the formula file." switch "--no-audit", description: "Don't run `brew audit` before opening the PR." switch "--strict", description: "Run `brew audit --strict` before opening the PR." switch "--online", description: "Run `brew audit --online` before opening the PR." switch "--no-browse", description: "Print the pull request URL instead of opening in a browser." switch "--no-fork", description: "Don't try to fork the repository." comma_array "--mirror", description: "Use the specified <URL> as a mirror URL. If <URL> is a comma-separated list "\ "of URLs, multiple mirrors will be added." flag "--version=", description: "Use the specified <version> to override the value parsed from the URL or tag. Note "\ "that `--version=0` can be used to delete an existing version override from a "\ "formula if it has become redundant." flag "--message=", description: "Append <message> to the default pull request message." flag "--url=", description: "Specify the <URL> for the new download. If a <URL> is specified, the <SHA-256> "\ "checksum of the new download should also be specified." flag "--sha256=", depends_on: "--url=", description: "Specify the <SHA-256> checksum of the new download." flag "--tag=", description: "Specify the new git commit <tag> for the formula." flag "--revision=", depends_on: "--tag=", description: "Specify the new git commit <revision> corresponding to the specified <tag>." switch "-f", "--force", description: "Ignore duplicate open PRs. Remove all mirrors if --mirror= was not specified." conflicts "--dry-run", "--write" conflicts "--no-audit", "--strict" conflicts "--no-audit", "--online" conflicts "--url", "--tag" max_named 1 end end |
.bump_revision ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'Library/Homebrew/dev-cmd/bump-revision.rb', line 27 def bump_revision args = bump_revision_args.parse # As this command is simplifying user-run commands then let's just use a # user path, too. ENV["PATH"] = ENV["HOMEBREW_PATH"] args.named.to_formulae.each do |formula| current_revision = formula.revision if current_revision.zero? formula_spec = formula.stable hash_type, old_hash = if (checksum = formula_spec.checksum) [checksum.hash_type, checksum.hexdigest] end old = if formula.license license_string = case formula.license when String "\"#{formula.license}\"" when Symbol ":#{formula.license}" else formula.license.to_s.gsub(/:(\w+)=>/, '\1: ') # Change `:any_of=>` to `any_of: ` .tr("{}", "") # Remove braces .gsub(/=>with: "([a-zA-Z0-9-]+)"/, ' => { with: "\1" }') # Add braces and spacing around exceptions end # insert replacement revision after license <<~EOS license #{license_string} EOS elsif formula.path.read.include?("stable do\n") # insert replacement revision after homepage <<~EOS homepage "#{formula.homepage}" EOS elsif hash_type # insert replacement revision after hash <<~EOS #{hash_type} "#{old_hash}" EOS else # insert replacement revision after :revision <<~EOS revision: "#{formula_spec.specs[:revision]}" EOS end replacement = "#{old} revision 1\n" else old = "revision #{current_revision}" replacement = "revision #{current_revision+1}" end if args.dry_run? ohai "replace #{old.inspect} with #{replacement.inspect}" unless args.quiet? else Utils::Inreplace.inreplace(formula.path) do |s| s.gsub!(old, replacement) end end = "#{formula.name}: revision bump #{args.}" if args.dry_run? ohai "git commit --no-edit --verbose --message=#{} -- #{formula.path}" else formula.path.parent.cd do safe_system "git", "commit", "--no-edit", "--verbose", "--message=#{}", "--", formula.path end end end end |
.bump_revision_args ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'Library/Homebrew/dev-cmd/bump-revision.rb', line 10 def bump_revision_args Homebrew::CLI::Parser.new do <<~EOS `bump-revision` [<options>] <formula> [<formula> ...] Create a commit to increment the revision of <formula>. If no revision is present, "revision 1" will be added. EOS switch "-n", "--dry-run", description: "Print what would be done rather than doing it." flag "--message=", description: "Append <message> to the default commit message." min_named :formula end end |
.cask ⇒ Object
13 14 15 16 |
# File 'Library/Homebrew/cmd/cask.rb', line 13 def cask ARGV.freeze Cask::Cmd.run(*ARGV) end |
.cask_args ⇒ Object
9 10 11 |
# File 'Library/Homebrew/cmd/cask.rb', line 9 def cask_args Cask::Cmd.parser end |
.cat ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'Library/Homebrew/dev-cmd/cat.rb', line 20 def cat args = cat_args.parse cd HOMEBREW_REPOSITORY pager = if Homebrew::EnvConfig.bat? ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path "#{HOMEBREW_PREFIX}/bin/bat" else "cat" end safe_system pager, args.named.to_formulae_paths.first end |
.cat_args ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'Library/Homebrew/dev-cmd/cat.rb', line 9 def cat_args Homebrew::CLI::Parser.new do <<~EOS `cat` <formula> Display the source of <formula>. EOS named :formula end end |
.changed_formulae(tap, original_commit) ⇒ Object
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'Library/Homebrew/dev-cmd/pr-pull.rb', line 309 def changed_formulae(tap, original_commit) if Homebrew::EnvConfig.disable_load_formula? opoo "Can't check if updated bottles are necessary as formula loading is disabled!" return end Utils.popen_read("git", "-C", tap.path, "diff-tree", "-r", "--name-only", "--diff-filter=AM", original_commit, "HEAD", "--", tap.formula_dir) .lines .map do |line| next unless line.end_with? ".rb\n" name = "#{tap.name}/#{File.basename(line.chomp, ".rb")}" Formula[name] end.compact end |
.check_bottled_formulae(bottles_hash) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'Library/Homebrew/dev-cmd/pr-upload.rb', line 36 def check_bottled_formulae(bottles_hash) bottles_hash.each do |name, bottle_hash| formula_path = HOMEBREW_REPOSITORY/bottle_hash["formula"]["path"] formula_version = Formulary.factory(formula_path).pkg_version bottle_version = PkgVersion.parse bottle_hash["formula"]["pkg_version"] next if formula_version == bottle_version odie "Bottles are for #{name} #{bottle_version} but formula is version #{formula_version}!" end end |
.check_closed_pull_requests(formula, tap_full_name, args:, version: nil, url: nil, tag: nil) ⇒ Object
222 223 224 225 226 |
# File 'Library/Homebrew/dev-cmd/bump-cask-pr.rb', line 222 def check_closed_pull_requests(cask, tap_full_name, version:, args:) # if we haven't already found open requests, try for an exact match across closed requests pr_title = "Update #{cask.token} from #{cask.version} to #{version}" GitHub.check_for_duplicate_pull_requests(pr_title, tap_full_name, state: "closed", args: args) end |
.check_for_dependents(kegs, named_args: []) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 |
# File 'Library/Homebrew/cmd/uninstall.rb', line 158 def check_for_dependents(kegs, named_args: []) return false unless result = Keg.find_some_installed_dependents(kegs) if Homebrew::EnvConfig.developer? DeveloperDependentsMessage.new(*result, named_args: named_args).output else NondeveloperDependentsMessage.new(*result, named_args: named_args).output end true end |
.check_for_mirrors(formula, old_mirrors, new_mirrors, args:) ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'Library/Homebrew/dev-cmd/bump-formula-pr.rb', line 399 def check_for_mirrors(formula, old_mirrors, new_mirrors, args:) return if new_mirrors || old_mirrors.empty? if args.force? opoo "#{formula}: Removing all mirrors because a --mirror= argument was not specified." else odie <<~EOS #{formula}: a --mirror= argument for updating the mirror URL(s) was not specified. Use --force to remove all mirrors. EOS end end |
.check_open_pull_requests(formula, tap_full_name, args:) ⇒ Object
218 219 220 |
# File 'Library/Homebrew/dev-cmd/bump-cask-pr.rb', line 218 def check_open_pull_requests(cask, tap_full_name, args:) GitHub.check_for_duplicate_pull_requests(cask.token, tap_full_name, state: "open", args: args) end |
.cherry_pick_pr!(user, repo, pr, args:, path: ".") ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'Library/Homebrew/dev-cmd/pr-pull.rb', line 265 def cherry_pick_pr!(user, repo, pr, args:, path: ".") if args.dry_run? puts <<~EOS git fetch --force origin +refs/pull/#{pr}/head git merge-base HEAD FETCH_HEAD git cherry-pick --ff --allow-empty $merge_base..FETCH_HEAD EOS return end commits = GitHub.pull_request_commits(user, repo, pr) safe_system "git", "-C", path, "fetch", "--quiet", "--force", "origin", commits.last ohai "Using #{commits.count} commit#{"s" unless commits.count == 1} from ##{pr}" Utils::Git.cherry_pick!(path, "--ff", "--allow-empty", *commits, verbose: args.verbose?, resolve: args.resolve?) end |
.cleanup ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'Library/Homebrew/cmd/cleanup.rb', line 34 def cleanup args = cleanup_args.parse if args.prune.present? && !Integer(args.prune, exception: false) && args.prune != "all" raise UsageError, "--prune= expects an integer or 'all'." end cleanup = Cleanup.new(*args.named, dry_run: args.dry_run?, scrub: args.s?, days: args.prune&.to_i) if args.prune_prefix? cleanup.prune_prefix_symlinks_and_directories return end cleanup.clean! unless cleanup.disk_cleanup_size.zero? disk_space = disk_usage_readable(cleanup.disk_cleanup_size) if args.dry_run? ohai "This operation would free approximately #{disk_space} of disk space." else ohai "This operation has freed approximately #{disk_space} of disk space." end end return if cleanup.unremovable_kegs.empty? ofail <<~EOS Could not cleanup old kegs! Fix your permissions on: #{cleanup.unremovable_kegs.join "\n "} EOS end |
.cleanup_args ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'Library/Homebrew/cmd/cleanup.rb', line 10 def cleanup_args Homebrew::CLI::Parser.new do days = Homebrew::EnvConfig::ENVS[:HOMEBREW_CLEANUP_MAX_AGE_DAYS][:default] <<~EOS `cleanup` [<options>] [<formula>|<cask>] Remove stale lock files and outdated downloads for all formulae and casks, and remove old versions of installed formulae. If arguments are specified, only do this for the given formulae and casks. Removes all downloads more than #{days} days old. This can be adjusted with `HOMEBREW_CLEANUP_MAX_AGE_DAYS`. EOS flag "--prune=", description: "Remove all cache files older than specified <days>." switch "-n", "--dry-run", description: "Show what would be removed, but do not actually remove anything." switch "-s", description: "Scrub the cache, including downloads for even the latest versions. "\ "Note downloads for any installed formulae or casks will still not be deleted. "\ "If you want to delete those too: `rm -rf \"$(brew --cache)\"`" switch "--prune-prefix", description: "Only prune the symlinks and directories from the prefix and remove no other files." end end |
.cmd_comment_manpage_lines(cmd_path) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 188 def cmd_comment_manpage_lines(cmd_path) comment_lines = cmd_path.read.lines.grep(/^#:/) return if comment_lines.empty? return if comment_lines.first.include?("@hide_from_man_page") lines = [(comment_lines.first).chomp] comment_lines.slice(1..-1) .each do |line| line = line.slice(4..-2) unless line lines.last << "\n" next end # Omit the common global_options documented separately in the man page. next if line.match?(/--(debug|help|quiet|verbose) /) # Format one option or a comma-separated pair of short and long options. lines << line.gsub(/^ +(-+[a-z-]+), (-+[a-z-]+) +/, "* `\\1`, `\\2`:\n ") .gsub(/^ +(-+[a-z-]+) +/, "* `\\1`:\n ") end lines.last << "\n" lines end |
.cmd_comment_options(cmd_path) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'Library/Homebrew/cmd/options.rb', line 62 def (cmd_path) = [] comment_lines = cmd_path.read.lines.grep(/^#:/) return if comment_lines.empty? # skip the comment's initial usage summary lines comment_lines.slice(2..-1).each do |line| if / (?<option>-[-\w]+) +(?<desc>.*)$/ =~ line << [option, desc] end end end |
.cmd_parser_manpage_lines(cmd_parser) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 173 def cmd_parser_manpage_lines(cmd_parser) lines = [(cmd_parser.)] lines += cmd_parser..map do |short, long, _, desc| if long.present? next if Homebrew::CLI::Parser..include?([short, long, desc]) next if Homebrew::CLI::Parser..any? do |_, option, description:, **| [long, "#{long}="].include?(option) && description == desc end end generate_option_doc(short, long, desc) end.reject(&:blank?) lines end |
.command ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'Library/Homebrew/dev-cmd/command.rb', line 22 def command args = command_args.parse args.named.each do |cmd| path = Commands.path(cmd) odie "Unknown command: #{cmd}" unless path puts path end end |
.command_args ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'Library/Homebrew/dev-cmd/command.rb', line 10 def command_args Homebrew::CLI::Parser.new do <<~EOS `command` <cmd> Display the path to the file being used when invoking `brew` <cmd>. EOS min_named 1 end end |
.commands ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'Library/Homebrew/cmd/commands.rb', line 26 def commands args = commands_args.parse if args.quiet? puts Formatter.columns(Commands.commands(aliases: args.include_aliases?)) return end prepend_separator = false { "Built-in commands" => Commands.internal_commands, "Built-in developer commands" => Commands.internal_developer_commands, "External commands" => Commands.external_commands, "Cask commands" => Commands.cask_internal_commands, "External cask commands" => Commands.cask_external_commands, }.each do |title, commands| next if commands.blank? puts if prepend_separator ohai title, Formatter.columns(commands) prepend_separator ||= true end end |
.commands_args ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'Library/Homebrew/cmd/commands.rb', line 9 def commands_args Homebrew::CLI::Parser.new do <<~EOS `commands` [<options>] Show lists of built-in and external commands. EOS switch "-q", "--quiet", description: "List only the names of commands without category headers." switch "--include-aliases", depends_on: "--quiet", description: "Include aliases of internal commands." max_named 0 end end |
.condense_requirements(deps, args:) ⇒ Object
119 120 121 122 |
# File 'Library/Homebrew/cmd/deps.rb', line 119 def condense_requirements(deps, args:) deps.select! { |dep| dep.is_a?(Dependency) } unless args.include_requirements? deps.select! { |dep| dep.is_a?(Requirement) || dep.installed? } if args.installed? end |
.config ⇒ Object
23 24 25 26 27 |
# File 'Library/Homebrew/cmd/config.rb', line 23 def config config_args.parse SystemConfig.dump_verbose_config end |
.config_args ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'Library/Homebrew/cmd/config.rb', line 10 def config_args Homebrew::CLI::Parser.new do <<~EOS `config` Show Homebrew and system configuration info useful for debugging. If you file a bug report, you will be required to provide this information. EOS max_named 0 end end |
.convert_man_page(markup, target, preserve_date:) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 102 def convert_man_page(markup, target, preserve_date:) manual = target.basename(".1") organisation = "Homebrew" # Set the manpage date to the existing one if we're checking for changes. # This avoids the only change being e.g. a new date. date = if preserve_date && target.extname == ".1" && target.exist? /"(\d{1,2})" "([A-Z][a-z]+) (\d{4})" "#{organisation}" "#{manual}"/ =~ target.read Date.parse("#{Regexp.last_match(1)} #{Regexp.last_match(2)} #{Regexp.last_match(3)}") else Date.today end date = date.strftime("%Y-%m-%d") shared_args = %W[ --pipe --organization=#{organisation} --manual=#{target.basename(".1")} --date=#{date} ] format_flag, format_desc = target_path_to_format(target) puts "Writing #{format_desc} to #{target}" Utils.popen(["ronn", format_flag] + shared_args, "rb+") do |ronn| ronn.write markup ronn.close_write ronn_output = ronn.read odie "Got no output from ronn!" if ronn_output.blank? case format_flag when "--markdown" ronn_output = ronn_output.gsub(%r{<var>(.*?)</var>}, "*`\\1`*") .gsub(/\n\n\n+/, "\n\n") when "--roff" ronn_output = ronn_output.gsub(%r{<code>(.*?)</code>}, "\\fB\\1\\fR") .gsub(%r{<var>(.*?)</var>}, "\\fI\\1\\fR") .gsub(/(^\[?\\fB.+): /, "\\1\n ") end target.atomic_write ronn_output end end |
.create ⇒ Object
Create a formula from a tarball URL.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'Library/Homebrew/dev-cmd/create.rb', line 67 def create args = create_args.parse # Ensure that the cache exists so we can fetch the tarball HOMEBREW_CACHE.mkpath url = args.named.first # Pull the first (and only) url from ARGV version = args.set_version name = args.set_name license = args.set_license tap = args.tap fc = FormulaCreator.new(args) fc.name = name fc.version = version fc.license = license fc.tap = Tap.fetch(tap || "homebrew/core") raise TapUnavailableError, tap unless fc.tap.installed? fc.url = url fc.mode = if args.cmake? :cmake elsif args.autotools? :autotools elsif args.meson? :meson elsif args.crystal? :crystal elsif args.go? :go elsif args.node? :node elsif args.perl? :perl elsif args.python? :python elsif args.ruby? :ruby elsif args.rust? :rust end if fc.name.nil? || fc.name.strip.empty? stem = Pathname.new(url).stem print "Formula name [#{stem}]: " fc.name = __gets || stem fc.update_path end # Check for disallowed formula, or names that shadow aliases, # unless --force is specified. unless args.force? if reason = MissingFormula.disallowed_reason(fc.name) raise <<~EOS #{fc.name} is not allowed to be created. #{reason} If you really want to create this formula use --force. EOS end if Formula.aliases.include? fc.name realname = Formulary.canonical_name(fc.name) raise <<~EOS The formula #{realname} is already aliased to #{fc.name} Please check that you are not creating a duplicate. To force creation use --force. EOS end end fc.generate! PyPI.update_python_resources! Formula[fc.name], ignore_non_pypi_packages: true if args.python? puts "Please run `brew audit --new-formula #{fc.name}` before submitting, thanks." exec_editor fc.path end |
.create_args ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'Library/Homebrew/dev-cmd/create.rb', line 13 def create_args Homebrew::CLI::Parser.new do <<~EOS `create` [<options>] <URL> Generate a formula for the downloadable file at <URL> and open it in the editor. Homebrew will attempt to automatically derive the formula name and version, but if it fails, you'll have to make your own template. The `wget` formula serves as a simple example. For the complete API, see: <https://rubydoc.brew.sh/Formula> EOS switch "--autotools", description: "Create a basic template for an Autotools-style build." switch "--cmake", description: "Create a basic template for a CMake-style build." switch "--crystal", description: "Create a basic template for a Crystal build." switch "--go", description: "Create a basic template for a Go build." switch "--meson", description: "Create a basic template for a Meson-style build." switch "--node", description: "Create a basic template for a Node build." switch "--perl", description: "Create a basic template for a Perl build." switch "--python", description: "Create a basic template for a Python build." switch "--ruby", description: "Create a basic template for a Ruby build." switch "--rust", description: "Create a basic template for a Rust build." switch "--no-fetch", description: "Homebrew will not download <URL> to the cache and will thus not add its SHA-256 "\ "to the formula for you, nor will it check the GitHub API for GitHub projects "\ "(to fill out its description and homepage)." switch "--HEAD", description: "Indicate that <URL> points to the package's repository rather than a file." flag "--set-name=", description: "Explicitly set the <name> of the new formula." flag "--set-version=", description: "Explicitly set the <version> of the new formula." flag "--set-license=", description: "Explicitly set the <license> of the new formula." flag "--tap=", description: "Generate the new formula within the given tap, specified as <user>`/`<repo>." switch "-f", "--force", description: "Ignore errors for disallowed formula names and named that shadow aliases." conflicts "--autotools", "--cmake", "--crystal", "--go", "--meson", "--node", "--perl", "--python", "--rust" named 1 end end |
.create_gist(files, description, private:) ⇒ Object
127 128 129 130 131 132 |
# File 'Library/Homebrew/cmd/gist-logs.rb', line 127 def create_gist(files, description, private:) url = "https://api.github.com/gists" data = { "public" => !private, "files" => files, "description" => description } scopes = GitHub::CREATE_GIST_SCOPES GitHub.open_api(url, data: data, scopes: scopes)["html_url"] end |
.create_issue(repo, title, body) ⇒ Object
134 135 136 137 138 139 |
# File 'Library/Homebrew/cmd/gist-logs.rb', line 134 def create_issue(repo, title, body) url = "https://api.github.com/repos/#{repo}/issues" data = { "title" => title, "body" => body } scopes = GitHub::CREATE_ISSUE_FORK_OR_PR_SCOPES GitHub.open_api(url, data: data, scopes: scopes)["html_url"] end |
.decorate_dependencies(dependencies) ⇒ Object
303 304 305 306 307 308 309 310 311 312 |
# File 'Library/Homebrew/cmd/info.rb', line 303 def decorate_dependencies(dependencies) deps_status = dependencies.map do |dep| if dep.satisfied?([]) pretty_installed(dep_display_s(dep)) else pretty_uninstalled(dep_display_s(dep)) end end deps_status.join(", ") end |
.decorate_requirements(requirements) ⇒ Object
314 315 316 317 318 319 320 |
# File 'Library/Homebrew/cmd/info.rb', line 314 def decorate_requirements(requirements) req_status = requirements.map do |req| req_s = req.display_s req.satisfied? ? pretty_installed(req_s) : pretty_uninstalled(req_s) end req_status.join(", ") end |
.default_prefix?(prefix = HOMEBREW_PREFIX) ⇒ Boolean
87 88 89 |
# File 'Library/Homebrew/global.rb', line 87 def Homebrew.default_prefix?(prefix = HOMEBREW_PREFIX) prefix.to_s == DEFAULT_PREFIX end |
.dep_display_name(dep, args:) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'Library/Homebrew/cmd/deps.rb', line 124 def dep_display_name(dep, args:) str = if dep.is_a? Requirement if args.include_requirements? ":#{dep.display_s}" else # This shouldn't happen, but we'll put something here to help debugging "::#{dep.name}" end elsif args.full_name? dep.to_formula.full_name else dep.name end if args.annotate? str = "#{str} " if args.tree? str = "#{str} [build]" if dep.build? str = "#{str} [test]" if dep.test? str = "#{str} [optional]" if dep.optional? str = "#{str} [recommended]" if dep.recommended? end str end |
.dep_display_s(dep) ⇒ Object
322 323 324 325 326 |
# File 'Library/Homebrew/cmd/info.rb', line 322 def dep_display_s(dep) return dep.name if dep..empty? "#{dep.name} #{dep..map { |o| "--#{o}" }.join(" ")}" end |
.deps ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'Library/Homebrew/cmd/deps.rb', line 63 def deps args = deps_args.parse Formulary.enable_factory_cache! recursive = !args.send("1?") installed = args.installed? || dependents(args.named.to_formulae_and_casks).all?(&:any_version_installed?) @use_runtime_dependencies = installed && recursive && !args.tree? && !args.include_build? && !args.include_test? && !args.include_optional? && !args.skip_recommended? if args.tree? dependents = if args.named.present? sorted_dependents(args.named.to_formulae_and_casks) elsif args.installed? sorted_dependents(Formula.installed + Cask::Caskroom.casks(config: Cask::Config.from_args(args))) else raise FormulaUnspecifiedError end puts_deps_tree dependents, recursive: recursive, args: args return elsif args.all? puts_deps sorted_dependents(Formula.to_a + Cask::Cask.to_a), recursive: recursive, args: args return elsif !args.no_named? && args.for_each? puts_deps sorted_dependents(args.named.to_formulae_and_casks), recursive: recursive, args: args return end if args.no_named? raise FormulaUnspecifiedError unless args.installed? puts_deps sorted_dependents(Formula.installed + Cask::Caskroom.casks(config: Cask::Config.from_args(args))), recursive: recursive, args: args return end dependents = dependents(args.named.to_formulae_and_casks) all_deps = deps_for_dependents(dependents, recursive: recursive, args: args, &(args.union? ? :| : :&)) condense_requirements(all_deps, args: args) all_deps.map! { |d| dep_display_name(d, args: args) } all_deps.uniq! all_deps.sort! unless args.n? puts all_deps end |
.deps_args ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'Library/Homebrew/cmd/deps.rb', line 15 def deps_args Homebrew::CLI::Parser.new do <<~EOS `deps` [<options>] [<formula>] Show dependencies for <formula>. Additional options specific to <formula> may be appended to the command. When given multiple formula arguments, show the intersection of dependencies for each formula. EOS switch "-n", description: "Sort dependencies in topological order." switch "--1", description: "Only show dependencies one level down, instead of recursing." switch "--union", description: "Show the union of dependencies for multiple <formula>, instead of the intersection." switch "--full-name", description: "List dependencies by their full name." switch "--include-build", description: "Include `:build` dependencies for <formula>." switch "--include-optional", description: "Include `:optional` dependencies for <formula>." switch "--include-test", description: "Include `:test` dependencies for <formula> (non-recursive)." switch "--skip-recommended", description: "Skip `:recommended` dependencies for <formula>." switch "--include-requirements", description: "Include requirements in addition to dependencies for <formula>." switch "--tree", description: "Show dependencies as a tree. When given multiple formula arguments, "\ "show individual trees for each formula." switch "--annotate", description: "Mark any build, test, optional, or recommended dependencies as "\ "such in the output." switch "--installed", description: "List dependencies for formulae that are currently installed. If <formula> is "\ "specified, list only its dependencies that are currently installed." switch "--all", description: "List dependencies for all available formulae." switch "--for-each", description: "Switch into the mode used by the `--all` option, but only list dependencies "\ "for each provided <formula>, one formula per line. This is used for "\ "debugging the `--installed`/`--all` display mode." conflicts "--installed", "--all" end end |
.deps_for_dependent(d, args:, recursive: false) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'Library/Homebrew/cmd/deps.rb', line 149 def deps_for_dependent(d, args:, recursive: false) includes, ignores = args_includes_ignores(args) deps = d.runtime_dependencies if @use_runtime_dependencies if recursive deps ||= recursive_includes(Dependency, d, includes, ignores) reqs = recursive_includes(Requirement, d, includes, ignores) else deps ||= reject_ignores(d.deps, ignores, includes) reqs = reject_ignores(d.requirements, ignores, includes) end deps + reqs.to_a end |
.deps_for_dependents(dependents, args:, recursive: false, &block) ⇒ Object
165 166 167 |
# File 'Library/Homebrew/cmd/deps.rb', line 165 def deps_for_dependents(dependents, args:, recursive: false, &block) dependents.map { |d| deps_for_dependent(d, recursive: recursive, args: args) }.reduce(&block) end |
.desc ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'Library/Homebrew/cmd/desc.rb', line 38 def desc args = desc_args.parse search_type = if args.search? :either elsif args.name? :name elsif args.description? :desc end results = if search_type.nil? desc = {} args.named.to_formulae.each { |f| desc[f.full_name] = f.desc } Descriptions.new(desc) else query = args.named.join(" ") string_or_regex = query_regexp(query) CacheStoreDatabase.use(:descriptions) do |db| cache_store = DescriptionCacheStore.new(db) Descriptions.search(string_or_regex, search_type, cache_store) end end results.print end |
.desc_args ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'Library/Homebrew/cmd/desc.rb', line 14 def desc_args Homebrew::CLI::Parser.new do <<~EOS `desc` [<options>] (<text>|`/`<text>`/`|<formula>) Display <formula>'s name and one-line description. Formula descriptions are cached; the cache is created on the first search, making that search slower than subsequent ones. EOS switch "-s", "--search", description: "Search both names and descriptions for <text>. If <text> is flanked by "\ "slashes, it is interpreted as a regular expression." switch "-n", "--name", description: "Search just names for <text>. If <text> is flanked by slashes, it is "\ "interpreted as a regular expression." switch "-d", "--description", description: "Search just descriptions for <text>. If <text> is flanked by slashes, "\ "it is interpreted as a regular expression." conflicts "--search", "--name", "--description" min_named 1 end end |
.detect_name(path, version) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'Library/Homebrew/dev-cmd/diy.rb', line 56 def detect_name(path, version) basename = path.basename.to_s detected_name = basename[/(.*?)-?#{Regexp.escape(version)}/, 1] || basename detected_name.downcase! canonical_name = Formulary.canonical_name(detected_name) odie <<~EOS if detected_name != canonical_name The detected name #{detected_name.inspect} exists in Homebrew as an alias of #{canonical_name.inspect}. Consider using the canonical name instead: brew diy --name=#{canonical_name} To continue using the detected name, pass it explicitly: brew diy --name=#{detected_name} EOS detected_name end |
.detect_version(path) ⇒ Object
49 50 51 52 53 54 |
# File 'Library/Homebrew/dev-cmd/diy.rb', line 49 def detect_version(path) version = path.version.to_s raise "Couldn't determine version, set it with --version=<version>" if version.empty? version end |
.determine_bump_subject(old_contents, new_contents, formula_path, reason: nil) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'Library/Homebrew/dev-cmd/pr-pull.rb', line 107 def determine_bump_subject(old_contents, new_contents, formula_path, reason: nil) formula_path = Pathname(formula_path) formula_name = formula_path.basename.to_s.chomp(".rb") new_formula = begin Formulary.from_contents(formula_name, formula_path, new_contents, :stable) rescue FormulaUnavailableError return "#{formula_name}: delete #{reason}".strip end old_formula = begin Formulary.from_contents(formula_name, formula_path, old_contents, :stable) rescue FormulaUnavailableError return "#{formula_name} #{new_formula.stable.version} (new formula)" end if old_formula.stable.version != new_formula.stable.version "#{formula_name} #{new_formula.stable.version}" elsif old_formula.revision != new_formula.revision "#{formula_name}: revision #{reason}".strip else "#{formula_name}: #{reason || "rebuild"}".strip end end |
.determine_formula_from_url(url) ⇒ Object
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'Library/Homebrew/dev-cmd/bump-formula-pr.rb', line 366 def determine_formula_from_url(url) # Split the new URL on / and find any formulae that have the same URL # except for the last component, but don't try to match any more than the # first five components since sometimes the last component isn't the only # one to change. url_split = url.split("/") maximum_url_components_to_match = 5 components_to_match = [url_split.count - 1, maximum_url_components_to_match].min base_url = url_split.first(components_to_match).join("/") base_url = /#{Regexp.escape(base_url)}/ guesses = [] Formula.each do |f| guesses << f if f.stable&.url && f.stable.url.match(base_url) end return guesses.shift if guesses.count == 1 return if guesses.count <= 1 odie "Couldn't guess formula for sure; could be one of these:\n#{guesses.map(&:name).join(", ")}" end |
.determine_mirror(url) ⇒ Object
386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'Library/Homebrew/dev-cmd/bump-formula-pr.rb', line 386 def determine_mirror(url) case url when %r{.*ftp.gnu.org/gnu.*} url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org" when %r{.*download.savannah.gnu.org/*} url.sub "download.savannah.gnu.org", "download-mirror.savannah.gnu.org" when %r{.*www.apache.org/dyn/closer.lua\?path=.*} url.sub "www.apache.org/dyn/closer.lua?path=", "archive.apache.org/dist/" when %r{.*mirrors.ocf.berkeley.edu/debian.*} url.sub "mirrors.ocf.berkeley.edu/debian", "mirrorservice.org/sites/ftp.debian.org/debian" end end |
.dispatch_build_bottle ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'Library/Homebrew/dev-cmd/dispatch-build-bottle.rb', line 30 def dispatch_build_bottle args = dispatch_build_bottle_args.parse raise FormulaUnspecifiedError if args.named.empty? odie "Must specify --macos option" unless args.macos macos = begin MacOS::Version.from_symbol(args.macos.to_sym) rescue MacOSVersionError MacOS::Version.new(args.macos) end tap = Tap.fetch(args.tap || CoreTap.instance.name) user, repo = tap.full_name.split("/") workflow = args.workflow || "dispatch-build-bottle.yml" ref = "master" args.named.to_resolved_formulae.each do |formula| # Required inputs inputs = { formula: formula.name, macos: macos.to_s, } # Optional inputs # These cannot be passed as nil to GitHub API inputs[:issue] = args.issue if args.issue inputs[:upload] = args.upload?.to_s if args.upload? ohai "Dispatching #{tap} bottling request of formula \"#{formula.name}\" for macOS #{macos}" GitHub.workflow_dispatch_event(user, repo, workflow, ref, inputs) end end |
.dispatch_build_bottle_args ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'Library/Homebrew/dev-cmd/dispatch-build-bottle.rb', line 10 def dispatch_build_bottle_args Homebrew::CLI::Parser.new do <<~EOS `dispatch-build-bottle` [<options>] <formula> [<formula> ...] Build bottles for these formulae with GitHub Actions. EOS flag "--tap=", description: "Target tap repository (default: `homebrew/core`)." flag "--issue=", description: "If specified, post a comment to this issue number if the job fails." flag "--macos=", description: "Version of macOS the bottle should be built for." flag "--workflow=", description: "Dispatch specified workflow (default: `dispatch-build-bottle.yml`)." switch "--upload", description: "Upload built bottles to Bintray." end end |
.display(formulae) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'Library/Homebrew/dev-cmd/bump.rb', line 77 def display(formulae) formulae.each do |formula, package_details| title = (up_to_date?(package_details) ? "#{formula} is up to date!" : formula).to_s ohai title puts "Current formula version: #{package_details[:current_formula_version]}" puts "Latest Repology version: #{package_details[:repology_latest_version]}" puts "Latest livecheck version: #{package_details[:livecheck_latest_version]}" puts "Open pull requests: #{package_details[:open_pull_requests]}" end end |
.diy ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'Library/Homebrew/dev-cmd/diy.rb', line 28 def diy args = diy_args.parse path = Pathname.getwd version = args.version || detect_version(path) name = args.name || detect_name(path, version) prefix = HOMEBREW_CELLAR/name/version if File.file? "CMakeLists.txt" puts "-DCMAKE_INSTALL_PREFIX=#{prefix}" elsif File.file? "configure" puts "--prefix=#{prefix}" elsif File.file? "meson.build" puts "-Dprefix=#{prefix}" else raise "Couldn't determine build system. You can manually put files into #{prefix}" end end |
.diy_args ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'Library/Homebrew/dev-cmd/diy.rb', line 10 def diy_args Homebrew::CLI::Parser.new do <<~EOS `diy` [<options>] Automatically determine the installation prefix for non-Homebrew software. Using the output from this command, you can install your own software into the Cellar and then link it into Homebrew's prefix with `brew link`. EOS flag "--name=", description: "Explicitly set the <name> of the package being installed." flag "--version=", description: "Explicitly set the <version> of the package being installed." max_named 0 end end |
.doctor ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'Library/Homebrew/cmd/doctor.rb', line 30 def doctor args = doctor_args.parse inject_dump_stats!(Diagnostic::Checks, /^check_*/) if args.audit_debug? checks = Diagnostic::Checks.new(verbose: args.verbose?) if args.list_checks? puts checks.all.sort return end if args.no_named? slow_checks = %w[ check_for_broken_symlinks check_missing_deps ] methods = (checks.all.sort - slow_checks) + slow_checks methods -= checks.cask_checks if Cask::Caskroom.casks.blank? else methods = args.named end first_warning = true methods.each do |method| $stderr.puts Formatter.headline("Checking #{method}", color: :magenta) if args.debug? unless checks.respond_to?(method) Homebrew.failed = true puts "No check available by the name: #{method}" next end out = checks.send(method) next if out.nil? || out.empty? if first_warning $stderr.puts <<~EOS #{Tty.bold}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!#{Tty.reset} EOS end $stderr.puts opoo out Homebrew.failed = true first_warning = false end puts "Your system is ready to brew." unless Homebrew.failed? end |
.doctor_args ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'Library/Homebrew/cmd/doctor.rb', line 11 def doctor_args Homebrew::CLI::Parser.new do <<~EOS `doctor` [<options>] Check your system for potential problems. Will exit with a non-zero status if any potential problems are found. 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. EOS switch "--list-checks", description: "List all audit methods, which can be run individually "\ "if provided as arguments." switch "-D", "--audit-debug", description: "Enable debugging and profiling of audit methods." end end |
.download_artifact(url, dir, pr) ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'Library/Homebrew/dev-cmd/pr-pull.rb', line 327 def download_artifact(url, dir, pr) token, username = GitHub.api_credentials case GitHub.api_credentials_type when :env_username_password, :keychain_username_password curl_args = ["--user", "#{username}:#{token}"] when :env_token curl_args = ["--header", "Authorization: token #{token}"] when :none raise "Credentials must be set to access the Artifacts API" end # Download the artifact as a zip file and unpack it into `dir`. This is # preferred over system `curl` and `tar` as this leverages the Homebrew # cache to avoid repeated downloads of (possibly large) bottles. FileUtils.chdir dir do downloader = GitHubArtifactDownloadStrategy.new(url, "artifact", pr, curl_args: curl_args, secrets: [token]) downloader.fetch downloader.stage end end |
.edit ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'Library/Homebrew/dev-cmd/edit.rb', line 21 def edit args = edit_args.parse unless (HOMEBREW_REPOSITORY/".git").directory? raise <<~EOS Changes will be lost! The first time you `brew update`, all local changes will be lost; you should thus `brew update` before you `brew edit`! EOS end paths = args.named.to_formulae_paths.select do |path| next path if path.exist? raise UsageError, "#{path} doesn't exist on disk. " \ "Run #{Formatter.identifier("brew create $URL")} to create a new Formula!" end.presence # If no brews are listed, open the project root in an editor. paths ||= [HOMEBREW_REPOSITORY] exec_editor(*paths) end |
.edit_args ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'Library/Homebrew/dev-cmd/edit.rb', line 10 def edit_args Homebrew::CLI::Parser.new do <<~EOS `edit` [<formula>] Open <formula> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, or open the Homebrew repository for editing if no formula is provided. EOS end end |
.ensure_relocation_formulae_installed! ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'Library/Homebrew/dev-cmd/bottle.rb', line 97 def ensure_relocation_formulae_installed! Keg.relocation_formulae.each do |f| next if Formula[f].latest_version_installed? ohai "Installing #{f}..." safe_system HOMEBREW_BREW_FILE, "install", f end end |
.env_vars_manpage ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 229 def env_vars_manpage lines = Homebrew::EnvConfig::ENVS.flat_map do |env, hash| entry = " * `#{env}`:\n #{hash[:description]}\n" default = hash[:default_text] default ||= "`#{hash[:default]}`." if hash[:default] entry += "\n\n *Default:* #{default}\n" if default entry end lines.join("\n") end |
.extract ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'Library/Homebrew/dev-cmd/extract.rb', line 101 def extract args = extract_args.parse if args.named.first !~ HOMEBREW_TAP_FORMULA_REGEX name = args.named.first.downcase source_tap = CoreTap.instance else name = Regexp.last_match(3).downcase source_tap = Tap.fetch(Regexp.last_match(1), Regexp.last_match(2)) raise TapFormulaUnavailableError.new(source_tap, name) unless source_tap.installed? end destination_tap = Tap.fetch(args.named.second) unless Homebrew::EnvConfig.developer? odie "Cannot extract formula to homebrew/core!" if destination_tap.core_tap? odie "Cannot extract formula to the same tap!" if destination_tap == source_tap end destination_tap.install unless destination_tap.installed? repo = source_tap.path pattern = if source_tap.core_tap? [repo/"Formula/#{name}.rb"] else # A formula can technically live in the root directory of a tap or in any of its subdirectories [repo/"#{name}.rb", repo/"**/#{name}.rb"] end if args.version ohai "Searching repository history" version = args.version version_segments = Gem::Version.new(version).segments if Gem::Version.correct?(version) rev = nil test_formula = nil result = "" loop do rev = rev.nil? ? "HEAD" : "#{rev}~1" rev, (path,) = Utils::Git.last_revision_commit_of_files(repo, pattern, before_commit: rev) if rev.nil? && source_tap.shallow? odie <<~EOS Could not find #{name} but #{source_tap} is a shallow clone! Try again after running: git -C "#{source_tap.path}" fetch --unshallow EOS elsif rev.nil? odie "Could not find #{name}! The formula or version may not have existed." end file = repo/path result = Utils::Git.last_revision_of_file(repo, file, before_commit: rev) if result.empty? odebug "Skipping revision #{rev} - file is empty at this revision" next end test_formula = formula_at_revision(repo, name, file, rev) break if test_formula.nil? || test_formula.version == version if version_segments && Gem::Version.correct?(test_formula.version) test_formula_version_segments = Gem::Version.new(test_formula.version).segments if version_segments.length < test_formula_version_segments.length odebug "Apply semantic versioning with #{test_formula_version_segments}" break if version_segments == test_formula_version_segments.first(version_segments.length) end end odebug "Trying #{test_formula.version} from revision #{rev} against desired #{version}" end odie "Could not find #{name}! The formula or version may not have existed." if test_formula.nil? else # Search in the root directory of <repo> as well as recursively in all of its subdirectories files = Dir[repo/"{,**/}"].map do |dir| Pathname.glob(["#{dir}/#{name}.rb"]).find(&:file?) end.compact if files.empty? ohai "Searching repository history" rev, (path,) = Utils::Git.last_revision_commit_of_files(repo, pattern) odie "Could not find #{name}! The formula or version may not have existed." if rev.nil? file = repo/path version = formula_at_revision(repo, name, file, rev).version result = Utils::Git.last_revision_of_file(repo, file) else file = files.first.realpath rev = "HEAD" version = Formulary.factory(file).version result = File.read(file) end end # The class name has to be renamed to match the new filename, # e.g. Foo version 1.2.3 becomes FooAT123 and resides in [email protected] class_name = Formulary.class_s(name) # Remove any existing version suffixes, as a new one will be added later name.sub!(/\[email protected](.*)\z\b/i, "") versioned_name = Formulary.class_s("#{name}@#{version}") result.sub!("class #{class_name} < Formula", "class #{versioned_name} < Formula") # Remove bottle blocks, they won't work. result.sub!(/ bottle do.+?end\n\n/m, "") if destination_tap != source_tap path = destination_tap.path/"Formula/#{name}@#{version}.rb" if path.exist? unless args.force? odie <<~EOS Destination formula already exists: #{path} To overwrite it and continue anyways, run: brew extract --force --version=#{version} #{name} #{destination_tap.name} EOS end odebug "Overwriting existing formula at #{path}" path.delete end ohai "Writing formula for #{name} from revision #{rev} to:" puts path path.write result end |
.extract_args ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'Library/Homebrew/dev-cmd/extract.rb', line 81 def extract_args Homebrew::CLI::Parser.new do <<~EOS `extract` [<options>] <formula> <tap> Look through repository history to find the most recent version of <formula> and create a copy in <tap>`/Formula/`<formula>`@`<version>`.rb`. If the tap is not installed yet, attempt to install/clone the tap before continuing. To extract a formula from a tap that is not `homebrew/core` use its fully-qualified form of <user>`/`<repo>`/`<formula>. EOS flag "--version=", description: "Extract the specified <version> of <formula> instead of the most recent." switch "-f", "--force", description: "Overwrite the destination formula if it already exists." named 2 end end |
.failed? ⇒ Boolean
91 92 93 94 |
# File 'Library/Homebrew/global.rb', line 91 def failed? @failed ||= false @failed == true end |
.fetch ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'Library/Homebrew/cmd/fetch.rb', line 49 def fetch args = fetch_args.parse if args.deps? bucket = [] args.named.to_formulae.each do |f| bucket << f bucket.concat f.recursive_dependencies.map(&:to_formula) end bucket.uniq! else bucket = args.named.to_formulae end puts "Fetching: #{bucket * ", "}" if bucket.size > 1 bucket.each do |f| f.print_tap_action verb: "Fetching" fetched_bottle = false if fetch_bottle?(f, args: args) begin fetch_formula(f.bottle, args: args) rescue Interrupt raise rescue => e raise if Homebrew::EnvConfig.developer? fetched_bottle = false onoe e. opoo "Bottle fetch failed: fetching the source." else fetched_bottle = true end end next if fetched_bottle fetch_formula(f, args: args) f.resources.each do |r| fetch_resource(r, args: args) r.patches.each { |p| fetch_patch(p, args: args) if p.external? } end f.patchlist.each { |p| fetch_patch(p, args: args) if p.external? } end end |
.fetch_args ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'Library/Homebrew/cmd/fetch.rb', line 13 def fetch_args Homebrew::CLI::Parser.new do <<~EOS `fetch` [<options>] <formula> Download a bottle (if available) or source packages for <formula>. For tarballs, also print SHA-256 checksums. EOS switch "--HEAD", description: "Fetch HEAD version instead of stable version." switch "--devel", description: "Fetch development version instead of stable version." switch "-f", "--force", description: "Remove a previously cached version and re-fetch." switch "-v", "--verbose", description: "Do a verbose VCS checkout, if the URL represents a VCS. This is useful for "\ "seeing if an existing VCS cache has been updated." switch "--retry", description: "Retry if downloading fails or re-download if the checksum of a previously cached "\ "version no longer matches." switch "--deps", description: "Also download dependencies for any listed <formula>." switch "-s", "--build-from-source", description: "Download source packages rather than a bottle." switch "--build-bottle", description: "Download source packages (for eventual bottling) rather than a bottle." switch "--force-bottle", description: "Download a bottle if it exists for the current or newest version of macOS, "\ "even if it would not be used during installation." conflicts "--devel", "--HEAD" conflicts "--build-from-source", "--build-bottle", "--force-bottle" min_named :formula end end |
.fetch_fetchable(f, args:) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'Library/Homebrew/cmd/fetch.rb', line 131 def fetch_fetchable(f, args:) f.clear_cache if args.force? already_fetched = f.cached_download.exist? begin download = f.fetch(verify_download_integrity: false) rescue DownloadError retry if retry_fetch?(f, args: args) raise end return unless download.file? puts "Downloaded to: #{download}" unless already_fetched puts Checksum::TYPES.map { |t| "#{t.to_s.upcase}: #{download.send(t)}" } f.verify_download_integrity(download) end |
.fetch_formula(f, args:) ⇒ Object
105 106 107 108 109 110 |
# File 'Library/Homebrew/cmd/fetch.rb', line 105 def fetch_formula(f, args:) fetch_fetchable f, args: args rescue ChecksumMismatchError => e retry if retry_fetch?(f, args: args) opoo "Formula reports different #{e.hash_type}: #{e.expected}" end |
.fetch_patch(p, args:) ⇒ Object
112 113 114 115 116 117 |
# File 'Library/Homebrew/cmd/fetch.rb', line 112 def fetch_patch(p, args:) fetch_fetchable p, args: args rescue ChecksumMismatchError => e Homebrew.failed = true opoo "Patch reports different #{e.hash_type}: #{e.expected}" end |
.fetch_resource(formula, new_version, url, **specs) ⇒ Object
97 98 99 100 101 102 103 |
# File 'Library/Homebrew/cmd/fetch.rb', line 97 def fetch_resource(r, args:) puts "Resource: #{r.name}" fetch_fetchable r, args: args rescue ChecksumMismatchError => e retry if retry_fetch?(r, args: args) opoo "Resource #{r.name} reports different #{e.hash_type}: #{e.expected}" end |
.filtered_list(args:) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'Library/Homebrew/cmd/list.rb', line 160 def filtered_list(args:) names = if args.no_named? Formula.racks else racks = args.named.map { |n| Formulary.to_rack(n) } racks.select do |rack| Homebrew.failed = true unless rack.exist? rack.exist? end end if args.pinned? pinned_versions = {} names.sort.each do |d| keg_pin = (HOMEBREW_PINNED_KEGS/d.basename.to_s) pinned_versions[d] = keg_pin.readlink.basename.to_s if keg_pin.exist? || keg_pin.symlink? end pinned_versions.each do |d, version| puts d.basename.to_s.concat(args.versions? ? " #{version}" : "") end else # --versions without --pinned names.sort.each do |d| versions = d.subdirs.map { |pn| pn.basename.to_s } next if args.multiple? && versions.length < 2 puts "#{d.basename} #{versions * " "}" end end end |
.find_in_path(executable) ⇒ Object
87 88 89 90 91 |
# File 'Library/Homebrew/utils/gems.rb', line 87 def find_in_path(executable) ENV["PATH"].split(":").find do |path| File.executable?("#{path}/#{executable}") end end |
.force_auto_update?(args:) ⇒ Boolean
75 76 77 78 |
# File 'Library/Homebrew/cmd/tap.rb', line 75 def force_auto_update?(args:) # if no relevant flag is present, return nil, meaning "no change" true if args.force_auto_update? end |
.format_long_opt(opt) ⇒ Object
253 254 255 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 253 def format_long_opt(opt) "`#{opt}`" unless opt.nil? end |
.format_problem(message, location) ⇒ Object
186 187 188 |
# File 'Library/Homebrew/dev-cmd/audit.rb', line 186 def format_problem(, location) "* #{location&.to_s&.dup&.concat(": ")}#{.chomp.gsub("\n", "\n ")}" end |
.format_problem_lines(problems) ⇒ Object
181 182 183 184 |
# File 'Library/Homebrew/dev-cmd/audit.rb', line 181 def format_problem_lines(problems) problems.uniq .map { |message:, location:| format_problem(, location) } end |
.format_short_opt(opt) ⇒ Object
249 250 251 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 249 def format_short_opt(opt) "`#{opt}`" unless opt.nil? end |
.format_usage_banner(usage_banner) ⇒ Object
257 258 259 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 257 def () &.sub(/^(#: *\* )?/, "### ") end |
.formula ⇒ Object
22 23 24 25 26 |
# File 'Library/Homebrew/dev-cmd/formula.rb', line 22 def formula args = formula_args.parse args.named.to_formulae_paths.each(&method(:puts)) end |
.formula_args ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'Library/Homebrew/dev-cmd/formula.rb', line 10 def formula_args Homebrew::CLI::Parser.new do <<~EOS `formula` <formula> Display the path where <formula> is located. EOS min_named :formula end end |
.formula_version(formula, spec, contents = nil) ⇒ Object
422 423 424 425 426 427 428 429 430 |
# File 'Library/Homebrew/dev-cmd/bump-formula-pr.rb', line 422 def formula_version(formula, spec, contents = nil) name = formula.name path = formula.path if contents Formulary.from_contents(name, path, contents, spec).version else Formulary::FormulaLoader.new(name, path).get_formula(spec).version end end |
.formulae_need_bottles?(tap, original_commit, args:) ⇒ Boolean
281 282 283 284 285 286 287 |
# File 'Library/Homebrew/dev-cmd/pr-pull.rb', line 281 def formulae_need_bottles?(tap, original_commit, args:) return if args.dry_run? changed_formulae(tap, original_commit).any? do |f| !f.bottle_unneeded? && !f.bottle_disabled? end end |
.gem_user_bindir ⇒ Object
20 21 22 23 |
# File 'Library/Homebrew/utils/gems.rb', line 20 def gem_user_bindir require "rubygems" "#{Gem.user_dir}/bin" end |
.generate_cmd_manpages(cmd_paths) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 153 def generate_cmd_manpages(cmd_paths) man_page_lines = [] # preserve existing manpage order cmd_paths.sort_by(&method(:sort_key_for_path)) .each do |cmd_path| cmd_man_page_lines = if cmd_parser = CLI::Parser.from_cmd_path(cmd_path) next if cmd_parser.hide_from_man_page cmd_parser_manpage_lines(cmd_parser).join else cmd_comment_manpage_lines(cmd_path) end man_page_lines << cmd_man_page_lines end man_page_lines.compact.join("\n") end |
.generate_option_doc(short, long, desc) ⇒ Object
241 242 243 244 245 246 247 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 241 def generate_option_doc(short, long, desc) comma = (short && long) ? ", " : "" <<~EOS * #{format_short_opt(short)}#{comma}#{format_long_opt(long)}: #{desc} EOS end |
.gist_logs ⇒ Object
141 142 143 144 145 146 147 |
# File 'Library/Homebrew/cmd/gist-logs.rb', line 141 def gist_logs args = gist_logs_args.parse Install.perform_preinstall_checks(all_fatal: true) Install.perform_build_from_source_checks(all_fatal: true) gistify_logs(args.named.to_resolved_formulae.first, args: args) end |
.gist_logs_args ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'Library/Homebrew/cmd/gist-logs.rb', line 16 def gist_logs_args Homebrew::CLI::Parser.new do <<~EOS `gist-logs` [<options>] <formula> Upload logs for a failed build of <formula> to a new Gist. Presents an error message if no logs are found. EOS switch "--with-hostname", description: "Include the hostname in the Gist." switch "-n", "--new-issue", description: "Automatically create a new issue in the appropriate GitHub repository "\ "after creating the Gist." switch "-p", "--private", description: "The Gist will be marked private and will not appear in listings but will "\ "be accessible with its link." named :formula end end |
.gistify_logs(f, args:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'Library/Homebrew/cmd/gist-logs.rb', line 37 def gistify_logs(f, args:) files = load_logs(f.logs) build_time = f.logs.ctime = build_time.strftime("%Y-%m-%d_%H-%M-%S") s = StringIO.new SystemConfig.dump_verbose_config s # Dummy summary file, asciibetically first, to control display title of gist files["# #{f.name} - #{}.txt"] = { content: brief_build_info(f, with_hostname: args.with_hostname?) } files["00.config.out"] = { content: s.string } files["00.doctor.out"] = { content: Utils.popen_read("#{HOMEBREW_PREFIX}/bin/brew", "doctor", err: :out) } unless f.core_formula? tap = <<~EOS Formula: #{f.name} Tap: #{f.tap} Path: #{f.path} EOS files["00.tap.out"] = { content: tap } end if GitHub.api_credentials_type == :none puts <<~EOS You can create a new personal access token: #{GitHub::ALL_SCOPES_URL} #{Utils::Shell.set_variable_in_profile("HOMEBREW_GITHUB_API_TOKEN", "your_token_here")} EOS odeprecated "`brew gist-logs` with a password", "HOMEBREW_GITHUB_API_TOKEN" login! end # Description formatted to work well as page title when viewing gist descr = if f.core_formula? "#{f.name} on #{OS_VERSION} - Homebrew build logs" else "#{f.name} (#{f.full_name}) on #{OS_VERSION} - Homebrew build logs" end url = create_gist(files, descr, private: args.private?) url = create_issue(f.tap, "#{f.name} failed to build on #{MacOS.full_version}", url) if args.new_issue? puts url if url end |
.git_log(cd_dir, path = nil, tap = nil, args:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'Library/Homebrew/cmd/log.rb', line 49 def git_log(cd_dir, path = nil, tap = nil, args:) cd cd_dir repo = Utils.popen_read("git rev-parse --show-toplevel").chomp if tap name = tap.to_s git_cd = "$(brew --repo #{tap})" elsif cd_dir == HOMEBREW_REPOSITORY name = "Homebrew/brew" git_cd = "$(brew --repo)" else name, git_cd = cd_dir end if File.exist? "#{repo}/.git/shallow" opoo <<~EOS #{name} is a shallow clone so only partial output will be shown. To get a full clone run: git -C "#{git_cd}" fetch --unshallow EOS end git_args = [] git_args << "--patch" if args.patch? git_args << "--stat" if args.stat? git_args << "--oneline" if args.oneline? git_args << "-1" if args.public_send(:'1?') git_args << "--max-count" << args.max_count if args.max_count git_args += ["--follow", "--", path] if path.present? system "git", "log", *git_args end |
.github_info(f) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'Library/Homebrew/cmd/info.rb', line 198 def github_info(f) if f.tap if remote = f.tap.remote path = if f.class.superclass == Formula f.path.relative_path_from(f.tap.path) elsif f.is_a?(Cask::Cask) f.sourcefile_path.relative_path_from(f.tap.path) end github_remote_path(remote, path) else f.path end else f.path end end |
.github_releases?(bottles_hash) ⇒ Boolean
47 48 49 50 51 52 53 54 55 |
# File 'Library/Homebrew/dev-cmd/pr-upload.rb', line 47 def github_releases?(bottles_hash) @github_releases ||= bottles_hash.values.all? do |bottle_hash| root_url = bottle_hash["bottle"]["root_url"] url_match = root_url.match HOMEBREW_RELEASES_URL_REGEX _, _, _, tag = *url_match tag end end |
.github_remote_path(remote, path) ⇒ Object
190 191 192 193 194 195 196 |
# File 'Library/Homebrew/cmd/info.rb', line 190 def github_remote_path(remote, path) if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$} "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/HEAD/#{path}" else "#{remote}/#{path}" end end |
.global_cask_options_manpage ⇒ Object
213 214 215 216 217 218 219 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 213 def lines = ["These options are applicable to subcommands accepting a `--cask` flag and all `cask` commands.\n"] lines += Homebrew::CLI::Parser..map do |_, long, description:, **| generate_option_doc(nil, long, description) end lines.join("\n") end |
.global_options_manpage ⇒ Object
221 222 223 224 225 226 227 |
# File 'Library/Homebrew/dev-cmd/man.rb', line 221 def lines = ["These options are applicable across multiple subcommands.\n"] lines += Homebrew::CLI::Parser..map do |short, long, desc| generate_option_doc(short, long, desc) end lines.join("\n") end |
.handle_unsatisfied_dependents(kegs_by_rack, ignore_dependencies: false, named_args: []) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'Library/Homebrew/cmd/uninstall.rb', line 148 def handle_unsatisfied_dependents(kegs_by_rack, ignore_dependencies: false, named_args: []) return if ignore_dependencies all_kegs = kegs_by_rack.values.flatten(1) check_for_dependents(all_kegs, named_args: named_args) rescue MethodDeprecatedError # Silently ignore deprecations when uninstalling. nil end |
.home ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'Library/Homebrew/cmd/home.rb', line 20 def home args = home_args.parse if args.no_named? exec_browser HOMEBREW_WWW return end homepages = args.named.to_formulae_and_casks.map do |formula_or_cask| puts "Opening homepage for #{name_of(formula_or_cask)}" formula_or_cask.homepage end exec_browser(*homepages) end |
.home_args ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'Library/Homebrew/cmd/home.rb', line 9 def home_args Homebrew::CLI::Parser.new do <<~EOS `home` [<formula>] Open <formula>'s homepage in a browser, or open Homebrew's own homepage if no formula is provided. EOS end end |
.info ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'Library/Homebrew/cmd/info.rb', line 65 def info args = info_args.parse if args.analytics? if args.days.present? && !VALID_DAYS.include?(args.days) raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}" end if args.category.present? if args.named.present? && !VALID_FORMULA_CATEGORIES.include?(args.category) raise UsageError, "--category must be one of #{VALID_FORMULA_CATEGORIES.join(", ")} when querying formulae" end unless VALID_CATEGORIES.include?(args.category) raise UsageError, "--category must be one of #{VALID_CATEGORIES.join(", ")}" end end print_analytics(args: args) elsif args.json print_json(args: args) elsif args.github? raise FormulaOrCaskUnspecifiedError if args.no_named? exec_browser(*args.named.to_formulae_and_casks.map { |f| github_info(f) }) else print_info(args: args) end end |
.info_args ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'Library/Homebrew/cmd/info.rb', line 22 def info_args Homebrew::CLI::Parser.new do <<~EOS `info` [<options>] [<formula>] Display brief statistics for your Homebrew installation. If <formula> is provided, show summary of information about <formula>. EOS switch "--analytics", description: "List global Homebrew analytics data or, if specified, installation and "\ "build error data for <formula> (provided neither `HOMEBREW_NO_ANALYTICS` "\ "nor `HOMEBREW_NO_GITHUB_API` are set)." flag "--days=", depends_on: "--analytics", description: "How many days of analytics data to retrieve. "\ "The value for <days> must be `30`, `90` or `365`. The default is `30`." flag "--category=", depends_on: "--analytics", description: "Which type of analytics data to retrieve. "\ "The value for <category> must be `install`, `install-on-request` or `build-error`; "\ "`cask-install` or `os-version` may be specified if <formula> is not. "\ "The default is `install`." switch "--github", description: "Open the GitHub source page for <formula> in a browser. "\ "To view formula history locally: `brew log -p` <formula>" flag "--json", description: "Print a JSON representation of <formula>. Currently the default and only accepted "\ "value for <version> is `v1`. See the docs for examples of using the JSON "\ "output: <https://docs.brew.sh/Querying-Brew>" switch "--installed", depends_on: "--json", description: "Print JSON of formulae that are currently installed." switch "--all", depends_on: "--json", description: "Print JSON of all available formulae." switch "-v", "--verbose", description: "Show more verbose analytics data for <formula>." conflicts "--installed", "--all" end end |
.info_cask(cask, args:) ⇒ Object
328 329 330 331 332 |
# File 'Library/Homebrew/cmd/info.rb', line 328 def info_cask(cask, args:) require "cask/cmd/info" Cask::Cmd::Info.info(cask) end |
.info_formula(f, args:) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'Library/Homebrew/cmd/info.rb', line 215 def info_formula(f, args:) specs = [] if stable = f.stable s = "stable #{stable.version}" s += " (bottled)" if stable.bottled? specs << s end specs << "HEAD" if f.head attrs = [] attrs << "pinned at #{f.pinned_version}" if f.pinned? attrs << "keg-only" if f.keg_only? puts "#{f.full_name}: #{specs * ", "}#{" [#{attrs * ", "}]" unless attrs.empty?}" puts f.desc if f.desc puts Formatter.url(f.homepage) if f.homepage deprecate_disable_type, deprecate_disable_reason = DeprecateDisable.deprecate_disable_info f if deprecate_disable_type.present? if deprecate_disable_reason.present? puts "#{deprecate_disable_type.capitalize} because it #{deprecate_disable_reason}!" else puts "#{deprecate_disable_type.capitalize}!" end end conflicts = f.conflicts.map do |c| reason = " (because #{c.reason})" if c.reason "#{c.name}#{reason}" end.sort! unless conflicts.empty? puts <<~EOS Conflicts with: #{conflicts.join("\n ")} EOS end kegs = f.installed_kegs heads, versioned = kegs.partition { |k| k.version.head? } kegs = [ *heads.sort_by { |k| -Tab.for_keg(k).time.to_i }, *versioned.sort_by(&:version), ] if kegs.empty? puts "Not installed" else kegs.each do |keg| puts "#{keg} (#{keg.abv})#{" *" if keg.linked?}" tab = Tab.for_keg(keg).to_s puts " #{tab}" unless tab.empty? end end puts "From: #{Formatter.url(github_info(f))}" puts "License: #{SPDX.license_expression_to_string f.license}" if f.license.present? unless f.deps.empty? ohai "Dependencies" %w[build required recommended optional].map do |type| deps = f.deps.send(type).uniq puts "#{type.capitalize}: #{decorate_dependencies deps}" unless deps.empty? end end unless f.requirements.to_a.empty? ohai "Requirements" %w[build required recommended optional].map do |type| reqs = f.requirements.select(&:"#{type}?") next if reqs.to_a.empty? puts "#{type.capitalize}: #{decorate_requirements(reqs)}" end end if !f..empty? || f.head ohai "Options" Options.dump_for_formula f end caveats = Caveats.new(f) ohai "Caveats", caveats.to_s unless caveats.empty? Utils::Analytics.formula_output(f, args: args) end |
.inject_dump_stats!(the_module, pattern) ⇒ Object
rubocop:disable Style/GlobalVars
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'Library/Homebrew/utils.rb', line 50 def inject_dump_stats!(the_module, pattern) @injected_dump_stat_modules ||= {} @injected_dump_stat_modules[the_module] ||= [] injected_methods = @injected_dump_stat_modules[the_module] the_module.module_eval do instance_methods.grep(pattern).each do |name| next if injected_methods.include? name method = instance_method(name) define_method(name) do |*args, &block| time = Time.now method.bind(self).call(*args, &block) ensure $times[name] ||= 0 $times[name] += Time.now - time end end end return unless $times.nil? $times = {} at_exit do col_width = [$times.keys.map(&:size).max.to_i + 2, 15].max $times.sort_by { |_k, v| v }.each do |method, time| puts format("%<method>-#{col_width}s %<time>0.4f sec", method: "#{method}:", time: time) end end end |
.install ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'Library/Homebrew/cmd/install.rb', line 130 def install args = install_args.parse only = :formula if args.formula? && !args.cask? only = :cask if args.cask? && !args.formula? args.named.each do |name| next if File.exist?(name) next if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX tap = Tap.fetch(Regexp.last_match(1), Regexp.last_match(2)) tap.install unless tap.installed? end if args.ignore_dependencies? opoo <<~EOS #{Tty.bold}--ignore-dependencies is an unsupported Homebrew developer flag!#{Tty.reset} Adjust your PATH to put any preferred versions of applications earlier in the PATH rather than using this unsupported flag! EOS end formulae, casks = args.named.to_formulae_and_casks(only: only) .partition { |formula_or_cask| formula_or_cask.is_a?(Formula) } if casks.any? Cask::Cmd::Install.install_casks( *casks, binaries: args.binaries?, verbose: args.verbose?, force: args.force?, skip_cask_deps: args.skip_cask_deps?, require_sha: args.require_sha?, quarantine: args.quarantine?, ) end # if the user's flags will prevent bottle only-installations when no # developer tools are available, we need to stop them early on FormulaInstaller.prevent_build_flags(args) installed_formulae = [] formulae.each do |f| # head-only without --HEAD is an error if !args.HEAD? && f.stable.nil? raise <<~EOS #{f.full_name} is a head-only formula Install with `brew install --HEAD #{f.full_name}` EOS end # --HEAD, fail with no head defined raise "No head is defined for #{f.full_name}" if args.HEAD? && f.head.nil? installed_head_version = f.latest_head_version if installed_head_version && !f.head_version_outdated?(installed_head_version, fetch_head: args.fetch_HEAD?) new_head_installed = true end prefix_installed = f.prefix.exist? && !f.prefix.children.empty? if f.keg_only? && f.any_version_installed? && f.optlinked? && !args.force? # keg-only install is only possible when no other version is # linked to opt, because installing without any warnings can break # dependencies. Therefore before performing other checks we need to be # sure --force flag is passed. if f.outdated? optlinked_version = Keg.for(f.opt_prefix).version onoe <<~EOS #{f.full_name} #{optlinked_version} is already installed To upgrade to #{f.version}, run `brew upgrade #{f.full_name}` EOS elsif args.only_dependencies? installed_formulae << f else opoo <<~EOS #{f.full_name} #{f.pkg_version} is already installed and up-to-date To reinstall #{f.pkg_version}, run `brew reinstall #{f.name}` EOS end elsif (args.HEAD? && new_head_installed) || prefix_installed # After we're sure that --force flag is passed for linked to opt # keg-only we need to be sure that the version we're attempting to # install is not already installed. installed_version = if args.HEAD? f.latest_head_version else f.pkg_version end msg = "#{f.full_name} #{installed_version} is already installed" linked_not_equals_installed = f.linked_version != installed_version if f.linked? && linked_not_equals_installed msg = <<~EOS #{msg} The currently linked version is #{f.linked_version} You can use `brew switch #{f} #{installed_version}` to link this version. EOS elsif !f.linked? || f.keg_only? msg = <<~EOS #{msg}, it's just not linked You can use `brew link #{f}` to link this version. EOS elsif args.only_dependencies? msg = nil installed_formulae << f else msg = <<~EOS #{msg} and up-to-date To reinstall #{f.pkg_version}, run `brew reinstall #{f.name}` EOS end opoo msg if msg elsif !f.any_version_installed? && old_formula = f.old_installed_formulae.first msg = "#{old_formula.full_name} #{old_formula.any_installed_version} already installed" if !old_formula.linked? && !old_formula.keg_only? msg = <<~EOS #{msg}, it's just not linked. You can use `brew link #{old_formula.full_name}` to link this version. EOS end opoo msg elsif f.migration_needed? && !args.force? # Check if the formula we try to install is the same as installed # but not migrated one. If --force is passed then install anyway. opoo <<~EOS #{f.oldname} is already installed, it's just not migrated You can migrate this formula with `brew migrate #{f}` Or you can force install it with `brew install #{f} --force` EOS else # If none of the above is true and the formula is linked, then # FormulaInstaller will handle this case. installed_formulae << f end # Even if we don't install this formula mark it as no longer just # installed as a dependency. next unless f.opt_prefix.directory? keg = Keg.new(f.opt_prefix.resolved_path) tab = Tab.for_keg(keg) unless tab.installed_on_request tab.installed_on_request = true tab.write end end return if installed_formulae.empty? Install.perform_preinstall_checks(cc: args.cc) installed_formulae.each do |f| Migrator.migrate_if_needed(f, force: args.force?) install_formula(f, args: args) Cleanup.install_formula_clean!(f) end Upgrade.check_installed_dependents(args: args) Homebrew..(display_times: args.display_times?) rescue FormulaUnreadableError, FormulaClassUnavailableError, TapFormulaUnreadableError, TapFormulaClassUnavailableError => e # Need to rescue before `FormulaUnavailableError` (superclass of this) # is handled, as searching for a formula doesn't make sense here (the # formula was found, but there's a problem with its implementation). $stderr.puts e.backtrace if Homebrew::EnvConfig.developer? ofail e. rescue FormulaOrCaskUnavailableError => e if e.name == "updog" ofail "What's updog?" return end ohai "Searching for similarly named formulae..." formulae_search_results = search_formulae(e.name) case formulae_search_results.length when 0 ofail "No similarly named formulae found." when 1 puts "This similarly named formula was found:" puts formulae_search_results puts "To install it, run:\n brew install #{formulae_search_results.first}" else puts "These similarly named formulae were found:" puts Formatter.columns(formulae_search_results) puts "To install one of them, run (for example):\n brew install #{formulae_search_results.first}" end ofail e. if (reason = MissingFormula.reason(e.name)) $stderr.puts reason return end # Do not search taps if the formula name is qualified return if e.name.include?("/") taps_search_results = search_taps(e.name)[:formulae] case taps_search_results.length when 0 ofail "No formulae found in taps." when 1 puts "This formula was found in a tap:" puts taps_search_results puts "To install it, run:\n brew install #{taps_search_results.first}" else puts "These formulae were found in taps:" puts Formatter.columns(taps_search_results) puts "To install one of them, run (for example):\n brew install #{taps_search_results.first}" end end |
.install_args ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'Library/Homebrew/cmd/install.rb', line 21 def install_args Homebrew:: |