1 # Copyright (C) 2002-2024 Free Software Foundation, Inc.
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 from __future__
import annotations
18 #===============================================================================
19 # Define global imports
20 #===============================================================================
23 import subprocess
as sp
24 from pygnulib
import __author__
, __copyright__
25 from .constants
import DIRS
, joinpath
28 #===============================================================================
30 #===============================================================================
32 '''This class is used to get formatted information about gnulib-tool.
33 This information is mainly used in stdout messages, but can be used
34 anywhere else. The return values are not the same as for the module,
35 but still depends on them.'''
37 def __repr__(self
) -> str:
38 '''x.__repr__ <==> repr(x)'''
39 result
= '<pygnulib.GLInfo %s>' % hex(id(self
))
42 def package(self
) -> str:
43 '''Return formatted string which contains name of the package.'''
47 def authors(self
) -> str:
48 '''Return formatted string which contains authors.
49 The special __author__ variable is used (type is list).'''
51 for item
in __author__
:
52 if item
== __author__
[-1]:
53 result
+= 'and %s' % item
55 result
+= '%s, ' % item
58 def license(self
) -> str:
59 '''Return formatted string which contains license and its description.'''
60 result
= 'License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>\n'
61 result
+= 'This is free software: you are free to change and redistribute it.\n'
62 result
+= 'There is NO WARRANTY, to the extent permitted by law.'
65 def copyright(self
) -> str:
66 '''Return formatted string which contains copyright.
67 The special __copyright__ variable is used (type is str).'''
68 copyright
= __copyright__
69 # Per the GNU Coding Standards, show only the last year.
70 copyright
= re
.compile(r
'^[0-9]*-').sub(r
'', copyright
)
71 result
= 'Copyright (C) %s' % copyright
74 def date(self
) -> str:
75 '''Return formatted string which contains date and time in GMT format.'''
76 if os
.path
.isdir(DIRS
['git']):
78 sp
.check_call(['git', '--version'], stdout
=sp
.DEVNULL
)
84 sp
.check_call(['date', '--version'], stdout
=sp
.DEVNULL
)
89 args
= ['git', 'log', '-n', '1', '--format=medium', '--date=iso', 'ChangeLog']
90 result
= sp
.check_output(args
, cwd
=DIRS
['root']).decode('UTF-8')
91 # Get date as "2008-03-21 07:16:51 -0600" from string
92 pattern
= re
.compile(r
'^Date:[\t ]*(.*?)$', re
.M
)
93 result
= pattern
.findall(result
)
98 # Use GNU date to compute the time in GMT
99 args
= ['date', '-d', result
, '-u', '+%Y-%m-%d %H:%M:%S']
100 proc
= sp
.check_output(args
)
101 result
= str(proc
, 'UTF-8')
102 result
= result
.rstrip(os
.linesep
)
104 # gnulib copy without versioning information.
105 with
open(os
.path
.join(DIRS
['root'], 'ChangeLog'), mode
='r', newline
='\n', encoding
='utf-8') as file:
106 line
= file.readline()
107 first_changelog_line
= line
.rstrip()
108 result
= re
.compile(r
' .*').sub(r
'', first_changelog_line
)
111 def copyright_range(self
) -> str:
112 '''Returns a formatted copyright string showing a year range.'''
113 return f
'Copyright (C) {__copyright__}'
115 def usage(self
) -> str:
116 '''Show help message.'''
118 Usage: gnulib-tool --list
119 gnulib-tool --find filename
120 gnulib-tool --import [module1 ... moduleN]
121 gnulib-tool --add-import [module1 ... moduleN]
122 gnulib-tool --remove-import [module1 ... moduleN]
124 gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
125 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
126 gnulib-tool --test --dir=directory [module1 ... moduleN]
127 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
128 gnulib-tool --extract-description module
129 gnulib-tool --extract-comment module
130 gnulib-tool --extract-status module
131 gnulib-tool --extract-notice module
132 gnulib-tool --extract-applicability module
133 gnulib-tool --extract-usability-in-testdir module
134 gnulib-tool --extract-filelist module
135 gnulib-tool --extract-dependencies module
136 gnulib-tool --extract-recursive-dependencies module
137 gnulib-tool --extract-dependents module
138 gnulib-tool --extract-recursive-dependents module
139 gnulib-tool --extract-autoconf-snippet module
140 gnulib-tool --extract-automake-snippet module
141 gnulib-tool --extract-include-directive module
142 gnulib-tool --extract-link-directive module
143 gnulib-tool --extract-recursive-link-directive module
144 gnulib-tool --extract-license module
145 gnulib-tool --extract-maintainer module
146 gnulib-tool --extract-tests-module module
147 gnulib-tool --copy-file file [destination]
151 --list print the available module names
152 --find find the modules which contain the specified file
153 --import import the given modules into the current package
154 --add-import augment the list of imports from gnulib into the
155 current package, by adding the given modules;
156 if no modules are specified, update the current
157 package from the current gnulib
158 --remove-import reduce the list of imports from gnulib into the
159 current package, by removing the given modules
160 --update update the current package, restore files omitted
162 --create-testdir create a scratch package with the given modules
163 --create-megatestdir create a mega scratch package with the given modules
164 one by one and all together
165 --test test the combination of the given modules
166 (recommended to use CC=\"gcc -Wall\" here)
167 --megatest test the given modules one by one and all together
168 (recommended to use CC=\"gcc -Wall\" here)
169 --extract-description extract the description
170 --extract-comment extract the comment
171 --extract-status extract the status (obsolete etc.)
172 --extract-notice extract the notice or banner
173 --extract-applicability extract the applicability
174 --extract-usability-in-testdir extract the usability in testdirs
175 --extract-filelist extract the list of files
176 --extract-dependencies extract the dependencies
177 --extract-recursive-dependencies extract the dependencies of the module
178 and its dependencies, recursively, all
179 together, but without the conditions
180 --extract-dependents list the modules which depend on the given
181 module directly. This is also known as the
182 "reverse dependencies".
183 --extract-recursive-dependents list the modules which depend on the given
184 module directly or indirectly
185 --extract-autoconf-snippet extract the snippet for configure.ac
186 --extract-automake-snippet extract the snippet for library makefile
187 --extract-include-directive extract the #include directive
188 --extract-link-directive extract the linker directive
189 --extract-recursive-link-directive extract the linker directive of the
190 module and its dependencies,
191 recursively, all together
192 --extract-license report the license terms of the source files
194 --extract-maintainer report the maintainer(s) inside gnulib
195 --extract-tests-module report the unit test module, if it exists
196 --copy-file copy a file that is not part of any module
197 --help Show this help text.
198 --version Show version and authorship information.
202 --dir=DIRECTORY Specify the target directory.
203 For --import, this specifies where your
204 configure.ac can be found. Defaults to current
206 --local-dir=DIRECTORY Specify a local override directory where to look
207 up files before looking in gnulib's directory.
208 --verbose Increase verbosity. May be repeated.
209 --quiet Decrease verbosity. May be repeated.
211 Options for --import, --add/remove-import, --update:
213 --dry-run Only print what would have been done.
215 Options for --import, --add/remove-import:
217 --with-tests Include unit tests for the included modules.
219 Options for --create-[mega]testdir, --[mega]test:
221 --without-tests Don't include unit tests for the included modules.
223 Options for --import, --add/remove-import,
224 --create-[mega]testdir, --[mega]test:
226 --with-obsolete Include obsolete modules when they occur among the
227 dependencies. By default, dependencies to obsolete
229 --with-c++-tests Include even unit tests for C++ interoperability.
230 --without-c++-tests Exclude unit tests for C++ interoperability.
231 --with-longrunning-tests
232 Include even unit tests that are long-runners.
233 --without-longrunning-tests
234 Exclude unit tests that are long-runners.
235 --with-privileged-tests
236 Include even unit tests that require root
238 --without-privileged-tests
239 Exclude unit tests that require root privileges.
240 --with-unportable-tests
241 Include even unit tests that fail on some platforms.
242 --without-unportable-tests
243 Exclude unit tests that fail on some platforms.
244 --with-all-tests Include all kinds of problematic unit tests.
245 --avoid=MODULE Avoid including the given MODULE. Useful if you
246 have code that provides equivalent functionality.
247 This option can be repeated.
248 --conditional-dependencies
249 Support conditional dependencies (may save configure
250 time and object code).
251 --no-conditional-dependencies
252 Don't use conditional dependencies.
253 --libtool Use libtool rules.
254 --no-libtool Don't use libtool rules.
256 Options for --import, --add/remove-import:
258 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
259 --source-base=DIRECTORY
260 Directory relative to --dir where source code is
261 placed (default \"lib\").
262 --m4-base=DIRECTORY Directory relative to --dir where *.m4 macros are
263 placed (default \"m4\").
264 --po-base=DIRECTORY Directory relative to --dir where *.po files are
265 placed (default \"po\").
266 --doc-base=DIRECTORY Directory relative to --dir where doc files are
267 placed (default \"doc\").
268 --tests-base=DIRECTORY
269 Directory relative to --dir where unit tests are
270 placed (default \"tests\").
271 --aux-dir=DIRECTORY Directory relative to --dir where auxiliary build
272 tools are placed (default comes from configure.ac).
273 --gnu-make Output for GNU Make instead of for the default
275 --lgpl[=2|=3orGPLv2|=3]
276 Abort if modules aren't available under the LGPL.
277 The version number of the LGPL can be specified;
278 the default is currently LGPLv3.
279 --gpl=[2|3] Abort if modules aren't available under the
280 specified GPL version.
281 --makefile-name=NAME Name of makefile in the source-base and tests-base
282 directories (default \"Makefile.am\", or
283 \"Makefile.in\" if --gnu-make).
284 --tests-makefile-name=NAME
285 Name of makefile in the tests-base directory
286 (default as specified through --makefile-name).
287 --automake-subdir Specify that the makefile in the source-base
288 directory be generated in such a way that it can
289 be 'include'd from the toplevel Makefile.am.
290 --automake-subdir-tests
291 Likewise, but for the tests directory.
292 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
293 'gl_INIT'. Default is 'gl'.
294 --po-domain=NAME Specify the prefix of the i18n domain. Usually use
295 the package name. A suffix '-gnulib' is appended.
296 --witness-c-macro=NAME Specify the C macro that is defined when the
297 sources in this directory are compiled or used.
298 --vc-files Update version control related files.
299 --no-vc-files Don't update version control related files
300 (.gitignore and/or .cvsignore).
302 Options for --create-[mega]testdir, --[mega]test:
304 --single-configure Generate a single configure file, not a separate
305 configure file for the tests directory.
307 Options for --import, --add/remove-import, --update,
308 --create-[mega]testdir, --[mega]test:
310 -s, --symbolic, --symlink Make symbolic links instead of copying files.
311 --local-symlink Make symbolic links instead of copying files, only
312 for files from the local override directory.
313 -h, --hardlink Make hard links instead of copying files.
314 --local-hardlink Make hard links instead of copying files, only
315 for files from the local override directory.
317 Options for --import, --add/remove-import, --update:
319 -S, --more-symlinks Deprecated; equivalent to --symlink.
320 -H, --more-hardlinks Deprecated; equivalent to --hardlink.
322 Report bugs to <bug-gnulib@gnu.org>.'''
325 def version(self
) -> str:
326 '''Return formatted string which contains git version.'''
327 if os
.path
.isdir(DIRS
['git']):
329 sp
.check_call(['git', '--version'], stdout
=sp
.DEVNULL
)
334 version_gen
= joinpath(DIRS
['build-aux'], 'git-version-gen')
335 args
= [version_gen
, '/dev/null']
336 result
= sp
.check_output(args
, cwd
=DIRS
['root']).decode('UTF-8')
337 result
= result
.strip()
338 result
= result
.replace('-dirty', '-modified')
339 if result
== 'UNKNOWN':
342 # gnulib copy without versioning information.