[PATCH] D150990: [split-file] Add flags to support comments and adding extension to output files
Vlad Serebrennikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 19 12:43:51 PDT 2023
Endill created this revision.
Endill added reviewers: aaron.ballman, MaskRay.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
- `--allow-comments` cuts part name at the colon if one is present
- `--add-file-extension` adds specified extension to output files
Those two features allow us to integrate split-file notation and C++ DR tests notation:
`// dr164: 16` becomes `//--- dr164: 16`, which produces `dr164.cpp` file with the corresponding test.
I go into more details on motivation in Discourse thread <https://discourse.llvm.org/t/rfc-opt-in-way-to-make-verifydiagnosticconsumer-slightly-less-strict/70747>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150990
Files:
llvm/utils/split-file/split-file.cpp
Index: llvm/utils/split-file/split-file.cpp
===================================================================
--- llvm/utils/split-file/split-file.cpp
+++ llvm/utils/split-file/split-file.cpp
@@ -43,6 +43,15 @@
cl::desc("Don't preserve line numbers (default)"),
cl::cat(cat));
+static cl::opt<std::string> addFileExtension("add-file-extension",
+ cl::desc("Add extension to output file names"),
+ cl::value_desc("ext"),
+ cl::cat(cat));
+
+static cl::opt<bool> allowComments("allow-comments",
+ cl::desc("Allow comments to be introduced with a colon after part name"),
+ cl::cat(cat));
+
static StringRef toolName;
static int errorCount;
@@ -80,7 +89,15 @@
line.substr(markerLen - 4).startswith("--- ")))
continue;
separator = line.substr(0, markerLen);
- const StringRef partName = line.substr(markerLen);
+ const StringRef partName = [&] {
+ StringRef partName = line.substr(markerLen);
+ if (allowComments) {
+ auto colonPos = partName.find(':');
+ if (colonPos != StringRef::npos)
+ partName = partName.substr(0, colonPos);
+ }
+ return partName;
+ }();
if (partName.empty()) {
error(input, lineNo, "empty part name");
continue;
@@ -118,6 +135,10 @@
for (auto &keyValue : partToBegin) {
partPath.clear();
sys::path::append(partPath, output, keyValue.first);
+ if (!addFileExtension.empty()) {
+ partPath.append(".");
+ partPath.append(addFileExtension.getValue());
+ }
std::error_code ec =
sys::fs::create_directories(sys::path::parent_path(partPath));
if (ec)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150990.523860.patch
Type: text/x-patch
Size: 1889 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230519/3b4a374c/attachment.bin>
More information about the llvm-commits
mailing list