NOTE: This patch should be applied after PR #68496, whose branch is jdenny-ornl:lit-python-script-fatal and whose final commit is currently 909a48a4d1dd04b1841d5e6953797001a560c432.
For example, you can put this in a lit test:
// PYTHON: def check(cflags, fcprefix): // PYTHON: lit.run(f""" // PYTHON: %clang_cc1 -verify -fopenmp -fopenmp-version=51 // PYTHON: {cflags} -emit-llvm -o - %s | // PYTHON: FileCheck -check-prefix={fcprefix} %s // PYTHON: """) // PYTHON: // PYTHON: check("-triple x86_64-apple-darwin10.6.0 -fopenmp-simd", "SIMD") // PYTHON: check("-triple x86_64-apple-darwin10.6.0", "NO-SIMD") // PYTHON: check("-triple x86_64-unknown-linux-gnu", "NO-SIMD")
where lit.run(cmd) behaves like RUN: cmd.
To define check at the start of every test file in a test directory, you can move it to a lit.prologue.py file and, in a lit configuration file, set config.prologue to that file.
The idea of a PYTHON directive was proposed at https://reviews.llvm.org/D150856#4436879 (but some details have evolved since then). The rationale is that we are continuing to incrementally evolve lit RUN lines toward a full blown scripting language. A simpler alternative is to just use an existing scripting language, and python seems like the obvious choice. That will lower the learning curve for lit users, quickly and significantly increase the flexibility of lit RUN lines, and lower the burden for lit developers and reviewers.
Toward those goals, PYTHON directives can also eventually replace some other existing and proposed lit features. Lit's existing %if x substitutions can become PYTHON: if lit.has('x'):. Python functions can replace parameterized substitutions and my proposed function-like substitutions.
For further discussion and examples, see this patch's additions to llvm/docs/TestingGuide.rst.
I think we can provide an example for this case as well:
But it could be better to hold it until we come up with a variant of run that runs in parallel with other runs, in order to avoid the issue you're describing.