|
4 | 4 | require "abstract_command" |
5 | 5 | require "formula" |
6 | 6 | require "utils/bottles" |
| 7 | +require "utils/portable_ruby" |
7 | 8 |
|
8 | 9 | module Homebrew |
9 | 10 | module DevCmd |
10 | 11 | class UpdatePortableRuby < AbstractCommand |
11 | 12 | cmd_args do |
12 | 13 | description <<~EOS |
13 | | - Update the vendored portable Ruby version files, bottle checksums, |
14 | | - `utils/ruby.sh` and `Gemfile.lock` entries from the current |
15 | | - `portable-ruby` formula. |
| 14 | + Update the vendored `portable-ruby` from the current `portable-ruby` formula: |
| 15 | + write the version files and bottle checksums, run `brew vendor-install ruby`, |
| 16 | + then sync `utils/ruby.sh`, vendored gems and RBI files to the bundler shipped |
| 17 | + by the new ruby. |
16 | 18 | EOS |
17 | | - switch "-n", "--dry-run", |
18 | | - description: "Print what would be done rather than doing it." |
19 | | - switch "--skip-vendor-install", |
20 | | - description: "Do not run `brew vendor-install ruby`; skip the `utils/ruby.sh`, " \ |
21 | | - "`Gemfile.lock` and RBI updates." |
22 | | - |
23 | 19 | named_args :none |
| 20 | + |
| 21 | + hide_from_man_page! |
24 | 22 | end |
25 | 23 |
|
26 | 24 | sig { override.void } |
27 | 25 | def run |
28 | 26 | formula = Homebrew.with_no_api_env { Formulary.factory("portable-ruby") } |
29 | | - |
30 | 27 | version = formula.version.to_s |
31 | 28 | pkg_version = formula.pkg_version.to_s |
32 | 29 | vendor_dir = HOMEBREW_LIBRARY_PATH/"vendor" |
33 | 30 |
|
34 | | - write_file(vendor_dir/"portable-ruby-version", "#{pkg_version}\n") |
35 | | - write_file(HOMEBREW_LIBRARY_PATH/".ruby-version", "#{version}\n") |
| 31 | + (vendor_dir/"portable-ruby-version").atomic_write("#{pkg_version}\n") |
| 32 | + (HOMEBREW_LIBRARY_PATH/".ruby-version").atomic_write("#{version}\n") |
36 | 33 |
|
37 | 34 | formula.bottle_specification.checksums.each do |checksum| |
38 | 35 | tag_symbol = checksum.fetch("tag") |
39 | 36 | tag = Utils::Bottles::Tag.from_symbol(tag_symbol) |
40 | 37 | os = tag.linux? ? "linux" : "darwin" |
41 | 38 | path = vendor_dir/"portable-ruby-#{tag.standardized_arch}-#{os}" |
42 | | - write_file(path, "ruby_TAG=#{tag_symbol}\nruby_SHA=#{checksum.fetch("digest")}\n") |
| 39 | + path.atomic_write("ruby_TAG=#{tag_symbol}\nruby_SHA=#{checksum.fetch("digest")}\n") |
43 | 40 | end |
44 | 41 |
|
45 | | - return if args.skip_vendor_install? |
46 | | - |
47 | | - if args.dry_run? |
48 | | - ohai "brew vendor-install ruby" |
49 | | - ohai "Would update #{HOMEBREW_LIBRARY_PATH/"utils/ruby.sh"} and #{HOMEBREW_LIBRARY_PATH/"Gemfile.lock"} " \ |
50 | | - "with the bundler version shipped by portable-ruby #{pkg_version}." |
51 | | - ohai "brew typecheck --update" |
52 | | - return |
53 | | - end |
54 | | - |
55 | | - ohai "brew vendor-install ruby" |
56 | 42 | safe_system HOMEBREW_BREW_FILE, "vendor-install", "ruby" |
57 | 43 |
|
58 | | - bundler_dir = Pathname.glob(vendor_dir/"portable-ruby/#{pkg_version}/lib/ruby/gems/*/gems/bundler-*").first |
59 | | - odie "Cannot find vendored bundler for portable-ruby #{pkg_version}." if bundler_dir.nil? |
60 | | - bundler_version = bundler_dir.basename.to_s.delete_prefix("bundler-") |
61 | | - |
62 | | - ruby_sh = HOMEBREW_LIBRARY_PATH/"utils/ruby.sh" |
63 | | - original = ruby_sh.read |
64 | | - updated = original.sub(/(?<=^export HOMEBREW_BUNDLER_VERSION=")[^"]+/, bundler_version) |
65 | | - if original != updated |
66 | | - ohai "Writing #{ruby_sh}" |
67 | | - ruby_sh.atomic_write(updated) |
68 | | - end |
69 | | - |
70 | | - ohai "brew vendor-gems --no-commit --update=--ruby,--bundler=#{bundler_version}" |
71 | | - safe_system HOMEBREW_BREW_FILE, "vendor-gems", "--no-commit", "--update=--ruby,--bundler=#{bundler_version}" |
72 | | - |
73 | | - ohai "brew typecheck --update" |
| 44 | + bundler_version = Utils::PortableRuby.sync_bundler_version!(pkg_version) |
| 45 | + safe_system HOMEBREW_BREW_FILE, "vendor-gems", "--no-commit", |
| 46 | + "--update=--ruby,--bundler=#{bundler_version}" |
74 | 47 | safe_system HOMEBREW_BREW_FILE, "typecheck", "--update" |
75 | 48 | end |
76 | | - |
77 | | - private |
78 | | - |
79 | | - sig { params(path: Pathname, contents: String).void } |
80 | | - def write_file(path, contents) |
81 | | - if args.dry_run? |
82 | | - ohai "Write #{path}:" |
83 | | - puts contents |
84 | | - else |
85 | | - ohai "Writing #{path}" |
86 | | - path.atomic_write(contents) |
87 | | - end |
88 | | - end |
89 | 49 | end |
90 | 50 | end |
91 | 51 | end |
0 commit comments