diff --git a/libcxx/test/lit.cfg b/libcxx/test/lit.cfg --- a/libcxx/test/lit.cfg +++ b/libcxx/test/lit.cfg @@ -20,6 +20,9 @@ # test_source_root: The root path where tests are located. config.test_source_root = os.path.dirname(__file__) +# Allow expanding substitutions that are based on other substitutions +config.recursiveExpansionLimit = 10 + loaded_site_cfg = getattr(config, 'loaded_site_config', False) if not loaded_site_cfg: import libcxx.test.config diff --git a/libcxx/utils/libcxx/test/format.py b/libcxx/utils/libcxx/test/format.py --- a/libcxx/utils/libcxx/test/format.py +++ b/libcxx/utils/libcxx/test/format.py @@ -132,13 +132,13 @@ # Apply substitutions in FILE_DEPENDENCIES markup data_files = lit.TestRunner.applySubstitutions(test.file_dependencies, substitutions, - recursion_limit=10) + recursion_limit=test.config.recursiveExpansionLimit) local_cwd = os.path.dirname(test.getSourcePath()) data_files = [f if os.path.isabs(f) else os.path.join(local_cwd, f) for f in data_files] substitutions.append(('%{file_dependencies}', ' '.join(data_files))) script = lit.TestRunner.applySubstitutions(script, substitutions, - recursion_limit=10) + recursion_limit=test.config.recursiveExpansionLimit) test_cxx = copy.deepcopy(self.cxx) if is_fail_test: diff --git a/libcxx/utils/libcxx/test/newformat.py b/libcxx/utils/libcxx/test/newformat.py --- a/libcxx/utils/libcxx/test/newformat.py +++ b/libcxx/utils/libcxx/test/newformat.py @@ -190,7 +190,6 @@ # Modified version of lit.TestRunner.executeShTest to handle custom parsers correctly. def _executeShTest(self, test, litConfig, steps, fileDependencies=None): - recursiveExpansionLimit = 10 # TODO: Use the value in litConfig once we set it. if test.config.unsupported: return lit.Test.Result(lit.Test.UNSUPPORTED, 'Test is unsupported') @@ -228,7 +227,7 @@ # need to resolve %{file_dependencies} now, because otherwise we won't be able to # make all paths absolute below. fileDependencies = lit.TestRunner.applySubstitutions(fileDependencies, substitutions, - recursion_limit=recursiveExpansionLimit) + recursion_limit=test.config.recursiveExpansionLimit) # Add the %{file_dependencies} substitution before we perform substitutions # inside the script. @@ -238,6 +237,6 @@ # Perform substitution in the script itself. script = lit.TestRunner.applySubstitutions(script, substitutions, - recursion_limit=recursiveExpansionLimit) + recursion_limit=test.config.recursiveExpansionLimit) return lit.TestRunner._runShTest(test, litConfig, useExternalSh, script, tmpBase) diff --git a/libcxxabi/test/lit.cfg b/libcxxabi/test/lit.cfg --- a/libcxxabi/test/lit.cfg +++ b/libcxxabi/test/lit.cfg @@ -20,6 +20,9 @@ # suffixes: A list of file extensions to treat as test files. config.suffixes = ['.cpp', '.s'] +# Allow expanding substitutions that are based on other substitutions +config.recursiveExpansionLimit = 10 + # test_source_root: The root path where tests are located. config.test_source_root = os.path.dirname(__file__) diff --git a/llvm/docs/CommandGuide/lit.rst b/llvm/docs/CommandGuide/lit.rst --- a/llvm/docs/CommandGuide/lit.rst +++ b/llvm/docs/CommandGuide/lit.rst @@ -455,12 +455,12 @@ modules :ref:`local-configuration-files`. By default, substitutions are expanded exactly once, so that if e.g. a -substitution ``%build`` is defined in top of another substitution ``%cxx``, -``%build`` will expand to ``%cxx`` textually, not to what ``%cxx`` expands to. -However, if the ``recursiveExpansionLimit`` property of the ``LitConfig`` is -set to a non-negative integer, substitutions will be expanded recursively until -that limit is reached. It is an error if the limit is reached and expanding -substitutions again would yield a different result. +substitution ``%{build}`` is defined in top of another substitution ``%{cxx}``, +``%{build}`` will expand to ``%{cxx}`` textually, not to what ``%{cxx}`` expands +to. However, if the ``recursiveExpansionLimit`` property of the ``TestingConfig`` +is set to a non-negative integer, substitutions will be expanded recursively +until that limit is reached. It is an error if the limit is reached and +expanding substitutions again would yield a different result. More detailed information on substitutions can be found in the :doc:`../TestingGuide`. diff --git a/llvm/utils/lit/lit/LitConfig.py b/llvm/utils/lit/lit/LitConfig.py --- a/llvm/utils/lit/lit/LitConfig.py +++ b/llvm/utils/lit/lit/LitConfig.py @@ -66,19 +66,6 @@ self.maxIndividualTestTime = maxIndividualTestTime self.parallelism_groups = parallelism_groups self.echo_all_commands = echo_all_commands - self._recursiveExpansionLimit = None - - @property - def recursiveExpansionLimit(self): - return self._recursiveExpansionLimit - - @recursiveExpansionLimit.setter - def recursiveExpansionLimit(self, value): - if value is not None and not isinstance(value, int): - self.fatal('recursiveExpansionLimit must be either None or an integer (got <{}>)'.format(value)) - if isinstance(value, int) and value < 0: - self.fatal('recursiveExpansionLimit must be a non-negative integer (got <{}>)'.format(value)) - self._recursiveExpansionLimit = value @property def maxIndividualTestTime(self): diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -1552,6 +1552,6 @@ substitutions += getDefaultSubstitutions(test, tmpDir, tmpBase, normalize_slashes=useExternalSh) script = applySubstitutions(script, substitutions, - recursion_limit=litConfig.recursiveExpansionLimit) + recursion_limit=test.config.recursiveExpansionLimit) return _runShTest(test, litConfig, useExternalSh, script, tmpBase) diff --git a/llvm/utils/lit/lit/TestingConfig.py b/llvm/utils/lit/lit/TestingConfig.py --- a/llvm/utils/lit/lit/TestingConfig.py +++ b/llvm/utils/lit/lit/TestingConfig.py @@ -2,7 +2,7 @@ import sys -class TestingConfig: +class TestingConfig(object): """" TestingConfig - Information on the tests inside a suite. """ @@ -126,6 +126,19 @@ # Whether the suite should be tested early in a given run. self.is_early = bool(is_early) self.parallelism_group = parallelism_group + self._recursiveExpansionLimit = None + + @property + def recursiveExpansionLimit(self): + return self._recursiveExpansionLimit + + @recursiveExpansionLimit.setter + def recursiveExpansionLimit(self, value): + if value is not None and not isinstance(value, int): + raise ValueError('recursiveExpansionLimit must be either None or an integer (got <{}>)'.format(value)) + if isinstance(value, int) and value < 0: + raise ValueError('recursiveExpansionLimit must be a non-negative integer (got <{}>)'.format(value)) + self._recursiveExpansionLimit = value def finish(self, litConfig): """finish() - Finish this config object, after loading is complete.""" diff --git a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/does-not-substitute-within-limit/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/does-not-substitute-within-limit/lit.cfg --- a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/does-not-substitute-within-limit/lit.cfg +++ b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/does-not-substitute-within-limit/lit.cfg @@ -9,4 +9,4 @@ ("%rec3", "%rec2"), ("%rec4", "%rec3"), ("%rec5", "%rec4")] -lit_config.recursiveExpansionLimit = 2 +config.recursiveExpansionLimit = 2 diff --git a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/negative-integer/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/negative-integer/lit.cfg --- a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/negative-integer/lit.cfg +++ b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/negative-integer/lit.cfg @@ -5,4 +5,4 @@ config.test_source_root = None config.test_exec_root = None -lit_config.recursiveExpansionLimit = -4 +config.recursiveExpansionLimit = -4 diff --git a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/not-an-integer/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/not-an-integer/lit.cfg --- a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/not-an-integer/lit.cfg +++ b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/not-an-integer/lit.cfg @@ -5,4 +5,4 @@ config.test_source_root = None config.test_exec_root = None -lit_config.recursiveExpansionLimit = "not-an-integer" +config.recursiveExpansionLimit = "not-an-integer" diff --git a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/set-to-none/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/set-to-none/lit.cfg --- a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/set-to-none/lit.cfg +++ b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/set-to-none/lit.cfg @@ -5,4 +5,4 @@ config.test_source_root = None config.test_exec_root = None -lit_config.recursiveExpansionLimit = None +config.recursiveExpansionLimit = None diff --git a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/substitutes-within-limit/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/substitutes-within-limit/lit.cfg --- a/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/substitutes-within-limit/lit.cfg +++ b/llvm/utils/lit/tests/Inputs/shtest-recursive-substitution/substitutes-within-limit/lit.cfg @@ -9,4 +9,4 @@ ("%rec3", "%rec2"), ("%rec4", "%rec3"), ("%rec5", "%rec4")] -lit_config.recursiveExpansionLimit = 5 +config.recursiveExpansionLimit = 5