Merge pull request #17792 from Homebrew/explain-std_-_args

This commit is contained in:
Patrick Linnane 2024-07-18 08:10:48 -07:00 committed by GitHub
commit e3851595f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 90 additions and 23 deletions

View File

@ -1773,16 +1773,16 @@ class Formula
"#<Formula #{name} (#{active_spec_sym}) #{path}>"
end
# Standard parameters for configure builds.
sig {
params(
prefix: T.any(String, Pathname),
libdir: T.any(String, Pathname),
).returns(T::Array[String])
}
def std_configure_args(prefix: self.prefix, libdir: "lib")
libdir = Pathname(libdir).expand_path(prefix)
["--disable-debug", "--disable-dependency-tracking", "--prefix=#{prefix}", "--libdir=#{libdir}"]
# Standard parameters for cabal-v2 builds.
sig { returns(T::Array[String]) }
def std_cabal_v2_args
# cabal-install's dependency-resolution backtracking strategy can
# easily need more than the default 2,000 maximum number of
# "backjumps," since Hackage is a fast-moving, rolling-release
# target. The highest known needed value by a formula was 43,478
# for git-annex, so 100,000 should be enough to avoid most
# gratuitous backjumps build failures.
["--jobs=#{ENV.make_jobs}", "--max-backjumps=100000", "--install-method=copy", "--installdir=#{bin}"]
end
# Standard parameters for cargo builds.
@ -1819,6 +1819,18 @@ class Formula
end
alias generic_std_cmake_args std_cmake_args
# Standard parameters for configure builds.
sig {
params(
prefix: T.any(String, Pathname),
libdir: T.any(String, Pathname),
).returns(T::Array[String])
}
def std_configure_args(prefix: self.prefix, libdir: "lib")
libdir = Pathname(libdir).expand_path(prefix)
["--disable-debug", "--disable-dependency-tracking", "--prefix=#{prefix}", "--libdir=#{libdir}"]
end
# Standard parameters for Go builds.
sig {
params(output: T.any(String, Pathname),
@ -1830,18 +1842,6 @@ class Formula
args
end
# Standard parameters for cabal-v2 builds.
sig { returns(T::Array[String]) }
def std_cabal_v2_args
# cabal-install's dependency-resolution backtracking strategy can
# easily need more than the default 2,000 maximum number of
# "backjumps," since Hackage is a fast-moving, rolling-release
# target. The highest known needed value by a formula was 43,478
# for git-annex, so 100,000 should be enough to avoid most
# gratuitous backjumps build failures.
["--jobs=#{ENV.make_jobs}", "--max-backjumps=100000", "--install-method=copy", "--installdir=#{bin}"]
end
# Standard parameters for meson builds.
sig { returns(T::Array[String]) }
def std_meson_args

View File

@ -448,7 +448,7 @@ end
### Standard arguments
For any formula using a well-known build system, there'll be arguments that should be passed during compilation such that its build conforms to Homebrew standards. These have been collected into a set of `std_*_args` methods (like [`std_configure_args`](https://rubydoc.brew.sh/Formula#std_configure_args-instance_method) and [`std_cmake_args`](https://rubydoc.brew.sh/Formula#std_cmake_args-instance_method) as seen in the [output of `brew create`](#grab-the-url)) that set the build type and installation paths, plus any other applicable options.
For any formula using certain well-known build systems, there will be arguments that should be passed during compilation so that the build conforms to Homebrew standards. These have been collected into a set of `std_*_args` methods.
Most of these methods accept parameters to customize their output. For example, to set the install prefix to [**`libexec`**](#variables-for-directory-locations) for `configure` or `cmake`:
@ -457,6 +457,73 @@ system "./configure", *std_configure_args(prefix: libexec)
system "cmake", "-S", ".", "-B", "build", *std_cmake_args(install_prefix: libexec)
```
The `std_*_args` methods, as well as the arguments they pass, are:
#### `std_cabal_v2_args`
```ruby
"--jobs=#{ENV.make_jobs}"
"--max-backjumps=100000"
"--install-method=copy"
"--installdir=#{bin}"
```
#### `std_cargo_args`
```ruby
"--locked"
"--root=#{root}"
"--path=#{path}"
```
#### `std_cmake_args`
```ruby
"-DCMAKE_INSTALL_PREFIX=#{install_prefix}"
"-DCMAKE_INSTALL_LIBDIR=#{install_libdir}"
"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_FIND_FRAMEWORK=#{find_framework}"
"-DCMAKE_VERBOSE_MAKEFILE=ON"
"-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=#{HOMEBREW_LIBRARY_PATH}/cmake/trap_fetchcontent_provider.cmake"
"-Wno-dev"
"-DBUILD_TESTING=OFF"
```
#### `std_configure_args`
```ruby
"--disable-debug"
"--disable-dependency-tracking"
"--prefix=#{prefix}"
"--libdir=#{libdir}"
```
#### `std_go_args`
```ruby
"-trimpath"
"-o=#{output}"
```
#### `std_meson_args`
```ruby
"--prefix=#{prefix}"
"--libdir=#{lib}"
"--buildtype=release"
"--wrap-mode=nofallback"
```
#### `std_pip_args`
```ruby
"--verbose"
"--no-deps"
"--no-binary=:all:"
"--ignore-installed"
"--no-compile"
```
### `bin.install "foo"`
Youll see stuff like this in some formulae. This moves the file `foo` into the formulas `bin` directory (`/usr/local/Cellar/pkg/0.1/bin`) and makes it executable (`chmod 0555 foo`).