Merge pull request #713 from MikeMcQuaid/ship-sandbox

Enable sandbox by default for homebrew/core
This commit is contained in:
Mike McQuaid 2016-08-17 08:30:16 +01:00 committed by GitHub
commit 2ab5c77d0c
5 changed files with 41 additions and 12 deletions

View File

@ -21,12 +21,10 @@ module Homebrew
args << "--devel" args << "--devel"
end end
if Sandbox.available? && ARGV.sandbox? Sandbox.print_sandbox_message if Sandbox.formula?(formula)
Sandbox.print_sandbox_message
end
Utils.safe_fork do Utils.safe_fork do
if Sandbox.available? && ARGV.sandbox? if Sandbox.formula?(formula)
sandbox = Sandbox.new sandbox = Sandbox.new
formula.logs.mkpath formula.logs.mkpath
sandbox.record_log(formula.logs/"sandbox.postinstall.log") sandbox.record_log(formula.logs/"sandbox.postinstall.log")

View File

@ -57,12 +57,10 @@ module Homebrew
args << "--devel" args << "--devel"
end end
if Sandbox.available? && !ARGV.no_sandbox? Sandbox.print_sandbox_message if Sandbox.test?
Sandbox.print_sandbox_message
end
Utils.safe_fork do Utils.safe_fork do
if Sandbox.available? && !ARGV.no_sandbox? if Sandbox.test?
sandbox = Sandbox.new sandbox = Sandbox.new
f.logs.mkpath f.logs.mkpath
sandbox.record_log(f.logs/"sandbox.test.log") sandbox.record_log(f.logs/"sandbox.test.log")

View File

@ -588,15 +588,13 @@ class FormulaInstaller
#{formula.path} #{formula.path}
].concat(build_argv) ].concat(build_argv)
if Sandbox.available? && ARGV.sandbox? Sandbox.print_sandbox_message if Sandbox.formula?(formula)
Sandbox.print_sandbox_message
end
Utils.safe_fork do Utils.safe_fork do
# Invalidate the current sudo timestamp in case a build script calls sudo # Invalidate the current sudo timestamp in case a build script calls sudo
system "/usr/bin/sudo", "-k" system "/usr/bin/sudo", "-k"
if Sandbox.available? && ARGV.sandbox? if Sandbox.formula?(formula)
sandbox = Sandbox.new sandbox = Sandbox.new
formula.logs.mkpath formula.logs.mkpath
sandbox.record_log(formula.logs/"sandbox.build.log") sandbox.record_log(formula.logs/"sandbox.build.log")

View File

@ -3,11 +3,24 @@ require "tempfile"
class Sandbox class Sandbox
SANDBOX_EXEC = "/usr/bin/sandbox-exec".freeze SANDBOX_EXEC = "/usr/bin/sandbox-exec".freeze
SANDBOXED_TAPS = [
"homebrew/core",
].freeze
def self.available? def self.available?
OS.mac? && File.executable?(SANDBOX_EXEC) OS.mac? && File.executable?(SANDBOX_EXEC)
end end
def self.formula?(formula)
return false unless available?
ARGV.sandbox? || SANDBOXED_TAPS.include?(formula.tap.to_s)
end
def self.test?
return false unless available?
!ARGV.no_sandbox?
end
def self.print_sandbox_message def self.print_sandbox_message
unless @printed_sandbox_message unless @printed_sandbox_message
ohai "Using the sandbox" ohai "Using the sandbox"

View File

@ -13,6 +13,28 @@ class SandboxTest < Homebrew::TestCase
@dir.rmtree @dir.rmtree
end end
def test_formula?
f = formula { url "foo-1.0" }
f2 = formula { url "bar-1.0" }
f2.stubs(:tap).returns(Tap.fetch("test/tap"))
ARGV.stubs(:sandbox?).returns true
assert Sandbox.formula?(f),
"Formulae should be sandboxed if --sandbox was passed."
ARGV.stubs(:sandbox?).returns false
assert Sandbox.formula?(f),
"Formulae should be sandboxed if in a sandboxed tap."
refute Sandbox.formula?(f2),
"Formulae should not be sandboxed if not in a sandboxed tap."
end
def test_test?
ARGV.stubs(:no_sandbox?).returns false
assert Sandbox.test?,
"Tests should be sandboxed unless --no-sandbox was passed."
end
def test_allow_write def test_allow_write
@sandbox.allow_write @file @sandbox.allow_write @file
@sandbox.exec "touch", @file @sandbox.exec "touch", @file