Class: Homebrew::FormulaCreator Private

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/formula_creator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class for generating a formula from a template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ FormulaCreator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FormulaCreator.


15
16
17
# File 'Library/Homebrew/formula_creator.rb', line 15

def initialize(args)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


12
13
14
# File 'Library/Homebrew/formula_creator.rb', line 12

def args
  @args
end

#descObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


12
13
14
# File 'Library/Homebrew/formula_creator.rb', line 12

def desc
  @desc
end

#homepageObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


12
13
14
# File 'Library/Homebrew/formula_creator.rb', line 12

def homepage
  @homepage
end

#licenseObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


13
14
15
# File 'Library/Homebrew/formula_creator.rb', line 13

def license
  @license
end

#modeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


13
14
15
# File 'Library/Homebrew/formula_creator.rb', line 13

def mode
  @mode
end

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


13
14
15
# File 'Library/Homebrew/formula_creator.rb', line 13

def name
  @name
end

#pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


13
14
15
# File 'Library/Homebrew/formula_creator.rb', line 13

def path
  @path
end

#sha256Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


12
13
14
# File 'Library/Homebrew/formula_creator.rb', line 12

def sha256
  @sha256
end

#tapObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


13
14
15
# File 'Library/Homebrew/formula_creator.rb', line 13

def tap
  @tap
end

#urlObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


12
13
14
# File 'Library/Homebrew/formula_creator.rb', line 12

def url
  @url
end

#versionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


13
14
15
# File 'Library/Homebrew/formula_creator.rb', line 13

def version
  @version
end

Instance Method Details

#fetch?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

51
52
53
# File 'Library/Homebrew/formula_creator.rb', line 51

def fetch?
  !args.no_fetch?
end

#generate!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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
# File 'Library/Homebrew/formula_creator.rb', line 59

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"]
        @license = ["license"]["spdx_id"] if ["license"]
      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, trim_mode: ">").result(binding)
end

#head?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

55
56
57
# File 'Library/Homebrew/formula_creator.rb', line 55

def head?
  @head || args.HEAD?
end

#templateObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'Library/Homebrew/formula_creator.rb', line 91

def template
  <<~ERB
    # Documentation: https://docs.brew.sh/Formula-Cookbook
    #                https://rubydoc.brew.sh/Formula
    # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
    <% if mode == :node %>
    require "language/node"

    <% end %>
    class #{Formulary.class_s(name)} < Formula
    <% if mode == :python %>
      include Language::Python::Virtualenv

    <% end %>
      desc "#{desc}"
      homepage "#{homepage}"
    <% unless head? %>
      url "#{url}"
    <% unless version.nil? or version.detected_from_url? %>
      version "#{version}"
    <% end %>
      sha256 "#{sha256}"
    <% end %>
      license "#{license}"
    <% if head? %>
      head "#{url}"
    <% end %>

    <% if mode == :cmake %>
      depends_on "cmake" => :build
    <% elsif mode == :crystal %>
      depends_on "crystal" => :build
    <% elsif mode == :go %>
      depends_on "go" => :build
    <% elsif mode == :meson %>
      depends_on "meson" => :build
      depends_on "ninja" => :build
    <% elsif mode == :node %>
      depends_on "node"
    <% elsif mode == :perl %>
      uses_from_macos "perl"
    <% elsif mode == :python %>
      depends_on "python"
    <% elsif mode == :ruby %>
      uses_from_macos "ruby"
    <% elsif mode == :rust %>
      depends_on "rust" => :build
    <% elsif mode.nil? %>
      # depends_on "cmake" => :build
    <% end %>

    <% if mode == :perl %>
      # Additional dependency
      # resource "" do
      #   url ""
      #   sha256 ""
      # end

    <% 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 == :crystal %>
        system "shards", "build", "--release"
        bin.install "bin/#{name}"
    <% elsif mode == :go %>
        system "go", "build", *std_go_args
    <% elsif mode == :meson %>
        mkdir "build" do
          system "meson", *std_meson_args, ".."
          system "ninja", "-v"
          system "ninja", "install", "-v"
        end
    <% elsif mode == :node %>
        system "npm", "install", *Language::Node.std_npm_install_args(libexec)
        bin.install_symlink Dir["\#{libexec}/bin/*"]
    <% elsif mode == :perl %>
        ENV.prepend_create_path "PERL5LIB", libexec/"lib/perl5"
        ENV.prepend_path "PERL5LIB", libexec/"lib"

        # Stage additional dependency (Makefile.PL style)
        # resource("").stage do
        #   system "perl", "Makefile.PL", "INSTALL_BASE=\#{libexec}"
        #   system "make"
        #   system "make", "install"
        # end

        # Stage additional dependency (Build.PL style)
        # resource("").stage do
        #   system "perl", "Build.PL", "--install_base", libexec
        #   system "./Build"
        #   system "./Build", "install"
        # end

        bin.install name
        bin.env_script_all_files(libexec/"bin", :PERL5LIB => ENV["PERL5LIB"])
    <% elsif mode == :python %>
        virtualenv_install_with_resources
    <% elsif mode == :ruby %>
        ENV["GEM_HOME"] = libexec
        system "gem", "build", "\#{name}.gemspec"
        system "gem", "install", "\#{name}-\#{version}.gem"
        bin.install libexec/"bin/\#{name}"
        bin.env_script_all_files(libexec/"bin", :GEM_HOME => ENV["GEM_HOME"])
    <% elsif mode == :rust %>
        system "cargo", "install", *std_cargo_args
    <% 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 == :autotools || mode == :cmake %>
        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
  ERB
end

#update_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


45
46
47
48
49
# File 'Library/Homebrew/formula_creator.rb', line 45

def update_path
  return if @name.nil? || @tap.nil?

  @path = Formulary.path "#{@tap}/#{@name}"
end