[llvm] 54e76cb - [split-file] Default to --no-leading-lines
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 16 19:23:16 PDT 2021
Author: Fangrui Song
Date: 2021-08-16T19:23:11-07:00
New Revision: 54e76cb17abdfef1b3549fff00f51e72ae966b4c
URL: https://github.com/llvm/llvm-project/commit/54e76cb17abdfef1b3549fff00f51e72ae966b4c
DIFF: https://github.com/llvm/llvm-project/commit/54e76cb17abdfef1b3549fff00f51e72ae966b4c.diff
LOG: [split-file] Default to --no-leading-lines
It turns out that the --leading-lines may be a bad default.
[[#@LINE+-num]] is rarely used.
Added:
Modified:
lld/test/ELF/linkerscript/overwrite-sections.test
llvm/test/tools/split-file/basic.test
llvm/tools/split-file/split-file.cpp
Removed:
################################################################################
diff --git a/lld/test/ELF/linkerscript/overwrite-sections.test b/lld/test/ELF/linkerscript/overwrite-sections.test
index 06918728826db..0a14542f7d10d 100644
--- a/lld/test/ELF/linkerscript/overwrite-sections.test
+++ b/lld/test/ELF/linkerscript/overwrite-sections.test
@@ -1,5 +1,5 @@
# REQUIRES: x86
-# RUN: rm -rf %t && split-file %s %t
+# RUN: rm -rf %t && split-file --leading-lines %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
## There is no main linker script. OVERWRITE_SECTIONS defines output section
diff --git a/llvm/test/tools/split-file/basic.test b/llvm/test/tools/split-file/basic.test
index 5d32c3429ed37..b47aeb1e11801 100644
--- a/llvm/test/tools/split-file/basic.test
+++ b/llvm/test/tools/split-file/basic.test
@@ -9,20 +9,20 @@ cc
//--- end
# RUN: rm -rf %t
-# RUN: split-file %s %t
+# RUN: split-file --leading-lines %s %t
# RUN:
diff %S/Inputs/basic-aa.txt %t/aa
# RUN:
diff %S/Inputs/basic-bb.txt %t/bb
# RUN:
diff %S/Inputs/basic-cc.txt %t/subdir/cc
# RUN: FileCheck %s --check-prefix=END < %t/end
## Can be called on a non-empty directory.
-# RUN: split-file %s %t
+# RUN: split-file --leading-lines %s %t
# RUN:
diff %S/Inputs/basic-aa.txt %t/aa
## Test that we will delete the output if it is a file, so that we can create
## a directory.
# RUN: rm -rf %t && touch %t
-# RUN: split-file %s %t
+# RUN: split-file --leading-lines %s %t
# RUN:
diff %S/Inputs/basic-aa.txt %t/aa
# END: RUN: split-file %s %t
diff --git a/llvm/tools/split-file/split-file.cpp b/llvm/tools/split-file/split-file.cpp
index 355678433ac16..bde7d21a51e9a 100644
--- a/llvm/tools/split-file/split-file.cpp
+++ b/llvm/tools/split-file/split-file.cpp
@@ -35,8 +35,12 @@ static cl::opt<std::string> input(cl::Positional, cl::desc("filename"),
static cl::opt<std::string> output(cl::Positional, cl::desc("directory"),
cl::value_desc("directory"), cl::cat(cat));
+static cl::opt<bool> leadingLines("leading-lines",
+ cl::desc("Preserve line numbers"),
+ cl::cat(cat));
+
static cl::opt<bool> noLeadingLines("no-leading-lines",
- cl::desc("Don't preserve line numbers"),
+ cl::desc("Don't preserve line numbers (default)"),
cl::cat(cat));
static StringRef toolName;
@@ -96,9 +100,9 @@ static int handle(MemoryBuffer &inputBuf, StringRef input) {
Part &cur = res.first->second;
if (!i.is_at_eof())
cur.begin = i->data();
- // If --no-leading-lines is not specified, numEmptyLines is 0. Append
- // newlines so that the extracted part preserves line numbers.
- cur.leadingLines = noLeadingLines ? 0 : i.line_number() - 1;
+ // If --leading-lines is specified, numEmptyLines is 0. Append newlines so
+ // that the extracted part preserves line numbers.
+ cur.leadingLines = leadingLines ? i.line_number() - 1 : 0;
lastPart = partName;
}
More information about the llvm-commits
mailing list