Module: FileUtils

Included in:
AbstractDownloadStrategy, Mktemp, Formula, Homebrew, Resource
Defined in:
Library/Homebrew/extend/fileutils.rb

Overview

Homebrew extends Ruby's FileUtils to make our code more readable.

Defined Under Namespace

Classes: Mktemp

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.mkdir(name, &_block) ⇒ Object

A version of mkdir that also changes to that folder in a block.



90
91
92
93
94
95
96
# File 'Library/Homebrew/extend/fileutils.rb', line 90

def mkdir(name, &_block)
  mkdir_p(name)
  return unless block_given?
  chdir name do
    yield
  end
end

.mktemp(prefix = name, opts = {}) ⇒ Object

Create a temporary directory then yield. When the block returns, recursively delete the temporary directory. Passing opts[:retain] or calling do |staging| ... staging.retain! in the block will skip the deletion and retain the temporary directory's contents.



12
13
14
15
16
# File 'Library/Homebrew/extend/fileutils.rb', line 12

def mktemp(prefix = name, opts = {})
  Mktemp.new(prefix, opts).run do |staging|
    yield staging
  end
end

Instance Method Details

#make(*args) ⇒ Object

Run make 3.81 or newer. Uses the system make on Leopard and newer, and the path to the actually-installed make on Tiger or older.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'Library/Homebrew/extend/fileutils.rb', line 112

def make(*args)
  if Utils.popen_read("/usr/bin/make", "--version").match(/Make (\d\.\d+)/)[1] > "3.80"
    make_path = "/usr/bin/make"
  else
    make = Formula["make"].opt_bin/"make"
    make_path = make.exist? ? make.to_s : (Formula["make"].opt_bin/"gmake").to_s
  end

  if superenv?
    make_name = File.basename(make_path)
    with_env "HOMEBREW_MAKE" => make_name do
      system "make", *args
    end
  else
    system make_path, *args
  end
end

#rake(*args) ⇒ Object

Run the rake from the ruby Homebrew is using rather than whatever is in the PATH.



105
106
107
# File 'Library/Homebrew/extend/fileutils.rb', line 105

def rake(*args)
  system RUBY_BIN/"rake", *args
end

#ruby(*args) ⇒ Object

Run the ruby Homebrew is using rather than whatever is in the PATH.



136
137
138
# File 'Library/Homebrew/extend/fileutils.rb', line 136

def ruby(*args)
  system RUBY_PATH, *args
end

#scons(*args) ⇒ Object

Run scons using a Homebrew-installed version rather than whatever is in the PATH.



100
101
102
# File 'Library/Homebrew/extend/fileutils.rb', line 100

def scons(*args)
  system Formulary.factory("scons").opt_bin/"scons", *args
end

#xcodebuild(*args) ⇒ Object

Run xcodebuild without Homebrew's compiler environment variables set.



141
142
143
144
145
146
# File 'Library/Homebrew/extend/fileutils.rb', line 141

def xcodebuild(*args)
  removed = ENV.remove_cc_etc
  system "xcodebuild", *args
ensure
  ENV.update(removed)
end