[PATCH] D154987: [lit] Implement PYTHON directive and config.prologue

Joel E. Denny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 10:17:35 PDT 2023


jdenny created this revision.
jdenny added reviewers: Endill, jhenderson, yln, ldionne, aaron.ballman, awarzynski, MaskRay, rnk, mstorsjo, asavonic.
Herald added subscribers: pengfei, delcypher, arichardson.
Herald added a project: All.
jdenny requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: libcxx-commits, jplehr, sstefan1.
Herald added projects: libc++, LLVM.
Herald added a reviewer: libc++.

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("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 <https://llvm.org/docs/TestingGuide.html#substitutions>
and my proposed function-like
substitutions <https://reviews.llvm.org/D133172>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154987

Files:
  libcxx/utils/libcxx/test/format.py
  llvm/docs/TestingGuide.rst
  llvm/utils/lit/lit/TestRunner.py
  llvm/utils/lit/lit/TestingConfig.py
  llvm/utils/lit/tests/Inputs/shtest-define/errors/no-run.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/README.md
  llvm/utils/lit/tests/Inputs/shtest-python/errors/incomplete-python.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/inconsistent-indent-2-lines.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/inconsistent-indent-3-lines.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/internal-api-inaccessible.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/lit.prologue.py
  llvm/utils/lit/tests/Inputs/shtest-python/errors/python-syntax-error-1-line.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/python-syntax-error-2-lines.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/python-syntax-error-3-lines.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/python-syntax-error-leading-indent.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/trace-compile-error.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/trace-exception.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/trace-prologue-exception.txt
  llvm/utils/lit/tests/Inputs/shtest-python/errors/trace-run-compile-error.txt
  llvm/utils/lit/tests/Inputs/shtest-python/exampleModule.py
  llvm/utils/lit/tests/Inputs/shtest-python/has.txt
  llvm/utils/lit/tests/Inputs/shtest-python/import.txt
  llvm/utils/lit/tests/Inputs/shtest-python/lit.cfg
  llvm/utils/lit/tests/Inputs/shtest-python/lit.prologue.py
  llvm/utils/lit/tests/Inputs/shtest-python/no-shell-commands.txt
  llvm/utils/lit/tests/Inputs/shtest-python/prologue.txt
  llvm/utils/lit/tests/Inputs/shtest-python/shell-affects-python.txt
  llvm/utils/lit/tests/Inputs/shtest-python/substs-affects-python.txt
  llvm/utils/lit/tests/Inputs/shtest-python/trace.txt
  llvm/utils/lit/tests/Inputs/shtest-python/write-to-stderr.py
  llvm/utils/lit/tests/Inputs/shtest-python/write-to-stdout-and-stderr.py
  llvm/utils/lit/tests/shtest-keyword-parse-errors.py
  llvm/utils/lit/tests/shtest-python.py
  llvm/utils/lit/tests/shtest-shell.py

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154987.539174.patch
Type: text/x-patch
Size: 68568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230711/f37ef68b/attachment.bin>


More information about the llvm-commits mailing list