Debian Codegraph @

doc/update-files.rb

raw symbols SCIP
1 #!/usr/bin/env ruby
2 #
3 # Copyright(C) 2023-2026 Sutou Kouhei <[email protected]>
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19 require "find"
20
21 IGNORE_PATHS = [
22 ".buildinfo",
23 ".buildinfo.bak",
24
25 # These are unnecessary for Japanese and cause build errors.
26 "_static/base-stemmer.js",
27 "_static/english-stemmer.js",
28 ]
29
30 def list_paths(variable_name, paths, output)
31 output.puts("#{variable_name} = \\")
32 paths.each do |path|
33 output.puts("\t#{path} \\")
34 end
35 output.puts("\t$(NULL)")
36 output.puts
37 end
38
39 source_dir = File.expand_path(__dir__)
40
41 # For GNU Autotools
42 File.open(File.join(source_dir, "files.am"), "w") do |output|
43 # Sphinx related
44 Dir.chdir(source_dir) do
45 files = []
46 Find.find("source") do |path|
47 next unless File.file?(path)
48 next if path.end_with?(".pyc")
49 files << path
50 end
51 files.sort!
52 ## absolute source file file list.
53 list_paths("absolute_source_files",
54 files.collect {|file| "$(top_srcdir)/doc/#{file}"},
55 output)
56 ## source file path list from doc/.
57 list_paths("source_files_relative_from_doc_dir",
58 files,
59 output)
60 end
61
62 # gettext related
63 pot_files = Dir.chdir("en/gettext") do
64 Dir.glob("**/*.pot").sort
65 end
66 ["po", "edit_po", "mo"].each do |type|
67 if type == "edit_po"
68 extension = ".edit"
69 else
70 extension = ".#{type}"
71 end
72 target_files = pot_files.collect {|pot| pot.gsub(/\.pot\z/, extension)}
73 list_paths("#{type}_files", target_files, output)
74 list_paths("#{type}_files_relative_from_locale_dir",
75 target_files.collect {|path| "LC_MESSAGES/#{path}"},
76 output)
77 end
78
79 # output files
80 Dir.chdir("en") do
81 ## HTML file path list relative from locale/$LANG/ dir.
82 html_files = []
83 Find.find("html") do |path|
84 next unless File.file?(path)
85 next if IGNORE_PATHS.include?(path.delete_prefix("html/"))
86 if path.start_with?("html/reference/api/")
87 base_name = File.basename(path, ".html")
88 source = File.join(source_dir,
89 "source",
90 "reference",
91 "api",
92 "#{base_name}.rst")
93 # Ignore Doxygen generated files
94 next unless File.exist?(source)
95 end
96 html_files << path
97 end
98 html_files.sort!
99 list_paths("html_files_relative_from_locale_dir", html_files, output)
100 end
101 end
102
103 # For CMake
104 File.open(File.join(source_dir, "files.cmake"), "w") do |output|
105 # Sphinx related
106 Dir.chdir(File.join(source_dir, "source")) do
107 files = []
108 Find.find(".") do |path|
109 path = path.delete_prefix("./")
110 next unless File.file?(path)
111 next if path.end_with?(".pyc")
112 files << path
113 end
114 files.sort!
115 output.print("set(GRN_DOC_SOURCES")
116 files.each do |file|
117 output.puts
118 output.print(" #{file}")
119 end
120 output.puts(")")
121 output.puts
122 end
123
124 # output files
125 Dir.chdir("en/html") do
126 ## HTML file path list relative from locale/$LANG/ dir.
127 html_files = []
128 Find.find(".") do |path|
129 path = path.delete_prefix("./")
130 next unless File.file?(path)
131 next if IGNORE_PATHS.include?(path)
132 if path.start_with?("reference/api/")
133 base_name = File.basename(path, ".html")
134 source = File.join(source_dir,
135 "source",
136 "reference",
137 "api",
138 "#{base_name}.rst")
139 # Ignore Doxygen generated files
140 next unless File.exist?(source)
141 end
142 html_files << path
143 end
144 html_files.sort!
145 output.print("set(GRN_DOC_HTML_FILES")
146 html_files.each do |html_file|
147 output.puts
148 output.print(" #{html_file}")
149 end
150 output.puts(")")
151 end
152 end