Commit 823b1bff by Jamie Madill Committed by Commit Bot

Trace/Replay: Always use Linux-style line endings.

This makes the traces consistent no matter which platform they are captured on. Will make it easier to use hashing with our code generator script. Bug: angleproject:4590 Change-Id: I7134b824c5cfefe4f2c21d8f9e21d80c2e8af57b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2188953 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
parent bcf99578
...@@ -649,30 +649,38 @@ size_t MaxClientArraySize(const gl::AttribArray<size_t> &clientArraySizes) ...@@ -649,30 +649,38 @@ size_t MaxClientArraySize(const gl::AttribArray<size_t> &clientArraySizes)
struct SaveFileHelper struct SaveFileHelper
{ {
SaveFileHelper(const std::string &filePathIn, std::ios_base::openmode mode = std::ios::out) public:
: ofs(filePathIn, mode), filePath(filePathIn) // We always use ios::binary to avoid inconsistent line endings when captured on Linux vs Win.
SaveFileHelper(const std::string &filePathIn)
: mOfs(filePathIn, std::ios::binary | std::ios::out), mFilePath(filePathIn)
{ {
if (!ofs.is_open()) if (!mOfs.is_open())
{ {
FATAL() << "Could not open " << filePathIn; FATAL() << "Could not open " << filePathIn;
} }
} }
~SaveFileHelper() { printf("Saved '%s'.\n", filePath.c_str()); } ~SaveFileHelper() { printf("Saved '%s'.\n", mFilePath.c_str()); }
template <typename T> template <typename T>
SaveFileHelper &operator<<(const T &value) SaveFileHelper &operator<<(const T &value)
{ {
ofs << value; mOfs << value;
if (ofs.bad()) if (mOfs.bad())
{ {
FATAL() << "Error writing to " << filePath; FATAL() << "Error writing to " << mFilePath;
} }
return *this; return *this;
} }
std::ofstream ofs; void write(const uint8_t *data, size_t size)
std::string filePath; {
mOfs.write(reinterpret_cast<const char *>(data), size);
}
private:
std::ofstream mOfs;
std::string mFilePath;
}; };
std::string GetBinaryDataFilePath(bool compression, std::string GetBinaryDataFilePath(bool compression,
...@@ -697,7 +705,7 @@ void SaveBinaryData(bool compression, ...@@ -697,7 +705,7 @@ void SaveBinaryData(bool compression,
std::string binaryDataFileName = GetBinaryDataFilePath(compression, contextId, captureLabel); std::string binaryDataFileName = GetBinaryDataFilePath(compression, contextId, captureLabel);
std::string dataFilepath = outDir + binaryDataFileName; std::string dataFilepath = outDir + binaryDataFileName;
SaveFileHelper saveData(dataFilepath, std::ios::binary); SaveFileHelper saveData(dataFilepath);
if (compression) if (compression)
{ {
...@@ -717,11 +725,11 @@ void SaveBinaryData(bool compression, ...@@ -717,11 +725,11 @@ void SaveBinaryData(bool compression,
FATAL() << "Error compressing binary data: " << zResult; FATAL() << "Error compressing binary data: " << zResult;
} }
saveData.ofs.write(reinterpret_cast<const char *>(compressedData.data()), compressedSize); saveData.write(compressedData.data(), compressedSize);
} }
else else
{ {
saveData.ofs.write(reinterpret_cast<const char *>(binaryData.data()), binaryData.size()); saveData.write(binaryData.data(), binaryData.size());
} }
} }
......
9d63c7fbd7bcd043e463a32dff0e93c7a40dcfa1 cf4368d97c92bbc3cb76d10bde464d387fe3b174
\ No newline at end of file \ No newline at end of file
66abc7eeb1567431586708fb0e203782ddcb097c de400ad21e57f7568fc2124158f5c3ca26338fde
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment