>From de028fc3637de15c3c0535e168bc5dda6a6084e6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 3 Aug 2022 22:29:52 +0200 Subject: [PATCH 11/12] gnulib-tool.py: Implement options --without-c++-tests etc. * gnulib-tool.py (main): Accept options --without-c++-tests, --without-longrunning-tests, --without-privileged-tests, --without-unportable-tests. Improve error message for --copy-file with invalid number of arguments. Check for invalid options given in --import, --add-import, --remove-import, --update modes. Pass both sets of test categories to the GLConfig constructor. * pygnulib/GLConfig.py (GLConfig.__init__): Accept incl_test_categories and excl_test_categories instead of testflags. (checkInclTestCategory): Renamed from checkTestFlag. (enableInclTestCategory): Renamed from enableTestFlag. (disableInclTestCategory): Renamed from disableTestFlag. (getInclTestCategories): Renamed from getTestFlags. (setInclTestCategories): Renamed from setTestFlags. (resetInclTestCategories): Renamed from resetTestFlags. (setInclTestCategory, checkExclTestCategory, enableExclTestCategory, disableExclTestCategory, getExclTestCategories, setExclTestCategories, resetExclTestCategories): New methods. * pygnulib/GLModuleSystem.py (GLModuleTable.__init__): Accept two booleans as second and third constructor arguments. (transitive_closure): Correct the determination of whether to include each module, depending on the with-* and without-* options. (transitive_closure_separately): Update. * pygnulib/GLMakefileTable.py: Update. * pygnulib/GLImport.py (__init__, actioncmd, gnulib_cache, execute): Update. * pygnulib/GLTestDir.py (GLTestDir.__init__, GLTestDir.execute, GLMegaTestDir.__init__): Update. --- ChangeLog | 30 +++++++ gnulib-tool.py | 104 +++++++++++++++++------ gnulib-tool.py.TODO | 4 - pygnulib/GLConfig.py | 159 ++++++++++++++++++++++++------------ pygnulib/GLImport.py | 59 +++++++------ pygnulib/GLMakefileTable.py | 5 +- pygnulib/GLModuleSystem.py | 106 ++++++++++++------------ pygnulib/GLTestDir.py | 17 ++-- pygnulib/constants.py | 2 +- 9 files changed, 315 insertions(+), 171 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d7b65eaf1..6723ba9c08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,35 @@ 2022-08-03 Bruno Haible + gnulib-tool.py: Implement options --without-c++-tests etc. + * gnulib-tool.py (main): Accept options --without-c++-tests, + --without-longrunning-tests, --without-privileged-tests, + --without-unportable-tests. + Improve error message for --copy-file with invalid number of arguments. + Check for invalid options given in --import, --add-import, + --remove-import, --update modes. + Pass both sets of test categories to the GLConfig constructor. + * pygnulib/GLConfig.py (GLConfig.__init__): Accept incl_test_categories + and excl_test_categories instead of testflags. + (checkInclTestCategory): Renamed from checkTestFlag. + (enableInclTestCategory): Renamed from enableTestFlag. + (disableInclTestCategory): Renamed from disableTestFlag. + (getInclTestCategories): Renamed from getTestFlags. + (setInclTestCategories): Renamed from setTestFlags. + (resetInclTestCategories): Renamed from resetTestFlags. + (setInclTestCategory, checkExclTestCategory, enableExclTestCategory, + disableExclTestCategory, getExclTestCategories, setExclTestCategories, + resetExclTestCategories): New methods. + * pygnulib/GLModuleSystem.py (GLModuleTable.__init__): Accept two + booleans as second and third constructor arguments. + (transitive_closure): Correct the determination of whether to include + each module, depending on the with-* and without-* options. + (transitive_closure_separately): Update. + * pygnulib/GLMakefileTable.py: Update. + * pygnulib/GLImport.py (__init__, actioncmd, gnulib_cache, execute): + Update. + * pygnulib/GLTestDir.py (GLTestDir.__init__, GLTestDir.execute, + GLMegaTestDir.__init__): Update. + gnulib-tool.py: Implement option --without-tests. * gnulib-tool.py (main): Accept option --without-tests. diff --git a/gnulib-tool.py b/gnulib-tool.py index efe3b1e1d6..bf7b98a61e 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -262,22 +262,38 @@ def main(): action='store_true') # c++-tests parser.add_argument('--with-c++-tests', - dest='cxx', + dest='inc_cxx_tests', + default=None, + action='store_true') + parser.add_argument('--without-c++-tests', + dest='excl_cxx_tests', default=None, action='store_true') # longrunning-tests parser.add_argument('--with-longrunning-tests', - dest='longrunning', + dest='inc_longrunning_tests', + default=None, + action='store_true') + parser.add_argument('--without-longrunning-tests', + dest='excl_longrunning_tests', default=None, action='store_true') # privileged-tests parser.add_argument('--with-privileged-tests', - dest='privileged', + dest='inc_privileged_tests', + default=None, + action='store_true') + parser.add_argument('--without-privileged-tests', + dest='excl_privileged_tests', default=None, action='store_true') # unportable-tests parser.add_argument('--with-unportable-tests', - dest='unportable', + dest='inc_unportable_tests', + default=None, + action='store_true') + parser.add_argument('--without-unportable-tests', + dest='excl_unportable_tests', default=None, action='store_true') # all-tests @@ -491,12 +507,40 @@ def main(): mode = 'copy-file' if len(cmdargs.non_option_arguments) < 1 or len(cmdargs.non_option_arguments) > 2: message = '%s: *** ' % constants.APP['name'] - message += 'invalid number of arguments for --%s' % mode - message += '\n%s: *** Stop.\n' % constants.APP['name'] + message += 'invalid number of arguments for --%s\n' % mode + message += 'Try \'gnulib-tool --help\' for more information.\n' + message += '%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) files = list(cmdargs.non_option_arguments) + if ((mode in ['import', 'add-import', 'remove-import'] + and (cmdargs.excl_cxx_tests or cmdargs.excl_longrunning_tests + or cmdargs.excl_privileged_tests or cmdargs.excl_unportable_tests)) + or (mode == 'update' + and (cmdargs.localpath != None or cmdargs.libname != None + or cmdargs.sourcebase != None or cmdargs.m4base != None + or cmdargs.pobase != None or cmdargs.docbase != None + or cmdargs.testsbase != None or cmdargs.auxdir != None + or cmdargs.inctests != None or cmdargs.obsolete != None + or cmdargs.inc_cxx_tests != None + or cmdargs.inc_longrunning_tests != None + or cmdargs.inc_privileged_tests != None + or cmdargs.inc_unportable_tests != None + or cmdargs.alltests != None + or cmdargs.excl_cxx_tests != None + or cmdargs.excl_longrunning_tests != None + or cmdargs.excl_privileged_tests != None + or cmdargs.excl_unportable_tests != None + or cmdargs.avoids != None or cmdargs.lgpl != None + or cmdargs.makefile != None))): + message = '%s: *** ' % constants.APP['name'] + message += 'invalid options for --%s mode\n' % mode + message += 'Try \'gnulib-tool --help\' for more information.\n' + message += '%s: *** Stop.\n' % constants.APP['name'] + sys.stderr.write(message) + sys.exit(1) + # Determine specific settings. destdir = cmdargs.destdir if destdir != None: @@ -533,21 +577,30 @@ def main(): inctests = False elif mode in ['create-testdir', 'create-megatestdir', 'test', 'megatest']: inctests = True - testflags = [] + incl_test_categories = [] if inctests: - testflags += [constants.TESTS['tests']] + incl_test_categories += [constants.TESTS['tests']] if cmdargs.obsolete: - testflags += [constants.TESTS['obsolete']] - if cmdargs.cxx: - testflags += [constants.TESTS['cxx-tests']] - if cmdargs.longrunning: - testflags += [constants.TESTS['longrunning-tests']] - if cmdargs.privileged: - testflags += [constants.TESTS['privileged-tests']] - if cmdargs.unportable: - testflags += [constants.TESTS['unportable-tests']] + incl_test_categories += [constants.TESTS['obsolete']] + if cmdargs.inc_cxx_tests: + incl_test_categories += [constants.TESTS['cxx-tests']] + if cmdargs.inc_longrunning_tests: + incl_test_categories += [constants.TESTS['longrunning-tests']] + if cmdargs.inc_privileged_tests: + incl_test_categories += [constants.TESTS['privileged-tests']] + if cmdargs.inc_unportable_tests: + incl_test_categories += [constants.TESTS['unportable-tests']] if cmdargs.alltests: - testflags += [constants.TESTS['all-tests']] + incl_test_categories += [constants.TESTS['all-tests']] + excl_test_categories = [] + if cmdargs.excl_cxx_tests: + excl_test_categories += [constants.TESTS['cxx-tests']] + if cmdargs.excl_longrunning_tests: + excl_test_categories += [constants.TESTS['longrunning-tests']] + if cmdargs.excl_privileged_tests: + excl_test_categories += [constants.TESTS['privileged-tests']] + if cmdargs.excl_unportable_tests: + excl_test_categories += [constants.TESTS['unportable-tests']] lgpl = cmdargs.lgpl if lgpl != None: lgpl = lgpl[-1] @@ -575,7 +628,8 @@ def main(): pobase=pobase, docbase=docbase, testsbase=testsbase, - testflags=testflags, + incl_test_categories=incl_test_categories, + excl_test_categories=excl_test_categories, libname=libname, lgpl=lgpl, makefile=makefile, @@ -721,8 +775,8 @@ def main(): elif mode == 'create-testdir': if not destdir: message = '%s: *** ' % constants.APP['name'] - message += 'please specify --dir option' - message += '\n%s: *** Stop.\n' % constants.APP['name'] + message += 'please specify --dir option\n' + message += '%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) if not auxdir: @@ -734,8 +788,8 @@ def main(): elif mode == 'create-megatestdir': if not destdir: message = '%s: *** ' % constants.APP['name'] - message += 'please specify --dir option' - message += '\n%s: *** Stop.\n' % constants.APP['name'] + message += 'please specify --dir option\n' + message += '%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) if not auxdir: @@ -977,8 +1031,8 @@ def main(): else: message = '%s: *** ' % constants.APP['name'] - message += 'no mode specified' - message += '\n%s: *** Stop.\n' % constants.APP['name'] + message += 'no mode specified\n' + message += '%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) diff --git a/gnulib-tool.py.TODO b/gnulib-tool.py.TODO index 00c766cfe5..e4dcabef51 100644 --- a/gnulib-tool.py.TODO +++ b/gnulib-tool.py.TODO @@ -24,10 +24,6 @@ Implement the options: --extract-recursive-dependencies --extract-recursive-link-directive --extract-tests-module - --without-c++-tests - --without-longrunning-tests - --without-privileged-tests - --without-unportable-tests --single-configure --conditional-dependencies --no-conditional-dependencies diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index f59b883a91..37b30753ea 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -58,7 +58,8 @@ class GLConfig(object): def __init__(self, destdir=None, localpath=None, auxdir=None, sourcebase=None, m4base=None, pobase=None, docbase=None, testsbase=None, - modules=None, avoids=None, files=None, testflags=None, libname=None, + modules=None, avoids=None, files=None, + incl_test_categories=None, excl_test_categories=None, libname=None, lgpl=None, makefile=None, libtool=None, conddeps=None, macro_prefix=None, podomain=None, witness_c_macro=None, vc_files=None, symbolic=None, lsymbolic=None, modcache=None, configure_ac=None, ac_version=None, @@ -117,10 +118,14 @@ class GLConfig(object): self.resetFiles() if files != None: self.setFiles(files) - # testflags - self.resetTestFlags() - if testflags != None: - self.setTestFlags(testflags) + # test categories to include + self.resetInclTestCategories + if incl_test_categories != None: + self.setInclTestCategories(incl_test_categories) + # test categories to exclude + self.resetExclTestCategories + if excl_test_categories != None: + self.setExclTestCategories(excl_test_categories) # libname self.resetLibName() if libname != None: @@ -351,7 +356,7 @@ class GLConfig(object): return 0 elif key == 'copyrights': return True - elif key in ['modules', 'avoids', 'tests', 'testflags']: + elif key in ['modules', 'avoids', 'tests', 'incl_test_categories', 'excl_test_categories']: return list() elif key in ['libtool', 'lgpl', 'conddeps', 'modcache', 'symbolic', 'lsymbolic', 'libtests', 'dryrun']: @@ -681,52 +686,104 @@ class GLConfig(object): '''Reset the list of files.''' self.table['files'] = list() - # Define tests/testflags methods - def checkTestFlag(self, flag): - '''Return the status of the test flag.''' - if flag in TESTS.values(): - return flag in self.table['testflags'] - else: # if flag is not in TESTS - raise TypeError('unknown flag: %s' % repr(flag)) - - def enableTestFlag(self, flag): - '''Enable test flag. You can get flags from TESTS variable.''' - if flag in TESTS.values(): - if flag not in self.table['testflags']: - self.table['testflags'].append(flag) - else: # if flag is not in TESTS - raise TypeError('unknown flag: %s' % repr(flag)) - - def disableTestFlag(self, flag): - '''Disable test flag. You can get flags from TESTS variable.''' - if flag in TESTS.values(): - if flag in self.table['testflags']: - self.table['testflags'].remove(flag) - else: # if flag is not in TESTS - raise TypeError('unknown flag: %s' % repr(flag)) - - def getTestFlags(self): - '''Return test flags. You can get flags from TESTS variable.''' - return list(self.table['testflags']) - - def setTestFlags(self, testflags): - '''Specify test flags. You can get flags from TESTS variable.''' - if type(testflags) is list or type(testflags) is tuple: - self.table['testflags'] = list() - for flag in testflags: - try: # Try to enable each flag - self.enableTestFlag(flag) + # Define incl_test_categories methods + def checkInclTestCategory(self, category): + '''Tests whether the given test category is included.''' + if category in TESTS.values(): + return category in self.table['incl_test_categories'] + else: # if category is not in TESTS + raise TypeError('unknown category: %s' % repr(category)) + + def enableInclTestCategory(self, category): + '''Enable the given test category.''' + if category in TESTS.values(): + if category not in self.table['incl_test_categories']: + self.table['incl_test_categories'].append(category) + else: # if category is not in TESTS + raise TypeError('unknown category: %s' % repr(category)) + + def disableInclTestCategory(self, category): + '''Disable the given test category.''' + if category in TESTS.values(): + if category in self.table['incl_test_categories']: + self.table['incl_test_categories'].remove(category) + else: # if category is not in TESTS + raise TypeError('unknown category: %s' % repr(category)) + + def setInclTestCategory(self, category, enable): + '''Enable or disable the given test category.''' + if (enable): + self.enableInclTestCategory(category) + else: + self.disableInclTestCategory(category) + + def getInclTestCategories(self): + '''Return the test categories that should be included. + To get the list of all test categories, use the TESTS variable.''' + return list(self.table['incl_test_categories']) + + def setInclTestCategories(self, categories): + '''Specify the test categories that should be included.''' + if type(categories) is list or type(categories) is tuple: + self.table['incl_test_categories'] = list() + for category in categories: + try: # Try to enable each category + self.enableInclTestCategory(category) + except TypeError as error: + raise TypeError('each category must be one of TESTS integers') + else: # if type of categories is not list or tuple + raise TypeError('categories must be a list or a tuple, not %s' % + type(categories).__name__) + + def resetInclTestCategories(self): + '''Reset test categories.''' + self.table['incl_test_categories'] = list() + + # Define excl_test_categories methods + def checkExclTestCategory(self, category): + '''Tests whether the given test category is excluded.''' + if category in TESTS.values(): + return category in self.table['excl_test_categories'] + else: # if category is not in TESTS + raise TypeError('unknown category: %s' % repr(category)) + + def enableExclTestCategory(self, category): + '''Enable the given test category.''' + if category in TESTS.values(): + if category not in self.table['excl_test_categories']: + self.table['excl_test_categories'].append(category) + else: # if category is not in TESTS + raise TypeError('unknown category: %s' % repr(category)) + + def disableExclTestCategory(self, category): + '''Disable the given test category.''' + if category in TESTS.values(): + if category in self.table['excl_test_categories']: + self.table['excl_test_categories'].remove(category) + else: # if category is not in TESTS + raise TypeError('unknown category: %s' % repr(category)) + + def getExclTestCategories(self): + '''Return the test categories that should be excluded. + To get the list of all test categories, use the TESTS variable.''' + return list(self.table['excl_test_categories']) + + def setExclTestCategories(self, categories): + '''Specify the test categories that should be excluded.''' + if type(categories) is list or type(categories) is tuple: + self.table['excl_test_categories'] = list() + for category in categories: + try: # Try to enable each category + self.enableExclTestCategory(category) except TypeError as error: - raise TypeError('each flag must be one of TESTS integers') - self.table['testflags'] = testflags - else: # if type of testflags is not list or tuple - raise TypeError('testflags must be a list or a tuple, not %s' % - type(testflags).__name__) - - def resetTestFlags(self): - '''Reset test flags (only default flag will be enabled).''' - self.table['testflags'] = list() - self.table['tests'] = self.table['testflags'] + raise TypeError('each category must be one of TESTS integers') + else: # if type of categories is not list or tuple + raise TypeError('categories must be a list or a tuple, not %s' % + type(categories).__name__) + + def resetExclTestCategories(self): + '''Reset test categories.''' + self.table['excl_test_categories'] = list() # Define libname methods. def getLibName(self): diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index 04b3fddaab..58b8eaab9f 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -149,25 +149,25 @@ class GLImport(object): self.cache.enableVCFiles() data = data.replace('gl_VC_FILES', '') if 'gl_WITH_TESTS' in data: - self.cache.enableTestFlag(TESTS['tests']) + self.cache.enableInclTestCategory(TESTS['tests']) data = data.replace('gl_WITH_TESTS', '') if 'gl_WITH_OBSOLETE' in data: - self.cache.enableTestFlag(TESTS['obsolete']) + self.cache.enableInclTestCategory(TESTS['obsolete']) data = data.replace('gl_WITH_OBSOLETE', '') if 'gl_WITH_CXX_TESTS' in data: - self.cache.enableTestFlag(TESTS['c++-test']) + self.cache.enableInclTestCategory(TESTS['c++-test']) data = data.replace('gl_WITH_CXX_TESTS', '') if 'gl_WITH_LONGRUNNING_TESTS' in data: - self.cache.enableTestFlag(TESTS['longrunning-test']) + self.cache.enableInclTestCategory(TESTS['longrunning-test']) data = data.replace('gl_WITH_LONGRUNNING_TESTS', '') if 'gl_WITH_PRIVILEGED_TESTS' in data: - self.cache.enableTestFlag(TESTS['privileged-test']) + self.cache.enableInclTestCategory(TESTS['privileged-test']) data = data.replace('gl_WITH_PRIVILEGED_TESTS', '') if 'gl_WITH_UNPORTABLE_TESTS' in data: - self.cache.enableTestFlag(TESTS['unportable-test']) + self.cache.enableInclTestCategory(TESTS['unportable-test']) data = data.replace('gl_WITH_UNPORTABLE_TESTS', '') if 'gl_WITH_ALL_TESTS' in data: - self.cache.enableTestFlag(TESTS['all-test']) + self.cache.enableInclTestCategory(TESTS['all-test']) data = data.replace('gl_WITH_ALL_TESTS', '') # Find string values result = dict(pattern.findall(data)) @@ -244,8 +244,8 @@ class GLImport(object): elif self.mode == MODES['update']: modules = self.cache.getModules() - # If user tries to apply conddeps and testflag['tests'] together. - if self.config['tests'] and self.config['conddeps']: + # If user tries to apply conddeps and TESTS['tests'] together. + if self.checkInclTestCategory(TESTS['tests']) and self.config['conddeps']: raise GLError(10, None) # Update configuration dictionary. @@ -257,7 +257,7 @@ class GLImport(object): self.config.setModules(modules) # Check if conddeps is enabled together with inctests. - inctests = self.config.checkTestFlag(TESTS['tests']) + inctests = self.config.checkInclTestCategory(TESTS['tests']) if self.config['conddeps'] and inctests: raise GLError(10, None) @@ -265,7 +265,9 @@ class GLImport(object): self.emiter = GLEmiter(self.config) self.filesystem = GLFileSystem(self.config) self.modulesystem = GLModuleSystem(self.config) - self.moduletable = GLModuleTable(self.config, list()) + 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): @@ -366,7 +368,6 @@ class GLImport(object): docbase = self.config.getDocBase() pobase = self.config.getPoBase() testsbase = self.config.getTestsBase() - testflags = self.config.getTestFlags() conddeps = self.config.checkCondDeps() libname = self.config.getLibName() lgpl = self.config.getLGPL() @@ -391,19 +392,19 @@ class GLImport(object): actioncmd += ' --doc-base=%s' % docbase actioncmd += ' --tests-base=%s' % testsbase actioncmd += ' --aux-dir=%s' % auxdir - if self.config.checkTestFlag(TESTS['tests']): + if self.config.checkInclTestCategory(TESTS['tests']): actioncmd += ' --with-tests' - if self.config.checkTestFlag(TESTS['obsolete']): + if self.config.checkInclTestCategory(TESTS['obsolete']): actioncmd += ' --with-obsolete' - if self.config.checkTestFlag(TESTS['c++-test']): + if self.config.checkInclTestCategory(TESTS['c++-test']): actioncmd += ' --with-c++-tests' - if self.config.checkTestFlag(TESTS['longrunning-test']): + if self.config.checkInclTestCategory(TESTS['longrunning-test']): actioncmd += ' --with-longrunning-tests' - if self.config.checkTestFlag(TESTS['privileged-test']): + if self.config.checkInclTestCategory(TESTS['privileged-test']): actioncmd += ' --with-privileged-test' - if self.config.checkTestFlag(TESTS['unportable-test']): + if self.config.checkInclTestCategory(TESTS['unportable-test']): actioncmd += ' --with-unportable-tests' - if self.config.checkTestFlag(TESTS['all-test']): + if self.config.checkInclTestCategory(TESTS['all-test']): actioncmd += ' --with-all-tests' for module in avoids: actioncmd += ' --avoid=%s' % module @@ -478,7 +479,6 @@ class GLImport(object): moduletable = self.moduletable actioncmd = self.actioncmd() localpath = self.config['localpath'] - testflags = list(self.config['testflags']) sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] pobase = self.config['pobase'] @@ -514,15 +514,15 @@ class GLImport(object): emit += 'gl_MODULES([\n' emit += ' %s\n' % '\n '.join(modules) emit += '])\n' - if self.config.checkTestFlag(TESTS['obsolete']): + if self.config.checkInclTestCategory(TESTS['obsolete']): emit += 'gl_WITH_OBSOLETE\n' - if self.config.checkTestFlag(TESTS['cxx-tests']): + if self.config.checkInclTestCategory(TESTS['cxx-tests']): emit += 'gl_WITH_CXX_TESTS\n' - if self.config.checkTestFlag(TESTS['privileged-tests']): + if self.config.checkInclTestCategory(TESTS['privileged-tests']): emit += 'gl_WITH_PRIVILEGED_TESTS\n' - if self.config.checkTestFlag(TESTS['unportable-tests']): + if self.config.checkInclTestCategory(TESTS['unportable-tests']): emit += 'gl_WITH_UNPORTABLE_TESTS\n' - if self.config.checkTestFlag(TESTS['all-tests']): + 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 @@ -530,7 +530,7 @@ class GLImport(object): emit += 'gl_PO_BASE([%s])\n' % pobase emit += 'gl_DOC_BASE([%s])\n' % docbase emit += 'gl_TESTS_BASE([%s])\n' % testsbase - if self.config.checkTestFlag(TESTS['tests']): + if self.config.checkInclTestCategory(TESTS['tests']): emit += 'gl_WITH_TESTS\n' emit += 'gl_LIB([%s])\n' % libname if lgpl != None: @@ -561,7 +561,6 @@ class GLImport(object): moduletable = self.moduletable destdir = self.config['destdir'] auxdir = self.config['auxdir'] - testflags = list(self.config['testflags']) sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] pobase = self.config['pobase'] @@ -764,7 +763,6 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix auxdir = self.config['auxdir'] modules = list(self.config['modules']) avoids = list(self.config['avoids']) - testflags = list(self.config['testflags']) sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] pobase = self.config['pobase'] @@ -1004,7 +1002,6 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix auxdir = self.config['auxdir'] modules = list(self.config['modules']) avoids = list(self.config['avoids']) - testflags = list(self.config['testflags']) sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] pobase = self.config['pobase'] @@ -1122,7 +1119,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix pobase_dir = os.path.dirname(pobase) pobase_base = os.path.basename(pobase) self.makefiletable.editor(pobase_dir, 'SUBDIRS', pobase_base) - if self.config.checkTestFlag(TESTS['tests']): + if self.config.checkInclTestCategory(TESTS['tests']): if makefile_am == 'Makefile.am': testsbase_dir = os.path.dirname(testsbase) testsbase_base = os.path.basename(testsbase) @@ -1313,7 +1310,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix os.remove(tmpfile) # Create tests Makefile. - inctests = self.config.checkTestFlag(TESTS['tests']) + inctests = self.config.checkInclTestCategory(TESTS['tests']) if inctests: basename = joinpath(testsbase, makefile_am) tmpfile = self.assistant.tmpfilename(basename) diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py index 4ee85b4d0c..fdb15ac132 100644 --- a/pygnulib/GLMakefileTable.py +++ b/pygnulib/GLMakefileTable.py @@ -90,12 +90,13 @@ class GLMakefileTable(object): Add a special row to Makefile.am table with the first parent directory which contains or will contain Makefile.am file. - GLConfig: sourcebase, m4base, testsbase, testflags, makefile.''' + GLConfig: sourcebase, m4base, testsbase, incl_test_categories, + excl_test_categories, makefile.''' m4base = self.config['m4base'] sourcebase = self.config['sourcebase'] testsbase = self.config['testsbase'] makefile = self.config['makefile'] - inctests = self.config.checkTestFlag(TESTS['tests']) + inctests = self.config.checkInclTestCategory(TESTS['tests']) dir1 = '%s%s' % (m4base, os.path.sep) mfd = 'Makefile.am' if not makefile: diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 25c34f8756..7e4c6148e3 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -868,18 +868,23 @@ Include:|Link:|License:|Maintainer:)' class GLModuleTable(object): '''GLModuleTable is used to work with the list of the modules.''' - def __init__(self, config, avoids=list()): - '''GLModuleTable.__init__(config, avoids) -> GLModuleTable + def __init__(self, config, inc_all_direct_tests, inc_all_indirect_tests): + '''GLModuleTable.__init__(config, inc_all_direct_tests, inc_all_indirect_tests) -> GLModuleTable Create new GLModuleTable instance. If modules are specified, then add every module from iterable as unconditional module. If avoids is specified, then in transitive_closure every dependency which is in avoids won't be - included in the final modules list. If testflags iterable is enabled, then - don't add module which status is in the testflags. If conddeps are enabled, + included in the final modules list. If conddeps are enabled, then store condition for each dependency if it has a condition. The only necessary argument is localpath, which is needed just to create - modulesystem instance to look for dependencies.''' - self.avoids = list() # Avoids + modulesystem instance to look for dependencies. + inc_all_direct_tests = True if all kinds of problematic unit tests among + the unit tests of the specified modules + should be included + inc_all_indirect_tests = True if all kinds of problematic unit tests + among the unit tests of the dependencies + should be included + ''' self.dependers = dict() # Dependencies self.conditionals = dict() # Conditional modules self.unconditionals = dict() # Unconditional modules @@ -890,11 +895,16 @@ class GLModuleTable(object): if type(config) is not GLConfig: raise TypeError('config must be a GLConfig, not %s' % type(config).__name__) - for avoid in avoids: + self.config = config + if type(inc_all_direct_tests) is not bool: + raise TypeError('inc_all_direct_tests must be a bool, not %s' % + type(inc_all_direct_tests).__name__) + self.inc_all_direct_tests = inc_all_direct_tests + self.inc_all_indirect_tests = inc_all_indirect_tests + self.avoids = list() # Avoids + for avoid in self.avoids: if type(avoid) is not GLModule: raise TypeError('each avoid must be a GLModule instance') - self.avoids += [avoids] - self.config = config self.filesystem = GLFileSystem(self.config) self.modulesystem = GLModuleSystem(self.config) @@ -982,14 +992,16 @@ class GLModuleTable(object): Use transitive closure to add module and its dependencies. Add every module and its dependencies from modules list, but do not add dependencies - which contain in avoids list. If any testflag is enabled, then do not add - dependencies which have the status as this flag. If conddeps are enabled, + which contain in avoids list. If any incl_test_categories is enabled, then + add dependencies which are in these categories. If any excl_test_categories, + then do not add dependencies which are in these categories. If conddeps are enabled, then store condition for each dependency if it has a condition. This method is used to update final list of modules. Method returns list of modules. - GLConfig: testflags.''' + GLConfig: incl_test_categories, excl_test_categories.''' for module in modules: if type(module) is not GLModule: raise TypeError('each module must be a GLModule instance') + inc_all_tests = self.inc_all_direct_tests handledmodules = list() inmodules = modules outmodules = list() @@ -1011,7 +1023,7 @@ class GLModuleTable(object): dependencies = module.getDependencies() depmodules = [pair[0] for pair in dependencies] conditions = [pair[1] for pair in dependencies] - if TESTS['tests'] in self.config['testflags']: + if self.config.checkInclTestCategory(TESTS['tests']): testsname = module.getTestsName() if self.modulesystem.exists(testsname): testsmodule = self.modulesystem.find(testsname) @@ -1019,34 +1031,34 @@ class GLModuleTable(object): conditions += [None] for depmodule in depmodules: include = True - includes = list() status = depmodule.getStatus() for word in status: if word == 'obsolete': - if TESTS['obsolete'] in self.config['testflags'] or \ - TESTS['all-test'] in self.config['testflags']: - includes += [False] + if not self.config.checkInclTestCategory(TESTS['obsolete']): + include = False elif word == 'c++-test': - if TESTS['c++-test'] in self.config['testflags'] or \ - TESTS['all-test'] in self.config['testflags']: - includes += [False] + if self.config.checkExclTestCategory(TESTS['c++-test']): + include = False + if not (inc_all_tests or self.config.checkInclTestCategory(TESTS['c++-test'])): + include = False elif word == 'longrunning-test': - if TESTS['longrunning-test'] in self.config['testflags'] or \ - TESTS['all-test'] in self.config['testflags']: - includes += [False] + if self.config.checkExclTestCategory(TESTS['longrunning-test']): + include = False + if not (inc_all_tests or self.config.checkInclTestCategory(TESTS['longrunning-test'])): + include = False elif word == 'privileged-test': - if TESTS['privileged-test'] in self.config['testflags'] or \ - TESTS['all-test'] in self.config['testflags']: - includes += [False] - elif word == 'all-test': - if TESTS['all-test'] in self.config['testflags'] or \ - TESTS['all-test'] in self.config['testflags']: - includes += [False] - else: # if any other word - if word.endswith('-tests'): - if TESTS['all-test'] in self.config['testflags']: - includes += [False] - include = any(includes) + if self.config.checkExclTestCategory(TESTS['privileged-test']): + include = False + if not (inc_all_tests or self.config.checkInclTestCategory(TESTS['privileged-test'])): + include = False + elif word == 'unportable-test': + if self.config.checkExclTestCategory(TESTS['unportable-test']): + include = False + if not (inc_all_tests or self.config.checkInclTestCategory(TESTS['unportable-test'])): + include = False + elif word.endswith('-test'): + if not inc_all_tests: + include = False if include and depmodule not in self.avoids: inmodules += [depmodule] if self.config['conddeps']: @@ -1064,11 +1076,12 @@ class GLModuleTable(object): listing = list() # Create empty list inmodules = sorted(set(inmodules)) handledmodules = sorted(set(handledmodules + inmodules_this_round)) - inmodules = \ - [ # Begin to filter inmodules - module for module in inmodules if module not in handledmodules - ] # Finish to filter inmodules + # Remove handledmodules from inmodules. + inmodules = [module + for module in inmodules + if module not in handledmodules] inmodules = sorted(set(inmodules)) + inc_all_tests = self.inc_all_indirect_tests modules = sorted(set(outmodules)) self.modules = modules return list(modules) @@ -1090,28 +1103,21 @@ class GLModuleTable(object): list after previous transitive_closure. Method returns tuple which contains two lists: the list of main modules and the list of tests-related modules. Both lists contain dependencies. - GLConfig: testflags.''' - inctests = False - main_modules = list() - tests_modules = list() - if TESTS['tests'] in self.config['testflags']: - self.config['testflags'].pop(TESTS['tests']) - inctests = True + GLConfig: incl_test_categories, excl_test_categories.''' for module in basemodules: if type(module) is not GLModule: raise TypeError('each module must be a GLModule instance') for module in finalmodules: if type(module) is not GLModule: raise TypeError('each module must be a GLModule instance') + saved_inctests = self.config.checkInclTestCategory(TESTS['tests']) + self.config.disableInclTestCategory(TESTS['tests']) main_modules = self.transitive_closure(basemodules) + self.config.setInclTestCategory(TESTS['tests'], saved_inctests) tests_modules = \ [m for m in finalmodules if m not in main_modules] + \ [m for m in main_modules if m.getApplicability() != 'main'] tests_modules = sorted(set(tests_modules)) - if inctests: - testflags = sorted( - set(self.config['testflags'] + [TESTS['tests']])) - self.config.setTestFlags(testflags) result = tuple([main_modules, tests_modules]) return result diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index 29c3010ce0..cb75ba1eab 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -87,7 +87,9 @@ class GLTestDir(object): self.emiter = GLEmiter(self.config) self.filesystem = GLFileSystem(self.config) self.modulesystem = GLModuleSystem(self.config) - self.moduletable = GLModuleTable(self.config) + self.moduletable = GLModuleTable(self.config, + True, + self.config.checkInclTestCategory(TESTS['all-tests'])) self.assistant = GLFileAssistant(self.config) self.makefiletable = GLMakefileTable(self.config) @@ -147,7 +149,6 @@ class GLTestDir(object): Create a scratch package with the given modules.''' auxdir = self.config['auxdir'] - testflags = list(self.config['testflags']) sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] pobase = self.config['pobase'] @@ -180,8 +181,8 @@ class GLTestDir(object): # When computing transitive closures, don't consider $module to depend on # $module-tests. Need this because tests are implicitly GPL and may depend # on GPL modules - therefore we don't want a warning in this case. - saved_testflags = list(self.config['testflags']) - self.config.disableTestFlag(TESTS['tests']) + saved_inctests = self.config.checkInclTestCategory(TESTS['tests']) + self.config.disableInclTestCategory(TESTS['tests']) for requested_module in base_modules: requested_licence = requested_module.getLicense() if requested_licence != 'GPL': @@ -213,7 +214,7 @@ class GLTestDir(object): if incompatible: errormsg = 'module %s depends on a module with an incompatible license: %s\n' % (requested_module, module) sys.stderr.write(errormsg) - self.config.setTestFlags(saved_testflags) + self.config.setInclTestCategory(TESTS['tests'], saved_inctests) # Determine final module list. modules = self.moduletable.transitive_closure(base_modules) @@ -389,7 +390,7 @@ class GLTestDir(object): subdirs_with_configure_ac = list() testsbase_appened = False - inctests = self.config.checkTestFlag(TESTS['tests']) + inctests = self.config.checkInclTestCategory(TESTS['tests']) if inctests: directory = joinpath(self.testdir, testsbase) if not isdir(directory): @@ -863,7 +864,9 @@ class GLMegaTestDir(object): self.emiter = GLEmiter(self.config) self.filesystem = GLFileSystem(self.config) self.modulesystem = GLModuleSystem(self.config) - self.moduletable = GLModuleTable(self.config) + self.moduletable = GLModuleTable(self.config, + True, + self.config.checkInclTestCategory(TESTS['all-tests'])) self.assistant = GLFileAssistant(self.config) self.makefiletable = GLMakefileTable(self.config) diff --git a/pygnulib/constants.py b/pygnulib/constants.py index ca5e3f79aa..bf01f86f39 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -104,7 +104,7 @@ MODES['verbose-min'] = -2 MODES['verbose-default'] = 0 MODES['verbose-max'] = 2 -# Set TESTS dictionary +# Define TESTS categories TESTS = \ { 'tests': 0, -- 2.34.1