Skip to content

Commit 63e1a2c

Browse files
authored
Merge pull request #20769 from Homebrew/portable_ruby
Import and support Portable Ruby
2 parents 2a93722 + f148967 commit 63e1a2c

File tree

12 files changed

+312
-20
lines changed

12 files changed

+312
-20
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,8 @@ jobs:
109109
- name: Run brew style on homebrew-core
110110
run: brew style homebrew/core
111111

112-
- name: Set up all Homebrew taps
113-
run: |
114-
brew tap homebrew/portable-ruby
115-
116-
# brew style doesn't like world writable directories
117-
sudo chmod -R g-w,o-w "$(brew --repo)/Library/Taps"
118-
119-
- name: Run brew style on official taps
120-
run: |
121-
brew style homebrew/portable-ruby \
122-
homebrew/cask
112+
- name: Run brew style on homebrew-cask
113+
run: brew style homebrew/cask
123114

124115
formula-audit:
125116
name: formula audit

Library/Homebrew/cmd/vendor-install.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ source "${HOMEBREW_LIBRARY}/Homebrew/utils/ruby.sh"
1212

1313
VENDOR_DIR="${HOMEBREW_LIBRARY}/Homebrew/vendor"
1414

15-
# Built from https://github.com/Homebrew/homebrew-portable-ruby.
1615
set_ruby_variables() {
1716
# Handle the case where /usr/local/bin/brew is run under arm64.
1817
# It's a x86_64 installation there (we refuse to install arm64 binaries) so
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "abstract_command"
5+
require "development_tools"
6+
require "dependency"
7+
8+
module Homebrew
9+
module Cmd
10+
class PortablePackageCmd < AbstractCommand
11+
cmd_args do
12+
usage_banner <<~EOS
13+
`portable-package` <formulae>
14+
15+
Build and package portable formulae.
16+
For internal use in Homebrew taps.
17+
EOS
18+
switch "--no-uninstall-deps",
19+
description: "Don't uninstall all dependencies of portable formulae before testing."
20+
switch "-v", "--verbose",
21+
description: "Pass `--verbose` to `brew` commands."
22+
named_args :formula, min: 1
23+
24+
hide_from_man_page!
25+
end
26+
27+
sig { override.void }
28+
def run
29+
ENV["HOMEBREW_DEVELOPER"] = "1"
30+
31+
verbose = []
32+
verbose << "--verbose" if args.verbose?
33+
verbose << "--debug" if args.debug?
34+
35+
# If test-bot cleanup is performed and auto-updates are disabled, this might not already be installed.
36+
unless DevelopmentTools.ca_file_handles_most_https_certificates?
37+
safe_system HOMEBREW_BREW_FILE, "install", "ca-certificates"
38+
end
39+
40+
args.named.each do |name|
41+
name = "portable-#{name}" unless name.start_with? "portable-"
42+
begin
43+
# On Linux, install glibc and linux-headers from bottles and don't install their build dependencies.
44+
bottled_dep_allowlist = /\A(?:glibc|linux-headers)@/
45+
deps = Dependency.expand(Formula[name], cache_key: "portable-package-#{name}") do |_dependent, dep|
46+
Dependency.prune if dep.test? || dep.optional?
47+
48+
next unless bottled_dep_allowlist.match?(dep.name)
49+
50+
Dependency.keep_but_prune_recursive_deps
51+
end.map(&:name)
52+
53+
bottled_deps, deps = deps.partition { |dep| bottled_dep_allowlist.match?(dep) }
54+
55+
safe_system HOMEBREW_BREW_FILE, "install", *verbose, *bottled_deps if bottled_deps.present?
56+
57+
# Build bottles for all other dependencies.
58+
safe_system HOMEBREW_BREW_FILE, "install", "--build-bottle", *verbose, *deps
59+
60+
safe_system HOMEBREW_BREW_FILE, "install", "--build-bottle", *verbose, name
61+
unless args.no_uninstall_deps?
62+
safe_system HOMEBREW_BREW_FILE, "uninstall", "--force", "--ignore-dependencies", *verbose, *deps
63+
end
64+
safe_system HOMEBREW_BREW_FILE, "test", *verbose, name
65+
puts "Linkage information:"
66+
safe_system HOMEBREW_BREW_FILE, "linkage", *verbose, name
67+
bottle_args = %w[
68+
--skip-relocation
69+
--json
70+
--no-rebuild
71+
]
72+
safe_system HOMEBREW_BREW_FILE, "bottle", *verbose, *bottle_args, name
73+
rescue => e
74+
ofail e
75+
end
76+
end
77+
end
78+
end
79+
end
80+
end

Library/Homebrew/github_runner_matrix.rb

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def active_runner_specs_hash
9191
def linux_runner_spec(arch)
9292
linux_runner = case arch
9393
when :arm64 then "ubuntu-22.04-arm"
94-
when :x86_64 then ENV.fetch("HOMEBREW_LINUX_RUNNER")
94+
when :x86_64 then ENV.fetch("HOMEBREW_LINUX_RUNNER", "ubuntu-latest")
9595
else raise "Unknown Linux architecture: #{arch}"
9696
end
9797

@@ -150,6 +150,38 @@ def runner_enabled?(macos_version)
150150
def generate_runners!
151151
return if @runners.present?
152152

153+
# gracefully handle non-GitHub Actions environments
154+
github_run_id = if ENV.key?("GITHUB_ACTIONS")
155+
ENV.fetch("GITHUB_RUN_ID")
156+
else
157+
ENV.fetch("GITHUB_RUN_ID", "")
158+
end
159+
160+
# Portable Ruby logic
161+
if @testing_formulae.any? { |tf| tf.name.start_with?("portable-") }
162+
@runners << create_runner(:linux, :x86_64)
163+
@runners << create_runner(:linux, :arm64)
164+
165+
x86_64_spec = MacOSRunnerSpec.new(
166+
name: "macOS 10.15 x86_64",
167+
runner: "10.15-#{github_run_id}",
168+
timeout: GITHUB_ACTIONS_LONG_TIMEOUT,
169+
cleanup: true,
170+
)
171+
x86_64_macos_version = MacOSVersion.new("10.15")
172+
@runners << create_runner(:macos, :x86_64, x86_64_spec, x86_64_macos_version)
173+
174+
arm64_spec = MacOSRunnerSpec.new(
175+
name: "macOS 11-arm64-cross",
176+
runner: "11-arm64-cross-#{github_run_id}",
177+
timeout: GITHUB_ACTIONS_LONG_TIMEOUT,
178+
cleanup: true,
179+
)
180+
arm64_macos_version = MacOSVersion.new("11")
181+
@runners << create_runner(:macos, :arm64, arm64_spec, arm64_macos_version)
182+
return
183+
end
184+
153185
if !@all_supported || ENV.key?("HOMEBREW_LINUX_RUNNER")
154186
@runners << create_runner(:linux, :x86_64)
155187

@@ -159,13 +191,6 @@ def generate_runners!
159191
end
160192
end
161193

162-
# gracefully handle non-GitHub Actions environments
163-
github_run_id = if ENV.key?("GITHUB_ACTIONS")
164-
ENV.fetch("GITHUB_RUN_ID")
165-
else
166-
ENV.fetch("GITHUB_RUN_ID", "")
167-
end
168-
169194
long_timeout = ENV.fetch("HOMEBREW_MACOS_LONG_TIMEOUT", "false") == "true"
170195
use_github_runner = ENV.fetch("HOMEBREW_MACOS_BUILD_ON_GITHUB_RUNNER", "false") == "true"
171196

Library/Homebrew/official_taps.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
livecheck
2525
nginx
2626
php
27+
portable-ruby
2728
python
2829
science
2930
services

Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/portable_package_cmd.rbi

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/test_bot_cmd.rbi

Lines changed: 133 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Library/Homebrew/test_bot/formulae.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ def formula!(formula_name, args:)
401401
return
402402
end
403403

404+
if tap&.core_tap? && formula.name.start_with?("portable-")
405+
test "brew", "portable-package", formula_name
406+
return
407+
end
408+
404409
test "brew", "deps", "--tree", "--annotate", "--include-build", "--include-test", named_args: formula_name
405410

406411
deps_without_compatible_bottles = formula.deps.map(&:to_formula)

completions/bash/brew

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,24 @@ _brew_pin() {
19521952
__brew_complete_installed_formulae
19531953
}
19541954

1955+
_brew_portable_package() {
1956+
local cur="${COMP_WORDS[COMP_CWORD]}"
1957+
case "${cur}" in
1958+
-*)
1959+
__brewcomp "
1960+
--debug
1961+
--help
1962+
--no-uninstall-deps
1963+
--quiet
1964+
--verbose
1965+
"
1966+
return
1967+
;;
1968+
*) ;;
1969+
esac
1970+
__brew_complete_formulae
1971+
}
1972+
19551973
_brew_post_install() {
19561974
local cur="${COMP_WORDS[COMP_CWORD]}"
19571975
case "${cur}" in
@@ -3360,6 +3378,7 @@ _brew() {
33603378
options) _brew_options ;;
33613379
outdated) _brew_outdated ;;
33623380
pin) _brew_pin ;;
3381+
portable-package) _brew_portable_package ;;
33633382
post_install) _brew_post_install ;;
33643383
postinstall) _brew_postinstall ;;
33653384
pr-automerge) _brew_pr_automerge ;;

completions/fish/brew.fish

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,15 @@ __fish_brew_complete_arg 'pin' -l verbose -d 'Make some output more verbose'
13091309
__fish_brew_complete_arg 'pin' -a '(__fish_brew_suggest_formulae_installed)'
13101310

13111311

1312+
__fish_brew_complete_cmd 'portable-package' 'Build and package portable formulae'
1313+
__fish_brew_complete_arg 'portable-package' -l debug -d 'Display any debugging information'
1314+
__fish_brew_complete_arg 'portable-package' -l help -d 'Show this message'
1315+
__fish_brew_complete_arg 'portable-package' -l no-uninstall-deps -d 'Don\'t uninstall all dependencies of portable formulae before testing'
1316+
__fish_brew_complete_arg 'portable-package' -l quiet -d 'Make some output more quiet'
1317+
__fish_brew_complete_arg 'portable-package' -l verbose -d 'Pass `--verbose` to `brew` commands'
1318+
__fish_brew_complete_arg 'portable-package' -a '(__fish_brew_suggest_formulae_all)'
1319+
1320+
13121321
__fish_brew_complete_cmd 'post_install' 'Rerun the post-install steps for formula'
13131322
__fish_brew_complete_arg 'post_install' -l debug -d 'Display any debugging information'
13141323
__fish_brew_complete_arg 'post_install' -l help -d 'Show this message'

0 commit comments

Comments
 (0)