Skip to content

Commit 4620ad0

Browse files
committed
Add glibc runtime action
Three glibc-family formulae share locale generation and timezone-link setup with different rules for the legacy variants. - derive requested locales while always providing the UTF-8 default - invoke the installed `localedef` with normalised charmaps - preserve host timezone links when their sources exist
1 parent e5f68fb commit 4620ad0

6 files changed

Lines changed: 54 additions & 3 deletions

File tree

Library/Homebrew/install_steps.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,11 @@ def install_gzipped_executable(source, target, source_base: nil, target_base: ni
611611
"target" => path_spec(target, base: target_base, default_base: @default_target_base))
612612
end
613613

614+
sig { void }
615+
def configure_glibc_runtime
616+
add_step("configure_glibc_runtime")
617+
end
618+
614619
private
615620

616621
sig { params(guard: PathSpec, block: ::T.proc.void).void }
@@ -856,6 +861,8 @@ def run_install_step(step)
856861
run_configure_gcc_runtime
857862
when "install_gzipped_executable"
858863
run_install_gzipped_executable(step)
864+
when "configure_glibc_runtime"
865+
run_configure_glibc_runtime
859866
when "set_permissions"
860867
run_set_permissions(step)
861868
when "set_ownership"

Library/Homebrew/install_steps/formula_actions.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,36 @@ def run_install_gzipped_executable(step)
8484
end
8585
target.chmod 0755
8686
end
87+
88+
sig { void }
89+
def run_configure_glibc_runtime
90+
(context_path("lib")/"locale").mkpath
91+
legacy_formula = context_name != "glibc"
92+
locales = ENV.filter_map do |key, value|
93+
next unless key.match?(legacy_formula ? /^LANG$|^LC_/ : /^HOMEBREW_LANG$|^LANG$|^LC_/)
94+
next if value == "C" || (legacy_formula && value.start_with?("C."))
95+
96+
value
97+
end
98+
locales = (locales + ["en_US.UTF-8"]).sort.uniq
99+
ohai "Installing locale data for #{locales.join(" ")}"
100+
locales.each do |locale|
101+
lang, charmap = locale.split(".", 2)
102+
next if lang.nil?
103+
104+
if charmap.present?
105+
charmap = "UTF-8" if charmap == "utf8"
106+
run_command context_path("bin")/"localedef", "-i", lang, "-f", charmap, locale
107+
else
108+
run_command context_path("bin")/"localedef", "-i", lang, locale
109+
end
110+
end
111+
112+
[[Pathname("/etc/localtime"), context_path("etc")/"localtime"],
113+
[Pathname("/usr/share/zoneinfo"), context_path("share")/"zoneinfo"]].each do |source, target|
114+
File.symlink source, target if source.exist? && !target.exist?
115+
end
116+
end
87117
end
88118
end
89119
end

Library/Homebrew/rubocops/shared/install_steps_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module InstallStepsHelper
1717
PERMISSION_STEP_METHODS = [:set_permissions, :set_ownership].freeze
1818
COMMAND_STEP_METHODS = [:run, :terminate_process].freeze
1919
NOTICE_STEP_METHODS = [:warn_if_exists].freeze
20-
FORMULA_ACTION_STEP_METHODS = [:configure_gcc_runtime, :install_compressed_executable].freeze
20+
FORMULA_ACTION_STEP_METHODS =
21+
[:configure_gcc_runtime, :install_compressed_executable, :install_glibc_locales].freeze
2122
ALLOWED_STEP_METHODS = T.let(
2223
[*FILE_PREPARATION_STEP_METHODS, *LINK_STEP_METHODS, *CONFIG_WRITE_STEP_METHODS, *SERVICE_DATA_STEP_METHODS,
2324
*REBUILD_ACTION_STEP_METHODS, :set_permissions, *COMMAND_STEP_METHODS, *NOTICE_STEP_METHODS,

Library/Homebrew/test/install_steps_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,17 @@
643643
expect(source).not_to exist
644644
end
645645

646+
specify "dispatches glibc runtime configuration" do
647+
steps = Homebrew::InstallSteps::DSL.build do
648+
configure_glibc_runtime
649+
end
650+
651+
runner = Homebrew::InstallSteps::Runner.new(context:)
652+
expect(runner).to receive(:run_configure_glibc_runtime)
653+
654+
runner.run(steps)
655+
end
656+
646657
describe "runs gtk_update_icon_cache rebuild action" do
647658
let(:formula) { instance_double(Formula, opt_bin: root/"opt/bin") }
648659
let(:steps) do

Library/Homebrew/test/rubocops/install_steps_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Foo < Formula
4242
4343
post_install_steps do
4444
system "true"
45-
^^^^^^^^^^^^^ FormulaAudit/InstallSteps: Steps blocks may only contain install step DSL calls: `mkdir`, `mkdir_p`, `touch`, `move`, `mv`, `move_children`, `copy`, `remove`, `replace`, `symlink`, `ln_s`, `ln_sf`, `link_dir`, `link_children`, `write`, `init_data_dir`, `compile_gsettings_schemas`, `gdk_pixbuf_query_loaders`, `gtk_update_icon_cache`, `update_mime_database`, `update_desktop_database`, `set_permissions`, `run`, `terminate_process`, `warn_if_exists`, `configure_gcc_runtime`, `install_compressed_executable`.
45+
^^^^^^^^^^^^^ FormulaAudit/InstallSteps: Steps blocks may only contain install step DSL calls: `mkdir`, `mkdir_p`, `touch`, `move`, `mv`, `move_children`, `copy`, `remove`, `replace`, `symlink`, `ln_s`, `ln_sf`, `link_dir`, `link_children`, `write`, `init_data_dir`, `compile_gsettings_schemas`, `gdk_pixbuf_query_loaders`, `gtk_update_icon_cache`, `update_mime_database`, `update_desktop_database`, `set_permissions`, `run`, `terminate_process`, `warn_if_exists`, `configure_gcc_runtime`, `install_compressed_executable`, `install_glibc_locales`.
4646
end
4747
end
4848
RUBY
@@ -66,6 +66,7 @@ class Foo < Formula
6666
warn_if_exists "foo", "foo exists"
6767
configure_gcc_runtime
6868
install_compressed_executable "compressed", "bin/executable"
69+
install_glibc_locales
6970
write "foo/banner", <<~TEXT
7071
literal banner
7172
TEXT
@@ -89,7 +90,7 @@ class Foo < Formula
8990
9091
post_install_steps do
9192
write "foo.conf", "prefix = #{prefix}"
92-
^^^^^^^^^ FormulaAudit/InstallSteps: Steps blocks may only contain install step DSL calls: `mkdir`, `mkdir_p`, `touch`, `move`, `mv`, `move_children`, `copy`, `remove`, `replace`, `symlink`, `ln_s`, `ln_sf`, `link_dir`, `link_children`, `write`, `init_data_dir`, `compile_gsettings_schemas`, `gdk_pixbuf_query_loaders`, `gtk_update_icon_cache`, `update_mime_database`, `update_desktop_database`, `set_permissions`, `run`, `terminate_process`, `warn_if_exists`, `configure_gcc_runtime`, `install_compressed_executable`.
93+
^^^^^^^^^ FormulaAudit/InstallSteps: Steps blocks may only contain install step DSL calls: `mkdir`, `mkdir_p`, `touch`, `move`, `mv`, `move_children`, `copy`, `remove`, `replace`, `symlink`, `ln_s`, `ln_sf`, `link_dir`, `link_children`, `write`, `init_data_dir`, `compile_gsettings_schemas`, `gdk_pixbuf_query_loaders`, `gtk_update_icon_cache`, `update_mime_database`, `update_desktop_database`, `set_permissions`, `run`, `terminate_process`, `warn_if_exists`, `configure_gcc_runtime`, `install_compressed_executable`, `install_glibc_locales`.
9394
end
9495
end
9596
RUBY

docs/Formula-Cookbook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ Use the named actions below for formula families that share post-install algorit
12391239

12401240
* `configure_gcc_runtime`: generate the Linux GCC runtime links and specs.
12411241
* `install_compressed_executable`: unpack and install a gzipped executable.
1242+
* `install_glibc_locales`: generate requested glibc locales and timezone links.
12421243

12431244
#### Service data directory steps
12441245

0 commit comments

Comments
 (0)