Class: FormulaCreator

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/dev-cmd/create.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc



95
96
97
# File 'Library/Homebrew/dev-cmd/create.rb', line 95

def desc
  @desc
end

#homepageObject (readonly)

Returns the value of attribute homepage



95
96
97
# File 'Library/Homebrew/dev-cmd/create.rb', line 95

def homepage
  @homepage
end

#modeObject

Returns the value of attribute mode



96
97
98
# File 'Library/Homebrew/dev-cmd/create.rb', line 96

def mode
  @mode
end

#nameObject

Returns the value of attribute name



96
97
98
# File 'Library/Homebrew/dev-cmd/create.rb', line 96

def name
  @name
end

#pathObject

Returns the value of attribute path



96
97
98
# File 'Library/Homebrew/dev-cmd/create.rb', line 96

def path
  @path
end

#sha256Object (readonly)

Returns the value of attribute sha256



95
96
97
# File 'Library/Homebrew/dev-cmd/create.rb', line 95

def sha256
  @sha256
end

#tapObject

Returns the value of attribute tap



96
97
98
# File 'Library/Homebrew/dev-cmd/create.rb', line 96

def tap
  @tap
end

#urlObject

Returns the value of attribute url



95
96
97
# File 'Library/Homebrew/dev-cmd/create.rb', line 95

def url
  @url
end

#versionObject

Returns the value of attribute version



96
97
98
# File 'Library/Homebrew/dev-cmd/create.rb', line 96

def version
  @version
end

Instance Method Details

#fetch?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'Library/Homebrew/dev-cmd/create.rb', line 129

def fetch?
  !ARGV.include?("--no-fetch")
end

#generate!Object



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
# File 'Library/Homebrew/dev-cmd/create.rb', line 137

def generate!
  raise "#{path} already exists" if path.exist?

  if version.nil? || version.null?
    opoo "Version cannot be determined from URL."
    puts "You'll need to add an explicit 'version' to the formula."
  elsif fetch?
    unless head?
      r = Resource.new
      r.url(url)
      r.version(version)
      r.owner = self
      @sha256 = r.fetch.sha256 if r.download_strategy == CurlDownloadStrategy
    end

    if @user && @name
      begin
         = GitHub.repository(@user, @name)
        @desc = ["description"]
        @homepage = ["homepage"]
      rescue GitHub::HTTPNotFoundError
        # If there was no repository found assume the network connection is at
        # fault rather than the input URL.
        nil
      end
    end
  end

  path.write ERB.new(template, nil, ">").result(binding)
end

#head?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'Library/Homebrew/dev-cmd/create.rb', line 133

def head?
  @head || ARGV.build_head?
end

#templateObject



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
# File 'Library/Homebrew/dev-cmd/create.rb', line 168

def template
  <<~EOS
    # Documentation: https://docs.brew.sh/Formula-Cookbook.html
    #                http://www.rubydoc.info/github/Homebrew/brew/master/Formula
    # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
     class #{Formulary.class_s(name)} < Formula
      desc "#{desc}"
      homepage "#{homepage}"
    <% if head? %>
      head "#{url}"
    <% else %>
      url "#{url}"
    <% unless version.nil? or version.detected_from_url? %>
      version "#{version}"
    <% end %>
      sha256 "#{sha256}"
    <% end %>
     <% if mode == :cmake %>
      depends_on "cmake" => :build
    <% elsif mode == :meson %>
      depends_on "meson" => :build
      depends_on "ninja" => :build
    <% elsif mode.nil? %>
      # depends_on "cmake" => :build
    <% end %>
       def install
        # ENV.deparallelize  # if your formula fails when building in parallel
     <% if mode == :cmake %>
        system "cmake", ".", *std_cmake_args
    <% elsif mode == :autotools %>
        # Remove unrecognized options if warned by configure
        system "./configure", "--disable-debug",
                              "--disable-dependency-tracking",
                              "--disable-silent-rules",
                              "--prefix=\#{prefix}"
    <% elsif mode == :meson %>
        mkdir "build" do
          system "meson", "--prefix=\#{prefix}", ".."
          system "ninja"
          system "ninja", "test"
          system "ninja", "install"
        end
    <% else %>
        # Remove unrecognized options if warned by configure
        system "./configure", "--disable-debug",
                              "--disable-dependency-tracking",
                              "--disable-silent-rules",
                              "--prefix=\#{prefix}"
        # system "cmake", ".", *std_cmake_args
    <% end %>
    <% if mode != :meson %>
        system "make", "install" # if this fails, try separate make/make install steps
    <% end %>
      end
       test do
        # `test do` will create, run in and delete a temporary directory.
        #
        # This test will fail and we won't accept that! For Homebrew/homebrew-core
        # this will need to be a test that verifies the functionality of the
        # software. Run the test with `brew test #{name}`. Options passed
        # to `brew install` such as `--HEAD` also need to be provided to `brew test`.
        #
        # The installed folder is not in the path, so use the entire path to any
        # executables being tested: `system "\#{bin}/program", "do", "something"`.
        system "false"
      end
    end
  EOS
end

#update_pathObject



124
125
126
127
# File 'Library/Homebrew/dev-cmd/create.rb', line 124

def update_path
  return if @name.nil? || @tap.nil?
  @path = Formulary.path "#{@tap}/#{@name}"
end