Class: Homebrew::FormulaCreator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc



8
9
10
# File 'brew/Library/Homebrew/formula_creator.rb', line 8

def desc
  @desc
end

#homepageObject (readonly)

Returns the value of attribute homepage



8
9
10
# File 'brew/Library/Homebrew/formula_creator.rb', line 8

def homepage
  @homepage
end

#modeObject

Returns the value of attribute mode



9
10
11
# File 'brew/Library/Homebrew/formula_creator.rb', line 9

def mode
  @mode
end

#nameObject

Returns the value of attribute name



9
10
11
# File 'brew/Library/Homebrew/formula_creator.rb', line 9

def name
  @name
end

#pathObject

Returns the value of attribute path



9
10
11
# File 'brew/Library/Homebrew/formula_creator.rb', line 9

def path
  @path
end

#sha256Object (readonly)

Returns the value of attribute sha256



8
9
10
# File 'brew/Library/Homebrew/formula_creator.rb', line 8

def sha256
  @sha256
end

#tapObject

Returns the value of attribute tap



9
10
11
# File 'brew/Library/Homebrew/formula_creator.rb', line 9

def tap
  @tap
end

#urlObject

Returns the value of attribute url



8
9
10
# File 'brew/Library/Homebrew/formula_creator.rb', line 8

def url
  @url
end

#versionObject

Returns the value of attribute version



9
10
11
# File 'brew/Library/Homebrew/formula_creator.rb', line 9

def version
  @version
end

Instance Method Details

#fetch?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'brew/Library/Homebrew/formula_creator.rb', line 43

def fetch?
  !Homebrew.args.no_fetch?
end

#generate!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'brew/Library/Homebrew/formula_creator.rb', line 51

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)


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

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

#templateObject



82
83
84
85
86
87
88
89
90
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
# File 'brew/Library/Homebrew/formula_creator.rb', line 82

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!
    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", "-v"
          system "ninja", "install", "-v"
        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
  ERB
end

#update_pathObject



37
38
39
40
41
# File 'brew/Library/Homebrew/formula_creator.rb', line 37

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

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