From b2df600e3eb9c0bbdb529917570ea86cb80fcb77 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Tue, 28 Nov 2023 18:07:32 +0000 Subject: [PATCH] Move `mode` into constructor params --- Library/Homebrew/dev-cmd/create.rb | 37 +++++++++++---------- Library/Homebrew/formula_creator.rb | 51 +++++++++++++++-------------- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb index 334c348b74..8b7ebff471 100644 --- a/Library/Homebrew/dev-cmd/create.rb +++ b/Library/Homebrew/dev-cmd/create.rb @@ -140,24 +140,7 @@ module Homebrew end def create_formula(args:) - fc = FormulaCreator.new( - 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? + mode = if args.autotools? :autotools elsif args.cmake? :cmake @@ -179,6 +162,24 @@ module Homebrew :rust 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, # unless --force is specified. unless args.force? diff --git a/Library/Homebrew/formula_creator.rb b/Library/Homebrew/formula_creator.rb index a10b1983b1..a30765a85a 100644 --- a/Library/Homebrew/formula_creator.rb +++ b/Library/Homebrew/formula_creator.rb @@ -10,12 +10,13 @@ module Homebrew # @api private class FormulaCreator 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 @version = Version.new(version) if version @tap = Tap.fetch(tap || "homebrew/core") + @mode = mode @license = license @fetch = fetch @head = head @@ -85,12 +86,12 @@ module Homebrew # 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 %> + <% if @mode == :node %> require "language/node" <% end %> class #{Formulary.class_s(name)} < Formula - <% if mode == :python %> + <% if @mode == :python %> include Language::Python::Virtualenv <% end %> @@ -108,30 +109,30 @@ module Homebrew head "#{url}" <% end %> - <% if mode == :cmake %> + <% if @mode == :cmake %> depends_on "cmake" => :build - <% elsif mode == :crystal %> + <% elsif @mode == :crystal %> depends_on "crystal" => :build - <% elsif mode == :go %> + <% elsif @mode == :go %> depends_on "go" => :build - <% elsif mode == :meson %> + <% elsif @mode == :meson %> depends_on "meson" => :build depends_on "ninja" => :build - <% elsif mode == :node %> + <% elsif @mode == :node %> depends_on "node" - <% elsif mode == :perl %> + <% elsif @mode == :perl %> uses_from_macos "perl" - <% elsif mode == :python %> + <% elsif @mode == :python %> depends_on "python" - <% elsif mode == :ruby %> + <% elsif @mode == :ruby %> uses_from_macos "ruby" - <% elsif mode == :rust %> + <% elsif @mode == :rust %> depends_on "rust" => :build - <% elsif mode.nil? %> + <% elsif @mode.nil? %> # depends_on "cmake" => :build <% end %> - <% if mode == :perl %> + <% if @mode == :perl %> # Additional dependency # resource "" do # url "" @@ -141,28 +142,28 @@ module Homebrew <% end %> def install # 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", "--build", "build" system "cmake", "--install", "build" - <% elsif mode == :autotools %> + <% elsif @mode == :autotools %> # Remove unrecognized options if warned by configure # https://rubydoc.brew.sh/Formula.html#std_configure_args-instance_method system "./configure", *std_configure_args, "--disable-silent-rules" system "make", "install" # if this fails, try separate make/make install steps - <% elsif mode == :crystal %> + <% elsif @mode == :crystal %> system "shards", "build", "--release" bin.install "bin/#{name}" - <% elsif mode == :go %> + <% elsif @mode == :go %> system "go", "build", *std_go_args(ldflags: "-s -w") - <% elsif mode == :meson %> + <% elsif @mode == :meson %> system "meson", "setup", "build", *std_meson_args system "meson", "compile", "-C", "build", "--verbose" system "meson", "install", "-C", "build" - <% elsif mode == :node %> + <% elsif @mode == :node %> system "npm", "install", *Language::Node.std_npm_install_args(libexec) bin.install_symlink Dir["\#{libexec}/bin/*"] - <% elsif mode == :perl %> + <% elsif @mode == :perl %> ENV.prepend_create_path "PERL5LIB", libexec/"lib/perl5" ENV.prepend_path "PERL5LIB", libexec/"lib" @@ -182,15 +183,15 @@ module Homebrew bin.install name bin.env_script_all_files(libexec/"bin", PERL5LIB: ENV["PERL5LIB"]) - <% elsif mode == :python %> + <% elsif @mode == :python %> virtualenv_install_with_resources - <% elsif mode == :ruby %> + <% 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 %> + <% elsif @mode == :rust %> system "cargo", "install", *std_cargo_args <% else %> # Remove unrecognized options if warned by configure