Branch
Hash :
b1fcec6d
Author :
Date :
2025-09-10T23:22:53
Remove support for IRIX. * all-modules: Update comments. * build-aux/install-reloc: Likewise. * build-aux/reloc-ldflags: Likewise. * gnulib-tool: Likewise. * gnulib-tool.py: Likewise. * gnulib-tool.sh: Likewise. * lib/aligned-malloc.h: Likewise. * lib/boot-time.c: Likewise. * lib/c32is-impl.h: Likewise. * lib/c32srtombs-state.c: Likewise. * lib/c32to-impl.h: Likewise. * lib/c32width.c: Likewise. * lib/errno.in.h: Likewise. * lib/euidaccess.c: Likewise. * lib/fbufmode.c: Likewise. * lib/fenv-except-state-get.c: Likewise. * lib/fenv-except-state-set.c: Likewise. * lib/fenv-except-tracking-clear.c: Likewise. * lib/fenv-except-tracking-set.c: Likewise. * lib/fenv-except-tracking-test.c: Likewise. * lib/fenv-except-trapping.c: Likewise. * lib/fenv-round.c: Likewise. * lib/fflush.c: Likewise. * lib/fileblocks.c: Likewise. * lib/forkpty.c: Likewise. * lib/fpending.c: Likewise. * lib/fpurge.c: Likewise. * lib/freadable.c: Likewise. * lib/freadahead.c: Likewise. * lib/freading.c: Likewise. * lib/freadptr.c: Likewise. * lib/freadseek.c: Likewise. * lib/fseeko.c: Likewise. * lib/fseterr.c: Likewise. * lib/fsusage.c: Likewise. * lib/fwritable.c: Likewise. * lib/fwriting.c: Likewise. * lib/getdomainname.c: Likewise. * lib/idpriv-drop.c: Likewise. * lib/idpriv-droptemp.c: Likewise. * lib/limits.in.h: Likewise. * lib/mbrtoc16.c: Likewise. * lib/mbrtoc32.c: Likewise. * lib/mbsrtoc32s-state.c: Likewise. * lib/mbsrtowcs-state.c: Likewise. * lib/mbtowc-lock.h: Likewise. * lib/minmax.h: Likewise. * lib/netdb.in.h: Likewise. * lib/pipe-filter-ii.c: Likewise. * lib/posix_openpt.c: Likewise. * lib/ptsname_r.c: Likewise. * lib/readutmp.c: Likewise. * lib/readutmp.h: Likewise. * lib/resource-ext.h: Likewise. * lib/safe-read.h: Likewise. * lib/safe-write.h: Likewise. * lib/save-cwd.c: Likewise. * lib/stdbool.in.h: Likewise. * lib/striconv.c: Likewise. * lib/striconveh.c: Likewise. * lib/termcap.h: Likewise. * lib/terminfo.h: Likewise. * lib/unistd.in.h: Likewise. * lib/vasnprintf.c: Likewise. * lib/wcrtomb.c: Likewise. * lib/wcsrtombs-state.c: Likewise. * m4/fenv-environment.m4: Likewise. * m4/fenv-exceptions-state.m4: Likewise. * m4/fenv-exceptions-tracking.m4: Likewise. * m4/fenv-rounding.m4: Likewise. * m4/fmod.m4: Likewise. * m4/getdomainname.m4: Likewise. * m4/getloadavg.m4: Likewise. * m4/getopt.m4: Likewise. * m4/hypot.m4: Likewise. * m4/hypotf.m4: Likewise. * m4/hypotl.m4: Likewise. * m4/iconv.m4: Likewise. * m4/intl-thread-locale.m4: Likewise. * m4/largefile.m4: Likewise. * m4/libdl.m4: Likewise. * m4/locale-ja.m4: Likewise. * m4/locale_h.m4: Likewise. * m4/log.m4: Likewise. * m4/log10.m4: Likewise. * m4/log10f.m4: Likewise. * m4/logf.m4: Likewise. * m4/modf.m4: Likewise. * m4/modff.m4: Likewise. * m4/modfl.m4: Likewise. * m4/pthread-rwlock.m4: Likewise. * m4/semaphore.m4: Likewise. * m4/socklen.m4: Likewise. * m4/stdint.m4: Likewise. * m4/strtod.m4: Likewise. * m4/strtof.m4: Likewise. * m4/strtold.m4: Likewise. * modules/sigsegv: Likewise. * posix-modules: Likewise. * pygnulib/GLImport.py: Likewise. * tests/init.sh: Likewise. * tests/test-echo.sh: Likewise. * tests/test-isatty.c: Likewise. * tests/test-math-h.c: Likewise. * tests/test-nonblocking-pipe.h: Likewise. * tests/test-nonblocking-socket.h: Likewise. * tests/test-strtod.h: Likewise. * tests/test-strtof.h: Likewise. * tests/test-strtold.h: Likewise. * tests/test-vasnprintf.c: Likewise. * tests/test-vasnwprintf.c: Likewise.
1 2 3 4 5 6 7 8 9 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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
# Copyright (C) 2002-2025 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import annotations
#===============================================================================
# Define global imports
#===============================================================================
import os
import re
import subprocess as sp
from .constants import (
DIRS,
UTILS,
MODES,
TESTS,
cleaner,
joinpath,
lines_to_multiline,
movefile,
copyfile,
copyfile2,
substart,
subend,
bold_escapes,
relconcat,
relativize,
rmtree,
)
from .functions import rewrite_file_name
from .GLError import GLError
from .GLConfig import GLConfig
from .GLModuleSystem import GLModuleTable
from .GLModuleSystem import GLModuleSystem
from .GLFileSystem import GLFileSystem
from .GLFileSystem import GLFileAssistant
from .GLMakefileTable import GLMakefileTable
from .GLEmiter import GLEmiter
from .GLFileTable import GLFileTable
#===============================================================================
# Define GLImport class
#===============================================================================
class GLImport:
'''GLImport class is used to provide methods for --import, --add-import,
--remove-import and --update actions. This is a high-level class, so
developers may have to use lower-level classes to create their own
scripts. However, if user needs just to use power of gnulib-tool, this class
is a very good choice.'''
mode: int
m4dirs: list[str]
config: GLConfig
cache: GLConfig
emitter: GLEmiter
modulesystem: GLModuleSystem
moduletable: GLModuleTable
makefiletable: GLMakefileTable
def __init__(self, config: GLConfig, mode: int, m4dirs: list[str]) -> None:
'''Create GLImport instance.
config - must be a GLConfig object.
mode - must be one of the values of the constants.MODES values.
m4dirs - list of all directories that contain relevant .m4 files.'''
if type(config) is not GLConfig:
raise TypeError('config must have GLConfig type, not %s'
% repr(config))
if not (type(mode) is int and MODES['import'] <= mode <= MODES['update']):
raise TypeError('mode must be 0 <= mode <= 3, not %s'
% repr(mode))
if type(m4dirs) is not list:
raise TypeError('m4dirs must be a list of strings, not %s'
% repr(m4dirs))
self.mode = mode
self.m4dirs = m4dirs
# config contains the configuration, as specified through command-line
# parameters.
# self.config records the configuration that we are building/deducing.
# Initialize it with the properties from config.
self.config = config.copy()
# self.cache is the configuration extracted from some files on the
# file system: configure.{ac,in}, gnulib-cache.m4, gnulib-comp.m4.
self.cache = GLConfig()
# Read configure.{ac,in}.
with open(self.config.getAutoconfFile(), mode='r', newline='\n', encoding='utf-8') as file:
data = file.read()
# Get cached auxdir from configure.{ac,in}.
self.cache.setAuxDir('.')
pattern = re.compile(r'^AC_CONFIG_AUX_DIR\([\[ ]*([^]"$`\\)]+).*?$', re.MULTILINE)
match = pattern.search(data)
if match:
self.cache.setAuxDir(match.group(1))
if self.config['auxdir'] == '':
self.config.setAuxDir(self.cache['auxdir'])
# Get libtool guess from configure.{ac,in}.
# XXX This is not actually used.
pattern = re.compile(r'A[CM]_PROG_LIBTOOL', re.M)
guessed_libtool = bool(pattern.findall(data))
# Guess autoconf version.
pattern = re.compile(r'.*AC_PREREQ\((.*)\)', re.M)
versions = cleaner(pattern.findall(data))
if versions:
version = max({ float(version)
for version in versions })
self.config.setAutoconfVersion(version)
if version < 2.64:
raise GLError(4, version)
# Get other cached variables.
path = joinpath(self.config['m4base'], 'gnulib-cache.m4')
if os.path.isfile(path):
with open(path, mode='r', newline='\n', encoding='utf-8') as file:
data = file.read()
# gl_LGPL is special, because it can occur with or without
# an argument list.
pattern = re.compile(r'^gl_LGPL$', re.M)
if pattern.search(data):
self.cache.setLGPL(True)
# Find gl_* macros without an argument list.
if 'gl_LIBTOOL' in data:
self.cache.setLibtool(True)
data = data.replace('gl_LIBTOOL', '')
if 'gl_CONDITIONAL_DEPENDENCIES' in data:
self.cache.setCondDeps(True)
data = data.replace('gl_CONDITIONAL_DEPENDENCIES', '')
if 'gl_WITH_TESTS' in data:
self.cache.enableInclTestCategory(TESTS['tests'])
data = data.replace('gl_WITH_TESTS', '')
if 'gl_WITH_OBSOLETE' in data:
self.cache.setIncObsolete(True)
data = data.replace('gl_WITH_OBSOLETE', '')
if 'gl_WITH_CXX_TESTS' in data:
self.cache.enableInclTestCategory(TESTS['c++-test'])
data = data.replace('gl_WITH_CXX_TESTS', '')
if 'gl_WITH_LONGRUNNING_TESTS' in data:
self.cache.enableInclTestCategory(TESTS['longrunning-test'])
data = data.replace('gl_WITH_LONGRUNNING_TESTS', '')
if 'gl_WITH_PRIVILEGED_TESTS' in data:
self.cache.enableInclTestCategory(TESTS['privileged-test'])
data = data.replace('gl_WITH_PRIVILEGED_TESTS', '')
if 'gl_WITH_UNPORTABLE_TESTS' in data:
self.cache.enableInclTestCategory(TESTS['unportable-test'])
data = data.replace('gl_WITH_UNPORTABLE_TESTS', '')
if 'gl_WITH_ALL_TESTS' in data:
self.cache.enableInclTestCategory(TESTS['all-test'])
data = data.replace('gl_WITH_ALL_TESTS', '')
if 'gl_AUTOMAKE_SUBDIR' in data:
self.cache.setAutomakeSubdir(True)
data = data.replace('gl_AUTOMAKE_SUBDIR', '')
# Find gl_* macros with an argument list.
pattern = re.compile(r'^(gl_[A-Z0-9_]*)\((.*?)\)$', re.S | re.M)
keys = \
[
'gl_LOCAL_DIR', 'gl_MODULES', 'gl_AVOID', 'gl_SOURCE_BASE',
'gl_M4_BASE', 'gl_PO_BASE', 'gl_DOC_BASE', 'gl_TESTS_BASE',
'gl_LIB', 'gl_LGPL', 'gl_GPL',
'gl_MAKEFILE_NAME', 'gl_TESTS_MAKEFILE_NAME',
'gl_MACRO_PREFIX', 'gl_PO_DOMAIN', 'gl_WITNESS_C_MACRO',
'gl_VC_FILES',
]
result = dict(pattern.findall(data))
values = cleaner([ result.get(key, '')
for key in keys ])
tempdict = dict(zip(keys, values))
if 'gl_LGPL' in tempdict:
lgpl = cleaner(tempdict['gl_LGPL'])
if lgpl != '':
self.cache.setLGPL(lgpl)
else: # if 'gl_LGPL' not in tempdict
self.cache.setLGPL(None)
if tempdict['gl_LIB']:
self.cache.setLibName(cleaner(tempdict['gl_LIB']))
if tempdict['gl_GPL']:
self.cache.setLibName(cleaner(tempdict['gl_GPL']))
if tempdict['gl_LOCAL_DIR']:
self.cache.setLocalPath(cleaner(tempdict['gl_LOCAL_DIR']).split(':'))
if tempdict['gl_MODULES']:
self.cache.setModules(cleaner(tempdict['gl_MODULES'].split()))
if tempdict['gl_AVOID']:
self.cache.setAvoids(cleaner(tempdict['gl_AVOID'].split()))
if tempdict['gl_SOURCE_BASE']:
self.cache.setSourceBase(cleaner(tempdict['gl_SOURCE_BASE']))
if tempdict['gl_M4_BASE']:
self.cache.setM4Base(cleaner(tempdict['gl_M4_BASE']))
if tempdict['gl_PO_BASE']:
self.cache.setPoBase(cleaner(tempdict['gl_PO_BASE']))
if tempdict['gl_DOC_BASE']:
self.cache.setDocBase(cleaner(tempdict['gl_DOC_BASE']))
if tempdict['gl_TESTS_BASE']:
self.cache.setTestsBase(cleaner(tempdict['gl_TESTS_BASE']))
if tempdict['gl_MAKEFILE_NAME']:
self.cache.setMakefileName(cleaner(tempdict['gl_MAKEFILE_NAME']))
if tempdict['gl_TESTS_MAKEFILE_NAME']:
self.cache.setTestsMakefileName(cleaner(tempdict['gl_TESTS_MAKEFILE_NAME']))
if tempdict['gl_MACRO_PREFIX']:
self.cache.setMacroPrefix(cleaner(tempdict['gl_MACRO_PREFIX']))
if tempdict['gl_PO_DOMAIN']:
self.cache.setPoDomain(cleaner(tempdict['gl_PO_DOMAIN']))
if tempdict['gl_WITNESS_C_MACRO']:
self.cache.setWitnessCMacro(cleaner(tempdict['gl_WITNESS_C_MACRO']))
if tempdict['gl_VC_FILES'] != '':
self.cache.setVCFiles(cleaner(tempdict['gl_VC_FILES']))
# Get cached filelist from gnulib-comp.m4.
destdir, m4base = self.config.getDestDir(), self.config.getM4Base()
path = joinpath(destdir, m4base, 'gnulib-comp.m4')
if os.path.isfile(path):
with open(path, mode='r', newline='\n', encoding='utf-8') as file:
data = file.read()
regex = r'AC_DEFUN\(\[%s_FILE_LIST\], \[(.*?)\]\)' % self.cache['macro_prefix']
pattern = re.compile(regex, re.S | re.M)
matches = pattern.findall(data)
if matches:
files = matches[-1].strip().split()
else:
files = []
self.cache.setFiles(files)
# The self.config['localpath'] defaults to the cached one. Recall that
# the cached one is relative to self.config['destdir'], whereas the one
# we use is relative to . or absolute.
if len(self.config['localpath']) == 0:
if len(self.cache['localpath']) > 0:
localpath = [ self.relative_to_currdir(localdir)
for localdir in self.cache['localpath'] ]
self.config.setLocalPath(localpath)
if self.mode == MODES['import']:
self.config.setModules(sorted(self.config.getModules()))
else:
if self.cache['m4base'] and (self.config['m4base'] != self.cache['m4base']):
raise GLError(5, m4base)
# Perform actions with modules. In --add-import, append each given module
# to the list of cached modules; in --remove-import, remove each given
# module from the list of cached modules; in --update, simply set
# self.config['modules'] to its cached version.
new, old = self.config.getModules(), self.cache.getModules()
if self.mode == MODES['add-import']:
modules = sorted(set(new + old))
elif self.mode == MODES['remove-import']:
modules = [ module
for module in old
if not module in new ]
elif self.mode == MODES['update']:
modules = self.cache.getModules()
# Merge the configuration found on disk.
self.config.update(self.cache)
self.config.setModules(modules)
# Merge with the configuration from the command-line parameters;
# they override the configuration found on disk.
for key in config.keys():
if key not in ['modules', 'avoids',
'incl_test_categories', 'excl_test_categories']:
value = config[key]
if not config.isdefault(key, value):
self.config.update_key(config, key)
# Determine whether --automake-subdir/--automake-subdir-tests are supported.
if self.config['automake_subdir'] or self.config['automake_subdir_tests']:
found_subdir_objects = False
if self.config['destdir']:
with open(self.config['configure_ac'], mode='r', newline='\n', encoding='utf-8') as file:
data = file.read()
pattern = re.compile(r'^.*AM_INIT_AUTOMAKE\([\[ ]*([^])]*).*$', re.MULTILINE)
configure_ac_automake_options = pattern.findall(data)
if configure_ac_automake_options:
automake_options = { x
for y in configure_ac_automake_options
for x in y.split() }
found_subdir_objects = 'subdir-objects' in automake_options
if not found_subdir_objects:
if self.config['destdir']:
base = self.config['destdir']
else:
base = '.'
if os.path.isfile(joinpath(base, 'Makefile.am')):
with open(joinpath(base, 'Makefile.am'), mode='r', newline='\n', encoding='utf-8') as file:
data = file.read()
pattern = re.compile(r'^AUTOMAKE_OPTIONS[\t ]*=(.*)$', re.MULTILINE)
automake_options = pattern.findall(data)
if automake_options:
automake_options = { x
for y in automake_options
for x in y.split() }
found_subdir_objects = 'subdir-objects' in automake_options
if not found_subdir_objects:
raise GLError(21, None)
# Define GLImport attributes.
self.emitter = GLEmiter(self.config)
self.modulesystem = GLModuleSystem(self.config)
self.moduletable = GLModuleTable(self.config,
self.config.checkInclTestCategory(TESTS['all-tests']),
self.config.checkInclTestCategory(TESTS['all-tests']))
self.makefiletable = GLMakefileTable(self.config)
def __repr__(self) -> str:
'''x.__repr__ <==> repr(x)'''
result = '<pygnulib.GLImport %s>' % hex(id(self))
return result
def actioncmd(self) -> str:
'''Return command-line invocation comment.'''
modules = self.config.getModules()
avoids = self.config.getAvoids()
localpath = self.config.getLocalPath()
auxdir = self.config.getAuxDir()
sourcebase = self.config.getSourceBase()
m4base = self.config.getM4Base()
docbase = self.config.getDocBase()
pobase = self.config.getPoBase()
testsbase = self.config.getTestsBase()
conddeps = self.config.checkCondDeps()
libname = self.config.getLibName()
lgpl = self.config.getLGPL()
gpl = self.config.getGPL()
gnu_make = self.config.getGnuMake()
makefile_name = self.config.getMakefileName()
tests_makefile_name = self.config.getTestsMakefileName()
automake_subdir = self.config.getAutomakeSubdir()
automake_subdir_tests = self.config.getAutomakeSubdirTests()
libtool = self.config.checkLibtool()
macro_prefix = self.config.getMacroPrefix()
witness_c_macro = self.config.getWitnessCMacro()
podomain = self.config.getPoDomain()
vc_files = self.config.checkVCFiles()
# Command-line invocation printed in a comment in generated gnulib-cache.m4.
actioncmd = '# gnulib-tool --import'
# Break the action command log into multiple lines.
# Emacs puts some gnulib-tool log lines in its source repository, and
# git send-email rejects patch lines longer than 998 characters.
# Also, config.status uses awk, and the HP-UX 11.00 awk fails if a
# line has length >= 3071.
if len(localpath) > 0:
actioncmd += ''.join([f' \\\n# --local-dir={x}' for x in localpath])
actioncmd += ' \\\n# --lib=%s' % libname
actioncmd += ' \\\n# --source-base=%s' % sourcebase
actioncmd += ' \\\n# --m4-base=%s' % m4base
if pobase:
actioncmd += ' \\\n# --po-base=%s' % pobase
actioncmd += ' \\\n# --doc-base=%s' % docbase
actioncmd += ' \\\n# --tests-base=%s' % testsbase
actioncmd += ' \\\n# --aux-dir=%s' % auxdir
if self.config.checkInclTestCategory(TESTS['tests']):
actioncmd += ' \\\n# --with-tests'
if self.config.checkIncObsolete():
actioncmd += ' \\\n# --with-obsolete'
if self.config.checkInclTestCategory(TESTS['c++-test']):
actioncmd += ' \\\n# --with-c++-tests'
if self.config.checkInclTestCategory(TESTS['longrunning-test']):
actioncmd += ' \\\n# --with-longrunning-tests'
if self.config.checkInclTestCategory(TESTS['privileged-test']):
actioncmd += ' \\\n# --with-privileged-tests'
if self.config.checkInclTestCategory(TESTS['unportable-test']):
actioncmd += ' \\\n# --with-unportable-tests'
if self.config.checkInclTestCategory(TESTS['all-test']):
actioncmd += ' \\\n# --with-all-tests'
if lgpl:
if lgpl == True:
actioncmd += ' \\\n# --lgpl'
else: # if lgpl != True
actioncmd += ' \\\n# --lgpl=%s' % lgpl
if gpl:
actioncmd += ' \\\n# --gpl=%s' % gpl
if gnu_make:
actioncmd += ' \\\n# --gnu-make'
if makefile_name:
actioncmd += ' \\\n# --makefile-name=%s' % makefile_name
if tests_makefile_name:
actioncmd += ' \\\n# --tests-makefile-name=%s' % tests_makefile_name
if automake_subdir:
actioncmd += ' \\\n# --automake-subdir'
if automake_subdir_tests:
actioncmd += ' \\\n# --automake-subdir-tests'
if conddeps == True:
actioncmd += ' \\\n# --conditional-dependencies'
else: # if conddeps == False or conddeps == None
actioncmd += ' \\\n# --no-conditional-dependencies'
if libtool == True:
actioncmd += ' \\\n# --libtool'
else: # if libtool == False or libtool == None
actioncmd += ' \\\n# --no-libtool'
actioncmd += ' \\\n# --macro-prefix=%s' % macro_prefix
if podomain:
actioncmd += ' \\\n# --po-domain=%s' % podomain
if witness_c_macro:
actioncmd += ' \\\n# --witness-c-macro=%s' % witness_c_macro
if vc_files == True:
actioncmd += ' \\\n# --vc-files'
elif vc_files == False:
actioncmd += ' \\\n# --no-vc-files'
if len(avoids) > 0:
actioncmd += ''.join([f' \\\n# --avoid={x}' for x in avoids])
if len(modules) > 0:
actioncmd += ''.join([f' \\\n# {x}' for x in modules])
return actioncmd
def relative_to_destdir(self, dir: str) -> str:
'''Convert a filename that represents dir, relative to the current
directory, to a filename relative to destdir.
GLConfig: destdir.'''
destdir = self.config['destdir']
if os.path.isabs(dir):
return dir
else:
if os.path.isabs(destdir):
# XXX This doesn't look right.
return dir
else:
return relativize(destdir, dir)
def relative_to_currdir(self, dir: str) -> str:
'''The opposite of GLImport.relative_to_destdir:
Convert a filename that represents dir, relative to destdir,
to a filename relative to the current directory.
GLConfig: destdir.'''
destdir = self.config['destdir']
if os.path.isabs(dir):
return dir
else:
if os.path.isabs(destdir):
# XXX This doesn't look right.
return joinpath(destdir, dir)
else:
return relconcat(destdir, dir)
def gnulib_cache(self) -> str:
'''Emit the contents of generated $m4base/gnulib-cache.m4 file.
GLConfig: destdir, localpath, tests, sourcebase, m4base, pobase, docbase,
testsbase, conddeps, libtool, macro_prefix, podomain, vc_files.'''
emit = ''
actioncmd = self.actioncmd()
localpath = self.config['localpath']
sourcebase = self.config['sourcebase']
m4base = self.config['m4base']
pobase = self.config['pobase']
docbase = self.config['docbase']
testsbase = self.config['testsbase']
lgpl = self.config['lgpl']
gpl = self.config['gpl']
libname = self.config['libname']
makefile_name = self.config['makefile_name']
tests_makefile_name = self.config['tests_makefile_name']
automake_subdir = self.config['automake_subdir']
conddeps = self.config['conddeps']
libtool = self.config['libtool']
macro_prefix = self.config['macro_prefix']
podomain = self.config['podomain']
witness_c_macro = self.config['witness_c_macro']
vc_files = self.config['vc_files']
modules = self.config['modules']
avoids = self.config['avoids']
emit += self.emitter.copyright_notice()
emit += '''#
# This file represents the specification of how gnulib-tool is used.
# It acts as a cache: It is written and read by gnulib-tool.
# In projects that use version control, this file is meant to be put under
# version control, like the configure.ac and various Makefile.am files.
# Specification in the form of a command-line invocation:
%s
# Specification in the form of a few gnulib-tool.m4 macro invocations:\n''' % actioncmd
# Store the localpath relative to destdir.
relative_localpath = [ self.relative_to_destdir(localdir)
for localdir in localpath ]
emit += 'gl_LOCAL_DIR([%s])\n' % ':'.join(relative_localpath)
emit += 'gl_MODULES([\n'
emit += ' %s\n' % '\n '.join(modules)
emit += '])\n'
if self.config.checkIncObsolete():
emit += 'gl_WITH_OBSOLETE\n'
if self.config.checkInclTestCategory(TESTS['cxx-tests']):
emit += 'gl_WITH_CXX_TESTS\n'
if self.config.checkInclTestCategory(TESTS['longrunning-tests']):
emit += 'gl_WITH_LONGRUNNING_TESTS\n'
if self.config.checkInclTestCategory(TESTS['privileged-tests']):
emit += 'gl_WITH_PRIVILEGED_TESTS\n'
if self.config.checkInclTestCategory(TESTS['unportable-tests']):
emit += 'gl_WITH_UNPORTABLE_TESTS\n'
if self.config.checkInclTestCategory(TESTS['all-tests']):
emit += 'gl_WITH_ALL_TESTS\n'
emit += 'gl_AVOID([%s])\n' % ' '.join(avoids)
emit += 'gl_SOURCE_BASE([%s])\n' % sourcebase
emit += 'gl_M4_BASE([%s])\n' % m4base
emit += 'gl_PO_BASE([%s])\n' % pobase
emit += 'gl_DOC_BASE([%s])\n' % docbase
emit += 'gl_TESTS_BASE([%s])\n' % testsbase
if self.config.checkInclTestCategory(TESTS['tests']):
emit += 'gl_WITH_TESTS\n'
emit += 'gl_LIB([%s])\n' % libname
if lgpl != None:
if lgpl == True:
emit += 'gl_LGPL\n'
else: # if lgpl != True
emit += 'gl_LGPL([%s])\n' % lgpl
if gpl != None:
emit += 'gl_GPL([%s])\n' % gpl
emit += 'gl_MAKEFILE_NAME([%s])\n' % makefile_name
if tests_makefile_name:
emit += 'gl_TESTS_MAKEFILE_NAME([%s])\n' % tests_makefile_name
if automake_subdir:
emit += 'gl_AUTOMAKE_SUBDIR\n'
if conddeps:
emit += 'gl_CONDITIONAL_DEPENDENCIES\n'
if libtool:
emit += 'gl_LIBTOOL\n'
emit += 'gl_MACRO_PREFIX([%s])\n' % macro_prefix
emit += 'gl_PO_DOMAIN([%s])\n' % podomain
emit += 'gl_WITNESS_C_MACRO([%s])\n' % witness_c_macro
if vc_files != None:
# Convert Python bools to shell (True -> true).
emit += 'gl_VC_FILES([%s])\n' % str(vc_files).lower()
return emit
def gnulib_comp(self, filetable: GLFileTable, gentests: bool) -> str:
'''Emit the contents of generated $m4base/gnulib-comp.m4 file.
GLConfig: destdir, localpath, tests, sourcebase, m4base, pobase, docbase,
testsbase, conddeps, libtool, macro_prefix, podomain, vc_files.
filetable is a GLFileTable containing file information for this
import.
gentests is True if a tests Makefile.am is being generated, False
otherwise.'''
if type(filetable) is not GLFileTable:
raise TypeError(f'filetable should be a GLFileTable, not {type(filetable).__name__}')
if type(gentests) is not bool:
raise TypeError(f'gentests should be a bool, not {type(gentests).__name__}')
emit = ''
moduletable = self.moduletable
auxdir = self.config['auxdir']
sourcebase = self.config['sourcebase']
m4base = self.config['m4base']
testsbase = self.config['testsbase']
libname = self.config['libname']
libtool = self.config['libtool']
macro_prefix = self.config['macro_prefix']
witness_c_macro = self.config['witness_c_macro']
configure_ac = self.config['configure_ac']
libtests = self.config['libtests']
emit += '# DO NOT EDIT! GENERATED AUTOMATICALLY!\n'
emit += self.emitter.copyright_notice()
emit += '''#
# This file represents the compiled summary of the specification in
# gnulib-cache.m4. It lists the computed macro invocations that need
# to be invoked from configure.ac.
# In projects that use version control, this file can be treated like
# other built files.
# This macro should be invoked from %s, in the section
# "Checks for programs", right after AC_PROG_CC, and certainly before
# any checks for libraries, header files, types and library functions.
AC_DEFUN([%s_EARLY],
[
m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace
m4_pattern_allow([^gl_ES$])dnl a valid locale name
m4_pattern_allow([^gl_LIBOBJS$])dnl a variable
m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable\n''' % (configure_ac, macro_prefix)
emit += self.emitter.preEarlyMacros(True, ' ', moduletable.getFinalModules())
for module in moduletable.getFinalModules():
emit += ' # Code from module %s:\n' % module.name
snippet = module.getAutoconfEarlySnippet()
lines = [ line
for line in snippet.split('\n')
if line != '' ]
if lines:
emit += ' %s\n' % '\n '.join(lines)
emit += '])\n'
emit += '''
# This macro should be invoked from %s, in the section
# "Check for header files, types and library functions".
AC_DEFUN([%s_INIT],
[\n''' % (configure_ac, macro_prefix)
# This AC_CONFIG_LIBOBJ_DIR invocation silences an error from the automake
# front end:
# error: required file './alloca.c' not found
# It is needed because of the last remaining use of AC_LIBSOURCES in
# _AC_LIBOBJ_ALLOCA, invoked from AC_FUNC_ALLOCA.
# All the m4_pushdef/m4_popdef logic in func_emit_initmacro_start/_end
# does not help to avoid this error.
newfile_set = { pair[1]
for pair in filetable.new_files }
if 'lib/alloca.c' in newfile_set:
emit += ' AC_CONFIG_LIBOBJ_DIR([%s])\n' % sourcebase
elif 'tests=lib/alloca.c' in newfile_set:
# alloca.c will be present in $testsbase.
emit += ' AC_CONFIG_LIBOBJ_DIR([%s])\n' % testsbase
if libtool:
emit += ' AM_CONDITIONAL([GL_COND_LIBTOOL], [true])\n'
emit += ' gl_cond_libtool=true\n'
else: # if not libtool
emit += ' AM_CONDITIONAL([GL_COND_LIBTOOL], [false])\n'
emit += ' gl_cond_libtool=false\n'
emit += ' gl_libdeps=\n'
emit += ' gl_ltlibdeps=\n'
replace_auxdir = False
if auxdir != 'build-aux':
replace_auxdir = True
emit += ' gl_m4_base=\'%s\'\n' % m4base
emit += self.emitter.initmacro_start(macro_prefix, False)
emit += self.emitter.shellvars_init(False, sourcebase)
if witness_c_macro:
emit += ' m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [%s])\n' % witness_c_macro
# Emit main autoconf snippets.
emit += self.emitter.autoconfSnippets(moduletable.getMainModules(), moduletable.getMainModules(),
moduletable, lambda module: True, True, False, True, replace_auxdir)
if witness_c_macro:
emit += ' m4_popdef([gl_MODULE_INDICATOR_CONDITION])\n'
emit += ' # End of code from modules\n'
emit += self.emitter.initmacro_end(macro_prefix, False)
emit += ' gltests_libdeps=\n'
emit += ' gltests_ltlibdeps=\n'
emit += self.emitter.initmacro_start('%stests' % macro_prefix, gentests)
emit += self.emitter.shellvars_init(True, testsbase)
# Define a tests witness macro that depends on the package.
# PACKAGE is defined by AM_INIT_AUTOMAKE, PACKAGE_TARNAME is defined by
# AC_INIT.
# See <https://lists.gnu.org/r/automake/2009-05/msg00145.html>.
emit += 'changequote(,)dnl\n'
emit += ' %stests_WITNESS=' % macro_prefix
emit += 'IN_`echo "${PACKAGE-$PACKAGE_TARNAME}" | LC_ALL=C tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | LC_ALL=C sed -e \'s/[^A-Z0-9_]/_/g\'`_GNULIB_TESTS\n'
emit += 'changequote([, ])dnl\n'
emit += ' AC_SUBST([%stests_WITNESS])\n' % macro_prefix
emit += ' gl_module_indicator_condition=$%stests_WITNESS\n' % macro_prefix
emit += ' m4_pushdef([gl_MODULE_INDICATOR_CONDITION], '
emit += '[$gl_module_indicator_condition])\n'
# Emit tests autoconf snippets.
emit += self.emitter.autoconfSnippets(moduletable.getTestsModules(),
moduletable.getMainModules() + moduletable.getTestsModules(),
moduletable, lambda module: True, True, True, True, replace_auxdir)
emit += ' m4_popdef([gl_MODULE_INDICATOR_CONDITION])\n'
emit += self.emitter.initmacro_end('%stests' % macro_prefix, gentests)
emit += ' AC_REQUIRE([gl_CC_GNULIB_WARNINGS])\n'
# _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
# created using libtool, because libtool already handles the dependencies.
if not libtool:
libname_upper = libname.upper().replace('-', '_')
emit += ' %s_LIBDEPS="$gl_libdeps"\n' % libname_upper
emit += ' AC_SUBST([%s_LIBDEPS])\n' % libname_upper
emit += ' %s_LTLIBDEPS="$gl_ltlibdeps"\n' % libname_upper
emit += ' AC_SUBST([%s_LTLIBDEPS])\n' % libname_upper
if libtests:
emit += ' LIBTESTS_LIBDEPS="$gltests_libdeps"\n'
emit += ' AC_SUBST([LIBTESTS_LIBDEPS])\n'
emit += '])\n'
emit += self.emitter.initmacro_done(macro_prefix, sourcebase)
emit += self.emitter.initmacro_done('%stests' % macro_prefix, testsbase)
emit += '''
# This macro records the list of files which have been installed by
# gnulib-tool and may be removed by future gnulib-tool invocations.
AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
emit += ' %s\n' % '\n '.join(filetable.all_files)
emit += '])\n'
return emit
def _done_dir_(self, directory: str, files_added: list[str], files_removed: list[str]) -> None:
'''This method is used to determine ignore argument for _update_ignorelist_
method and then call it.'''
destdir = self.config['destdir']
if (os.path.isdir(joinpath(destdir, 'CVS'))
or os.path.isdir(joinpath(destdir, directory, 'CVS'))
or os.path.isfile(joinpath(destdir, directory, '.cvsignore'))):
self._update_ignorelist_(directory, '.cvsignore',
files_added, files_removed)
if (os.path.isdir(joinpath(destdir, '.git'))
or os.path.isfile(joinpath(destdir, '.gitignore'))
or os.path.isfile(joinpath(destdir, directory, '.gitignore'))):
self._update_ignorelist_(directory, '.gitignore',
files_added, files_removed)
def _update_ignorelist_(self, directory: str, ignore: str, files_added: list[str],
files_removed: list[str]) -> None:
'''Update .gitignore or .cvsignore files.'''
destdir = self.config['destdir']
if ignore == '.gitignore':
# In a .gitignore file, "foo" applies to the current directory and all
# subdirectories, whereas "/foo" applies to the current directory only.
anchor = '/'
else:
anchor = ''
srcpath = joinpath(directory, ignore)
backupname = '%s~' % srcpath
if os.path.isfile(joinpath(destdir, srcpath)):
if files_added or files_removed:
with open(joinpath(destdir, srcpath), mode='r', newline='\n', encoding='utf-8') as file:
original_lines = file.readlines()
# Clean the newlines but not trailing whitespace.
original_lines = [ line.rstrip('\n')
for line in original_lines ]
already_listed_filenames = { substart(anchor, '', filename)
for filename in original_lines
if filename.strip() }
filenames_to_add = set(files_added).difference(already_listed_filenames)
filenames_to_remove = set(files_removed)
if filenames_to_add or filenames_to_remove:
if not self.config['dryrun']:
print('Updating %s (backup in %s)' % (srcpath, backupname))
copyfile2(joinpath(destdir, srcpath), joinpath(destdir, backupname))
new_lines = original_lines + [ f'{anchor}{filename}'
for filename in sorted(filenames_to_add) ]
if anchor != '':
lines_to_remove = filenames_to_remove.union({ f'{anchor}{filename}'
for filename in filenames_to_remove })
else:
lines_to_remove = filenames_to_remove
new_lines = [ line
for line in new_lines
if line not in lines_to_remove ]
with open(joinpath(destdir, srcpath), mode='w', newline='\n', encoding='utf-8') as file:
file.write(lines_to_multiline(new_lines))
else: # if self.config['dryrun']
print('Update %s (backup in %s)' % (srcpath, backupname))
else: # if not os.path.isfile(joinpath(destdir, srcpath))
if files_added:
if not self.config['dryrun']:
print('Creating %s' % srcpath)
files_added = sorted(set(files_added))
files_added = [ '%s%s' % (anchor, f)
for f in files_added ]
if ignore == '.cvsignore':
# Automake generates Makefile rules that create .dirstamp files.
files_added = ['.deps', '.dirstamp'] + files_added
with open(joinpath(destdir, srcpath), mode='w', newline='\n', encoding='utf-8') as file:
file.write(lines_to_multiline(files_added))
else: # if self.config['dryrun']
print('Create %s' % srcpath)
def prepare(self) -> tuple[GLFileTable, dict[str, tuple[re.Pattern, str] | None]]:
'''Perform preperations before GLImport.execute().
Returns a filetable and the transformers passed to GLFileAssistant().'''
destdir = self.config['destdir']
modules = list(self.config['modules'])
m4base = self.config['m4base']
lgpl = self.config['lgpl']
gpl = self.config['gpl']
verbose = self.config['verbosity']
base_modules = set()
for name in modules:
module = self.modulesystem.find(name)
if module is not None:
base_modules.add(module)
base_modules = sorted(base_modules)
# Perform transitive closure.
final_modules = self.moduletable.transitive_closure(base_modules)
# Show final module list.
if verbose >= 0:
(bold_on, bold_off) = bold_escapes()
print('Module list with included dependencies (indented):')
for module in final_modules:
if module.name in self.config.getModules():
print(' %s%s%s' % (bold_on, module.name, bold_off))
else: # if module.name not in self.config.getModules()
print(' %s' % module.name)
# Separate modules into main_modules and tests_modules.
modules = \
self.moduletable.transitive_closure_separately(base_modules, final_modules)
main_modules, tests_modules = modules
# Print main_modules and tests_modules.
if verbose >= 1:
print('Main module list:')
for module in main_modules:
print(' %s' % module.name)
print('Tests-related module list:')
for module in tests_modules:
print(' %s' % module.name)
# Determine whether a $testsbase/libtests.a is needed.
libtests = False
for module in tests_modules:
files = module.getFiles()
for file in files:
if file.startswith('lib/'):
libtests = True
break
if libtests:
self.config.setLibtests(True)
# Add the dummy module to the main module list if needed.
main_modules = self.moduletable.add_dummy(main_modules)
if libtests: # if we need to use libtests.a
# Add the dummy module to the tests-related module list if needed.
tests_modules = self.moduletable.add_dummy(tests_modules)
# Transmit base_modules, final_modules, main_modules and tests_modules.
self.moduletable.setBaseModules(base_modules)
self.moduletable.setFinalModules(final_modules)
self.moduletable.setMainModules(main_modules)
self.moduletable.setTestsModules(tests_modules)
# Check license incompatibilities.
listing = []
compatibilities = dict()
compatibilities['all'] = ['GPLv2+ build tool', 'GPLed build tool',
'public domain', 'unlimited',
'unmodifiable license text']
compatibilities['GPLv3'] = ['LGPLv2+', 'LGPLv3+ or GPLv2+', 'LGPLv3+', 'LGPL', 'GPLv2+', 'GPLv3+', 'GPL']
compatibilities['GPLv2'] = ['LGPLv2+', 'LGPLv3+ or GPLv2+', 'GPLv2+']
compatibilities['LGPLv3'] = ['LGPLv2+', 'LGPLv3+ or GPLv2+', 'LGPLv3+', 'LGPL']
compatibilities['LGPLv3orGPLv2'] = ['LGPLv2+', 'LGPLv3+ or GPLv2+']
compatibilities['LGPLv2'] = ['LGPLv2+']
if lgpl or gpl:
for module in main_modules:
license = module.getLicense()
if license not in compatibilities['all']:
if lgpl == True:
if license not in compatibilities['LGPLv3']:
listing.append(tuple([module.name, license]))
elif lgpl:
if license not in compatibilities['LGPLv'+lgpl]:
listing.append(tuple([module.name, license]))
elif gpl:
if license not in compatibilities['GPLv'+gpl]:
listing.append(tuple([module.name, license]))
if listing:
raise GLError(11, listing)
# Print notices from modules.
if verbose >= -1:
for module in main_modules:
notice = module.getNotice().strip('\n')
if notice:
print('Notice from module %s:' % module.name)
pattern = re.compile(r'^(.*?)$', re.S | re.M)
notice = pattern.sub(r' \1', notice)
print(notice)
# Determine script to apply to imported library files.
sed_transform_lib_file = None
if 'config-h' in [ module.name
for module in main_modules ]:
sed_transform_lib_file = (re.compile(r'^#ifdef[\t ]*HAVE_CONFIG_H[\t ]*$', re.MULTILINE), r'#if 1')
sed_transform_main_lib_file = sed_transform_lib_file
# Determine script to apply to auxiliary files that go into $auxdir/.
sed_transform_build_aux_file = None
# Determine script to apply to library files that go into $testsbase/.
sed_transform_testsrelated_lib_file = sed_transform_lib_file
# Determine the final file lists.
main_filelist, tests_filelist = \
self.moduletable.filelist_separately(main_modules, tests_modules)
filelist = sorted(set(main_filelist + tests_filelist))
if not filelist:
raise GLError(12, None)
# Print list of files.
if verbose >= 0:
print('File list:')
for file in filelist:
if file.startswith('tests=lib/'):
rest = file[10:]
print(' lib/%s -> tests/%s' % (rest, rest))
else:
print(' %s' % file)
# Prepare basic filelist and basic old_files/new_files variables.
filelist = sorted(set(filelist))
# Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
new_files = filelist + ['m4/gnulib-tool.m4']
old_files = list(self.cache['files'])
path = joinpath(destdir, m4base, 'gnulib-tool.m4')
if os.path.isfile(path):
old_files.append(joinpath('m4', 'gnulib-tool.m4'))
# old_files is the list of files according to the last gnulib-tool invocation.
# new_files is the list of files after this gnulib-tool invocation.
# Construct the transformers.
transformers = dict()
transformers['lib'] = sed_transform_lib_file
transformers['aux'] = sed_transform_build_aux_file
transformers['main'] = sed_transform_main_lib_file
transformers['tests'] = sed_transform_testsrelated_lib_file
# old_table is a table with two columns: (rewritten-file-name original-file-name),
# representing the files according to the last gnulib-tool invocation.
old_table = { (rewrite_file_name(file_name, self.cache, True), file_name)
for file_name in old_files }
# new_table is a table with two columns: (rewritten-file-name original-file-name),
# representing the files after this gnulib-tool invocation.
new_table = { (rewrite_file_name(file_name, self.config, True), file_name)
for file_name in new_files }
# Prepare the filetable.
filetable = GLFileTable(sorted(set(filelist)))
filetable.old_files = sorted(old_table, key=lambda pair: pair[0])
filetable.new_files = sorted(new_table, key=lambda pair: pair[0])
# Return the result.
result = tuple([filetable, transformers])
return result
def execute(self, filetable: GLFileTable, transformers: dict[str, tuple[re.Pattern, str] | None]) -> None:
'''Perform operations on the lists of files, which are given in a special
format except filelist argument. Such lists of files can be created using
GLImport.prepare() function.'''
if type(filetable) is not GLFileTable:
raise TypeError('filetable must be a GLFileTable, not %s'
% type(filetable).__name__)
destdir = self.config['destdir']
auxdir = self.config['auxdir']
sourcebase = self.config['sourcebase']
m4base = self.config['m4base']
pobase = self.config['pobase']
docbase = self.config['docbase']
testsbase = self.config['testsbase']
libname = self.config['libname']
makefile_name = self.config['makefile_name']
tests_makefile_name = self.config['tests_makefile_name']
automake_subdir = self.config['automake_subdir']
macro_prefix = self.config['macro_prefix']
vc_files = self.config['vc_files']
configure_ac = self.config['configure_ac']
actioncmd = self.actioncmd()
# Determine whether to put anything into $testsbase.
testsfiles = [ file
for file in filetable.all_files
if file.startswith('tests/') or file.startswith('tests=lib/') ]
gentests = len(testsfiles) > 0
# Create all necessary directories.
dirs = [sourcebase, m4base]
if pobase:
dirs.append(pobase)
if [ file
for file in filetable.all_files
if file.startswith('doc/') ]:
dirs.append(docbase)
if gentests:
dirs.append(testsbase)
dirs.append(auxdir)
dirs += sorted([ os.path.dirname(pair[0])
for pair in filetable.new_files ])
dirs = [ os.path.join(destdir, d)
for d in dirs ]
for directory in dirs:
if not os.path.isdir(directory):
print('Creating directory %s' % directory)
if not self.config['dryrun']:
try: # Try to create directory
os.makedirs(directory)
except Exception as exc:
raise GLError(13, directory) from exc
else: # if self.config['dryrun']
print('Create directory %s' % directory)
# Create GLFileAssistant instance to process files.
assistant = GLFileAssistant(self.config, transformers)
# Set of rewritten-file-names from filetable.old_files.
old_rewritten_files = { pair[0]
for pair in filetable.old_files }
# Set of rewritten-file-names from filetable.new_files.
new_rewritten_files = { pair[0]
for pair in filetable.new_files }
# Files which are in filetable.old_files and not in filetable.new_files.
# They will be removed and added to filetable.removed_files list.
pairs = [ pair
for pair in filetable.old_files
if pair[0] not in new_rewritten_files ]
pairs = sorted(set(pairs), key=lambda pair: pair[0])
files = sorted(set(pair[0] for pair in pairs))
for file in files:
path = joinpath(destdir, file)
if os.path.isfile(path) or os.path.islink(path):
if not self.config['dryrun']:
backup = '%s~' % path
print('Removing file %s (backup in %s)' % (path, backup))
try: # Try to move file
if os.path.exists(backup):
os.remove(backup)
movefile(path, '%s~' % path)
except Exception as exc:
raise GLError(14, file) from exc
else: # if self.config['dryrun']
print('Remove file %s (backup in %s~)' % (path, path))
filetable.removed_files.append(file)
# Files which are in filetable.new_files and not in filetable.old_files.
# They will be added/updated and added to filetable.added_files list.
already_present = False
pairs = [ pair
for pair in filetable.new_files
if pair[0] not in old_rewritten_files ]
pairs = sorted(set(pairs))
for pair in pairs:
original = pair[1]
rewritten = pair[0]
assistant.setOriginal(original)
assistant.setRewritten(rewritten)
assistant.add_or_update(already_present)
# Files which are in filetable.new_files and in filetable.old_files.
# They will be added/updated and added to filetable.added_files list.
already_present = True
pairs = [ pair
for pair in filetable.new_files
if pair[0] in old_rewritten_files ]
pairs = sorted(set(pairs))
for pair in pairs:
original = pair[1]
rewritten = pair[0]
assistant.setOriginal(original)
assistant.setRewritten(rewritten)
assistant.add_or_update(already_present)
# Add files which were added to the list of filetable.added_files.
filetable.added_files += assistant.getFiles()
filetable.added_files = sorted(set(filetable.added_files))
# Default the source makefile name to Makefile.am.
if makefile_name:
source_makefile_am = makefile_name
else:
source_makefile_am = 'Makefile.am'
# Default the tests makefile name to the source makefile name.
if tests_makefile_name:
tests_makefile_am = tests_makefile_name
else:
tests_makefile_am = source_makefile_am
# Create normal Makefile.ams.
for_test = False
# Setup list of Makefile.am edits that are to be performed afterwards.
# Some of these edits apply to files that we will generate; others are
# under the responsibility of the developer.
if source_makefile_am == 'Makefile.am':
sourcebase_dir = os.path.dirname(sourcebase)
sourcebase_base = os.path.basename(sourcebase)
self.makefiletable.editor(sourcebase_dir, 'SUBDIRS', sourcebase_base)
if pobase:
pobase_dir = os.path.dirname(pobase)
pobase_base = os.path.basename(pobase)
self.makefiletable.editor(pobase_dir, 'SUBDIRS', pobase_base)
if self.config.checkInclTestCategory(TESTS['tests']):
if tests_makefile_am == 'Makefile.am':
testsbase_dir = os.path.dirname(testsbase)
testsbase_base = os.path.basename(testsbase)
self.makefiletable.editor(testsbase_dir, 'SUBDIRS', testsbase_base, True)
self.makefiletable.editor('', 'ACLOCAL_AMFLAGS', m4base)
self.makefiletable.parent(gentests, source_makefile_am, tests_makefile_am)
# Create po/ directory.
filesystem = GLFileSystem(self.config)
if pobase:
# Create po makefile and auxiliary files.
for file in ['Makefile.in.in', 'remove-potcdate.sin', 'remove-potcdate.sed']:
tmpfile = assistant.tmpfilename(joinpath(pobase, file))
path = joinpath('build-aux', 'po', file)
if os.path.exists(joinpath(DIRS['root'], path)):
lookedup, flag = filesystem.lookup(path)
copyfile(lookedup, tmpfile)
basename = joinpath(pobase, file)
filename, backup, flag = assistant.super_update(basename, tmpfile)
if flag == 1:
if not self.config['dryrun']:
print('Updating %s (backup in %s)' % (filename, backup))
else: # if self.config['dryrun']
print('Update %s (backup in %s)' % (filename, backup))
elif flag == 2:
if not self.config['dryrun']:
print('Creating %s' % filename)
else: # if self.config['dryrun']:
print('Create %s' % filename)
filetable.added_files.append(filename)
if os.path.isfile(tmpfile):
os.remove(tmpfile)
# Create po makefile parameterization, part 1.
basename = joinpath(pobase, 'Makevars')
tmpfile = assistant.tmpfilename(basename)
emit = self.emitter.po_Makevars()
with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
filename, backup, flag = assistant.super_update(basename, tmpfile)
if flag == 1:
if not self.config['dryrun']:
print('Updating %s (backup in %s)' % (filename, backup))
else: # if self.config['dryrun']
print('Update %s (backup in %s)' % (filename, backup))
elif flag == 2:
if not self.config['dryrun']:
print('Creating %s' % filename)
else: # if self.config['dryrun']:
print('Create %s' % filename)
filetable.added_files.append(filename)
if os.path.isfile(tmpfile):
os.remove(tmpfile)
# Create po makefile parameterization, part 2.
basename = joinpath(pobase, 'POTFILES.in')
tmpfile = assistant.tmpfilename(basename)
with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file:
file.write(self.emitter.po_POTFILES_in(filetable.all_files))
basename = joinpath(pobase, 'POTFILES.in')
filename, backup, flag = assistant.super_update(basename, tmpfile)
if flag == 1:
if not self.config['dryrun']:
print('Updating %s (backup in %s)' % (filename, backup))
else: # if self.config['dryrun']
print('Update %s (backup in %s)' % (filename, backup))
elif flag == 2:
if not self.config['dryrun']:
print('Creating %s' % filename)
else: # if self.config['dryrun']:
print('Create %s' % filename)
filetable.added_files.append(filename)
if os.path.isfile(tmpfile):
os.remove(tmpfile)
# Fetch PO files.
TP_URL = 'https://translationproject.org/latest/'
if not self.config['dryrun']:
print('Fetching gnulib PO files from %s' % TP_URL)
args = ['wget', '--no-verbose', '--mirror', '--level=1', '-nd', '-A.po', '-P', '.',
'%sgnulib/' % TP_URL]
sp.call(args, cwd=joinpath(destdir, pobase))
else: # if self.config['dryrun']
print('Fetch gnulib PO files from %s' % TP_URL)
# Create po/LINGUAS.
basename = joinpath(pobase, 'LINGUAS')
if not self.config['dryrun']:
tmpfile = assistant.tmpfilename(basename)
data = '# Set of available languages.\n'
files = sorted([ subend('.po', '', file)
for file in os.listdir(joinpath(destdir, pobase))
if file.endswith('.po') ])
data += lines_to_multiline(files)
with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file:
file.write(data)
filename, backup, flag = assistant.super_update(basename, tmpfile)
if flag == 1:
print('Updating %s (backup in %s)' % (filename, backup))
elif flag == 2:
print('Creating %s' % filename)
filetable.added_files.append(filename)
if os.path.isfile(tmpfile):
os.remove(tmpfile)
else: # if not self.config['dryrun']
backupname = '%s~' % basename
if os.path.isfile(joinpath(destdir, basename)):
print('Update %s (backup in %s)' % (basename, backupname))
else: # if not os.path.isfile(joinpath(destdir, basename))
print('Create %s' % basename)
# Create m4/gnulib-cache.m4.
basename = joinpath(m4base, 'gnulib-cache.m4')
tmpfile = assistant.tmpfilename(basename)
emit = self.gnulib_cache()
with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
filename, backup, flag = assistant.super_update(basename, tmpfile)
if flag == 1:
if not self.config['dryrun']:
print('Updating %s (backup in %s)' % (filename, backup))
else: # if self.config['dryrun']
print('Update %s (backup in %s)' % (filename, backup))
elif flag == 2:
if not self.config['dryrun']:
print('Creating %s' % filename)
else: # if self.config['dryrun']:
print('Create %s' % filename)
if emit[-2:] == '\r\n':
emit = emit[:-2]
elif emit[-1:] == '\n':
emit = emit[:-1]
print(emit)
if os.path.isfile(tmpfile):
os.remove(tmpfile)
# Create m4/gnulib-comp.m4.
basename = joinpath(m4base, 'gnulib-comp.m4')
tmpfile = assistant.tmpfilename(basename)
emit = self.gnulib_comp(filetable, gentests)
with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
filename, backup, flag = assistant.super_update(basename, tmpfile)
if flag == 1:
if not self.config['dryrun']:
print('Updating %s (backup in %s)' % (filename, backup))
else: # if self.config['dryrun']
print('Update %s (backup in %s)' % (filename, backup))
elif flag == 2:
if not self.config['dryrun']:
print('Creating %s' % filename)
else: # if self.config['dryrun']:
print('Create %s' % filename)
if emit[-2:] == '\r\n':
emit = emit[:-2]
elif emit[-1:] == '\n':
emit = emit[:-1]
print(emit)
if os.path.isfile(tmpfile):
os.remove(tmpfile)
if self.config['gnu_make']:
# Regenerate aclocal.m4.
# This is needed because the next step may run 'autoconf -t' and
# the preceding steps may have added new *.m4 files (which need to
# be reflected in aclocal.m4 before 'autoconf -t' is run).
aclocal_args = []
for dir in self.m4dirs:
aclocal_args.append('-I')
aclocal_args.append(dir)
sp.run([UTILS['aclocal']] + aclocal_args, cwd=destdir)
# Create library makefile.
# Do this after creating gnulib-comp.m4, because func_emit_lib_Makefile_am
# can run 'autoconf -t', which reads gnulib-comp.m4.
basename = joinpath(sourcebase, source_makefile_am)
tmpfile = assistant.tmpfilename(basename)
emit = self.emitter.lib_Makefile_am(basename, self.moduletable.getMainModules(),
self.moduletable, self.makefiletable,
actioncmd, for_test)
if automake_subdir:
emit = sp.run([joinpath(DIRS['root'], 'build-aux/prefix-gnulib-mk'), '--from-gnulib-tool',
f'--lib-name={libname}', f'--prefix={sourcebase}/'],
input=emit, text=True, capture_output=True).stdout
with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
filename, backup, flag = assistant.super_update(basename, tmpfile)
if flag == 1:
if not self.config['dryrun']:
print('Updating %s (backup in %s)' % (filename, backup))
else: # if self.config['dryrun']
print('Update %s (backup in %s)' % (filename, backup))
elif flag == 2:
if not self.config['dryrun']:
print('Creating %s' % filename)
else: # if self.config['dryrun']:
print('Create %s' % filename)
filetable.added_files.append(filename)
if os.path.isfile(tmpfile):
os.remove(tmpfile)
# Create tests Makefile.
if gentests:
basename = joinpath(testsbase, tests_makefile_am)
tmpfile = assistant.tmpfilename(basename)
emit = self.emitter.tests_Makefile_am(basename, self.moduletable.getTestsModules(),
self.moduletable, self.makefiletable,
'%stests_WITNESS' % macro_prefix, for_test)
with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
filename, backup, flag = assistant.super_update(basename, tmpfile)
if flag == 1:
if not self.config['dryrun']:
print('Updating %s (backup in %s)' % (filename, backup))
else: # if self.config['dryrun']
print('Update %s (backup in %s)' % (filename, backup))
elif flag == 2:
if not self.config['dryrun']:
print('Creating %s' % filename)
else: # if self.config['dryrun']:
print('Create %s' % filename)
filetable.added_files.append(filename)
if os.path.isfile(tmpfile):
os.remove(tmpfile)
if vc_files != False:
# Update the .cvsignore and .gitignore files.
ignorelist = []
# Treat gnulib-comp.m4 like an added file, even if it already existed.
filetable.added_files.append(joinpath(m4base, 'gnulib-comp.m4'))
filetable.added_files = sorted(set(filetable.added_files))
filetable.removed_files = sorted(set(filetable.removed_files))
for file in filetable.added_files:
directory, basename = os.path.split(file)
ignorelist.append(tuple([directory, '|A|', basename]))
for file in filetable.removed_files:
directory, basename = os.path.split(file)
ignorelist.append(tuple([directory, '|R|', basename]))
# Sort ignorelist by directory.
ignorelist = sorted(ignorelist, key=lambda row: row[0])
last_dir = ''
last_dir_files_added = []
last_dir_files_removed = []
for row in ignorelist:
next_dir = row[0]
operand = row[1]
filename = row[2]
if next_dir != last_dir:
self._done_dir_(last_dir, last_dir_files_added, last_dir_files_removed)
last_dir = next_dir
last_dir_files_added = []
last_dir_files_removed = []
if operand == '|A|':
last_dir_files_added.append(filename)
elif operand == '|R|':
last_dir_files_removed.append(filename)
self._done_dir_(last_dir, last_dir_files_added, last_dir_files_removed)
# Finish the work.
print('Finished.\n')
print('You may need to add #include directives for the following .h files.')
# Intersect 'base' modules and 'main' modules
# (since 'base' modules is not necessarily of subset of 'main' modules
# - some may have been skipped through --avoid, and since the elements of
# 'main' modules but not in 'base' modules can go away without explicit
# notice - through changes in the module dependencies).
modules = sorted(set(self.moduletable.getBaseModules()).intersection(self.moduletable.getMainModules()))
# First the #include <...> directives without #ifs, sorted for convenience,
# then the #include "..." directives without #ifs, sorted for convenience,
# then the #include directives that are surrounded by #ifs. Not sorted.
include_angles = []
include_quotes = []
include_if = []
for module in modules:
include = module.getInclude()
if '\n#if' in '\n'+include:
include_if += [ f' {line}'
for line in include.split('\n')
if line.strip() ]
else:
include_angles += [ f' {line}'
for line in include.split('\n')
if 'include "' not in line and line.strip() ]
include_quotes += [ f' {line}'
for line in include.split('\n')
if 'include "' in line and line.strip() ]
includes = lines_to_multiline(sorted(set(include_angles)))
includes += lines_to_multiline(sorted(set(include_quotes)))
includes += lines_to_multiline(include_if)
print(includes, end='')
# Get link directives.
links = [ module.getLink()
for module in self.moduletable.getMainModules() ]
lines = [ line
for link in links
for line in link.split('\n')
if line != '' ]
lines = sorted(set(lines))
if lines:
print('''
You may need to use the following Makefile variables when linking.
Use them in <program>_LDADD when linking a program, or
in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library.''')
for line in lines:
print(' %s' % line)
# Print reminders.
print('')
print('Don\'t forget to')
if source_makefile_am == 'Makefile.am':
print(' - add "%s/Makefile" to AC_CONFIG_FILES in %s,' % (sourcebase, configure_ac))
else: # if makefile_am != 'Makefile.am'
print(' - "include %s" from within "%s/Makefile.am",' % (source_makefile_am, sourcebase))
if pobase:
print(' - add "%s/Makefile.in" to AC_CONFIG_FILES in %s,' % (pobase, configure_ac))
if gentests:
if tests_makefile_am == 'Makefile.am':
print(' - add "%s/Makefile" to AC_CONFIG_FILES in %s,' % (testsbase, configure_ac))
else: # if makefile_am != 'Makefile.am'
print(' - "include %s" from within "%s/Makefile.am",' % (tests_makefile_am, testsbase))
# Print makefile edits.
for current_edit in range(0, self.makefiletable.count()):
dictionary = self.makefiletable[current_edit]
if 'var' in dictionary:
if dictionary['var'] == 'ACLOCAL_AMFLAGS':
print(' - mention "-I %s" in %s in %s'
% (dictionary['val'], dictionary['var'], joinpath(dictionary['dir'], 'Makefile.am')))
print(' or add an AC_CONFIG_MACRO_DIRS([%s]) invocation in %s,'
% (dictionary['val'], configure_ac))
else:
print(' - mention "%s" in %s in %s,'
% (dictionary['val'], dictionary['var'], joinpath(dictionary['dir'], 'Makefile.am')))
# Detect position_early_after.
with open(configure_ac, mode='r', newline='\n', encoding='utf-8') as file:
data = file.read()
match_result1 = re.compile(r'^ *AC_PROG_CC_STDC', re.MULTILINE).search(data)
match_result2 = re.compile(r'^ *AC_PROG_CC_C99', re.MULTILINE).search(data)
if match_result1:
print(' - replace AC_PROG_CC_STDC with AC_PROG_CC in %s,' % (configure_ac))
position_early_after = 'AC_PROG_CC_STDC'
elif match_result2:
print(' - replace AC_PROG_CC_C99 with AC_PROG_CC in %s,' % (configure_ac))
position_early_after = 'AC_PROG_CC_C99'
else: # if not any([match_result1, match_result2])
position_early_after = 'AC_PROG_CC'
print(' - invoke %s_EARLY in %s, right after %s,' % (macro_prefix, configure_ac, position_early_after))
print(' - invoke %s_INIT in %s.' % (macro_prefix, configure_ac))