3 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program 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
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # This program is meant for authors or maintainers which want to import
20 # modules from gnulib into their packages.
23 #===============================================================================
24 # Define global imports
25 #===============================================================================
33 import subprocess
as sp
34 from pprint
import pprint
35 from pygnulib
import constants
36 from pygnulib
import classes
39 #===============================================================================
40 # Define global constants
41 #===============================================================================
42 PYTHON3
= constants
.PYTHON3
46 UTILS
= constants
.UTILS
47 FILES
= constants
.FILES
48 MODES
= constants
.MODES
49 TESTS
= constants
.TESTS
50 compiler
= constants
.compiler
51 joinpath
= constants
.joinpath
52 cleaner
= constants
.cleaner
53 string
= constants
.string
56 isfile
= os
.path
.isfile
57 normpath
= os
.path
.normpath
58 relpath
= os
.path
.relpath
61 #===============================================================================
63 #===============================================================================
87 witness_c_macro
= None
92 info
= classes
.GLInfo()
93 parser
= argparse
.ArgumentParser(
94 prog
=constants
.APP
['name'],
95 usage
='gnulib-tool.py --help',
98 parser
.add_argument('-h', '--help', '--hel', '--he', '--h',
103 parser
.add_argument('--version', '--versio', '--versi', '--vers',
108 parser
.add_argument('-l', '--list', '--lis',
113 parser
.add_argument('-f', '--find', '--fin', '--fi', '--f',
118 parser
.add_argument('-i', '--import',
123 parser
.add_argument('-a', '--add-import',
124 dest
='mode_add_import',
128 parser
.add_argument('-r', '--remove-import',
129 dest
='mode_remove_import',
133 parser
.add_argument('-u', '--update',
138 parser
.add_argument('-td', '--create-testdir',
139 dest
='mode_create_testdir',
143 parser
.add_argument('-mtd', '--create-megatestdir',
144 dest
='mode_create_megatestdir',
148 parser
.add_argument('-t', '--test',
153 parser
.add_argument('-mt', '--megatest', '--megates', '--megate', '--megat',
154 '--mega', '--meg', '--me', '--m',
155 dest
='mode_megatest',
159 parser
.add_argument('-c', '--copy-file',
160 dest
='mode_copy_file',
164 parser
.add_argument('-xD', '--extract-description',
165 dest
='mode_xdescription',
168 parser
.add_argument('-xc', '--extract-comment',
169 dest
='mode_xcomment',
172 parser
.add_argument('-xs', '--extract-status',
176 parser
.add_argument('-xn', '--extract-notice',
180 parser
.add_argument('-xa', '--extract-applicability',
181 dest
='mode_xapplicability',
184 parser
.add_argument('-xf', '--extract-filelist',
185 dest
='mode_xfilelist',
188 parser
.add_argument('-xd', '--extract-dependencies',
189 dest
='mode_xdependencies',
192 parser
.add_argument('-xac', '--extract-autoconf-snippet',
193 dest
='mode_xautoconf',
196 parser
.add_argument('-xam', '--extract-automake-snippet',
197 dest
='mode_xautomake',
200 parser
.add_argument('-xi', '--extract-include-directive',
201 dest
='mode_xinclude',
204 parser
.add_argument('-xl', '--extract-link-directive',
208 parser
.add_argument('-xL', '--extract-license',
209 dest
='mode_xlicense',
212 parser
.add_argument('-xm', '--extract-maintainer',
213 dest
='mode_xmaintainer',
217 parser
.add_argument('--no-changelog',
220 action
='store_false')
222 parser
.add_argument('-d', '--destdir',
227 parser
.add_argument('-ld', '--local-dir',
232 parser
.add_argument('-v', '--verbose',
236 parser
.add_argument('-q', '--quiet',
240 parser
.add_argument('--dry-run',
245 parser
.add_argument('--with-tests',
250 parser
.add_argument("--makefile-name",
255 parser
.add_argument('--with-obsolete',
260 parser
.add_argument('--with-c++-tests',
265 parser
.add_argument('--with-longrunning-tests',
270 parser
.add_argument('--with-privileged-tests',
275 parser
.add_argument('--with-unportable-tests',
280 parser
.add_argument('--with-all-tests',
285 parser
.add_argument('--aux-dir',
290 parser
.add_argument('--lib',
295 parser
.add_argument("--libtool",
300 parser
.add_argument('-sb', '--source-base',
305 parser
.add_argument('-mb', '--m4-base',
310 parser
.add_argument('-pb', '--po-base',
315 parser
.add_argument('-db', '--doc-base',
320 parser
.add_argument('-tb', '--tests-base',
325 parser
.add_argument('--lgpl',
331 parser
.add_argument('--avoid',
336 # Parse the given arguments.
337 cmdargs
= parser
.parse_args()
339 # Determine when user tries to combine modes.
343 cmdargs
.mode_add_import
,
344 cmdargs
.mode_remove_import
,
346 cmdargs
.mode_create_testdir
,
347 cmdargs
.mode_create_megatestdir
,
349 cmdargs
.mode_megatest
,
350 cmdargs
.mode_copy_file
,
351 cmdargs
.mode_xdescription
,
352 cmdargs
.mode_xcomment
,
353 cmdargs
.mode_xstatus
,
354 cmdargs
.mode_xnotice
,
355 cmdargs
.mode_xapplicability
,
356 cmdargs
.mode_xfilelist
,
357 cmdargs
.mode_xdependencies
,
358 cmdargs
.mode_xautoconf
,
359 cmdargs
.mode_xautomake
,
360 cmdargs
.mode_xinclude
,
362 cmdargs
.mode_xlicense
,
363 cmdargs
.mode_xmaintainer
,
365 overflow
= [arg
for arg
in args
if arg
]
366 if len(overflow
) > 1:
367 message
= 'gnulib-tool: Unable to combine different modes of work.\n'
368 message
+= 'Try \'gnulib-tool --help\' for more information.\n'
369 sys
.stderr
.write(message
)
372 # Determine selected mode.
373 if cmdargs
.help != None:
376 if cmdargs
.version
!= None:
377 message
= '''gnulib-tool (%s %s)%s\n%s\n%s\n\nWritten by %s.''' % \
378 (info
.package(), info
.date(), info
.version(), info
.copyright(),
379 info
.license(), info
.authors())
382 if cmdargs
.mode_list
!= None:
384 if cmdargs
.mode_import
!= None:
386 modules
= list(cmdargs
.mode_import
)
387 if cmdargs
.mode_add_import
!= None:
389 modules
= list(cmdargs
.mode_add_import
)
390 if cmdargs
.mode_remove_import
!= None:
391 mode
= 'remove-import'
392 modules
= list(cmdargs
.mode_remove_import
)
393 if cmdargs
.mode_update
!= None:
395 if cmdargs
.mode_create_testdir
!= None:
396 mode
= 'create-testdir'
397 modules
= list(cmdargs
.mode_create_testdir
)
398 if cmdargs
.mode_create_megatestdir
!= None:
399 mode
= 'create-megatestdir'
400 modules
= list(cmdargs
.mode_create_megatestdir
)
401 if cmdargs
.mode_test
!= None:
403 modules
= list(cmdargs
.mode_test
)
404 if cmdargs
.mode_megatest
!= None:
406 modules
= list(cmdargs
.mode_megatest
)
407 if cmdargs
.mode_xdescription
!= None:
408 mode
= 'extract-description'
409 modules
= list(cmdargs
.mode_xdescription
)
410 if cmdargs
.mode_xcomment
!= None:
411 mode
= 'extract-comment'
412 modules
= list(cmdargs
.mode_xcomment
)
413 if cmdargs
.mode_xstatus
!= None:
414 mode
= 'extract-status'
415 modules
= list(cmdargs
.mode_xstatus
)
416 if cmdargs
.mode_xnotice
!= None:
417 mode
= 'extract-notice'
418 modules
= list(cmdargs
.mode_xnotice
)
419 if cmdargs
.mode_xapplicability
!= None:
420 mode
= 'extract-applicability'
421 modules
= list(cmdargs
.mode_xapplicability
)
422 if cmdargs
.mode_xfilelist
!= None:
423 mode
= 'extract-filelist'
424 modules
= list(cmdargs
.mode_xfilelist
)
425 if cmdargs
.mode_xautoconf
!= None:
426 mode
= 'extract-autoconf-snippet'
427 modules
= list(cmdargs
.mode_xautoconf
)
428 if cmdargs
.mode_xautomake
!= None:
429 mode
= 'extract-automake-snippet'
430 modules
= list(cmdargs
.mode_xautomake
)
431 if cmdargs
.mode_xdependencies
!= None:
432 mode
= 'extract-dependencies'
433 modules
= list(cmdargs
.mode_xdependencies
)
434 if cmdargs
.mode_xinclude
!= None:
435 mode
= 'extract-include-directive'
436 modules
= list(cmdargs
.mode_xinclude
)
437 if cmdargs
.mode_xlink
!= None:
438 mode
= 'extract-link-directive'
439 modules
= list(cmdargs
.mode_xlink
)
440 if cmdargs
.mode_xlicense
!= None:
441 mode
= 'extract-license'
442 modules
= list(cmdargs
.mode_xlicense
)
443 if cmdargs
.mode_xmaintainer
!= None:
444 mode
= 'extract-maintainer'
445 modules
= list(cmdargs
.mode_xmaintainer
)
446 if cmdargs
.mode_copy_file
!= None:
448 if len(cmdargs
.mode_copy_file
) > 2:
449 message
= '%s: *** ' % constants
.APP
['name']
450 message
+= 'invalid number of arguments for --%s' % mode
451 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
452 sys
.stderr
.write(message
)
454 files
= list(cmdargs
.mode_copy_file
)
456 # Determine specific settings.
457 destdir
= cmdargs
.destdir
459 destdir
= cmdargs
.destdir
[0]
460 localdir
= cmdargs
.localdir
462 localdir
= cmdargs
.localdir
[0]
463 libname
= cmdargs
.libname
465 libname
= cmdargs
.libname
[0]
466 auxdir
= cmdargs
.auxdir
468 auxdir
= cmdargs
.auxdir
[0]
469 sourcebase
= cmdargs
.sourcebase
470 if sourcebase
!= None:
471 sourcebase
= cmdargs
.sourcebase
[0]
472 m4base
= cmdargs
.m4base
474 m4base
= cmdargs
.m4base
[0]
475 pobase
= cmdargs
.pobase
477 pobase
= cmdargs
.pobase
[0]
478 testsbase
= cmdargs
.testsbase
479 if testsbase
!= None:
480 testsbase
= cmdargs
.testsbase
[0]
481 dryrun
= cmdargs
.dryrun
482 verbose
= -cmdargs
.quiet
+ cmdargs
.verbose
483 inctests
= cmdargs
.inctests
484 flags
= [cmdargs
.inctests
, cmdargs
.obsolete
, cmdargs
.cxx
,
485 cmdargs
.longrunning
, cmdargs
.privileged
, cmdargs
.unportable
,
489 index
= flags
.index(flag
)
493 testflags
+= [constants
.TESTS
['tests']]
495 testflags
+= [constants
.TESTS
['obsolete']]
497 testflags
+= [constants
.TESTS
['cxx-tests']]
499 testflags
+= [constants
.TESTS
['longrunning-tests']]
501 testflags
+= [constants
.TESTS
['privileged-tests']]
503 testflags
+= [constants
.TESTS
['unportable-tests']]
505 testflags
+= [constants
.TESTS
['all-tests']]
507 libtool
= cmdargs
.libtool
508 makefile
= cmdargs
.makefile
511 avoids
= cmdargs
.avoids
513 # Create pygnulib configuration.
514 config
= classes
.GLConfig(
521 sourcebase
=sourcebase
,
531 macro_prefix
=macro_prefix
,
533 witness_c_macro
=witness_c_macro
,
540 # Canonicalize the inctests variable.
542 if mode
in ['import', 'add-import', 'remove-import', 'update']:
543 config
.disableTestFlag(TESTS
['tests'])
544 elif mode
in ['create-testdir', 'create-megatestdir', 'test', 'megatest']:
545 config
.enableTestFlag(TESTS
['tests'])
547 # Work in the given mode.
549 modulesystem
= classes
.GLModuleSystem(config
)
550 listing
= modulesystem
.list()
551 result
= '\n'.join(listing
)
552 os
.rmdir(config
['tempdir'])
555 elif mode
in ['import', 'add-import', 'remove-import', 'update']:
559 config
.setDestDir(destdir
)
561 if mode
== MODES
['import']:
562 # Set variables to default values.
573 config
.setSourceBase(sourcebase
)
574 config
.setM4Base(m4base
)
575 config
.setDocBase(docbase
)
576 config
.setTestsBase(testsbase
)
577 config
.setMacroPrefix(macro_prefix
)
579 # Perform GLImport actions.
580 importer
= classes
.GLImport(config
, mode
)
581 filetable
, transformers
= importer
.prepare()
582 importer
.execute(filetable
, transformers
)
584 else: # if mode != MODE['--import']
586 if not isfile(joinpath(destdir
, m4base
, 'gnulib-cache.m4')):
595 config
.setSourceBase(sourcebase
)
596 config
.setM4Base(m4base
)
597 config
.setDocBase(docbase
)
598 config
.setTestsBase(testsbase
)
599 config
.setMacroPrefix(macro_prefix
)
600 # Perform GLImport actions.
601 importer
= classes
.GLImport(config
, mode
)
602 filetable
, transformers
= importer
.prepare()
603 importer
.execute(filetable
, transformers
)
604 else: # if not m4base
607 filepath
= joinpath(destdir
, 'Makefile.am')
609 with codecs
.open(filepath
, 'rb', 'UTF-8') as file:
611 data
= data
.split('ACLOCAL_AMFLAGS')[1]
612 data
= data
[data
.find('=') + 1:data
.find('\n')]
613 aclocal_amflags
= data
.split()
614 for aclocal_amflag
in aclocal_amflags
:
616 if not isabs(aclocal_amflag
):
617 m4dirs
+= [aclocal_amflag
]
618 else: # if not dirisnext
619 if aclocal_amflag
== '-I':
621 else: # if aclocal_amflag != '-I'
623 else: # if not isfile(filepath)
624 filepath
= joinpath(destdir
, 'aclocal.m4')
626 pattern
= constants
.compiler(
627 r
'm4_include\(\[(.*?)\]\)')
628 with codecs
.open(filepath
, 'rb', 'UTF-8') as file:
629 m4dirs
= pattern
.findall(file.read())
630 m4dirs
= [os
.path
.dirname(m4dir
) for m4dir
in m4dirs
]
633 m4dir
for m4dir
in m4dirs \
634 if isfile(joinpath(destdir
, m4dir
, 'gnulib-cache.m4'))
636 m4dirs
= sorted(set(m4dirs
))
638 # First use of gnulib in a package.
639 # Any number of additional modules can be given.
649 config
.setSourceBase(sourcebase
)
650 config
.setM4Base(m4base
)
651 config
.setDocBase(docbase
)
652 config
.setTestsBase(testsbase
)
653 config
.setMacroPrefix(macro_prefix
)
654 # Perform GLImport actions.
655 importer
= classes
.GLImport(config
, mode
)
656 filetable
, transformers
= importer
.prepare()
657 importer
.execute(filetable
, transformers
)
658 elif len(m4dirs
) == 1:
660 config
.setM4Base(m4base
)
661 # Perform GLImport actions.
662 importer
= classes
.GLImport(config
, mode
)
663 filetable
, transformers
= importer
.prepare()
664 importer
.execute(filetable
, transformers
)
665 else: # if len(m4dirs) > 1
666 for m4base
in m4dirs
:
667 config
.setM4Base(m4base
)
668 # Perform GLImport actions.
669 importer
= classes
.GLImport(config
, mode
)
670 filetable
, transformers
= importer
.prepare()
671 importer
.execute(filetable
, transformers
)
673 elif mode
== 'create-testdir':
675 message
= '%s: *** ' % constants
.APP
['name']
676 message
+= 'please specify --dir option'
677 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
678 sys
.stderr
.write(message
)
682 config
.setAuxDir(auxdir
)
683 testdir
= classes
.GLTestDir(config
, destdir
)
686 elif mode
== 'create-megatestdir':
688 message
= '%s: *** ' % constants
.APP
['name']
689 message
+= 'please specify --dir option'
690 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
691 sys
.stderr
.write(message
)
695 config
.setAuxDir(auxdir
)
696 testdir
= classes
.GLMegaTestDir(config
, destdir
)
701 destdir
= 'testdir %04d' % random
.randrange(0, 9999)
704 config
.setAuxDir(auxdir
)
705 testdir
= classes
.GLTestDir(config
, destdir
)
710 try: # Try to execute commands
711 sp
.call(['../configure'])
712 sp
.call([UTILS
['make']])
713 sp
.call([UTILS
['make'], 'check'])
714 sp
.call([UTILS
['make'], 'distclean'])
715 except Exception as error
:
717 args
= ['find', '.', '-type', 'f', '-print']
718 remaining
= sp
.check_output(args
).decode(ENCS
['shell'])
719 lines
= [line
.strip()
720 for line
in remaining
.split('\n') if line
.strip()]
721 remaining
= ' '.join(lines
)
723 message
= 'Remaining files: %s\n' % remaining
724 message
+= 'gnulib-tool: *** Stop.\n'
725 sys
.stderr
.write(message
)
728 sp
.call(['rm', '-rf', destdir
], shell
=False)
730 elif mode
== 'megatest':
732 destdir
= 'testdir %04d' % random
.randrange(0, 9999)
735 config
.setAuxDir(auxdir
)
736 testdir
= classes
.GLMegaTestDir(config
, destdir
)
741 sp
.call(['../configure'])
742 sp
.call([UTILS
['make']])
743 sp
.call([UTILS
['make'], 'check'])
744 sp
.call([UTILS
['make'], 'distclean'])
745 args
= ['find', '.', '-type', 'f', '-print']
746 remaining
= sp
.check_output(args
).decode(ENCS
['shell'])
747 lines
= [line
.strip()
748 for line
in remaining
.split('\n') if line
.strip()]
749 remaining
= ' '.join(lines
)
751 message
= 'Remaining files: %s\n' % remaining
752 message
+= 'gnulib-tool: *** Stop.\n'
753 sys
.stderr
.write(message
)
756 sp
.call(['rm', '-rf', destdir
], shell
=False)
758 elif mode
== 'extract-description':
759 modulesystem
= classes
.GLModuleSystem(config
)
760 modules
= [modulesystem
.find(module
) for module
in modules
]
761 for module
in modules
:
762 print(module
.getDescription())
764 elif mode
== 'extract-comment':
765 modulesystem
= classes
.GLModuleSystem(config
)
766 modules
= [modulesystem
.find(module
) for module
in modules
]
767 for module
in modules
:
768 print(module
.getComment())
770 elif mode
== 'extract-status':
771 modulesystem
= classes
.GLModuleSystem(config
)
772 modules
= [modulesystem
.find(module
) for module
in modules
]
773 for module
in modules
:
774 status
= module
.getStatus()
775 print('\n'.join(status
))
777 elif mode
== 'extract-notice':
778 modulesystem
= classes
.GLModuleSystem(config
)
779 modules
= [modulesystem
.find(module
) for module
in modules
]
780 for module
in modules
:
781 print(module
.getNotice())
783 elif mode
== 'extract-applicability':
784 modulesystem
= classes
.GLModuleSystem(config
)
785 modules
= [modulesystem
.find(module
) for module
in modules
]
786 for module
in modules
:
787 print(module
.getApplicability())
789 elif mode
== 'extract-filelist':
790 modulesystem
= classes
.GLModuleSystem(config
)
791 modules
= [modulesystem
.find(module
) for module
in modules
]
792 for module
in modules
:
793 files
= module
.getFiles()
794 print('\n'.join(files
))
796 elif mode
== 'extract-dependencies':
799 message
= '%s: *** ' % constants
.APP
['name']
800 message
+= 'cannot combine --avoid and --extract-dependencies\n'
801 message
+= '%s: *** Exit.\n' % constants
.APP
['name']
802 sys
.stderr
.write(message
)
804 modulesystem
= classes
.GLModuleSystem(config
)
805 modules
= [modulesystem
.find(module
) for module
in modules
]
806 for module
in modules
:
807 dependencies
= module
.getDependencies()
809 for depmodule
, condition
in dependencies
:
810 if condition
== None:
811 result
+= '%s\n' % str(depmodule
)
812 else: # if condition != None
813 result
+= '%s\t%s' % (str(depmodule
), condition
)
816 elif mode
== 'extract-autoconf-snippet':
817 modulesystem
= classes
.GLModuleSystem(config
)
818 modules
= [modulesystem
.find(module
) for module
in modules
]
819 for module
in modules
:
820 print(module
.getAutoconfSnippet())
822 elif mode
== 'extract-automake-snippet':
823 modulesystem
= classes
.GLModuleSystem(config
)
824 modules
= [modulesystem
.find(module
) for module
in modules
]
825 for module
in modules
:
826 print(module
.getAutomakeSnippet())
828 elif mode
== 'extract-include-directive':
829 modulesystem
= classes
.GLModuleSystem(config
)
830 modules
= [modulesystem
.find(module
) for module
in modules
]
831 for module
in modules
:
832 print(module
.getInclude())
834 elif mode
== 'extract-link-directive':
835 modulesystem
= classes
.GLModuleSystem(config
)
836 modules
= [modulesystem
.find(module
) for module
in modules
]
837 for module
in modules
:
838 print(module
.getLink())
840 elif mode
== 'extract-license':
841 modulesystem
= classes
.GLModuleSystem(config
)
842 modules
= [modulesystem
.find(module
) for module
in modules
]
843 for module
in modules
:
844 print(module
.getLicense())
846 elif mode
== 'extract-maintainer':
847 modulesystem
= classes
.GLModuleSystem(config
)
848 modules
= [modulesystem
.find(module
) for module
in modules
]
849 for module
in modules
:
850 print(module
.getMaintainer())
852 elif mode
== 'extract-tests-module':
853 modulesystem
= classes
.GLModuleSystem(config
)
854 modules
= [modulesystem
.find(module
) for module
in modules
]
855 for module
in modules
:
856 if module
.getTestsModule():
857 print(module
.getTestsName())
859 elif mode
== 'copy-file':
863 else: # if len(files) != 2
865 if type(srcpath
) is bytes
:
866 srcpath
= srcpath
.decode(ENCS
['default'])
867 if type(dest
) is bytes
:
868 dest
= dest
.decode(ENCS
['default'])
879 config
.setAuxDir(auxdir
)
880 config
.setSourceBase(sourcebase
)
881 config
.setM4Base(m4base
)
882 config
.setDocBase(docbase
)
883 config
.setTestsBase(testsbase
)
884 filesystem
= classes
.GLFileSystem(config
)
885 lookedup
, flag
= filesystem
.lookup(srcpath
)
887 destdir
= string(dest
)
888 if srcpath
.startswith('build-aux/'):
889 destpath
= constants
.substart(
890 'build-aux/', '%s/' % auxdir
, srcpath
)
891 elif srcpath
.startswith('doc/'):
892 destpath
= constants
.substart('doc/', '%s/' % docbase
, srcpath
)
893 elif srcpath
.startswith('lib/'):
894 destpath
= constants
.substart(
895 'lib/', '%s/' % sourcebase
, srcpath
)
896 elif srcpath
.startswith('m4/'):
897 destpath
= constants
.substart('m4/', '%s/' % m4base
, srcpath
)
898 elif srcpath
.startswith('tests/'):
899 destpath
= constants
.substart(
900 'tests/', '%s/' % testsbase
, srcpath
)
901 elif srcpath
.startswith('tests=lib/'):
902 destpath
= constants
.substart(
903 'tests=lib/', '%s/' % testsbase
, srcpath
)
904 elif srcpath
.startswith('top/'):
905 destpath
= constants
.substart('top/', '', srcpath
)
908 else: # if not isdir(destpath)
909 destdir
= os
.path
.dirname(destpath
)
910 destpath
= os
.path
.basename(destpath
)
911 # Create the directory for destfile.
912 dirname
= os
.path
.dirname(joinpath(destdir
, destpath
))
913 if not config
['dryrun']:
914 if dirname
and not isdir(dirname
):
915 try: # Try to create directories
917 except Exception as error
:
920 assistant
= classes
.GLFileAssistant(config
)
921 tmpfile
= assistant
.tmpfilename(destpath
)
922 shutil
.copy(lookedup
, tmpfile
)
923 already_present
= True
924 assistant
.setOriginal(srcpath
)
925 assistant
.setRewritten(destpath
)
926 if isfile(joinpath(destdir
, destpath
)):
927 # The file already exists.
928 assistant
.update(lookedup
, flag
, tmpfile
, already_present
)
929 else: # if not isfile(joinpath(destdir, destpath))
931 # Don't protest if the file should be there but isn't: it happens
932 # frequently that developers don't put autogenerated files under version
934 assistant
.add(lookedup
, flag
, tmpfile
)
939 message
= '%s: *** ' % constants
.APP
['name']
940 message
+= 'no mode specified'
941 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
942 sys
.stderr
.write(message
)
946 if __name__
== '__main__':
947 try: # Try to execute
949 except classes
.GLError
as error
:
950 errmode
= 0 # gnulib-style errors
952 errinfo
= error
.errinfo
954 message
= '%s: *** ' % constants
.APP
['name']
958 message
+= 'file %s not found' % errinfo
960 message
+= 'patch file %s didn\'t apply cleanly' % errinfo
962 message
+= 'cannot find %s - make sure ' % errinfo
963 message
+= 'you run gnulib-tool from within your package\'s directory'
965 message
+= 'minimum supported autoconf version is 2.59. Try adding'
966 message
+= 'AC_PREREQ([%s])' % constants
.DEFAULT_AUTOCONF_MINVERSION
967 message
+= ' to your configure.ac.'
969 "%s is expected to contain gl_M4_BASE([%s])" % \
970 (repr(os
.path
.join(errinfo
, 'gnulib-comp.m4')), repr(errinfo
))
972 message
+= 'missing --source-base option'
974 message
+= 'missing --doc-base option. --doc-base has been introduced '
975 message
+= 'on 2006-07-11; if your last invocation of \'gnulib-tool '
976 message
+= '--import\' is before that date, you need to run'
977 message
+= '\'gnulib-tool --import\' once, with a --doc-base option.'
979 message
+= 'missing --tests-base option'
981 message
+= 'missing --lib option'
983 message
= 'gnulib-tool: option --conditional-dependencies is not '
984 message
+= 'supported with --with-tests\n'
986 incompatibilities
= string()
987 message
+= 'incompatible license on modules:%s' % constants
.NL
989 incompatibilities
+= pair
[0]
990 incompatibilities
+= ' %s' % pair
[1]
991 incompatibilities
+= constants
.NL
992 tempname
= tempfile
.mktemp()
993 with codecs
.open(tempname
, 'wb', 'UTF-8') as file:
994 file.write(incompatibilities
)
995 sed_table
= 's,^\\([^ ]*\\) ,\\1' + ' ' * 51 + ',\n'
996 sed_table
+= 's,^\\(' + '.' * 49 + \
997 '[^ ]*\) *,' + ' ' * 17 + '\\1 ,'
998 args
= ['sed', '-e', sed_table
, tempname
]
999 incompatibilities
= sp
.check_output(
1000 args
).decode(ENCS
['default'])
1001 message
+= incompatibilities
1004 message
+= 'refusing to do nothing'
1005 elif errno
in [13, 14, 15, 16, 17]:
1008 message
+= 'could not create destination directory: %s' % errinfo
1010 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
1011 sys
.stderr
.write(message
)