Skip to content

Commit 3c43471

Browse files
committed
treat text files as text files so autoconversion is done
1 parent 7045c14 commit 3c43471

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,9 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
413413
// On Windows, overwriting a file with an open file mapping doesn't work,
414414
// so read the whole file into memory when formatting in-place.
415415
ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
416-
!OutputXML && Inplace ? MemoryBuffer::getFileAsStream(FileName)
417-
: MemoryBuffer::getFileOrSTDIN(FileName);
416+
!OutputXML && Inplace
417+
? MemoryBuffer::getFileAsStream(FileName)
418+
: MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true);
418419
if (std::error_code EC = CodeOrErr.getError()) {
419420
errs() << EC.message() << "\n";
420421
return true;
@@ -558,7 +559,7 @@ static int dumpConfig() {
558559
// Read in the code in case the filename alone isn't enough to detect the
559560
// language.
560561
ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
561-
MemoryBuffer::getFileOrSTDIN(FileNames[0]);
562+
MemoryBuffer::getFileOrSTDIN(FileNames[0], /*IsText=*/true);
562563
if (std::error_code EC = CodeOrErr.getError()) {
563564
llvm::errs() << EC.message() << "\n";
564565
return 1;

llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ static std::vector<StringRef> getSearchPaths(opt::InputArgList *Args,
9595

9696
// Opens a file. Path has to be resolved already. (used for def file)
9797
std::unique_ptr<MemoryBuffer> openFile(const Twine &Path) {
98-
ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB = MemoryBuffer::getFile(Path);
98+
ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB =
99+
MemoryBuffer::getFile(Path, /*IsText=*/true);
99100

100101
if (std::error_code EC = MB.getError()) {
101102
llvm::errs() << "cannot open file " << Path << ": " << EC.message() << "\n";

llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,18 @@ int main(int argc, const char *argv[]) {
144144
cl::HideUnrelatedOptions({&CXXMapCategory, &getColorCategory()});
145145
cl::ParseCommandLineOptions(argc, argv, "LLVM C++ mangled name remapper\n");
146146

147-
auto OldSymbolBufOrError = MemoryBuffer::getFileOrSTDIN(OldSymbolFile);
147+
auto OldSymbolBufOrError =
148+
MemoryBuffer::getFileOrSTDIN(OldSymbolFile, /*IsText=*/true);
148149
if (!OldSymbolBufOrError)
149150
exitWithErrorCode(OldSymbolBufOrError.getError(), OldSymbolFile);
150151

151-
auto NewSymbolBufOrError = MemoryBuffer::getFileOrSTDIN(NewSymbolFile);
152+
auto NewSymbolBufOrError =
153+
MemoryBuffer::getFileOrSTDIN(NewSymbolFile, /*IsText=*/true);
152154
if (!NewSymbolBufOrError)
153155
exitWithErrorCode(NewSymbolBufOrError.getError(), NewSymbolFile);
154156

155-
auto RemappingBufOrError = MemoryBuffer::getFileOrSTDIN(RemappingFile);
157+
auto RemappingBufOrError =
158+
MemoryBuffer::getFileOrSTDIN(RemappingFile, /*IsText=*/true);
156159
if (!RemappingBufOrError)
157160
exitWithErrorCode(RemappingBufOrError.getError(), RemappingFile);
158161

llvm/tools/yaml2obj/yaml2obj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int main(int argc, char **argv) {
130130
}
131131

132132
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
133-
MemoryBuffer::getFileOrSTDIN(Input);
133+
MemoryBuffer::getFileOrSTDIN(Input, /*IsText=*/true);
134134
if (!Buf)
135135
return 1;
136136

llvm/utils/lit/lit/builtin_commands/cat.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,24 @@ def main(argv):
5555
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
5656
for filename in filenames:
5757
try:
58-
fileToCat = open(filename, "rb")
59-
contents = fileToCat.read()
58+
contents = None
59+
is_text = False
60+
try:
61+
if sys.platform != "win32":
62+
fileToCat = open(filename, "r")
63+
contents = fileToCat.read()
64+
is_text = True
65+
except:
66+
pass
67+
68+
if contents is None:
69+
fileToCat = open(filename, "rb")
70+
contents = fileToCat.read()
71+
6072
if show_nonprinting:
6173
contents = convertToCaretAndMNotation(contents)
74+
elif is_text:
75+
contents = contents.encode()
6276
writer.write(contents)
6377
sys.stdout.flush()
6478
fileToCat.close()

llvm/utils/lit/lit/llvm/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ def __init__(self, lit_config, config):
5757
self.lit_config.note("using lit tools: {}".format(path))
5858
lit_path_displayed = True
5959

60+
if platform.system() == "OS/390":
61+
self.with_environment("_BPXK_AUTOCVT", "ON")
62+
self.with_environment("_TAG_REDIR_IN", "TXT")
63+
self.with_environment("_TAG_REDIR_OUT", "TXT")
64+
self.with_environment("_TAG_REDIR_ERR", "TXT")
65+
self.with_environment("_CEE_RUNOPTS", "FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)")
66+
6067
# Choose between lit's internal shell pipeline runner and a real shell.
6168
# If LIT_USE_INTERNAL_SHELL is in the environment, we use that as an
6269
# override.

0 commit comments

Comments
 (0)