3 # Copyright (C) 2002-2017 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 <https://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 MODES
= constants
.MODES
48 TESTS
= constants
.TESTS
49 compiler
= constants
.compiler
50 joinpath
= constants
.joinpath
51 cleaner
= constants
.cleaner
52 string
= constants
.string
55 isfile
= os
.path
.isfile
56 normpath
= os
.path
.normpath
57 relpath
= os
.path
.relpath
60 #===============================================================================
62 #===============================================================================
86 witness_c_macro
= None
91 info
= classes
.GLInfo()
92 parser
= argparse
.ArgumentParser(
93 prog
=constants
.APP
['name'],
94 usage
='gnulib-tool.py --help',
97 parser
.add_argument('-h', '--help', '--hel', '--he', '--h',
102 parser
.add_argument('--version', '--versio', '--versi', '--vers',
107 parser
.add_argument('-l', '--list', '--lis',
112 parser
.add_argument('-f', '--find', '--fin', '--fi', '--f',
117 parser
.add_argument('-i', '--import',
122 parser
.add_argument('-a', '--add-import',
123 dest
='mode_add_import',
127 parser
.add_argument('-r', '--remove-import',
128 dest
='mode_remove_import',
132 parser
.add_argument('-u', '--update',
137 parser
.add_argument('-td', '--create-testdir',
138 dest
='mode_create_testdir',
142 parser
.add_argument('-mtd', '--create-megatestdir',
143 dest
='mode_create_megatestdir',
147 parser
.add_argument('-t', '--test',
152 parser
.add_argument('-mt', '--megatest', '--megates', '--megate', '--megat',
153 '--mega', '--meg', '--me', '--m',
154 dest
='mode_megatest',
158 parser
.add_argument('-c', '--copy-file',
159 dest
='mode_copy_file',
163 parser
.add_argument('-xD', '--extract-description',
164 dest
='mode_xdescription',
167 parser
.add_argument('-xc', '--extract-comment',
168 dest
='mode_xcomment',
171 parser
.add_argument('-xs', '--extract-status',
175 parser
.add_argument('-xn', '--extract-notice',
179 parser
.add_argument('-xa', '--extract-applicability',
180 dest
='mode_xapplicability',
183 parser
.add_argument('-xf', '--extract-filelist',
184 dest
='mode_xfilelist',
187 parser
.add_argument('-xd', '--extract-dependencies',
188 dest
='mode_xdependencies',
191 parser
.add_argument('-xac', '--extract-autoconf-snippet',
192 dest
='mode_xautoconf',
195 parser
.add_argument('-xam', '--extract-automake-snippet',
196 dest
='mode_xautomake',
199 parser
.add_argument('-xi', '--extract-include-directive',
200 dest
='mode_xinclude',
203 parser
.add_argument('-xl', '--extract-link-directive',
207 parser
.add_argument('-xL', '--extract-license',
208 dest
='mode_xlicense',
211 parser
.add_argument('-xm', '--extract-maintainer',
212 dest
='mode_xmaintainer',
215 # no-changelog: a no-op for backward compatibility
216 parser
.add_argument('--no-changelog',
219 action
='store_false')
221 parser
.add_argument('-d', '--dir',
226 parser
.add_argument('-ld', '--local-dir',
231 parser
.add_argument('-v', '--verbose',
235 parser
.add_argument('-q', '--quiet',
239 parser
.add_argument('--dry-run',
244 parser
.add_argument('--with-tests',
249 parser
.add_argument("--makefile-name",
254 parser
.add_argument('--with-obsolete',
259 parser
.add_argument('--with-c++-tests',
264 parser
.add_argument('--with-longrunning-tests',
269 parser
.add_argument('--with-privileged-tests',
274 parser
.add_argument('--with-unportable-tests',
279 parser
.add_argument('--with-all-tests',
284 parser
.add_argument('--aux-dir',
289 parser
.add_argument('--lib',
294 parser
.add_argument("--libtool",
299 parser
.add_argument('-sb', '--source-base',
304 parser
.add_argument('-mb', '--m4-base',
309 parser
.add_argument('-pb', '--po-base',
314 parser
.add_argument('-db', '--doc-base',
319 parser
.add_argument('-tb', '--tests-base',
324 parser
.add_argument('--lgpl',
330 parser
.add_argument('--avoid',
335 # Parse the given arguments.
336 cmdargs
= parser
.parse_args()
338 # Determine when user tries to combine modes.
342 cmdargs
.mode_add_import
,
343 cmdargs
.mode_remove_import
,
345 cmdargs
.mode_create_testdir
,
346 cmdargs
.mode_create_megatestdir
,
348 cmdargs
.mode_megatest
,
349 cmdargs
.mode_copy_file
,
350 cmdargs
.mode_xdescription
,
351 cmdargs
.mode_xcomment
,
352 cmdargs
.mode_xstatus
,
353 cmdargs
.mode_xnotice
,
354 cmdargs
.mode_xapplicability
,
355 cmdargs
.mode_xfilelist
,
356 cmdargs
.mode_xdependencies
,
357 cmdargs
.mode_xautoconf
,
358 cmdargs
.mode_xautomake
,
359 cmdargs
.mode_xinclude
,
361 cmdargs
.mode_xlicense
,
362 cmdargs
.mode_xmaintainer
,
364 overflow
= [arg
for arg
in args
if arg
]
365 if len(overflow
) > 1:
366 message
= 'gnulib-tool: Unable to combine different modes of work.\n'
367 message
+= 'Try \'gnulib-tool --help\' for more information.\n'
368 sys
.stderr
.write(message
)
371 # Determine selected mode.
372 if cmdargs
.help != None:
375 if cmdargs
.version
!= None:
376 message
= '''gnulib-tool (%s %s)%s\n%s\n%s\n\nWritten by %s.''' % \
377 (info
.package(), info
.date(), info
.version(), info
.copyright(),
378 info
.license(), info
.authors())
381 if cmdargs
.mode_list
!= None:
383 if cmdargs
.mode_import
!= None:
385 modules
= list(cmdargs
.mode_import
)
386 if cmdargs
.mode_add_import
!= None:
388 modules
= list(cmdargs
.mode_add_import
)
389 if cmdargs
.mode_remove_import
!= None:
390 mode
= 'remove-import'
391 modules
= list(cmdargs
.mode_remove_import
)
392 if cmdargs
.mode_update
!= None:
394 if cmdargs
.mode_create_testdir
!= None:
395 mode
= 'create-testdir'
396 modules
= list(cmdargs
.mode_create_testdir
)
397 if cmdargs
.mode_create_megatestdir
!= None:
398 mode
= 'create-megatestdir'
399 modules
= list(cmdargs
.mode_create_megatestdir
)
400 if cmdargs
.mode_test
!= None:
402 modules
= list(cmdargs
.mode_test
)
403 if cmdargs
.mode_megatest
!= None:
405 modules
= list(cmdargs
.mode_megatest
)
406 if cmdargs
.mode_xdescription
!= None:
407 mode
= 'extract-description'
408 modules
= list(cmdargs
.mode_xdescription
)
409 if cmdargs
.mode_xcomment
!= None:
410 mode
= 'extract-comment'
411 modules
= list(cmdargs
.mode_xcomment
)
412 if cmdargs
.mode_xstatus
!= None:
413 mode
= 'extract-status'
414 modules
= list(cmdargs
.mode_xstatus
)
415 if cmdargs
.mode_xnotice
!= None:
416 mode
= 'extract-notice'
417 modules
= list(cmdargs
.mode_xnotice
)
418 if cmdargs
.mode_xapplicability
!= None:
419 mode
= 'extract-applicability'
420 modules
= list(cmdargs
.mode_xapplicability
)
421 if cmdargs
.mode_xfilelist
!= None:
422 mode
= 'extract-filelist'
423 modules
= list(cmdargs
.mode_xfilelist
)
424 if cmdargs
.mode_xautoconf
!= None:
425 mode
= 'extract-autoconf-snippet'
426 modules
= list(cmdargs
.mode_xautoconf
)
427 if cmdargs
.mode_xautomake
!= None:
428 mode
= 'extract-automake-snippet'
429 modules
= list(cmdargs
.mode_xautomake
)
430 if cmdargs
.mode_xdependencies
!= None:
431 mode
= 'extract-dependencies'
432 modules
= list(cmdargs
.mode_xdependencies
)
433 if cmdargs
.mode_xinclude
!= None:
434 mode
= 'extract-include-directive'
435 modules
= list(cmdargs
.mode_xinclude
)
436 if cmdargs
.mode_xlink
!= None:
437 mode
= 'extract-link-directive'
438 modules
= list(cmdargs
.mode_xlink
)
439 if cmdargs
.mode_xlicense
!= None:
440 mode
= 'extract-license'
441 modules
= list(cmdargs
.mode_xlicense
)
442 if cmdargs
.mode_xmaintainer
!= None:
443 mode
= 'extract-maintainer'
444 modules
= list(cmdargs
.mode_xmaintainer
)
445 if cmdargs
.mode_copy_file
!= None:
447 if len(cmdargs
.mode_copy_file
) > 2:
448 message
= '%s: *** ' % constants
.APP
['name']
449 message
+= 'invalid number of arguments for --%s' % mode
450 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
451 sys
.stderr
.write(message
)
453 files
= list(cmdargs
.mode_copy_file
)
455 # Determine specific settings.
456 destdir
= cmdargs
.destdir
458 destdir
= cmdargs
.destdir
[0]
459 localdir
= cmdargs
.localdir
461 localdir
= cmdargs
.localdir
[0]
462 libname
= cmdargs
.libname
464 libname
= cmdargs
.libname
[0]
465 auxdir
= cmdargs
.auxdir
467 auxdir
= cmdargs
.auxdir
[0]
468 sourcebase
= cmdargs
.sourcebase
469 if sourcebase
!= None:
470 sourcebase
= cmdargs
.sourcebase
[0]
471 m4base
= cmdargs
.m4base
473 m4base
= cmdargs
.m4base
[0]
474 pobase
= cmdargs
.pobase
476 pobase
= cmdargs
.pobase
[0]
477 testsbase
= cmdargs
.testsbase
478 if testsbase
!= None:
479 testsbase
= cmdargs
.testsbase
[0]
480 dryrun
= cmdargs
.dryrun
481 verbose
= -cmdargs
.quiet
+ cmdargs
.verbose
482 inctests
= cmdargs
.inctests
483 flags
= [cmdargs
.inctests
, cmdargs
.obsolete
, cmdargs
.cxx
,
484 cmdargs
.longrunning
, cmdargs
.privileged
, cmdargs
.unportable
,
488 index
= flags
.index(flag
)
492 testflags
+= [constants
.TESTS
['tests']]
494 testflags
+= [constants
.TESTS
['obsolete']]
496 testflags
+= [constants
.TESTS
['cxx-tests']]
498 testflags
+= [constants
.TESTS
['longrunning-tests']]
500 testflags
+= [constants
.TESTS
['privileged-tests']]
502 testflags
+= [constants
.TESTS
['unportable-tests']]
504 testflags
+= [constants
.TESTS
['all-tests']]
506 libtool
= cmdargs
.libtool
507 makefile
= cmdargs
.makefile
510 avoids
= cmdargs
.avoids
512 # Create pygnulib configuration.
513 config
= classes
.GLConfig(
520 sourcebase
=sourcebase
,
530 macro_prefix
=macro_prefix
,
532 witness_c_macro
=witness_c_macro
,
539 # Canonicalize the inctests variable.
541 if mode
in ['import', 'add-import', 'remove-import', 'update']:
542 config
.disableTestFlag(TESTS
['tests'])
543 elif mode
in ['create-testdir', 'create-megatestdir', 'test', 'megatest']:
544 config
.enableTestFlag(TESTS
['tests'])
546 # Work in the given mode.
548 modulesystem
= classes
.GLModuleSystem(config
)
549 listing
= modulesystem
.list()
550 result
= '\n'.join(listing
)
551 os
.rmdir(config
['tempdir'])
554 elif mode
in ['import', 'add-import', 'remove-import', 'update']:
558 config
.setDestDir(destdir
)
560 if mode
== MODES
['import']:
561 # Set variables to default values.
572 config
.setSourceBase(sourcebase
)
573 config
.setM4Base(m4base
)
574 config
.setDocBase(docbase
)
575 config
.setTestsBase(testsbase
)
576 config
.setMacroPrefix(macro_prefix
)
578 # Perform GLImport actions.
579 importer
= classes
.GLImport(config
, mode
)
580 filetable
, transformers
= importer
.prepare()
581 importer
.execute(filetable
, transformers
)
583 else: # if mode != MODE['--import']
585 if not isfile(joinpath(destdir
, m4base
, 'gnulib-cache.m4')):
594 config
.setSourceBase(sourcebase
)
595 config
.setM4Base(m4base
)
596 config
.setDocBase(docbase
)
597 config
.setTestsBase(testsbase
)
598 config
.setMacroPrefix(macro_prefix
)
599 # Perform GLImport actions.
600 importer
= classes
.GLImport(config
, mode
)
601 filetable
, transformers
= importer
.prepare()
602 importer
.execute(filetable
, transformers
)
603 else: # if not m4base
606 filepath
= joinpath(destdir
, 'Makefile.am')
608 with codecs
.open(filepath
, 'rb', 'UTF-8') as file:
610 data
= data
.split('ACLOCAL_AMFLAGS')[1]
611 data
= data
[data
.find('=') + 1:data
.find('\n')]
612 aclocal_amflags
= data
.split()
613 for aclocal_amflag
in aclocal_amflags
:
615 if not isabs(aclocal_amflag
):
616 m4dirs
+= [aclocal_amflag
]
617 else: # if not dirisnext
618 if aclocal_amflag
== '-I':
620 else: # if aclocal_amflag != '-I'
622 else: # if not isfile(filepath)
623 filepath
= joinpath(destdir
, 'aclocal.m4')
625 pattern
= constants
.compiler(
626 r
'm4_include\(\[(.*?)\]\)')
627 with codecs
.open(filepath
, 'rb', 'UTF-8') as file:
628 m4dirs
= pattern
.findall(file.read())
629 m4dirs
= [os
.path
.dirname(m4dir
) for m4dir
in m4dirs
]
632 m4dir
for m4dir
in m4dirs \
633 if isfile(joinpath(destdir
, m4dir
, 'gnulib-cache.m4'))
635 m4dirs
= sorted(set(m4dirs
))
637 # First use of gnulib in a package.
638 # Any number of additional modules can be given.
648 config
.setSourceBase(sourcebase
)
649 config
.setM4Base(m4base
)
650 config
.setDocBase(docbase
)
651 config
.setTestsBase(testsbase
)
652 config
.setMacroPrefix(macro_prefix
)
653 # Perform GLImport actions.
654 importer
= classes
.GLImport(config
, mode
)
655 filetable
, transformers
= importer
.prepare()
656 importer
.execute(filetable
, transformers
)
657 elif len(m4dirs
) == 1:
659 config
.setM4Base(m4base
)
660 # Perform GLImport actions.
661 importer
= classes
.GLImport(config
, mode
)
662 filetable
, transformers
= importer
.prepare()
663 importer
.execute(filetable
, transformers
)
664 else: # if len(m4dirs) > 1
665 for m4base
in m4dirs
:
666 config
.setM4Base(m4base
)
667 # Perform GLImport actions.
668 importer
= classes
.GLImport(config
, mode
)
669 filetable
, transformers
= importer
.prepare()
670 importer
.execute(filetable
, transformers
)
672 elif mode
== 'create-testdir':
674 message
= '%s: *** ' % constants
.APP
['name']
675 message
+= 'please specify --dir option'
676 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
677 sys
.stderr
.write(message
)
681 config
.setAuxDir(auxdir
)
682 testdir
= classes
.GLTestDir(config
, destdir
)
685 elif mode
== 'create-megatestdir':
687 message
= '%s: *** ' % constants
.APP
['name']
688 message
+= 'please specify --dir option'
689 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
690 sys
.stderr
.write(message
)
694 config
.setAuxDir(auxdir
)
695 testdir
= classes
.GLMegaTestDir(config
, destdir
)
700 destdir
= 'testdir %04d' % random
.randrange(0, 9999)
703 config
.setAuxDir(auxdir
)
704 testdir
= classes
.GLTestDir(config
, destdir
)
709 try: # Try to execute commands
710 sp
.call(['../configure'])
711 sp
.call([UTILS
['make']])
712 sp
.call([UTILS
['make'], 'check'])
713 sp
.call([UTILS
['make'], 'distclean'])
714 except Exception as error
:
716 args
= ['find', '.', '-type', 'f', '-print']
717 remaining
= sp
.check_output(args
).decode(ENCS
['shell'])
718 lines
= [line
.strip()
719 for line
in remaining
.split('\n') if line
.strip()]
720 remaining
= ' '.join(lines
)
722 message
= 'Remaining files: %s\n' % remaining
723 message
+= 'gnulib-tool: *** Stop.\n'
724 sys
.stderr
.write(message
)
727 sp
.call(['rm', '-rf', destdir
], shell
=False)
729 elif mode
== 'megatest':
731 destdir
= 'testdir %04d' % random
.randrange(0, 9999)
734 config
.setAuxDir(auxdir
)
735 testdir
= classes
.GLMegaTestDir(config
, destdir
)
740 sp
.call(['../configure'])
741 sp
.call([UTILS
['make']])
742 sp
.call([UTILS
['make'], 'check'])
743 sp
.call([UTILS
['make'], 'distclean'])
744 args
= ['find', '.', '-type', 'f', '-print']
745 remaining
= sp
.check_output(args
).decode(ENCS
['shell'])
746 lines
= [line
.strip()
747 for line
in remaining
.split('\n') if line
.strip()]
748 remaining
= ' '.join(lines
)
750 message
= 'Remaining files: %s\n' % remaining
751 message
+= 'gnulib-tool: *** Stop.\n'
752 sys
.stderr
.write(message
)
755 sp
.call(['rm', '-rf', destdir
], shell
=False)
757 elif mode
== 'extract-description':
758 modulesystem
= classes
.GLModuleSystem(config
)
759 modules
= [modulesystem
.find(module
) for module
in modules
]
760 for module
in modules
:
761 print(module
.getDescription())
763 elif mode
== 'extract-comment':
764 modulesystem
= classes
.GLModuleSystem(config
)
765 modules
= [modulesystem
.find(module
) for module
in modules
]
766 for module
in modules
:
767 print(module
.getComment())
769 elif mode
== 'extract-status':
770 modulesystem
= classes
.GLModuleSystem(config
)
771 modules
= [modulesystem
.find(module
) for module
in modules
]
772 for module
in modules
:
773 status
= module
.getStatus()
774 print('\n'.join(status
))
776 elif mode
== 'extract-notice':
777 modulesystem
= classes
.GLModuleSystem(config
)
778 modules
= [modulesystem
.find(module
) for module
in modules
]
779 for module
in modules
:
780 print(module
.getNotice())
782 elif mode
== 'extract-applicability':
783 modulesystem
= classes
.GLModuleSystem(config
)
784 modules
= [modulesystem
.find(module
) for module
in modules
]
785 for module
in modules
:
786 print(module
.getApplicability())
788 elif mode
== 'extract-filelist':
789 modulesystem
= classes
.GLModuleSystem(config
)
790 modules
= [modulesystem
.find(module
) for module
in modules
]
791 for module
in modules
:
792 files
= module
.getFiles()
793 print('\n'.join(files
))
795 elif mode
== 'extract-dependencies':
798 message
= '%s: *** ' % constants
.APP
['name']
799 message
+= 'cannot combine --avoid and --extract-dependencies\n'
800 message
+= '%s: *** Exit.\n' % constants
.APP
['name']
801 sys
.stderr
.write(message
)
803 modulesystem
= classes
.GLModuleSystem(config
)
804 modules
= [modulesystem
.find(module
) for module
in modules
]
805 for module
in modules
:
806 dependencies
= module
.getDependencies()
808 for depmodule
, condition
in dependencies
:
809 if condition
== None:
810 result
+= '%s\n' % str(depmodule
)
811 else: # if condition != None
812 result
+= '%s\t%s' % (str(depmodule
), condition
)
815 elif mode
== 'extract-autoconf-snippet':
816 modulesystem
= classes
.GLModuleSystem(config
)
817 modules
= [modulesystem
.find(module
) for module
in modules
]
818 for module
in modules
:
819 print(module
.getAutoconfSnippet())
821 elif mode
== 'extract-automake-snippet':
822 modulesystem
= classes
.GLModuleSystem(config
)
823 modules
= [modulesystem
.find(module
) for module
in modules
]
824 for module
in modules
:
825 print(module
.getAutomakeSnippet())
827 elif mode
== 'extract-include-directive':
828 modulesystem
= classes
.GLModuleSystem(config
)
829 modules
= [modulesystem
.find(module
) for module
in modules
]
830 for module
in modules
:
831 print(module
.getInclude())
833 elif mode
== 'extract-link-directive':
834 modulesystem
= classes
.GLModuleSystem(config
)
835 modules
= [modulesystem
.find(module
) for module
in modules
]
836 for module
in modules
:
837 print(module
.getLink())
839 elif mode
== 'extract-license':
840 modulesystem
= classes
.GLModuleSystem(config
)
841 modules
= [modulesystem
.find(module
) for module
in modules
]
842 for module
in modules
:
843 print(module
.getLicense())
845 elif mode
== 'extract-maintainer':
846 modulesystem
= classes
.GLModuleSystem(config
)
847 modules
= [modulesystem
.find(module
) for module
in modules
]
848 for module
in modules
:
849 print(module
.getMaintainer())
851 elif mode
== 'extract-tests-module':
852 modulesystem
= classes
.GLModuleSystem(config
)
853 modules
= [modulesystem
.find(module
) for module
in modules
]
854 for module
in modules
:
855 if module
.getTestsModule():
856 print(module
.getTestsName())
858 elif mode
== 'copy-file':
862 else: # if len(files) != 2
864 if type(srcpath
) is bytes
:
865 srcpath
= srcpath
.decode(ENCS
['default'])
866 if type(dest
) is bytes
:
867 dest
= dest
.decode(ENCS
['default'])
878 config
.setAuxDir(auxdir
)
879 config
.setSourceBase(sourcebase
)
880 config
.setM4Base(m4base
)
881 config
.setDocBase(docbase
)
882 config
.setTestsBase(testsbase
)
883 filesystem
= classes
.GLFileSystem(config
)
884 lookedup
, flag
= filesystem
.lookup(srcpath
)
886 destdir
= string(dest
)
887 if srcpath
.startswith('build-aux/'):
888 destpath
= constants
.substart(
889 'build-aux/', '%s/' % auxdir
, srcpath
)
890 elif srcpath
.startswith('doc/'):
891 destpath
= constants
.substart('doc/', '%s/' % docbase
, srcpath
)
892 elif srcpath
.startswith('lib/'):
893 destpath
= constants
.substart(
894 'lib/', '%s/' % sourcebase
, srcpath
)
895 elif srcpath
.startswith('m4/'):
896 destpath
= constants
.substart('m4/', '%s/' % m4base
, srcpath
)
897 elif srcpath
.startswith('tests/'):
898 destpath
= constants
.substart(
899 'tests/', '%s/' % testsbase
, srcpath
)
900 elif srcpath
.startswith('tests=lib/'):
901 destpath
= constants
.substart(
902 'tests=lib/', '%s/' % testsbase
, srcpath
)
903 elif srcpath
.startswith('top/'):
904 destpath
= constants
.substart('top/', '', srcpath
)
907 else: # if not isdir(destpath)
908 destdir
= os
.path
.dirname(destpath
)
909 destpath
= os
.path
.basename(destpath
)
910 # Create the directory for destfile.
911 dirname
= os
.path
.dirname(joinpath(destdir
, destpath
))
912 if not config
['dryrun']:
913 if dirname
and not isdir(dirname
):
914 try: # Try to create directories
916 except Exception as error
:
919 assistant
= classes
.GLFileAssistant(config
)
920 tmpfile
= assistant
.tmpfilename(destpath
)
921 shutil
.copy(lookedup
, tmpfile
)
922 already_present
= True
923 assistant
.setOriginal(srcpath
)
924 assistant
.setRewritten(destpath
)
925 if isfile(joinpath(destdir
, destpath
)):
926 # The file already exists.
927 assistant
.update(lookedup
, flag
, tmpfile
, already_present
)
928 else: # if not isfile(joinpath(destdir, destpath))
930 # Don't protest if the file should be there but isn't: it happens
931 # frequently that developers don't put autogenerated files under version
933 assistant
.add(lookedup
, flag
, tmpfile
)
938 message
= '%s: *** ' % constants
.APP
['name']
939 message
+= 'no mode specified'
940 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
941 sys
.stderr
.write(message
)
945 if __name__
== '__main__':
946 try: # Try to execute
948 except classes
.GLError
as error
:
949 errmode
= 0 # gnulib-style errors
951 errinfo
= error
.errinfo
953 message
= '%s: *** ' % constants
.APP
['name']
957 message
+= 'file %s not found' % errinfo
959 message
+= 'patch file %s didn\'t apply cleanly' % errinfo
961 message
+= 'cannot find %s - make sure ' % errinfo
962 message
+= 'you run gnulib-tool from within your package\'s directory'
964 message
+= 'minimum supported autoconf version is 2.59. Try adding'
965 message
+= 'AC_PREREQ([%s])' % constants
.DEFAULT_AUTOCONF_MINVERSION
966 message
+= ' to your configure.ac.'
968 "%s is expected to contain gl_M4_BASE([%s])" % \
969 (repr(os
.path
.join(errinfo
, 'gnulib-comp.m4')), repr(errinfo
))
971 message
+= 'missing --source-base option'
973 message
+= 'missing --doc-base option. --doc-base has been introduced '
974 message
+= 'on 2006-07-11; if your last invocation of \'gnulib-tool '
975 message
+= '--import\' is before that date, you need to run'
976 message
+= '\'gnulib-tool --import\' once, with a --doc-base option.'
978 message
+= 'missing --tests-base option'
980 message
+= 'missing --lib option'
982 message
= 'gnulib-tool: option --conditional-dependencies is not '
983 message
+= 'supported with --with-tests\n'
985 incompatibilities
= string()
986 message
+= 'incompatible license on modules:%s' % constants
.NL
988 incompatibilities
+= pair
[0]
989 incompatibilities
+= ' %s' % pair
[1]
990 incompatibilities
+= constants
.NL
991 tempname
= tempfile
.mktemp()
992 with codecs
.open(tempname
, 'wb', 'UTF-8') as file:
993 file.write(incompatibilities
)
994 sed_table
= 's,^\\([^ ]*\\) ,\\1' + ' ' * 51 + ',\n'
995 sed_table
+= 's,^\\(' + '.' * 49 + \
996 '[^ ]*\) *,' + ' ' * 17 + '\\1 ,'
997 args
= ['sed', '-e', sed_table
, tempname
]
998 incompatibilities
= sp
.check_output(
999 args
).decode(ENCS
['default'])
1000 message
+= incompatibilities
1003 message
+= 'refusing to do nothing'
1004 elif errno
in [13, 14, 15, 16, 17]:
1007 message
+= 'could not create destination directory: %s' % errinfo
1009 message
+= '\n%s: *** Exit.\n' % constants
.APP
['name']
1010 sys
.stderr
.write(message
)