[PATCH] D150856: [lit] Add %{for-each-file} substitution

Joel E. Denny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 16 01:45:37 PDT 2023


jdenny added a comment.

For-each is one of the major use cases originally targeted by DEFINE/REDEFINE.  In the C++ DR scenario, the data set to iterate (the split-out files) is already harcoded in the lit test file.  Without any new lit features, I believe you can use DEFINE/REDEFINE now to iterate that data set as follows:

  // RUN: split-file %s %t
  // DEFINE: %{file} =
  // DEFINE: %{run} = \
  // DEFINE:     cmd1 %t/%{file} && \
  // DEFINE:     cmd2 && cmd3 && cmd4 
  
  //--- dr100.cpp
  // REDEFINE: %{file} = dr100.cpp
  // RUN: %{run}
  contents of dr100.cpp 
  
  //--- dr101.cpp
  // REDEFINE: %{file} = dr101.cpp
  // RUN: %{run}
  contents of dr101.cpp

Especially from the perspective of lit maintenance, that solution seems simpler to me than inventing additional for-each mechanisms, such as %{for-each-file}.  Moreover, it seems more flexible.  For example, some split-out files could be visited by a different command list, or some could be left out of the iteration entirely in order to serve some sort of auxiliary role in the test.

If anyone is bothered by the repetition of each file name, then perhaps someone should invent a built-in lit substitution that expands to the most recent split-out file name.  Maybe %{split-file-name}. In each RUN line, it should expand after all custom substitutions.  Then you could have:

  // RUN: split-file %s %t
  // DEFINE: %{run} = \
  // DEFINE:     cmd1 %t/%{split-file-name} && \
  // DEFINE:     cmd2 && cmd3 && cmd4 
  
  //--- dr100.cpp
  // RUN: %{run}
  contents of dr100.cpp 
  
  //--- dr101.cpp
  // RUN: %{run}
  contents of dr101.cpp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150856/new/

https://reviews.llvm.org/D150856



More information about the llvm-commits mailing list