Move mode into constructor params

This commit is contained in:
Anatoli Babenia 2023-11-28 18:07:32 +00:00
parent 912678ca5e
commit b2df600e3e
2 changed files with 45 additions and 43 deletions

View File

@ -140,24 +140,7 @@ module Homebrew
end end
def create_formula(args:) def create_formula(args:)
fc = FormulaCreator.new( mode = if args.autotools?
args.set_name,
args.set_version,
tap: args.tap,
license: args.set_license,
fetch: !args.no_fetch?,
head: args.HEAD?,
)
if fc.name.blank?
stem = Pathname.new(args.named.first).stem.rpartition("=").last
print "Formula name [#{stem}]: "
fc.name = __gets || stem
end
raise TapUnavailableError, fc.tap.name unless fc.tap.installed?
fc.url = args.named.first
fc.mode = if args.autotools?
:autotools :autotools
elsif args.cmake? elsif args.cmake?
:cmake :cmake
@ -179,6 +162,24 @@ module Homebrew
:rust :rust
end end
fc = FormulaCreator.new(
args.set_name,
args.set_version,
tap: args.tap,
mode: mode,
license: args.set_license,
fetch: !args.no_fetch?,
head: args.HEAD?,
)
if fc.name.blank?
stem = Pathname.new(args.named.first).stem.rpartition("=").last
print "Formula name [#{stem}]: "
fc.name = __gets || stem
end
raise TapUnavailableError, fc.tap.name unless fc.tap.installed?
fc.url = args.named.first
# Check for disallowed formula, or names that shadow aliases, # Check for disallowed formula, or names that shadow aliases,
# unless --force is specified. # unless --force is specified.
unless args.force? unless args.force?

View File

@ -10,12 +10,13 @@ module Homebrew
# @api private # @api private
class FormulaCreator class FormulaCreator
attr_reader :url, :sha256, :desc, :homepage attr_reader :url, :sha256, :desc, :homepage
attr_accessor :name, :tap, :mode attr_accessor :name, :tap
def initialize(name, version, tap:, license:, fetch: true, head: false) def initialize(name, version, tap:, mode:, license:, fetch: true, head: false)
@name = name @name = name
@version = Version.new(version) if version @version = Version.new(version) if version
@tap = Tap.fetch(tap || "homebrew/core") @tap = Tap.fetch(tap || "homebrew/core")
@mode = mode
@license = license @license = license
@fetch = fetch @fetch = fetch
@head = head @head = head
@ -85,12 +86,12 @@ module Homebrew
# Documentation: https://docs.brew.sh/Formula-Cookbook # Documentation: https://docs.brew.sh/Formula-Cookbook
# https://rubydoc.brew.sh/Formula # https://rubydoc.brew.sh/Formula
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST! # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
<% if mode == :node %> <% if @mode == :node %>
require "language/node" require "language/node"
<% end %> <% end %>
class #{Formulary.class_s(name)} < Formula class #{Formulary.class_s(name)} < Formula
<% if mode == :python %> <% if @mode == :python %>
include Language::Python::Virtualenv include Language::Python::Virtualenv
<% end %> <% end %>
@ -108,30 +109,30 @@ module Homebrew
head "#{url}" head "#{url}"
<% end %> <% end %>
<% if mode == :cmake %> <% if @mode == :cmake %>
depends_on "cmake" => :build depends_on "cmake" => :build
<% elsif mode == :crystal %> <% elsif @mode == :crystal %>
depends_on "crystal" => :build depends_on "crystal" => :build
<% elsif mode == :go %> <% elsif @mode == :go %>
depends_on "go" => :build depends_on "go" => :build
<% elsif mode == :meson %> <% elsif @mode == :meson %>
depends_on "meson" => :build depends_on "meson" => :build
depends_on "ninja" => :build depends_on "ninja" => :build
<% elsif mode == :node %> <% elsif @mode == :node %>
depends_on "node" depends_on "node"
<% elsif mode == :perl %> <% elsif @mode == :perl %>
uses_from_macos "perl" uses_from_macos "perl"
<% elsif mode == :python %> <% elsif @mode == :python %>
depends_on "python" depends_on "python"
<% elsif mode == :ruby %> <% elsif @mode == :ruby %>
uses_from_macos "ruby" uses_from_macos "ruby"
<% elsif mode == :rust %> <% elsif @mode == :rust %>
depends_on "rust" => :build depends_on "rust" => :build
<% elsif mode.nil? %> <% elsif @mode.nil? %>
# depends_on "cmake" => :build # depends_on "cmake" => :build
<% end %> <% end %>
<% if mode == :perl %> <% if @mode == :perl %>
# Additional dependency # Additional dependency
# resource "" do # resource "" do
# url "" # url ""
@ -141,28 +142,28 @@ module Homebrew
<% end %> <% end %>
def install def install
# ENV.deparallelize # if your formula fails when building in parallel # ENV.deparallelize # if your formula fails when building in parallel
<% if mode == :cmake %> <% if @mode == :cmake %>
system "cmake", "-S", ".", "-B", "build", *std_cmake_args system "cmake", "-S", ".", "-B", "build", *std_cmake_args
system "cmake", "--build", "build" system "cmake", "--build", "build"
system "cmake", "--install", "build" system "cmake", "--install", "build"
<% elsif mode == :autotools %> <% elsif @mode == :autotools %>
# Remove unrecognized options if warned by configure # Remove unrecognized options if warned by configure
# https://rubydoc.brew.sh/Formula.html#std_configure_args-instance_method # https://rubydoc.brew.sh/Formula.html#std_configure_args-instance_method
system "./configure", *std_configure_args, "--disable-silent-rules" system "./configure", *std_configure_args, "--disable-silent-rules"
system "make", "install" # if this fails, try separate make/make install steps system "make", "install" # if this fails, try separate make/make install steps
<% elsif mode == :crystal %> <% elsif @mode == :crystal %>
system "shards", "build", "--release" system "shards", "build", "--release"
bin.install "bin/#{name}" bin.install "bin/#{name}"
<% elsif mode == :go %> <% elsif @mode == :go %>
system "go", "build", *std_go_args(ldflags: "-s -w") system "go", "build", *std_go_args(ldflags: "-s -w")
<% elsif mode == :meson %> <% elsif @mode == :meson %>
system "meson", "setup", "build", *std_meson_args system "meson", "setup", "build", *std_meson_args
system "meson", "compile", "-C", "build", "--verbose" system "meson", "compile", "-C", "build", "--verbose"
system "meson", "install", "-C", "build" system "meson", "install", "-C", "build"
<% elsif mode == :node %> <% elsif @mode == :node %>
system "npm", "install", *Language::Node.std_npm_install_args(libexec) system "npm", "install", *Language::Node.std_npm_install_args(libexec)
bin.install_symlink Dir["\#{libexec}/bin/*"] bin.install_symlink Dir["\#{libexec}/bin/*"]
<% elsif mode == :perl %> <% elsif @mode == :perl %>
ENV.prepend_create_path "PERL5LIB", libexec/"lib/perl5" ENV.prepend_create_path "PERL5LIB", libexec/"lib/perl5"
ENV.prepend_path "PERL5LIB", libexec/"lib" ENV.prepend_path "PERL5LIB", libexec/"lib"
@ -182,15 +183,15 @@ module Homebrew
bin.install name bin.install name
bin.env_script_all_files(libexec/"bin", PERL5LIB: ENV["PERL5LIB"]) bin.env_script_all_files(libexec/"bin", PERL5LIB: ENV["PERL5LIB"])
<% elsif mode == :python %> <% elsif @mode == :python %>
virtualenv_install_with_resources virtualenv_install_with_resources
<% elsif mode == :ruby %> <% elsif @mode == :ruby %>
ENV["GEM_HOME"] = libexec ENV["GEM_HOME"] = libexec
system "gem", "build", "\#{name}.gemspec" system "gem", "build", "\#{name}.gemspec"
system "gem", "install", "\#{name}-\#{@version}.gem" system "gem", "install", "\#{name}-\#{@version}.gem"
bin.install libexec/"bin/\#{name}" bin.install libexec/"bin/\#{name}"
bin.env_script_all_files(libexec/"bin", GEM_HOME: ENV["GEM_HOME"]) bin.env_script_all_files(libexec/"bin", GEM_HOME: ENV["GEM_HOME"])
<% elsif mode == :rust %> <% elsif @mode == :rust %>
system "cargo", "install", *std_cargo_args system "cargo", "install", *std_cargo_args
<% else %> <% else %>
# Remove unrecognized options if warned by configure # Remove unrecognized options if warned by configure