@@ -37,9 +37,41 @@ def _install_dirs(ctx, ruby, *names):
3737 ctx .symlink (path , rel_path )
3838 return rel_paths
3939
40+ def _bin_install_path (ctx , ruby , bin ):
41+ """Transform the given command name "bin" to actual file name.
42+
43+ Uses the same logic as "script_installer" in tools/rbinstall.rb in Ruby.
44+ But it does not currently support RbConfig::CONFIG['program_transform_name']
45+ """
46+ install_name = ruby .expand_rbconfig (ruby , "${bindir}/${ruby_install_name}" )
47+ path = install_name .replace ("ruby" , bin , 1 )
48+ if ctx .path (path ).exists :
49+ return path
50+
51+ path = ruby .expand_rbconfig (ruby , "${bindir}/%s" % bin )
52+ if ctx .path (path ).exists :
53+ return path
54+ else :
55+ return ctx .which (bin )
56+
57+ # Commands installed together with ruby command.
58+ _DEFAULT_SCRIPTS = [
59+ "irb" ,
60+ "rdoc" ,
61+ "ri" ,
62+ "erb" ,
63+ "rake" ,
64+ "gem" ,
65+ ]
66+
4067def _install_host_ruby (ctx , ruby ):
4168 # Places SDK
4269 ctx .symlink (ruby .interpreter_realpath , ruby .rel_interpreter_path )
70+ for bin_name in _DEFAULT_SCRIPTS :
71+ script_path = _bin_install_path (ctx , ruby , bin_name )
72+ if not script_path :
73+ fail ("Failed to locate %s" % bin_name )
74+ ctx .symlink (script_path , "%s_bin" % bin_name )
4375
4476 # Places the interpreter at a predictable place regardless of the actual binary name
4577 # so that bundle_install can depend on it.
@@ -67,8 +99,8 @@ def _install_host_ruby(ctx, ruby):
6799
68100 return struct (
69101 includedirs = _install_dirs (ctx , ruby , "rubyarchhdrdir" , "rubyhdrdir" ),
70- static_library = _relativate (static_library ),
71102 shared_library = _relativate (shared_library ),
103+ static_library = _relativate (static_library ),
72104 )
73105
74106def _ruby_host_runtime_impl (ctx ):
@@ -107,7 +139,6 @@ def _ruby_host_runtime_impl(ctx):
107139 )
108140
109141ruby_host_runtime = repository_rule (
110- implementation = _ruby_host_runtime_impl ,
111142 attrs = {
112143 "interpreter_path" : attr .string (),
113144 "_install_bundler" : attr .label (
@@ -129,4 +160,5 @@ ruby_host_runtime = repository_rule(
129160 allow_single_file = True ,
130161 ),
131162 },
163+ implementation = _ruby_host_runtime_impl ,
132164)
0 commit comments