Merge branch 'master' into mkdir_with_intermediates

This commit is contained in:
Mike McQuaid 2016-09-24 20:48:03 +01:00
commit e767fd3df9
299 changed files with 7626 additions and 8672 deletions

View File

@ -1,4 +1,4 @@
- [ ] Have you followed the guidelines in our [Contributing](https://github.com/Homebrew/brew/blob/master/.github/CONTRIBUTING.md) document?
- [ ] Have you followed the guidelines in our [Contributing](https://github.com/Homebrew/brew/blob/master/CONTRIBUTING.md) document?
- [ ] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/Homebrew/brew/pulls) for the same change?
- [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
- [ ] Have you written new tests for your changes? [Here's an example](https://github.com/Homebrew/homebrew/pull/49031).

2
.gitignore vendored
View File

@ -13,11 +13,13 @@
/Library/Homebrew/cask/bin
/Library/Homebrew/cask/vendor
/Library/Homebrew/cask/coverage
/Library/Homebrew/cask/tmp
/Library/Homebrew/test/.bundle
/Library/Homebrew/test/bin
/Library/Homebrew/test/vendor
/Library/Homebrew/test/coverage
/Library/Homebrew/test/fs_leak_log
/Library/Homebrew/tmp
/Library/LinkedKegs
/Library/Locks
/Library/PinnedKegs

View File

@ -4,6 +4,8 @@ inherit_from:
AllCops:
TargetRubyVersion: 2.0
Include:
- '**/.simplecov'
Exclude:
- 'Homebrew/cask/**/*'
- 'Homebrew/vendor/**/*'

View File

@ -1,4 +1,3 @@
# ruby style guide favorite
Style/StringLiterals:
EnforcedStyle: double_quotes
@ -7,17 +6,30 @@ Style/StringLiterals:
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
# only for numbers >= 1_000_000
Style/NumericLiterals:
MinDigits: 7
# zero-prefixed octal literals are just too widely used (and mostly understood)
Style/NumericLiteralPrefix:
EnforcedOctalStyle: zero_only
# percent-x is allowed for multiline
Style/CommandLiteral:
EnforcedStyle: mixed
# depends_on foo: :bar looks rubbish
Style/HashSyntax:
EnforcedStyle: ruby19
Exclude:
- 'Taps/**/*'
# paths abound, easy escape
Style/RegexpLiteral:
EnforcedStyle: slashes
# too prevalent to change this now, but might be discussed/changed later
Style/Alias:
EnforcedStyle: prefer_alias_method
EnforcedStyle: prefer_alias
# our current conditional style is established, clear and
# requiring users to change that now would be confusing.
@ -58,14 +70,6 @@ Lint/ParenthesesAsGroupedExpression:
Style/EmptyLineBetweenDefs:
AllowAdjacentOneLineDefs: true
# port numbers and such tech stuff
Style/NumericLiterals:
Enabled: false
# zero-prefixed octal literals are just too widely used (and mostly understood)
Style/NumericLiteralPrefix:
EnforcedOctalStyle: zero_only
# consistency and readability when faced with string interpolation
Style/PercentLiteralDelimiters:
PreferredDelimiters:
@ -93,15 +97,25 @@ Style/AlignParameters:
# counterproductive in formulas, notably within the install method
Style/GuardClause:
Enabled: false
Exclude:
- 'Taps/**/*'
Style/IfUnlessModifier:
Exclude:
- 'Taps/**/*'
# TODO: enforce when rubocop has fixed this
# https://github.com/bbatsov/rubocop/issues/3516
Style/VariableNumber:
Enabled: false
# TODO: enforce when rubocop has shipped this
# https://github.com/bbatsov/rubocop/pull/3513
Style/TernaryParentheses:
Enabled: false
# dashes in filenames are typical
# TODO: enforce when rubocop has fixed this
# https://github.com/bbatsov/rubocop/issues/1545
Style/FileName:
Enabled: false
Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/
# no percent word array, being friendly to non-ruby users
# TODO: enforce when rubocop has fixed this
@ -134,6 +148,7 @@ Style/MethodName:
Style/PredicateName:
Exclude:
- 'Homebrew/compat/**/*'
NameWhitelist: is_32_bit?, is_64_bit?
# `formula do` uses nested method definitions
Lint/NestedMethodDefinition:

View File

@ -1,21 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 30`
# on 2016-09-18 15:15:22 +0100 using RuboCop version 0.41.2.
# `rubocop --auto-gen-config --exclude-limit 100`
# on 2016-09-22 20:07:41 +0200 using RuboCop version 0.43.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
# SupportedStyles: keyword, variable, start_of_line
Lint/EndAlignment:
Exclude:
- 'Homebrew/download_strategy.rb'
- 'Homebrew/keg.rb'
- 'Homebrew/os/mac/cctools_mach.rb'
# Offense count: 18
Lint/HandleExceptions:
Exclude:
@ -52,11 +42,6 @@ Lint/NestedMethodDefinition:
- 'Homebrew/dev-cmd/bottle.rb'
- 'Homebrew/dev-cmd/test-bot.rb'
# Offense count: 2
Lint/NonLocalExitFromIterator:
Exclude:
- 'Homebrew/extend/pathname.rb'
# Offense count: 28
Lint/RescueException:
Exclude:
@ -80,12 +65,7 @@ Lint/RescueException:
# Offense count: 1
Lint/ShadowedException:
Exclude:
- 'Homebrew/brew.rb'
# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'Homebrew/requirements.rb'
- 'Homebrew/utils/fork.rb'
# Offense count: 18
Metrics/BlockNesting:
@ -94,64 +74,17 @@ Metrics/BlockNesting:
# Offense count: 20
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 400
Max: 370
# Offense count: 1
# Offense count: 2
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 6
# Offense count: 2
Performance/FixedSize:
Exclude:
- 'Homebrew/dev-cmd/audit.rb'
- 'Homebrew/dev-cmd/bottle.rb'
# Offense count: 8
Style/AccessorMethodName:
Exclude:
- 'Homebrew/download_strategy.rb'
- 'Homebrew/extend/ENV/std.rb'
- 'Homebrew/formula.rb'
- 'Homebrew/formula_lock.rb'
- 'Homebrew/formulary.rb'
- 'Homebrew/migrator.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: prefer_alias, prefer_alias_method
Style/Alias:
Exclude:
- 'Homebrew/blacklist.rb'
# Offense count: 26
Style/CaseEquality:
Exclude:
- 'Homebrew/cleanup.rb'
- 'Homebrew/cmd/search.rb'
- 'Homebrew/compilers.rb'
- 'Homebrew/cxxstdlib.rb'
- 'Homebrew/debrew.rb'
- 'Homebrew/dependencies.rb'
- 'Homebrew/dependency_collector.rb'
- 'Homebrew/download_strategy.rb'
- 'Homebrew/formula.rb'
- 'Homebrew/options.rb'
- 'Homebrew/patch.rb'
- 'Homebrew/pkg_version.rb'
- 'Homebrew/requirement.rb'
- 'Homebrew/requirements.rb'
- 'Homebrew/software_spec.rb'
- 'Homebrew/version.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Style/CaseIndentation:
Exclude:
- 'Homebrew/keg.rb'
# Offense count: 11
Style/ClassVars:
@ -168,24 +101,6 @@ Style/ConstantName:
Exclude:
- 'Homebrew/os/mac.rb'
# Offense count: 10
Style/DoubleNegation:
Exclude:
- 'Homebrew/extend/ARGV.rb'
- 'Homebrew/formula_installer.rb'
- 'Homebrew/os/mac/cctools_keg.rb'
- 'Homebrew/os/mac/ruby_keg.rb'
- 'Homebrew/os/mac/xcode.rb'
- 'Homebrew/requirement.rb'
- 'Homebrew/software_spec.rb'
# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
Exclude:
- 'Homebrew/formula.rb'
# Offense count: 13
# Configuration parameters: AllowedVariables.
Style/GlobalVars:
@ -193,22 +108,20 @@ Style/GlobalVars:
- 'Homebrew/diagnostic.rb'
- 'Homebrew/utils.rb'
# Offense count: 2
Style/IdenticalConditionalBranches:
# Offense count: 51
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Exclude:
- 'Homebrew/formula_lock.rb'
- 'Taps/**/*'
- 'Homebrew/dev-cmd/audit.rb'
# Offense count: 5
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase
Style/MethodName:
Exclude:
- 'Homebrew/compat/**/*'
- 'Homebrew/cleanup.rb'
- 'Homebrew/diagnostic.rb'
- 'Homebrew/formula_cellar_checks.rb'
- 'Homebrew/formula_installer.rb'
- 'Homebrew/os/mac/cctools_mach.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray:
EnforcedStyle: special_inside_parentheses
# Offense count: 7
# Configuration parameters: EnforcedStyle, SupportedStyles.
@ -219,8 +132,6 @@ Style/ModuleFunction:
- 'Homebrew/os/mac.rb'
- 'Homebrew/os/mac/xcode.rb'
- 'Homebrew/os/mac/xquartz.rb'
- 'Homebrew/utils/github.rb'
- 'Homebrew/utils/json.rb'
# Offense count: 8
Style/MultilineBlockChain:
@ -241,14 +152,6 @@ Style/MutableConstant:
- 'Homebrew/tab.rb'
- 'Homebrew/tap.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
# SupportedStyles: skip_modifier_ifs, always
Style/Next:
Exclude:
- 'Homebrew/dev-cmd/test-bot.rb'
# Offense count: 9
Style/OpMethod:
Exclude:
@ -257,37 +160,9 @@ Style/OpMethod:
- 'Homebrew/install_renamed.rb'
- 'Homebrew/options.rb'
# Offense count: 4
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
# NamePrefix: is_, has_, have_
# NamePrefixBlacklist: is_, has_, have_
# NameWhitelist: is_a?
Style/PredicateName:
Exclude:
- 'Homebrew/compat/**/*'
- 'Homebrew/download_strategy.rb'
- 'Homebrew/hardware.rb'
# Offense count: 7
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'Homebrew/diagnostic.rb'
- 'Homebrew/keg.rb'
- 'Homebrew/version.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon:
Exclude:
- 'Homebrew/descriptions.rb'
# Offense count: 1
# Configuration parameters: Methods.
# Methods: {"reduce"=>["a", "e"]}, {"inject"=>["a", "e"]}
Style/SingleLineBlockParams:
Exclude:
- 'Homebrew/diagnostic.rb'
# Configuration parameters: SupportedStyles.
# SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars:
EnforcedStyle: use_perl_names

View File

@ -1,8 +1,8 @@
#!/usr/bin/env ruby
SimpleCov.start do
coverage_dir File.expand_path("../coverage", File.realpath(__FILE__))
root File.expand_path("../..", File.realpath(__FILE__))
coverage_dir File.expand_path("../test/coverage", File.realpath(__FILE__))
root File.expand_path("..", File.realpath(__FILE__))
# We manage the result cache ourselves and the default of 10 minutes can be
# too low (particularly on Travis CI), causing results from some integration
@ -16,14 +16,21 @@ SimpleCov.start do
add_filter "/Homebrew/vendor/"
if ENV["HOMEBREW_INTEGRATION_TEST"]
command_name ENV["HOMEBREW_INTEGRATION_TEST"]
command_name "#{ENV["HOMEBREW_INTEGRATION_TEST"]} (#{$$})"
at_exit do
exit_code = $!.nil? ? 0 : $!.status
$stdout.reopen("/dev/null")
SimpleCov.result # Just save result, but don't write formatted output.
# Just save result, but don't write formatted output.
coverage_result = Coverage.result
SimpleCov.add_not_loaded_files(coverage_result)
simplecov_result = SimpleCov::Result.new(coverage_result)
SimpleCov::ResultMerger.store_result(simplecov_result)
exit! exit_code
end
else
command_name "#{command_name} (#{$$})"
# Not using this during integration tests makes the tests 4x times faster
# without changing the coverage.
track_files "#{SimpleCov.root}/**/*.rb"

View File

@ -14,7 +14,7 @@ $:.unshift(HOMEBREW_LIBRARY_PATH.to_s)
require "global"
if ARGV == %w[--version] || ARGV == %w[-v]
puts "Homebrew #{Homebrew.homebrew_version_string}"
puts "Homebrew #{HOMEBREW_VERSION}"
puts "Homebrew/homebrew-core #{Homebrew.core_tap_version_string}"
exit 0
end
@ -37,9 +37,9 @@ begin
cmd = nil
ARGV.dup.each_with_index do |arg, i|
if help_flag && cmd
break
elsif help_flag_list.include?(arg)
break if help_flag && cmd
if help_flag_list.include?(arg)
# Option-style help: Both `--help <cmd>` and `<cmd> --help` are fine.
help_flag = true
elsif arg == "help" && !cmd

View File

@ -1,4 +1,8 @@
HOMEBREW_VERSION="0.9.9"
HOMEBREW_VERSION="$(git -C "$HOMEBREW_REPOSITORY" describe --tags --dirty 2>/dev/null)"
if [[ -z "$HOMEBREW_VERSION" ]]
then
HOMEBREW_VERSION=">1.0.0 (no git repository)"
fi
onoe() {
if [[ -t 2 ]] # check whether stderr is a tty.

View File

@ -31,10 +31,9 @@ class Build
def post_superenv_hacks
# Only allow Homebrew-approved directories into the PATH, unless
# a formula opts-in to allowing the user's path.
if formula.env.userpaths? || reqs.any? { |rq| rq.env.userpaths? }
return unless formula.env.userpaths? || reqs.any? { |rq| rq.env.userpaths? }
ENV.userpaths!
end
end
def effective_build_options_for(dependent)
args = dependent.build.used_options

View File

@ -47,7 +47,7 @@ class BuildOptions
def bottle?
include? "build-bottle"
end
alias_method :build_bottle?, :bottle?
alias build_bottle? bottle?
# True if a {Formula} is being built with {Formula.head} instead of {Formula.stable}.
# <pre>args << "--some-new-stuff" if build.head?</pre>

View File

@ -1,10 +1,8 @@
require: 'rubocop-cask'
AllCops:
TargetRubyVersion: 2.0
Exclude:
- '**/.simplecov'
- '**/Casks/**/*'
- 'developer/**/*'
- '**/vendor/**/*'
Metrics/AbcSize:
@ -16,10 +14,10 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/MethodLength:
Metrics/LineLength:
Enabled: false
Metrics/PerceivedComplexity:
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
@ -29,6 +27,16 @@ Metrics/ModuleLength:
- 'lib/hbc/macos.rb'
- 'lib/hbc/utils.rb'
Metrics/PerceivedComplexity:
Enabled: false
Style/AlignHash:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
Style/BarePercentLiterals:
EnforcedStyle: percent_q
Style/BlockDelimiters:
EnforcedStyle: semantic
FunctionalMethods:
@ -59,6 +67,8 @@ Style/BlockDelimiters:
- chdir
- context
- create
- define_method
- define_singleton_method
- each_with_object
- fork
- measure
@ -75,15 +85,47 @@ Style/BlockDelimiters:
- lambda
- proc
Style/ClassAndModuleChildren:
EnforcedStyle: compact
EnforcedStyle: nested
Style/PredicateName:
NameWhitelist: is_32_bit?, is_64_bit?
Style/Documentation:
Enabled: false
Style/FileName:
Regex: !ruby/regexp /^((([\dA-Z]+|[\da-z]+)(_([\dA-Z]+|[\da-z]+))*|(\-\-)?([\dA-Z]+|[\da-z]+)(-([\dA-Z]+|[\da-z]+))*))(\.rb)?$/
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys
Style/IndentArray:
EnforcedStyle: align_brackets
Style/IndentHash:
EnforcedStyle: align_braces
Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%': '{}'
'%i': '{}'
'%q': '{}'
'%Q': '{}'
'%r': '{}'
'%s': '()'
'%w': '[]'
'%W': '[]'
'%x': '()'
Style/RaiseArgs:
EnforcedStyle: exploded
Style/RegexpLiteral:
EnforcedStyle: percent_r
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: comma

View File

@ -1 +1 @@
../test/.simplecov
../.simplecov

View File

@ -7,15 +7,21 @@ group :debug do
gem "pry-byebug", platforms: :mri
end
group :development do
gem "rubocop-cask", "~> 0.8.3"
end
group :test do
# This is SimpleCov v0.12.0 with two fixes merged on top, that finally resolve
# all issues with parallel tests, uncovered files, and tracked files. Switch
# back to stable as soon as v0.12.1 or v0.13.0 is released. For details, see:
# - https://github.com/colszowka/simplecov/pull/513
# - https://github.com/colszowka/simplecov/pull/520
gem "simplecov", "0.12.0",
git: "https://github.com/colszowka/simplecov.git",
branch: "master", # commit 83d8031ddde0927f87ef9327200a98583ca18d77
require: false
gem "codecov", require: false
gem "minitest", "5.4.1"
gem "minitest-reporters"
gem "mocha", "1.1.0", require: false
gem "parallel_tests"
gem "rspec", "~> 3.0.0"
gem "rspec-its", require: false
gem "rspec-wait", require: false

View File

@ -1,8 +1,17 @@
GIT
remote: https://github.com/colszowka/simplecov.git
revision: 83d8031ddde0927f87ef9327200a98583ca18d77
branch: master
specs:
simplecov (0.12.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
GEM
remote: https://rubygems.org/
specs:
ansi (1.5.0)
ast (2.3.0)
builder (3.2.2)
byebug (9.0.5)
codecov (0.1.5)
@ -23,9 +32,9 @@ GEM
ruby-progressbar
mocha (1.1.0)
metaclass (~> 0.0.1)
parser (2.3.1.2)
ast (~> 2.2)
powerpack (0.1.1)
parallel (1.9.0)
parallel_tests (2.9.0)
parallel
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
@ -33,8 +42,6 @@ GEM
pry-byebug (3.4.0)
byebug (~> 9.0)
pry (~> 0.10)
public_suffix (2.0.2)
rainbow (2.1.0)
rake (10.4.2)
rspec (3.0.0)
rspec-core (~> 3.0.0)
@ -53,23 +60,9 @@ GEM
rspec-support (3.0.4)
rspec-wait (0.0.9)
rspec (>= 3, < 4)
rubocop (0.41.2)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-cask (0.8.3)
public_suffix (~> 2.0)
rubocop (~> 0.41.1)
ruby-progressbar (1.8.1)
simplecov (0.12.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
unicode-display_width (1.1.0)
url (0.3.2)
PLATFORMS
@ -80,13 +73,14 @@ DEPENDENCIES
minitest (= 5.4.1)
minitest-reporters
mocha (= 1.1.0)
parallel_tests
pry
pry-byebug
rake
rspec (~> 3.0.0)
rspec-its
rspec-wait
rubocop-cask (~> 0.8.3)
simplecov (= 0.12.0)!
BUNDLED WITH
1.12.5
1.13.1

View File

@ -1,29 +1,14 @@
require "rake/testtask"
require "rspec/core/rake_task"
require "rubocop/rake_task"
homebrew_repo = `brew --repository`.chomp
$LOAD_PATH.unshift(File.expand_path("#{homebrew_repo}/Library/Homebrew"))
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
namespace :test do
Rake::TestTask.new(:minitest) do |t|
# TODO: setting the --seed here is an ugly temporary hack, to remain only
# until test-suite glitches are fixed.
ENV["TESTOPTS"] = "--seed=14830" if ENV["TRAVIS"]
t.pattern = "test/**/*_test.rb"
t.libs << "test"
end
RSpec::Core::RakeTask.new(:rspec)
desc "Run tests for minitest and RSpec with coverage"
task :coverage do
ENV["HOMEBREW_TESTS_COVERAGE"] = "1"
Rake::Task[:test].invoke
if ENV["CODECOV_TOKEN"]
namespace :coverage do
desc "Upload coverage to Codecov"
task :upload do
require "simplecov"
require "codecov"
formatter = SimpleCov::Formatter::Codecov.new
@ -32,15 +17,6 @@ namespace :test do
end
end
desc "Run tests for minitest and RSpec"
task test: ["test:minitest", "test:rspec"]
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = ["--force-exclusion"]
end
task default: [:test, :rubocop]
desc "Open a REPL for debugging and experimentation"
task :console do
require "pry"

View File

@ -1,5 +1,12 @@
require "English"
def run_tests(executable, files, args = [])
opts = []
opts << "--serialize-stdout" if ENV["CI"]
system "bundle", "exec", executable, *opts, "--", *args, "--", *files
end
repo_root = Pathname(__FILE__).realpath.parent.parent
repo_root.cd do
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
@ -9,12 +16,26 @@ repo_root.cd do
system "bundle", "install", "--path", "vendor/bundle"
end
test_task = "test"
%w[rspec minitest coverage].each do |subtask|
next unless ARGV.flag?("--#{subtask}")
test_task = "test:#{subtask}"
rspec = ARGV.flag?("--rspec") || !ARGV.flag?("--minitest")
minitest = ARGV.flag?("--minitest") || !ARGV.flag?("--rspec")
ENV["HOMEBREW_TESTS_COVERAGE"] = "1" if ARGV.flag?("--coverage")
if rspec
run_tests "parallel_rspec", Dir["spec/**/*_spec.rb"], %w[
--format progress
--format ParallelTests::RSpec::RuntimeLogger
--out tmp/parallel_runtime_rspec.log
]
end
if minitest
run_tests "parallel_test", Dir["test/**/*_test.rb"]
end
if ENV["CODECOV_TOKEN"]
system "bundle", "exec", "rake", "test:coverage:upload"
end
system "bundle", "exec", "rake", test_task
Homebrew.failed = !$CHILD_STATUS.success?
end

View File

@ -40,22 +40,22 @@ require "utils"
require "vendor/plist/plist"
module Hbc
include Hbc::Locations
include Hbc::Scopes
include Hbc::Options
include Hbc::Utils
include Locations
include Scopes
include Options
include Utils
def self.init
Hbc::Cache.ensure_cache_exists
Hbc::Cache.migrate_legacy_cache
Cache.ensure_cache_exists
Cache.migrate_legacy_cache
Hbc::Caskroom.migrate_caskroom_from_repo_to_prefix
Hbc::Caskroom.ensure_caskroom_exists
Caskroom.migrate_caskroom_from_repo_to_prefix
Caskroom.ensure_caskroom_exists
end
def self.load(query)
odebug "Loading Cask definitions"
cask = Hbc::Source.for_query(query).load
cask = Source.for_query(query).load
cask.dumpcask
cask
end

View File

@ -1,5 +1,3 @@
module Hbc::Artifact; end
require "hbc/artifact/app"
require "hbc/artifact/artifact" # generic 'artifact' stanza
require "hbc/artifact/binary"
@ -24,34 +22,35 @@ require "hbc/artifact/suite"
require "hbc/artifact/uninstall"
require "hbc/artifact/zap"
module Hbc::Artifact
module Hbc
module Artifact
# NOTE: order is important here, since we want to extract nested containers
# before we handle any other artifacts
def self.artifacts
[
Hbc::Artifact::PreflightBlock,
Hbc::Artifact::NestedContainer,
Hbc::Artifact::Installer,
Hbc::Artifact::App,
Hbc::Artifact::Suite,
Hbc::Artifact::Artifact, # generic 'artifact' stanza
Hbc::Artifact::Colorpicker,
Hbc::Artifact::Pkg,
Hbc::Artifact::Prefpane,
Hbc::Artifact::Qlplugin,
Hbc::Artifact::Font,
Hbc::Artifact::Service,
Hbc::Artifact::StageOnly,
Hbc::Artifact::Binary,
Hbc::Artifact::InputMethod,
Hbc::Artifact::InternetPlugin,
Hbc::Artifact::AudioUnitPlugin,
Hbc::Artifact::VstPlugin,
Hbc::Artifact::Vst3Plugin,
Hbc::Artifact::ScreenSaver,
Hbc::Artifact::Uninstall,
Hbc::Artifact::PostflightBlock,
Hbc::Artifact::Zap,
PreflightBlock,
NestedContainer,
Installer,
App,
Suite,
Artifact, # generic 'artifact' stanza
Colorpicker,
Pkg,
Prefpane,
Qlplugin,
Font,
Service,
StageOnly,
Binary,
InputMethod,
InternetPlugin,
AudioUnitPlugin,
VstPlugin,
Vst3Plugin,
ScreenSaver,
Uninstall,
PostflightBlock,
Zap,
]
end
@ -63,3 +62,4 @@ module Hbc::Artifact
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/base"
class Hbc::Artifact::AbstractFlightBlock < Hbc::Artifact::Base
module Hbc
module Artifact
class AbstractFlightBlock < Base
def self.artifact_dsl_key
super.to_s.sub(%r{_block$}, "").to_sym
end
@ -10,7 +12,7 @@ class Hbc::Artifact::AbstractFlightBlock < Hbc::Artifact::Base
end
def self.class_for_dsl_key(dsl_key)
Object.const_get("Hbc::DSL::#{dsl_key.to_s.split('_').collect(&:capitalize).join}")
Object.const_get("Hbc::DSL::#{dsl_key.to_s.split("_").collect(&:capitalize).join}")
end
def self.me?(cask)
@ -34,3 +36,5 @@ class Hbc::Artifact::AbstractFlightBlock < Hbc::Artifact::Base
end
end
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::App < Hbc::Artifact::Moved
module Hbc
module Artifact
class App < Moved
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::Artifact < Hbc::Artifact::Moved
module Hbc
module Artifact
class Artifact < Moved
def self.artifact_english_name
"Generic Artifact"
end
@ -11,10 +13,12 @@ class Hbc::Artifact::Artifact < Hbc::Artifact::Moved
def load_specification(artifact_spec)
source_string, target_hash = artifact_spec
raise Hbc::CaskInvalidError.new(@cask.token, "no source given for artifact") if source_string.nil?
raise CaskInvalidError.new(@cask.token, "no source given for artifact") if source_string.nil?
@source = @cask.staged_path.join(source_string)
raise Hbc::CaskInvalidError.new(@cask.token, "target required for generic artifact #{source_string}") unless target_hash.is_a?(Hash)
raise CaskInvalidError.new(@cask.token, "target required for generic artifact #{source_string}") unless target_hash.is_a?(Hash)
target_hash.assert_valid_keys(:target)
@target = Pathname.new(target_hash[:target])
end
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::AudioUnitPlugin < Hbc::Artifact::Moved
module Hbc
module Artifact
class AudioUnitPlugin < Moved
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::Artifact::Base
module Hbc
module Artifact
class Base
def self.artifact_name
@artifact_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1_\2').downcase
end
@ -71,9 +73,11 @@ class Hbc::Artifact::Base
{}
end
def initialize(cask, command: Hbc::SystemCommand, force: false)
def initialize(cask, command: SystemCommand, force: false)
@cask = cask
@command = command
@force = force
end
end
end
end

View File

@ -1,7 +1,11 @@
require "hbc/artifact/symlinked"
class Hbc::Artifact::Binary < Hbc::Artifact::Symlinked
module Hbc
module Artifact
class Binary < Symlinked
def install_phase
super unless Hbc.no_binaries
end
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::Colorpicker < Hbc::Artifact::Moved
module Hbc
module Artifact
class Colorpicker < Moved
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::Font < Hbc::Artifact::Moved
module Hbc
module Artifact
class Font < Moved
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::InputMethod < Hbc::Artifact::Moved
module Hbc
module Artifact
class InputMethod < Moved
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/base"
class Hbc::Artifact::Installer < Hbc::Artifact::Base
module Hbc
module Artifact
class Installer < Base
# TODO: for backward compatibility, removeme
def install
install_phase
@ -27,7 +29,7 @@ class Hbc::Artifact::Installer < Hbc::Artifact::Base
{ must_succeed: true, sudo: true },
print_stdout: true)
ohai "Running #{self.class.artifact_dsl_key} script #{executable}"
raise Hbc::CaskInvalidError.new(@cask, "#{self.class.artifact_dsl_key} missing executable") if executable.nil?
raise CaskInvalidError.new(@cask, "#{self.class.artifact_dsl_key} missing executable") if executable.nil?
executable_path = @cask.staged_path.join(executable)
@command.run("/bin/chmod", args: ["--", "+x", executable_path]) if File.exist?(executable_path)
@command.run(executable_path, script_arguments)
@ -39,3 +41,5 @@ class Hbc::Artifact::Installer < Hbc::Artifact::Base
odebug "Nothing to do. The #{self.class.artifact_dsl_key} artifact has no uninstall phase."
end
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::InternetPlugin < Hbc::Artifact::Moved
module Hbc
module Artifact
class InternetPlugin < Moved
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/relocated"
class Hbc::Artifact::Moved < Hbc::Artifact::Relocated
module Hbc
module Artifact
class Moved < Relocated
def self.english_description
"#{artifact_english_name}s"
end
@ -9,7 +11,7 @@ class Hbc::Artifact::Moved < Hbc::Artifact::Relocated
each_artifact do |artifact|
load_specification(artifact)
next unless preflight_checks
delete if Hbc::Utils.path_occupied?(target) && force
delete if Utils.path_occupied?(target) && force
move
end
end
@ -39,7 +41,7 @@ class Hbc::Artifact::Moved < Hbc::Artifact::Relocated
end
def preflight_checks
if Hbc::Utils.path_occupied?(target)
if Utils.path_occupied?(target)
if force
ohai(warning_target_exists { |s| s << "overwriting." })
else
@ -49,7 +51,7 @@ class Hbc::Artifact::Moved < Hbc::Artifact::Relocated
end
unless source.exist?
message = "It seems the #{self.class.artifact_english_name} source is not there: '#{source}'"
raise Hbc::CaskError, message
raise CaskError, message
end
true
end
@ -64,10 +66,10 @@ class Hbc::Artifact::Moved < Hbc::Artifact::Relocated
def delete
ohai "Removing #{self.class.artifact_english_name}: '#{target}'"
if MacOS.undeletable?(target)
raise Hbc::CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}"
elsif force
Hbc::Utils.gain_permissions_remove(target, command: @command)
raise CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}" if MacOS.undeletable?(target)
if force
Utils.gain_permissions_remove(target, command: @command)
else
target.rmtree
end
@ -86,3 +88,5 @@ class Hbc::Artifact::Moved < Hbc::Artifact::Relocated
"#{warning}#{printable_target}#{target_abv}"
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/base"
class Hbc::Artifact::NestedContainer < Hbc::Artifact::Base
module Hbc
module Artifact
class NestedContainer < Base
def install_phase
@cask.artifacts[:nested_container].each { |container| extract(container) }
end
@ -11,10 +13,10 @@ class Hbc::Artifact::NestedContainer < Hbc::Artifact::Base
def extract(container_relative_path)
source = @cask.staged_path.join(container_relative_path)
container = Hbc::Container.for_path(source, @command)
container = Container.for_path(source, @command)
unless container
raise Hbc::CaskError, "Aw dang, could not identify nested container at '#{source}'"
raise CaskError, "Aw dang, could not identify nested container at '#{source}'"
end
ohai "Extracting nested container #{source.basename}"
@ -22,3 +24,5 @@ class Hbc::Artifact::NestedContainer < Hbc::Artifact::Base
FileUtils.remove_entry_secure(source)
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/base"
class Hbc::Artifact::Pkg < Hbc::Artifact::Base
module Hbc
module Artifact
class Pkg < Base
attr_reader :pkg_relative_path
def self.artifact_dsl_key
@ -18,7 +20,7 @@ class Hbc::Artifact::Pkg < Hbc::Artifact::Base
end
raise if pkg_description.nil?
rescue StandardError
raise Hbc::CaskInvalidError.new(@cask, "Bad pkg stanza")
raise CaskInvalidError.new(@cask, "Bad pkg stanza")
end
end
@ -40,7 +42,7 @@ class Hbc::Artifact::Pkg < Hbc::Artifact::Base
ohai "Package installers may write to any location; options such as --appdir are ignored."
source = @cask.staged_path.join(pkg_relative_path)
unless source.exist?
raise Hbc::CaskError, "pkg source file not found: '#{source}'"
raise CaskError, "pkg source file not found: '#{source}'"
end
args = [
"-pkg", source,
@ -51,3 +53,5 @@ class Hbc::Artifact::Pkg < Hbc::Artifact::Base
@command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true)
end
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/abstract_flight_block"
class Hbc::Artifact::PostflightBlock < Hbc::Artifact::AbstractFlightBlock
module Hbc
module Artifact
class PostflightBlock < AbstractFlightBlock
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/abstract_flight_block"
class Hbc::Artifact::PreflightBlock < Hbc::Artifact::AbstractFlightBlock
module Hbc
module Artifact
class PreflightBlock < AbstractFlightBlock
end
end
end

View File

@ -1,7 +1,11 @@
require "hbc/artifact/moved"
class Hbc::Artifact::Prefpane < Hbc::Artifact::Moved
module Hbc
module Artifact
class Prefpane < Moved
def self.artifact_english_name
"Preference Pane"
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::Qlplugin < Hbc::Artifact::Moved
module Hbc
module Artifact
class Qlplugin < Moved
def self.artifact_english_name
"QuickLook Plugin"
end
@ -19,3 +21,5 @@ class Hbc::Artifact::Qlplugin < Hbc::Artifact::Moved
@command.run!("/usr/bin/qlmanage", args: ["-r"])
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/base"
class Hbc::Artifact::Relocated < Hbc::Artifact::Base
module Hbc
module Artifact
class Relocated < Base
def summary
{
english_description: self.class.english_description,
@ -40,10 +42,10 @@ class Hbc::Artifact::Relocated < Hbc::Artifact::Base
def load_specification(artifact_spec)
source_string, target_hash = artifact_spec
raise Hbc::CaskInvalidError if source_string.nil?
raise CaskInvalidError if source_string.nil?
@source = @cask.staged_path.join(source_string)
if target_hash
raise Hbc::CaskInvalidError unless target_hash.respond_to?(:keys)
raise CaskInvalidError unless target_hash.respond_to?(:keys)
target_hash.assert_valid_keys(:target)
@target = Hbc.send(self.class.artifact_dirmethod).join(target_hash[:target])
else
@ -51,3 +53,5 @@ class Hbc::Artifact::Relocated < Hbc::Artifact::Base
end
end
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::ScreenSaver < Hbc::Artifact::Moved
module Hbc
module Artifact
class ScreenSaver < Moved
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::Service < Hbc::Artifact::Moved
module Hbc
module Artifact
class Service < Moved
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/base"
class Hbc::Artifact::StageOnly < Hbc::Artifact::Base
module Hbc
module Artifact
class StageOnly < Base
def self.artifact_dsl_key
:stage_only
end
@ -13,3 +15,5 @@ class Hbc::Artifact::StageOnly < Hbc::Artifact::Base
# do nothing
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::Suite < Hbc::Artifact::Moved
module Hbc
module Artifact
class Suite < Moved
def self.artifact_english_name
"App Suite"
end
@ -9,3 +11,5 @@ class Hbc::Artifact::Suite < Hbc::Artifact::Moved
:appdir
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/relocated"
class Hbc::Artifact::Symlinked < Hbc::Artifact::Relocated
module Hbc
module Artifact
class Symlinked < Relocated
def self.link_type_english_name
"Symlink"
end
@ -41,7 +43,7 @@ class Hbc::Artifact::Symlinked < Hbc::Artifact::Relocated
return false
end
unless source.exist?
raise Hbc::CaskError, "It seems the #{self.class.link_type_english_name.downcase} source is not there: '#{source}'"
raise CaskError, "It seems the #{self.class.link_type_english_name.downcase} source is not there: '#{source}'"
end
true
end
@ -63,3 +65,5 @@ class Hbc::Artifact::Symlinked < Hbc::Artifact::Relocated
"#{link_description}#{printable_target} -> #{target.readlink}#{target_readlink_abv}"
end
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/uninstall_base"
class Hbc::Artifact::Uninstall < Hbc::Artifact::UninstallBase
module Hbc
module Artifact
class Uninstall < UninstallBase
end
end
end

View File

@ -2,7 +2,9 @@ require "pathname"
require "hbc/artifact/base"
class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base
module Hbc
module Artifact
class UninstallBase < Base
# TODO: 500 is also hardcoded in cask/pkg.rb, but much of
# that logic is probably in the wrong location
@ -135,7 +137,7 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base
# :signal should come after :quit so it can be used as a backup when :quit fails
def uninstall_signal(directives)
Array(directives[:signal]).flatten.each_slice(2) do |pair|
raise Hbc::CaskInvalidError.new(@cask, "Each #{stanza} :signal must have 2 elements.") unless pair.length == 2
raise CaskInvalidError.new(@cask, "Each #{stanza} :signal must have 2 elements.") unless pair.length == 2
signal, id = pair
ohai "Signalling '#{signal}' to application ID '#{id}'"
pids = get_unix_pids(id)
@ -196,7 +198,7 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base
{ print_stdout: true },
directive_name)
ohai "Running uninstall script #{executable}"
raise Hbc::CaskInvalidError.new(@cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil?
raise CaskInvalidError.new(@cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil?
executable_path = @cask.staged_path.join(executable)
@command.run("/bin/chmod", args: ["--", "+x", executable_path]) if File.exist?(executable_path)
@command.run(executable_path, script_arguments)
@ -247,3 +249,5 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base
end
end
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::Vst3Plugin < Hbc::Artifact::Moved
module Hbc
module Artifact
class Vst3Plugin < Moved
end
end
end

View File

@ -1,4 +1,8 @@
require "hbc/artifact/moved"
class Hbc::Artifact::VstPlugin < Hbc::Artifact::Moved
module Hbc
module Artifact
class VstPlugin < Moved
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/artifact/uninstall_base"
class Hbc::Artifact::Zap < Hbc::Artifact::UninstallBase
module Hbc
module Artifact
class Zap < UninstallBase
def install_phase
odebug "Nothing to do. The zap artifact has no install phase."
end
@ -14,3 +16,5 @@ class Hbc::Artifact::Zap < Hbc::Artifact::UninstallBase
dispatch_uninstall_directives(expand_tilde)
end
end
end
end

View File

@ -2,12 +2,13 @@ require "hbc/checkable"
require "hbc/download"
require "digest"
class Hbc::Audit
include Hbc::Checkable
module Hbc
class Audit
include Checkable
attr_reader :cask, :download
def initialize(cask, download: false, check_token_conflicts: false, command: Hbc::SystemCommand)
def initialize(cask, download: false, check_token_conflicts: false, command: SystemCommand)
@cask = cask
@download = download
@check_token_conflicts = check_token_conflicts
@ -114,7 +115,7 @@ class Hbc::Audit
def check_appcast_http_code
odebug "Verifying appcast returns 200 HTTP response code"
result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--output", "/dev/null", "--write-out", "%{http_code}", cask.appcast], print_stderr: false)
result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--output", "/dev/null", "--write-out", "%{http_code}", cask.appcast], print_stderr: false)
if result.success?
http_code = result.stdout.chomp
add_warning "unexpected HTTP response code retrieving appcast: #{http_code}" unless http_code == "200"
@ -125,7 +126,7 @@ class Hbc::Audit
def check_appcast_checkpoint_accuracy
odebug "Verifying appcast checkpoint is accurate"
result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, cask.appcast], print_stderr: false)
result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, cask.appcast], print_stderr: false)
if result.success?
processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}, "")
# This step is necessary to replicate running `sed` from the command line
@ -209,8 +210,9 @@ class Hbc::Audit
return unless download && cask.url
odebug "Auditing download"
downloaded_path = download.perform
Hbc::Verify.all(cask, downloaded_path)
Verify.all(cask, downloaded_path)
rescue => e
add_error "download not possible: #{e.message}"
end
end
end

View File

@ -1,10 +1,12 @@
class Hbc::Auditor
module Hbc
class Auditor
def self.audit(cask, audit_download: false, check_token_conflicts: false)
download = audit_download && Hbc::Download.new(cask)
audit = Hbc::Audit.new(cask, download: download,
download = audit_download && Download.new(cask)
audit = Audit.new(cask, download: download,
check_token_conflicts: check_token_conflicts)
audit.run!
puts audit.summary
audit.success?
end
end
end

View File

@ -1,21 +1,23 @@
module Hbc::Cache
module Hbc
module Cache
module_function
def ensure_cache_exists
return if Hbc.cache.exist?
odebug "Creating Cache at #{Hbc.cache}"
Hbc.cache.mkpath
end
def migrate_legacy_cache
if Hbc.legacy_cache.exist?
ohai "Migrating cached files to #{Hbc.cache}..."
return unless Hbc.legacy_cache.exist?
ohai "Migrating cached files to #{Hbc.cache}..."
Hbc.legacy_cache.children.select(&:symlink?).each do |symlink|
file = symlink.readlink
new_name = file.basename
.sub(%r{\-((?:(\d|#{Hbc::DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x,
.sub(%r{\-((?:(\d|#{DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x,
'--\1')
renamed_file = Hbc.cache.join(new_name)

View File

@ -2,18 +2,19 @@ require "forwardable"
require "hbc/dsl"
class Hbc::Cask
module Hbc
class Cask
extend Forwardable
attr_reader :token, :sourcefile_path
def initialize(token, sourcefile_path: nil, dsl: nil, &block)
@token = token
@sourcefile_path = sourcefile_path
@dsl = dsl || Hbc::DSL.new(@token)
@dsl = dsl || DSL.new(@token)
@dsl.instance_eval(&block) if block_given?
end
Hbc::DSL::DSL_METHODS.each do |method_name|
DSL::DSL_METHODS.each do |method_name|
define_method(method_name) { @dsl.send(method_name) }
end
@ -31,12 +32,12 @@ class Hbc::Cask
def metadata_path(timestamp = :latest, create = false)
return nil unless metadata_versioned_container_path.respond_to?(:join)
if create && timestamp == :latest
raise Hbc::CaskError, "Cannot create metadata path when timestamp is :latest"
raise CaskError, "Cannot create metadata path when timestamp is :latest"
end
path = if timestamp == :latest
Pathname.glob(metadata_versioned_container_path.join("*")).sort.last
elsif timestamp == :now
Hbc::Utils.nowstamp_metadata_path(metadata_versioned_container_path)
Utils.nowstamp_metadata_path(metadata_versioned_container_path)
else
metadata_versioned_container_path.join(timestamp)
end
@ -49,10 +50,10 @@ class Hbc::Cask
def metadata_subdir(leaf, timestamp = :latest, create = false)
if create && timestamp == :latest
raise Hbc::CaskError, "Cannot create metadata subdir when timestamp is :latest"
raise CaskError, "Cannot create metadata subdir when timestamp is :latest"
end
unless leaf.respond_to?(:length) && !leaf.empty?
raise Hbc::CaskError, "Cannot create metadata subdir for empty leaf"
raise CaskError, "Cannot create metadata subdir for empty leaf"
end
parent = metadata_path(timestamp, create)
return nil unless parent.respond_to?(:join)
@ -87,7 +88,9 @@ class Hbc::Cask
end
def dumpcask
if Hbc.respond_to?(:debug) && Hbc.debug
return unless Hbc.respond_to?(:debug)
return unless Hbc.debug
odebug "Cask instance dumps in YAML:"
odebug "Cask instance toplevel:", to_yaml
[

View File

@ -1,6 +1,7 @@
require "hbc/topological_hash"
class Hbc::CaskDependencies
module Hbc
class CaskDependencies
attr_reader :cask, :graph, :sorted
def initialize(cask)
@ -22,12 +23,13 @@ class Hbc::CaskDependencies
}
graphed = walk.call({}, @cask.depends_on.cask)
Hbc::TopologicalHash[graphed]
TopologicalHash[graphed]
end
def sort
@graph.tsort
rescue TSort::Cyclic
raise Hbc::CaskCyclicCaskDependencyError, @cask.token
raise CaskCyclicCaskDependencyError, @cask.token
end
end
end

View File

@ -1,18 +1,26 @@
module Hbc::Caskroom
module Hbc
module Caskroom
module_function
def migrate_caskroom_from_repo_to_prefix
repo_caskroom = Hbc.homebrew_repository.join("Caskroom")
if !Hbc.caskroom.exist? && repo_caskroom.directory?
return if Hbc.caskroom.exist?
return unless repo_caskroom.directory?
ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX"
if Hbc.caskroom.parent.writable?
FileUtils.mv repo_caskroom, Hbc.caskroom
else
opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom."
system "/usr/bin/sudo", "--", "/bin/mv", "--", repo_caskroom.to_s, Hbc.caskroom.parent.to_s
end
end
def ensure_caskroom_exists
unless Hbc.caskroom.exist?
ohai "Creating Caskroom at #{Hbc.caskroom}"
return if Hbc.caskroom.exist?
ohai "Creating Caskroom at #{Hbc.caskroom}"
if Hbc.caskroom.parent.writable?
Hbc.caskroom.mkpath
else
@ -28,7 +36,7 @@ module Hbc::Caskroom
# sudo in system is rude.
system "/usr/bin/sudo", "--", "/bin/mkdir", "-p", "--", Hbc.caskroom
unless Hbc.caskroom.parent == toplevel_dir
system "/usr/bin/sudo", "--", "/usr/sbin/chown", "-R", "--", "#{Hbc::Utils.current_user}:staff", Hbc.caskroom.parent.to_s
system "/usr/bin/sudo", "--", "/usr/sbin/chown", "-R", "--", "#{Utils.current_user}:staff", Hbc.caskroom.parent.to_s
end
end
end

View File

@ -1,12 +1,14 @@
class Hbc::Caveats
module Hbc
class Caveats
def initialize(block)
@block = block
end
def eval_and_print(cask)
dsl = Hbc::DSL::Caveats.new(cask)
dsl = DSL::Caveats.new(cask)
retval = dsl.instance_eval(&@block)
return if retval.nil?
puts retval.to_s.sub(%r{[\r\n \t]*\Z}, "\n\n")
end
end
end

View File

@ -1,4 +1,5 @@
module Hbc::Checkable
module Hbc
module Checkable
def errors
Array(@errors)
end
@ -49,3 +50,4 @@ module Hbc::Checkable
summary.join("\n")
end
end
end

View File

@ -1,5 +1,3 @@
class Hbc::CLI; end
require "optparse"
require "shellwords"
@ -28,7 +26,8 @@ require "hbc/cli/internal_dump"
require "hbc/cli/internal_help"
require "hbc/cli/internal_stanza"
class Hbc::CLI
module Hbc
class CLI
ALIASES = {
"ls" => "list",
"homepage" => "home",
@ -72,8 +71,8 @@ class Hbc::CLI
}.freeze
def self.command_classes
@command_classes ||= Hbc::CLI.constants
.map(&Hbc::CLI.method(:const_get))
@command_classes ||= self.constants
.map(&method(:const_get))
.select { |sym| sym.respond_to?(:run) }
end
@ -99,31 +98,31 @@ class Hbc::CLI
end
def self.should_init?(command)
(command.is_a? Class) && (command < Hbc::CLI::Base) && command.needs_init?
(command.is_a? Class) && (command < CLI::Base) && command.needs_init?
end
def self.run_command(command, *rest)
if command.respond_to?(:run)
# usual case: built-in command verb
command.run(*rest)
elsif require? Hbc::Utils.which("brewcask-#{command}.rb").to_s
elsif require? Utils.which("brewcask-#{command}.rb").to_s
# external command as Ruby library on PATH, Homebrew-style
elsif command.to_s.include?("/") && require?(command.to_s)
# external command as Ruby library with literal path, useful
# for development and troubleshooting
sym = Pathname.new(command.to_s).basename(".rb").to_s.capitalize
klass = begin
Hbc::CLI.const_get(sym)
self.const_get(sym)
rescue NameError
nil
end
if klass.respond_to?(:run)
# invoke "run" on a Ruby library which follows our coding conventions
klass.run(*rest)
else
# other Ruby libraries must do everything via "require"
klass.run(*rest)
end
elsif Hbc::Utils.which "brewcask-#{command}"
elsif Utils.which "brewcask-#{command}"
# arbitrary external executable on PATH, Homebrew-style
exec "brewcask-#{command}", *ARGV[1..-1]
elsif Pathname.new(command.to_s).executable? &&
@ -134,7 +133,7 @@ class Hbc::CLI
exec command, *ARGV[1..-1]
else
# failure
Hbc::CLI::NullCommand.new(command).run
NullCommand.new(command).run
end
end
@ -145,14 +144,14 @@ class Hbc::CLI
Hbc.default_tap.install unless Hbc.default_tap.installed?
Hbc.init if should_init?(command)
run_command(command, *rest)
rescue Hbc::CaskError, Hbc::CaskSha256MismatchError => e
rescue CaskError, CaskSha256MismatchError => e
msg = e.message
msg << e.backtrace.join("\n") if Hbc.debug
onoe msg
exit 1
rescue StandardError, ScriptError, NoMemoryError => e
msg = e.message
msg << Hbc::Utils.error_message_with_suggestions
msg << Utils.error_message_with_suggestions
msg << e.backtrace.join("\n")
onoe msg
exit 1
@ -216,9 +215,9 @@ class Hbc::CLI
remaining << head
retry
rescue OptionParser::MissingArgument
raise Hbc::CaskError, "The option '#{head}' requires an argument"
raise CaskError, "The option '#{head}' requires an argument"
rescue OptionParser::AmbiguousOption
raise Hbc::CaskError, "There is more than one possible option that starts with '#{head}'"
raise CaskError, "There is more than one possible option that starts with '#{head}'"
end
end
@ -240,7 +239,7 @@ class Hbc::CLI
purpose
usage
unless @attempted_verb.to_s.strip.empty? || @attempted_verb == "help"
raise Hbc::CaskError, "Unknown command: #{@attempted_verb}"
raise CaskError, "Unknown command: #{@attempted_verb}"
end
end
end
@ -254,10 +253,10 @@ class Hbc::CLI
end
def usage
max_command_len = Hbc::CLI.commands.map(&:length).max
max_command_len = CLI.commands.map(&:length).max
puts "Commands:\n\n"
Hbc::CLI.command_classes.each do |klass|
CLI.command_classes.each do |klass|
next unless klass.visible
puts " #{klass.command_name.ljust(max_command_len)} #{_help_for(klass)}"
end
@ -273,3 +272,4 @@ class Hbc::CLI
end
end
end
end

View File

@ -1,12 +1,14 @@
class Hbc::CLI::Audit < Hbc::CLI::Base
module Hbc
class CLI
class Audit < Base
def self.help
"verifies installability of Casks"
end
def self.run(*args)
failed_casks = new(args, Hbc::Auditor).run
failed_casks = new(args, Auditor).run
return if failed_casks.empty?
raise Hbc::CaskError, "audit failed for casks: #{failed_casks.join(' ')}"
raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
end
def initialize(args, auditor)
@ -50,3 +52,5 @@ class Hbc::CLI::Audit < Hbc::CLI::Base
true
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::CLI::Base
module Hbc
class CLI
class Base
def self.command_name
@command_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1_\2').downcase
end
@ -19,3 +21,5 @@ class Hbc::CLI::Base
false
end
end
end
end

View File

@ -1,11 +1,13 @@
class Hbc::CLI::Cat < Hbc::CLI::Base
module Hbc
class CLI
class Cat < Base
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
raise CaskUnspecifiedError if cask_tokens.empty?
# only respects the first argument
cask_token = cask_tokens.first.sub(%r{\.rb$}i, "")
cask_path = Hbc.path(cask_token)
raise Hbc::CaskUnavailableError, cask_token.to_s unless cask_path.exist?
raise CaskUnavailableError, cask_token.to_s unless cask_path.exist?
puts File.open(cask_path, &:read)
end
@ -13,3 +15,5 @@ class Hbc::CLI::Cat < Hbc::CLI::Base
"dump raw source of the given Cask to the standard output"
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::CLI::Cleanup < Hbc::CLI::Base
module Hbc
class CLI
class Cleanup < Base
OUTDATED_DAYS = 10
OUTDATED_TIMESTAMP = Time.now - (60 * 60 * 24 * OUTDATED_DAYS)
@ -60,12 +62,12 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
end
def disk_cleanup_size
Hbc::Utils.size_in_bytes(cache_files)
Utils.size_in_bytes(cache_files)
end
def remove_cache_files(*tokens)
message = "Removing cached downloads"
message.concat " for #{tokens.join(', ')}" unless tokens.empty?
message.concat " for #{tokens.join(", ")}" unless tokens.empty?
message.concat " older than #{OUTDATED_DAYS} days old" if outdated_only
ohai message
@ -88,7 +90,7 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
paths.each do |item|
next unless item.exist?
processed_files += 1
if Hbc::Utils.file_locked?(item)
if Utils.file_locked?(item)
puts "skipping: #{item} is locked"
next
end
@ -106,3 +108,5 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
end
end
end
end
end

View File

@ -1,12 +1,14 @@
class Hbc::CLI::Create < Hbc::CLI::Base
module Hbc
class CLI
class Create < Base
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
raise CaskUnspecifiedError if cask_tokens.empty?
cask_token = cask_tokens.first.sub(%r{\.rb$}i, "")
cask_path = Hbc.path(cask_token)
odebug "Creating Cask #{cask_token}"
raise Hbc::CaskAlreadyCreatedError, cask_token if cask_path.exist?
raise CaskAlreadyCreatedError, cask_token if cask_path.exist?
File.open(cask_path, "w") do |f|
f.write template(cask_token)
@ -35,3 +37,5 @@ class Hbc::CLI::Create < Hbc::CLI::Base
"creates the given Cask and opens it in an editor"
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::CLI::Doctor < Hbc::CLI::Base
module Hbc
class CLI
class Doctor < Base
def self.run
ohai "macOS Release:", render_with_none_as_error(MacOS.full_version)
ohai "Hardware Architecture:", render_with_none_as_error("#{Hardware::CPU.type}-#{Hardware::CPU.bits}")
@ -47,14 +49,14 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
homebrew_origin = notfound_string
begin
Dir.chdir(homebrew_repository) do
homebrew_origin = Hbc::SystemCommand.run("/usr/bin/git",
homebrew_origin = SystemCommand.run("/usr/bin/git",
args: %w[config --get remote.origin.url],
print_stderr: false).stdout.strip
end
if homebrew_origin !~ %r{\S}
homebrew_origin = "#{none_string} #{error_string}"
elsif homebrew_origin !~ %r{(mxcl|Homebrew)/(home)?brew(\.git)?\Z}
homebrew_origin.concat " #{error_string 'warning: nonstandard origin'}"
homebrew_origin.concat " #{error_string "warning: nonstandard origin"}"
end
rescue StandardError
homebrew_origin = error_string "Not Found - Error running git"
@ -85,7 +87,7 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
return @homebrew_constants[name] if @homebrew_constants.key?(name)
@homebrew_constants[name] = notfound_string
begin
@homebrew_constants[name] = Hbc::SystemCommand.run!(Hbc.homebrew_executable,
@homebrew_constants[name] = SystemCommand.run!(Hbc.homebrew_executable,
args: ["--#{name}"],
print_stderr: false)
.stdout
@ -106,7 +108,7 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
end
def self.privileged_uid
Process.euid == 0 ? "Yes #{error_string 'warning: not recommended'}" : "No"
Process.euid.zero? ? "Yes #{error_string "warning: not recommended"}" : "No"
rescue StandardError
notfound_string
end
@ -143,7 +145,7 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
if dir.nil? || dir.to_s.empty?
none_string
elsif dir.to_s.match(legacy_tap_pattern)
dir.to_s.concat(" #{error_string 'Warning: legacy tap path'}")
dir.to_s.concat(" #{error_string "Warning: legacy tap path"}")
else
dir.to_s
end
@ -175,9 +177,9 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
def self.render_staging_location(path)
path = Pathname.new(path)
if !path.exist?
"#{path} #{error_string 'error: path does not exist'}}"
"#{path} #{error_string "error: path does not exist"}}"
elsif !path.writable?
"#{path} #{error_string 'error: not writable by current user'}"
"#{path} #{error_string "error: not writable by current user"}"
else
path
end
@ -189,7 +191,7 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
end
def self.render_cached_downloads
cleanup = Hbc::CLI::Cleanup.default
cleanup = CLI::Cleanup.default
files = cleanup.cache_files
count = files.count
size = cleanup.disk_cleanup_size
@ -203,3 +205,5 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
"checks for configuration issues"
end
end
end
end

View File

@ -1,13 +1,15 @@
class Hbc::CLI::Edit < Hbc::CLI::Base
module Hbc
class CLI
class Edit < Base
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
raise CaskUnspecifiedError if cask_tokens.empty?
# only respects the first argument
cask_token = cask_tokens.first.sub(%r{\.rb$}i, "")
cask_path = Hbc.path(cask_token)
odebug "Opening editor for Cask #{cask_token}"
unless cask_path.exist?
raise Hbc::CaskUnavailableError, %Q{#{cask_token}, run "brew cask create #{cask_token}" to create a new Cask}
raise CaskUnavailableError, %Q{#{cask_token}, run "brew cask create #{cask_token}" to create a new Cask}
end
exec_editor cask_path
end
@ -16,3 +18,5 @@ class Hbc::CLI::Edit < Hbc::CLI::Base
"edits the given Cask"
end
end
end
end

View File

@ -1,14 +1,16 @@
class Hbc::CLI::Fetch < Hbc::CLI::Base
module Hbc
class CLI
class Fetch < Base
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
raise CaskUnspecifiedError if cask_tokens.empty?
force = args.include? "--force"
cask_tokens.each do |cask_token|
ohai "Downloading external files for Cask #{cask_token}"
cask = Hbc.load(cask_token)
downloaded_path = Hbc::Download.new(cask, force: force).perform
Hbc::Verify.all(cask, downloaded_path)
downloaded_path = Download.new(cask, force: force).perform
Verify.all(cask, downloaded_path)
ohai "Success! Downloaded to -> #{downloaded_path}"
end
end
@ -17,3 +19,5 @@ class Hbc::CLI::Fetch < Hbc::CLI::Base
"downloads remote application files to local cache"
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::CLI::Home < Hbc::CLI::Base
module Hbc
class CLI
class Home < Base
def self.run(*cask_tokens)
if cask_tokens.empty?
odebug "Opening project homepage"
@ -16,3 +18,5 @@ class Hbc::CLI::Home < Hbc::CLI::Base
"opens the homepage of the given Cask"
end
end
end
end

View File

@ -1,7 +1,9 @@
class Hbc::CLI::Info < Hbc::CLI::Base
module Hbc
class CLI
class Info < Base
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
raise CaskUnspecifiedError if cask_tokens.empty?
cask_tokens.each do |cask_token|
odebug "Getting info for Cask #{cask_token}"
cask = Hbc.load(cask_token)
@ -21,7 +23,7 @@ class Hbc::CLI::Info < Hbc::CLI::Base
puts "From: #{formatted_url(github_info(cask))}" if github_info(cask)
name_info(cask)
artifact_info(cask)
Hbc::Installer.print_caveats(cask)
Installer.print_caveats(cask)
end
def self.formatted_url(url)
@ -49,13 +51,13 @@ class Hbc::CLI::Info < Hbc::CLI::Base
end
def self.github_info(cask)
user, repo, token = Hbc::QualifiedToken.parse(Hbc.all_tokens.detect { |t| t.split("/").last == cask.token })
user, repo, token = QualifiedToken.parse(Hbc.all_tokens.detect { |t| t.split("/").last == cask.token })
"#{Tap.fetch(user, repo).default_remote}/blob/master/Casks/#{token}.rb"
end
def self.artifact_info(cask)
ohai "Artifacts"
Hbc::DSL::ORDINARY_ARTIFACT_TYPES.each do |type|
DSL::ORDINARY_ARTIFACT_TYPES.each do |type|
next if cask.artifacts[type].empty?
cask.artifacts[type].each do |artifact|
activatable_item = type == :stage_only ? "<none>" : artifact.first
@ -64,3 +66,5 @@ class Hbc::CLI::Info < Hbc::CLI::Base
end
end
end
end
end

View File

@ -1,16 +1,17 @@
class Hbc::CLI::Install < Hbc::CLI::Base
module Hbc
class CLI
class Install < Base
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
raise CaskUnspecifiedError if cask_tokens.empty?
force = args.include? "--force"
skip_cask_deps = args.include? "--skip-cask-deps"
require_sha = args.include? "--require-sha"
retval = install_casks cask_tokens, force, skip_cask_deps, require_sha
# retval is ternary: true/false/nil
raise Hbc::CaskError, "nothing to install" if retval.nil?
raise Hbc::CaskError, "install incomplete" unless retval
raise CaskError, "nothing to install" if retval.nil?
raise CaskError, "install incomplete" unless retval
end
def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
@ -18,29 +19,29 @@ class Hbc::CLI::Install < Hbc::CLI::Base
cask_tokens.each do |cask_token|
begin
cask = Hbc.load(cask_token)
Hbc::Installer.new(cask,
Installer.new(cask,
force: force,
skip_cask_deps: skip_cask_deps,
require_sha: require_sha).install
count += 1
rescue Hbc::CaskAlreadyInstalledError => e
rescue CaskAlreadyInstalledError => e
opoo e.message
count += 1
rescue Hbc::CaskAutoUpdatesError => e
rescue CaskAutoUpdatesError => e
opoo e.message
count += 1
rescue Hbc::CaskUnavailableError => e
rescue CaskUnavailableError => e
warn_unavailable_with_suggestion cask_token, e
rescue Hbc::CaskNoShasumError => e
rescue CaskNoShasumError => e
opoo e.message
count += 1
end
end
count == 0 ? nil : count == cask_tokens.length
count.zero? ? nil : count == cask_tokens.length
end
def self.warn_unavailable_with_suggestion(cask_token, e)
exact_match, partial_matches = Hbc::CLI::Search.search(cask_token)
exact_match, partial_matches = Search.search(cask_token)
errmsg = e.message
if exact_match
errmsg.concat(". Did you mean:\n#{exact_match}")
@ -58,3 +59,5 @@ class Hbc::CLI::Install < Hbc::CLI::Base
true
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
module Hbc
class CLI
class InternalAuditModifiedCasks < InternalUseBase
RELEVANT_STANZAS = %i{version sha256 url appcast}.freeze
class << self
@ -62,7 +64,7 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
end
def git_root
@git_root ||= git(*%w[rev-parse --show-toplevel])
@git_root ||= git("rev-parse", "--show-toplevel")
end
def modified_cask_files
@ -83,8 +85,8 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
@modified_casks = modified_cask_files.map { |f| Hbc.load(f) }
if @modified_casks.any?
num_modified = @modified_casks.size
ohai "#{num_modified} modified #{pluralize('cask', num_modified)}: " \
"#{@modified_casks.join(' ')}"
ohai "#{num_modified} modified #{pluralize("cask", num_modified)}: " \
"#{@modified_casks.join(" ")}"
end
@modified_casks
end
@ -92,7 +94,7 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
def audit(cask, cask_file)
audit_download = audit_download?(cask, cask_file)
check_token_conflicts = added_cask_files.include?(cask_file)
success = Hbc::Auditor.audit(cask, audit_download: audit_download,
success = Auditor.audit(cask, audit_download: audit_download,
check_token_conflicts: check_token_conflicts)
failed_casks << cask unless success
end
@ -122,7 +124,7 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
num_failed = failed_casks.size
cask_pluralized = pluralize("cask", num_failed)
odie "audit failed for #{num_failed} #{cask_pluralized}: " \
"#{failed_casks.join(' ')}"
"#{failed_casks.join(" ")}"
end
def pluralize(str, num)
@ -130,6 +132,8 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
end
def cleanup
Hbc::CLI::Cleanup.run if cleanup?
Cleanup.run if cleanup?
end
end
end
end

View File

@ -1,9 +1,11 @@
class Hbc::CLI::InternalCheckurl < Hbc::CLI::InternalUseBase
module Hbc
class CLI
class InternalCheckurl < InternalUseBase
def self.run(*args)
casks_to_check = args.empty? ? Hbc.all : args.map { |arg| Hbc.load(arg) }
casks_to_check.each do |cask|
odebug "Checking URL for Cask #{cask}"
checker = Hbc::UrlChecker.new(cask)
checker = UrlChecker.new(cask)
checker.run
puts checker.summary
end
@ -13,3 +15,5 @@ class Hbc::CLI::InternalCheckurl < Hbc::CLI::InternalUseBase
"checks for bad Cask URLs"
end
end
end
end

View File

@ -1,12 +1,14 @@
class Hbc::CLI::InternalDump < Hbc::CLI::InternalUseBase
module Hbc
class CLI
class InternalDump < InternalUseBase
def self.run(*arguments)
cask_tokens = cask_tokens_from(arguments)
raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
raise CaskUnspecifiedError if cask_tokens.empty?
retval = dump_casks(*cask_tokens)
# retval is ternary: true/false/nil
raise Hbc::CaskError, "nothing to dump" if retval.nil?
raise Hbc::CaskError, "dump incomplete" unless retval
raise CaskError, "nothing to dump" if retval.nil?
raise CaskError, "dump incomplete" unless retval
end
def self.dump_casks(*cask_tokens)
@ -21,10 +23,12 @@ class Hbc::CLI::InternalDump < Hbc::CLI::InternalUseBase
opoo "#{cask_token} was not found or would not load: #{e}"
end
end
count == 0 ? nil : count == cask_tokens.length
count.zero? ? nil : count == cask_tokens.length
end
def self.help
"Dump the given Cask in YAML format"
end
end
end
end

View File

@ -1,8 +1,10 @@
class Hbc::CLI::InternalHelp < Hbc::CLI::InternalUseBase
module Hbc
class CLI
class InternalHelp < InternalUseBase
def self.run(*_ignored)
max_command_len = Hbc::CLI.commands.map(&:length).max
max_command_len = CLI.commands.map(&:length).max
puts "Unstable Internal-use Commands:\n\n"
Hbc::CLI.command_classes.each do |klass|
CLI.command_classes.each do |klass|
next if klass.visible
puts " #{klass.command_name.ljust(max_command_len)} #{help_for(klass)}"
end
@ -17,3 +19,5 @@ class Hbc::CLI::InternalHelp < Hbc::CLI::InternalUseBase
"Print help strings for unstable internal-use commands"
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::CLI::InternalStanza < Hbc::CLI::InternalUseBase
module Hbc
class CLI
class InternalStanza < InternalUseBase
# Syntax
#
# brew cask _stanza <stanza_name> [ --table | --yaml | --inspect | --quiet ] [ <cask_token> ... ]
@ -61,10 +63,10 @@ class Hbc::CLI::InternalStanza < Hbc::CLI::InternalUseBase
# retval is ternary: true/false/nil
if retval.nil?
exit 1 if quiet
raise Hbc::CaskError, "nothing to print"
raise CaskError, "nothing to print"
elsif !retval
exit 1 if quiet
raise Hbc::CaskError, "print incomplete"
raise CaskError, "print incomplete"
end
end
@ -118,10 +120,12 @@ class Hbc::CLI::InternalStanza < Hbc::CLI::InternalUseBase
count += 1
end
count == 0 ? nil : count == cask_tokens.length
count.zero? ? nil : count == cask_tokens.length
end
def self.help
"Extract and render a specific stanza for the given Casks"
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::CLI::InternalUseBase < Hbc::CLI::Base
module Hbc
class CLI
class InternalUseBase < Base
def self.command_name
super.sub(%r{^internal_}i, "_")
end
@ -7,3 +9,5 @@ class Hbc::CLI::InternalUseBase < Hbc::CLI::Base
false
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::CLI::List < Hbc::CLI::Base
module Hbc
class CLI
class List < Base
def self.run(*arguments)
@options = {}
@options[:one] = true if arguments.delete("-1")
@ -14,9 +16,9 @@ class Hbc::CLI::List < Hbc::CLI::Base
if retval.nil? && !arguments.any?
opoo "nothing to list" # special case: avoid exit code
elsif retval.nil?
raise Hbc::CaskError, "nothing to list"
raise CaskError, "nothing to list"
elsif !retval
raise Hbc::CaskError, "listing incomplete"
raise CaskError, "listing incomplete"
end
end
@ -43,16 +45,16 @@ class Hbc::CLI::List < Hbc::CLI::Base
else
opoo "#{cask} is not installed"
end
rescue Hbc::CaskUnavailableError => e
rescue CaskUnavailableError => e
onoe e
end
end
count == 0 ? nil : count == cask_tokens.length
count.zero? ? nil : count == cask_tokens.length
end
def self.list_artifacts(cask)
Hbc::Artifact.for_cask(cask).each do |artifact|
Artifact.for_cask(cask).each do |artifact|
summary = artifact.new(cask).summary
ohai summary[:english_description], summary[:contents] unless summary.empty?
end
@ -84,3 +86,5 @@ class Hbc::CLI::List < Hbc::CLI::Base
true
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::CLI::Search < Hbc::CLI::Base
module Hbc
class CLI
class Search < Base
def self.run(*arguments)
render_results(*search(*arguments))
end
@ -16,7 +18,7 @@ class Hbc::CLI::Search < Hbc::CLI::Base
partial_matches = []
search_term = arguments.join(" ")
search_regexp = extract_regexp arguments.first
all_tokens = Hbc::CLI.nice_listing(Hbc.all_tokens)
all_tokens = CLI.nice_listing(Hbc.all_tokens)
if search_regexp
search_term = arguments.first
partial_matches = all_tokens.grep(%r{#{search_regexp}}i)
@ -53,3 +55,5 @@ class Hbc::CLI::Search < Hbc::CLI::Base
"searches all known Casks"
end
end
end
end

View File

@ -1,13 +1,15 @@
require "English"
class Hbc::CLI::Style < Hbc::CLI::Base
module Hbc
class CLI
class Style < Base
def self.help
"checks Cask style using RuboCop"
end
def self.run(*args)
retval = new(args).run
raise Hbc::CaskError, "style check failed" unless retval
raise CaskError, "style check failed" unless retval
end
attr_reader :args
@ -24,11 +26,11 @@ class Hbc::CLI::Style < Hbc::CLI::Base
RUBOCOP_CASK_VERSION = "~> 0.8.3".freeze
def install_rubocop
Hbc::Utils.capture_stderr do
Utils.capture_stderr do
begin
Homebrew.install_gem_setup_path! "rubocop-cask", RUBOCOP_CASK_VERSION, "rubocop"
rescue SystemExit
raise Hbc::CaskError, $stderr.string.chomp.sub("#{Tty.red}Error#{Tty.reset}: ", "")
raise CaskError, $stderr.string.chomp.sub("#{Tty.red}Error#{Tty.reset}: ", "")
end
end
end
@ -67,3 +69,5 @@ class Hbc::CLI::Style < Hbc::CLI::Base
args.any? { |arg| arg =~ %r{--(fix|(auto-?)?correct)} }
end
end
end
end

View File

@ -1,14 +1,16 @@
class Hbc::CLI::Uninstall < Hbc::CLI::Base
module Hbc
class CLI
class Uninstall < Base
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
raise CaskUnspecifiedError if cask_tokens.empty?
force = args.include? "--force"
cask_tokens.each do |cask_token|
odebug "Uninstalling Cask #{cask_token}"
cask = Hbc.load(cask_token)
raise Hbc::CaskNotInstalledError, cask unless cask.installed? || force
raise CaskNotInstalledError, cask unless cask.installed? || force
latest_installed_version = cask.timestamped_versions.last
@ -21,15 +23,15 @@ class Hbc::CLI::Uninstall < Hbc::CLI::Base
cask = Hbc.load(latest_installed_cask_file) if latest_installed_cask_file.exist?
end
Hbc::Installer.new(cask, force: force).uninstall
Installer.new(cask, force: force).uninstall
next if (versions = cask.versions).empty?
single = versions.count == 1
puts <<-EOS.undent
#{cask_token} #{versions.join(', ')} #{single ? 'is' : 'are'} still installed.
Remove #{single ? 'it' : 'them all'} with `brew cask uninstall --force #{cask_token}`.
#{cask_token} #{versions.join(", ")} #{single ? "is" : "are"} still installed.
Remove #{single ? "it" : "them all"} with `brew cask uninstall --force #{cask_token}`.
EOS
end
end
@ -38,3 +40,5 @@ class Hbc::CLI::Uninstall < Hbc::CLI::Base
"uninstalls the given Cask"
end
end
end
end

View File

@ -1,6 +1,8 @@
class Hbc::CLI::Update < Hbc::CLI::Base
module Hbc
class CLI
class Update < Base
def self.run(*_ignored)
result = Hbc::SystemCommand.run(Hbc.homebrew_executable,
result = SystemCommand.run(Hbc.homebrew_executable,
args: %w[update])
# TODO: separating stderr/stdout is undesirable here.
# Hbc::SystemCommand should have an option for plain
@ -14,3 +16,5 @@ class Hbc::CLI::Update < Hbc::CLI::Base
"a synonym for 'brew update'"
end
end
end
end

View File

@ -1,11 +1,13 @@
class Hbc::CLI::Zap < Hbc::CLI::Base
module Hbc
class CLI
class Zap < Base
def self.run(*args)
cask_tokens = cask_tokens_from(args)
raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
raise CaskUnspecifiedError if cask_tokens.empty?
cask_tokens.each do |cask_token|
odebug "Zapping Cask #{cask_token}"
cask = Hbc.load(cask_token)
Hbc::Installer.new(cask).zap
Installer.new(cask).zap
end
end
@ -13,3 +15,5 @@ class Hbc::CLI::Zap < Hbc::CLI::Base
"zaps all files associated with the given Cask"
end
end
end
end

View File

@ -1,5 +1,3 @@
class Hbc::Container; end
require "hbc/container/base"
require "hbc/container/air"
require "hbc/container/bzip2"
@ -22,26 +20,27 @@ require "hbc/container/xip"
require "hbc/container/xz"
require "hbc/container/zip"
class Hbc::Container
module Hbc
class Container
def self.autodetect_containers
[
Hbc::Container::Pkg,
Hbc::Container::Ttf,
Hbc::Container::Otf,
Hbc::Container::Air,
Hbc::Container::Cab,
Hbc::Container::Dmg,
Hbc::Container::SevenZip,
Hbc::Container::Sit,
Hbc::Container::Rar,
Hbc::Container::Zip,
Hbc::Container::Xip, # needs to be before xar as this is a cpio inside a gzip inside a xar
Hbc::Container::Xar, # need to be before tar as tar can also list xar
Hbc::Container::Tar, # or compressed tar (bzip2/gzip/lzma/xz)
Hbc::Container::Bzip2, # pure bzip2
Hbc::Container::Gzip, # pure gzip
Hbc::Container::Lzma, # pure lzma
Hbc::Container::Xz, # pure xz
Pkg,
Ttf,
Otf,
Air,
Cab,
Dmg,
SevenZip,
Sit,
Rar,
Zip,
Xip, # needs to be before xar as this is a cpio inside a gzip inside a xar
Xar, # need to be before tar as tar can also list xar
Tar, # or compressed tar (bzip2/gzip/lzma/xz)
Bzip2, # pure bzip2
Gzip, # pure gzip
Lzma, # pure lzma
Xz, # pure xz
]
# for explicit use only (never autodetected):
# Hbc::Container::Naked
@ -50,7 +49,7 @@ class Hbc::Container
def self.for_path(path, command)
odebug "Determining which containers to use based on filetype"
criteria = Hbc::Container::Criteria.new(path, command)
criteria = Criteria.new(path, command)
autodetect_containers.find do |c|
odebug "Checking container class #{c}"
c.me?(criteria)
@ -60,9 +59,10 @@ class Hbc::Container
def self.from_type(type)
odebug "Determining which containers to use based on 'container :type'"
begin
Hbc::Container.const_get(type.to_s.split("_").map(&:capitalize).join)
self.const_get(type.to_s.split("_").map(&:capitalize).join)
rescue NameError
false
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/container/base"
class Hbc::Container::Air < Hbc::Container::Base
module Hbc
class Container
class Air < Base
INSTALLER_PATHNAME =
Pathname("/Applications/Utilities/Adobe AIR Application Installer.app" \
"/Contents/MacOS/Adobe AIR Application Installer")
@ -11,7 +13,7 @@ class Hbc::Container::Air < Hbc::Container::Base
def self.installer_cmd
return @installer_cmd ||= INSTALLER_PATHNAME if installer_exist?
raise Hbc::CaskError, <<-EOS.undent
raise CaskError, <<-EOS.undent
Adobe AIR runtime not present, try installing it via
brew cask install adobe-air
@ -28,6 +30,8 @@ class Hbc::Container::Air < Hbc::Container::Base
args: ["-silent", "-location", @cask.staged_path, Pathname.new(@path).realpath])
return unless install.exit_status == 9
raise Hbc::CaskError, "Adobe AIR application #{@cask} already exists on the system, and cannot be reinstalled."
raise CaskError, "Adobe AIR application #{@cask} already exists on the system, and cannot be reinstalled."
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::Container::Base
module Hbc
class Container
class Base
def initialize(cask, path, command, nested: false)
@cask = cask
@path = path
@ -25,7 +27,7 @@ class Hbc::Container::Base
end
def extract_nested_container(source)
container = Hbc::Container.for_path(source, @command)
container = Container.for_path(source, @command)
return false unless container
@ -35,3 +37,5 @@ class Hbc::Container::Base
true
end
end
end
end

View File

@ -2,7 +2,9 @@ require "tmpdir"
require "hbc/container/base"
class Hbc::Container::Bzip2 < Hbc::Container::Base
module Hbc
class Container
class Bzip2 < Base
def self.me?(criteria)
criteria.magic_number(%r{^BZh}n)
end
@ -16,3 +18,5 @@ class Hbc::Container::Bzip2 < Hbc::Container::Base
end
end
end
end
end

View File

@ -2,7 +2,9 @@ require "tmpdir"
require "hbc/container/base"
class Hbc::Container::Cab < Hbc::Container::Base
module Hbc
class Container
class Cab < Base
def self.me?(criteria)
cabextract = Hbc.homebrew_prefix.join("bin", "cabextract")
@ -15,7 +17,7 @@ class Hbc::Container::Cab < Hbc::Container::Base
cabextract = Hbc.homebrew_prefix.join("bin", "cabextract")
unless cabextract.exist?
raise Hbc::CaskError, "Expected to find cabextract executable. Cask '#{@cask}' must add: depends_on formula: 'cabextract'"
raise CaskError, "Expected to find cabextract executable. Cask '#{@cask}' must add: depends_on formula: 'cabextract'"
end
Dir.mktmpdir do |unpack_dir|
@ -24,3 +26,5 @@ class Hbc::Container::Cab < Hbc::Container::Base
end
end
end
end
end

View File

@ -1,4 +1,6 @@
class Hbc::Container::Criteria
module Hbc
class Container
class Criteria
attr_reader :path, :command
def initialize(path, command)
@ -16,3 +18,5 @@ class Hbc::Container::Criteria
@magic_number =~ regex
end
end
end
end

View File

@ -3,7 +3,9 @@ require "tempfile"
require "hbc/container/base"
class Hbc::Container::Dmg < Hbc::Container::Base
module Hbc
class Container
class Dmg < Base
def self.me?(criteria)
!criteria.command.run("/usr/bin/hdiutil",
# realpath is a failsafe against unusual filenames
@ -46,8 +48,8 @@ class Hbc::Container::Dmg < Hbc::Container::Base
args: ["eject", mountpath],
print_stderr: false)
raise Hbc::CaskError, "Failed to eject #{mountpath}" if mountpath.exist?
rescue Hbc::CaskError => e
raise CaskError, "Failed to eject #{mountpath}" if mountpath.exist?
rescue CaskError => e
raise e if (tries -= 1).zero?
sleep 1
retry
@ -120,6 +122,8 @@ class Hbc::Container::Dmg < Hbc::Container::Base
end
def assert_mounts_found
raise Hbc::CaskError, "No mounts found in '#{@path}'; perhaps it is a bad DMG?" if @mounts.empty?
raise CaskError, "No mounts found in '#{@path}'; perhaps it is a bad DMG?" if @mounts.empty?
end
end
end
end

View File

@ -2,7 +2,9 @@ require "tmpdir"
require "hbc/container/base"
class Hbc::Container::GenericUnar < Hbc::Container::Base
module Hbc
class Container
class GenericUnar < Base
def self.me?(criteria)
lsar = Hbc.homebrew_prefix.join("bin", "lsar")
lsar.exist? &&
@ -15,7 +17,7 @@ class Hbc::Container::GenericUnar < Hbc::Container::Base
unar = Hbc.homebrew_prefix.join("bin", "unar")
unless unar.exist?
raise Hbc::CaskError, "Expected to find unar executable. Cask #{@cask} must add: depends_on formula: 'unar'"
raise CaskError, "Expected to find unar executable. Cask #{@cask} must add: depends_on formula: 'unar'"
end
Dir.mktmpdir do |unpack_dir|
@ -24,3 +26,5 @@ class Hbc::Container::GenericUnar < Hbc::Container::Base
end
end
end
end
end

View File

@ -2,7 +2,9 @@ require "tmpdir"
require "hbc/container/base"
class Hbc::Container::Gzip < Hbc::Container::Base
module Hbc
class Container
class Gzip < Base
def self.me?(criteria)
criteria.magic_number(%r{^\037\213}n)
end
@ -16,3 +18,5 @@ class Hbc::Container::Gzip < Hbc::Container::Base
end
end
end
end
end

View File

@ -2,7 +2,9 @@ require "tmpdir"
require "hbc/container/base"
class Hbc::Container::Lzma < Hbc::Container::Base
module Hbc
class Container
class Lzma < Base
def self.me?(criteria)
criteria.magic_number(%r{^\]\000\000\200\000}n)
end
@ -11,7 +13,7 @@ class Hbc::Container::Lzma < Hbc::Container::Base
unlzma = Hbc.homebrew_prefix.join("bin", "unlzma")
unless unlzma.exist?
raise Hbc::CaskError, "Expected to find unlzma executable. Cask '#{@cask}' must add: depends_on formula: 'lzma'"
raise CaskError, "Expected to find unlzma executable. Cask '#{@cask}' must add: depends_on formula: 'lzma'"
end
Dir.mktmpdir do |unpack_dir|
@ -21,3 +23,5 @@ class Hbc::Container::Lzma < Hbc::Container::Base
end
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/container/base"
class Hbc::Container::Naked < Hbc::Container::Base
module Hbc
class Container
class Naked < Base
# Either inherit from this class and override with self.me?(criteria),
# or use this class directly as "container type: :naked",
# in which case self.me? is not called.
@ -17,3 +19,5 @@ class Hbc::Container::Naked < Hbc::Container::Base
URI.decode(File.basename(@cask.url.path))
end
end
end
end

View File

@ -1,7 +1,11 @@
require "hbc/container/naked"
class Hbc::Container::Otf < Hbc::Container::Naked
module Hbc
class Container
class Otf < Naked
def self.me?(criteria)
criteria.magic_number(%r{^OTTO}n)
end
end
end
end

View File

@ -1,9 +1,13 @@
require "hbc/container/naked"
class Hbc::Container::Pkg < Hbc::Container::Naked
module Hbc
class Container
class Pkg < Naked
def self.me?(criteria)
criteria.extension(%r{m?pkg$}) &&
(criteria.path.directory? ||
criteria.magic_number(%r{^xar!}n))
end
end
end
end

View File

@ -1,8 +1,12 @@
require "hbc/container/generic_unar"
class Hbc::Container::Rar < Hbc::Container::GenericUnar
module Hbc
class Container
class Rar < GenericUnar
def self.me?(criteria)
criteria.magic_number(%r{^Rar!}n) &&
super
end
end
end
end

View File

@ -1,9 +1,13 @@
require "hbc/container/generic_unar"
class Hbc::Container::SevenZip < Hbc::Container::GenericUnar
module Hbc
class Container
class SevenZip < GenericUnar
def self.me?(criteria)
# TODO: cover self-extracting archives
criteria.magic_number(%r{^7z}n) &&
super
end
end
end
end

View File

@ -1,8 +1,12 @@
require "hbc/container/generic_unar"
class Hbc::Container::Sit < Hbc::Container::GenericUnar
module Hbc
class Container
class Sit < GenericUnar
def self.me?(criteria)
criteria.magic_number(%r{^StuffIt}n) &&
super
end
end
end
end

View File

@ -2,7 +2,9 @@ require "tmpdir"
require "hbc/container/base"
class Hbc::Container::Tar < Hbc::Container::Base
module Hbc
class Container
class Tar < Base
def self.me?(criteria)
criteria.magic_number(%r{^.{257}ustar}n) ||
# or compressed tar (bzip2/gzip/lzma/xz)
@ -16,3 +18,5 @@ class Hbc::Container::Tar < Hbc::Container::Base
end
end
end
end
end

View File

@ -1,6 +1,8 @@
require "hbc/container/naked"
class Hbc::Container::Ttf < Hbc::Container::Naked
module Hbc
class Container
class Ttf < Naked
def self.me?(criteria)
# TrueType Font
criteria.magic_number(%r{^\000\001\000\000\000}n) ||
@ -8,3 +10,5 @@ class Hbc::Container::Ttf < Hbc::Container::Naked
criteria.magic_number(%r{^ttcf}n)
end
end
end
end

View File

@ -2,7 +2,9 @@ require "tmpdir"
require "hbc/container/base"
class Hbc::Container::Xar < Hbc::Container::Base
module Hbc
class Container
class Xar < Base
def self.me?(criteria)
criteria.magic_number(%r{^xar!}n)
end
@ -14,3 +16,5 @@ class Hbc::Container::Xar < Hbc::Container::Base
end
end
end
end
end

View File

@ -1,6 +1,8 @@
require "tmpdir"
class Hbc::Container::Xip < Hbc::Container::Base
module Hbc
class Container
class Xip < Base
def self.me?(criteria)
criteria.magic_number(%r{^xar!}n) &&
IO.popen(["/usr/bin/xar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| io.read =~ %r{\AContent\nMetadata\n\Z} }
@ -23,3 +25,5 @@ class Hbc::Container::Xip < Hbc::Container::Base
end
end
end
end
end

View File

@ -2,7 +2,9 @@ require "tmpdir"
require "hbc/container/base"
class Hbc::Container::Xz < Hbc::Container::Base
module Hbc
class Container
class Xz < Base
def self.me?(criteria)
criteria.magic_number(%r{^\xFD7zXZ\x00}n)
end
@ -11,7 +13,7 @@ class Hbc::Container::Xz < Hbc::Container::Base
unxz = Hbc.homebrew_prefix.join("bin", "unxz")
unless unxz.exist?
raise Hbc::CaskError, "Expected to find unxz executable. Cask '#{@cask}' must add: depends_on formula: 'xz'"
raise CaskError, "Expected to find unxz executable. Cask '#{@cask}' must add: depends_on formula: 'xz'"
end
Dir.mktmpdir do |unpack_dir|
@ -21,3 +23,5 @@ class Hbc::Container::Xz < Hbc::Container::Base
end
end
end
end
end

Some files were not shown because too many files have changed in this diff Show More