Commit 08d6d54
committed
Make it loose coupling between RubyGems and RDoc
Problems
1. If there are braking changes in RDoc, RubyGems is also broken.
2. When we maintain RDoc, we have to change RubyGems.
The reason why they are happened is that RubyGems creates documents about a gem with installing it.
Note that RubyGems uses functions of RDoc to create documents.
Specifically,
- Creating documents is executed by `rubygems/lib/rubygems/rdoc.rb`.
- `::RDoc::RubygemsHook` which is defined by RDoc is called by the file.
Solution
RubyGems has the plugin system.
If a gem includes `rubygems_plugin.rb`, RubyGems loads it.
RubyGems executes a process defined in it while installing gems, uninstalling gems or other events.
We can use the system to solve the problems.
The root cause is RubyGems directly references the class of RDoc.
We can remove the root cause by making RDoc RubyGems plugin.
Alternatively `rubygems_plugin.rb` creates documents about gems.
FAQ
Q1. Do we need to change codes of RubyGems?
A.
No, we don't.
If we change codes of RubyGems,
we can't keep a compatibility.
Example:
If we delete codes that uses `RDoc::RubygemsHook` in `rubygems/lib/rubygems/rdoc.rb`,
documentations are not created with old RDoc.
Q2. When can we delete `rubygems/lib/rubygems/rdoc.rb`?
A.
We can delete it when all users use RDoc including `rubygems_plugin`.
Next ruby version is 3.4.
If it includes the RDoc including `rubygems_plugin`,
we can delete `rubygems/lib/rubygems/rdoc.rb` after ruby 3.3 is EOL.
Q3. Is it a breaking change that Rubygems creates documents with
rubygems_plugin not RDoc::RubygemsHook?
A.
If we simply implement this approach,
we move the implementation from `rdoc/lib/rdoc/rubygems_hook.rb` to
`rubygems_plugin.rb`.
This way can be breaking change.
It seems to be fine that we just need to delete `rdoc/rubygems_hook.rb` but it doesn't work.
It generates multiple documents.
`rubygems/lib/rubygems/rdoc.rb` has the following code.
```
begin
require "rdoc/rubygems_hook"
# ...
rescue LoadError
end
```
This code ignores RDoc related processes when `rdoc/rubygems_hook` can't be required.
But, this 'require' is not failed.
This is because Ruby installs Rdoc as a default gem.
So, Rdoc installed as a default gem generates documents and one installed as a normal gem does it too.
If you think that this behavior is accectable,
we can just delete `rdoc/rubygems_hook.rb`.
What do you think about this approach?
In this change, we take another approach to solve the problem that creates multiple documents.
The reason why the approach that just deletes `rdoc/rubygems.rb` creates multiple documents is `Gem.done_installing(&Gem::RDoc.method(:generation_hook))` in `rubygems/rdoc.rb`.
`rubygems/rdoc.rb` が Gem.done_installing しているところで ドキュメント生成がデフォルト gem によって行われているので、既存の Rubygems が require している RDoc::RubygemsHook は何も処理を実行しないようにしている。
↑ 次回:
- 動作確認について、手順、結果
Note
When RDoc and other gem were installed,
RubyGems plugin of RDoc wasn't executed.
For example
```
gem install rdoc pkg-config
```
Expected
Installing RDoc creates a document of pkg-config.
Actual
Installed RDoc creates a document of pkg-config.
See also.
ruby/rubygems#6673
| RDoc / rubyGems | New | Old |
| changed | A | A |
| current | A | A |
Because RDoc is default gem,
インストール済みの RDoc でドキュメント生成される。
ただし、この RDoc のバージョン以降を一度インストールすれば、
以降は Plugin によってドキュメント生成がされる。
旧バージョンとの違いは、
Plugin がドキュメント生成するかどうかの違いで、
アウトプットには違いがない。
=======
テスト結果の説明のために、
rdoc 未インストールの状態で、gem install rdoc pkg-config を実行してみる。
このパターンでは実行結果が Expect になるはず。
=> Ruby 3.x 以降で RDoc が default gem から bundled gem になる提案がある。
将来の話、というテイでテストしておくのもあり?
=> 実際にテストしてみたところ、
installing の rdoc で plugin を利用して document 生成がされた。
テスト方法
default gem がない状態を再現する方法
1. Move to a directory includes default gems.
$ cd $(ruby -e 'print RbConfig::CONFIG["rubylibdir"]')
2. Rename 'rdoc' and 'rdoc.rb'.
$ mv rdoc{,.bk}
$ mv rdoc.rb{,.bk}
3. Move to a directory includes specifications of default gems.
$ cd $(gem environment gemdir)/specifications/default
4. Rename 'rdoc-<versions>.gemspec'.
$ mv $(echo rdoc-*.gemspec){,.bk}1 parent 9c14229 commit 08d6d54
File tree
4 files changed
+289
-247
lines changed- lib
- rdoc
- test/rdoc
4 files changed
+289
-247
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 1 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
241 | 12 | | |
242 | | - | |
243 | | - | |
| 13 | + | |
244 | 14 | | |
245 | | - | |
| 15 | + | |
246 | 16 | | |
247 | | - | |
248 | 17 | | |
0 commit comments