135 lines
4.7 KiB
Ruby
Raw Normal View History

#: * `create` <URL> [`--autotools`|`--cmake`|`--meson`] [`--no-fetch`] [`--set-name` <name>] [`--set-version` <version>] [`--tap` <user>`/`<repo>]:
2016-04-08 16:28:43 +02:00
#: Generate a formula for the downloadable file at <URL> and open it in the editor.
#: Homebrew will attempt to automatically derive the formula name
#: and version, but if it fails, you'll have to make your own template. The `wget`
#: formula serves as a simple example. For the complete API have a look at
2018-10-03 21:03:22 +00:00
#: <https://www.rubydoc.info/github/Homebrew/brew/master/Formula>.
2016-04-08 16:28:43 +02:00
#:
#: If `--autotools` is passed, create a basic template for an Autotools-style build.
#: If `--cmake` is passed, create a basic template for a CMake-style build.
#: If `--meson` is passed, create a basic template for a Meson-style build.
2016-04-08 16:28:43 +02:00
#:
#: If `--no-fetch` is passed, Homebrew will not download <URL> to the cache and
#: will thus not add the SHA256 to the formula for you. It will also not check
#: the GitHub API for GitHub projects (to fill out the description and homepage).
2016-04-08 16:28:43 +02:00
#:
#: The options `--set-name` and `--set-version` each take an argument and allow
#: you to explicitly set the name and version of the package you are creating.
#:
#: The option `--tap` takes a tap as its argument and generates the formula in
#: the specified tap.
2016-04-08 16:28:43 +02:00
require "formula"
require "formula_creator"
require "missing_formula"
2018-06-03 01:15:28 +05:30
require "cli_parser"
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
def create_args
Homebrew::CLI::Parser.new do
2018-09-28 21:39:52 +05:30
usage_banner <<~EOS
2018-10-03 10:19:46 +05:30
`create` <URL> [<options>]:
2018-09-28 21:39:52 +05:30
Generate a formula for the downloadable file at <URL> and open it in the editor.
Homebrew will attempt to automatically derive the formula name
and version, but if it fails, you'll have to make your own template. The `wget`
formula serves as a simple example. For the complete API have a look at
<http://www.rubydoc.info/github/Homebrew/brew/master/Formula>.
EOS
switch "--autotools",
description: "Create a basic template for an Autotools-style build."
switch "--cmake",
description: "Create a basic template for a CMake-style build."
switch "--meson",
description: "Create a basic template for a Meson-style build."
switch "--no-fetch",
description: "Homebrew will not download <URL> to the cache and will thus not add the SHA256 to "\
"the formula for you. It will also not check the GitHub API for GitHub projects "\
"(to fill out the description and homepage)."
2018-06-03 01:15:28 +05:30
switch "--HEAD"
2018-09-28 21:39:52 +05:30
flag "--set-name=",
description: "Set the provided name of the package you are creating."
flag "--set-version=",
description: "Set the provided version of the package you are creating."
flag "--tap=",
description: "Takes a tap [<user>`/`<repo>] as argument and generates the formula in the "\
"specified tap."
2018-06-03 01:15:28 +05:30
switch :force
switch :verbose
switch :debug
end
end
# Create a formula from a tarball URL
def create
create_args.parse
raise UsageError if ARGV.named.empty?
# Ensure that the cache exists so we can fetch the tarball
HOMEBREW_CACHE.mkpath
url = ARGV.named.first # Pull the first (and only) url from ARGV
2018-06-03 01:15:28 +05:30
version = args.set_version
name = args.set_name
tap = args.tap
fc = FormulaCreator.new
fc.name = name
fc.version = version
fc.tap = Tap.fetch(tap || "homebrew/core")
raise TapUnavailableError, tap unless fc.tap.installed?
2018-09-17 02:45:00 +02:00
fc.url = url
2018-06-03 01:15:28 +05:30
fc.mode = if args.cmake?
:cmake
2018-06-03 01:15:28 +05:30
elsif args.autotools?
:autotools
2018-06-03 01:15:28 +05:30
elsif args.meson?
:meson
end
2014-07-17 19:40:44 -05:00
if fc.name.nil? || fc.name.strip.empty?
stem = Pathname.new(url).stem
print "Formula name [#{stem}]: "
fc.name = __gets || stem
fc.update_path
end
# Don't allow blacklisted formula, or names that shadow aliases,
# unless --force is specified.
2018-06-03 01:15:28 +05:30
unless args.force?
2018-04-14 01:39:00 +02:00
if reason = MissingFormula.blacklisted_reason(fc.name)
raise <<~EOS
#{fc.name} is blacklisted for creation.
#{reason}
If you really want to create this formula use --force.
EOS
end
if Formula.aliases.include? fc.name
realname = Formulary.canonical_name(fc.name)
2017-10-15 02:28:32 +02:00
raise <<~EOS
The formula #{realname} is already aliased to #{fc.name}
Please check that you are not creating a duplicate.
To force creation use --force.
2018-06-06 23:34:19 -04:00
EOS
end
end
fc.generate!
puts "Please `brew audit --new-formula #{fc.name}` before submitting, thanks."
exec_editor fc.path
end
def __gets
gots = $stdin.gets.chomp
2016-09-11 17:41:51 +01:00
gots.empty? ? nil : gots
end
end