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)
struct SaveFileHelper
{
SaveFileHelper(const std::string &filePathIn, std::ios_base::openmode mode = std::ios::out)
: ofs(filePathIn, mode), filePath(filePathIn)
public:
// 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;
}
}
~SaveFileHelper() { printf("Saved '%s'.\n", filePath.c_str()); }
~SaveFileHelper() { printf("Saved '%s'.\n", mFilePath.c_str()); }
template <typename T>
SaveFileHelper &operator<<(const T &value)
{
ofs << value;
if (ofs.bad())
mOfs << value;
if (mOfs.bad())
{
FATAL() << "Error writing to " << filePath;
FATAL() << "Error writing to " << mFilePath;
}
return *this;
}
std::ofstream ofs;
std::string filePath;
void write(const uint8_t *data, size_t size)
{
mOfs.write(reinterpret_cast<const char *>(data), size);
}
private:
std::ofstream mOfs;
std::string mFilePath;
};
std::string GetBinaryDataFilePath(bool compression,
......@@ -697,7 +705,7 @@ void SaveBinaryData(bool compression,
std::string binaryDataFileName = GetBinaryDataFilePath(compression, contextId, captureLabel);
std::string dataFilepath = outDir + binaryDataFileName;
SaveFileHelper saveData(dataFilepath, std::ios::binary);
SaveFileHelper saveData(dataFilepath);
if (compression)
{
......@@ -717,11 +725,11 @@ void SaveBinaryData(bool compression,
FATAL() << "Error compressing binary data: " << zResult;
}
saveData.ofs.write(reinterpret_cast<const char *>(compressedData.data()), compressedSize);
saveData.write(compressedData.data(), compressedSize);
}
else
{
saveData.ofs.write(reinterpret_cast<const char *>(binaryData.data()), binaryData.size());
saveData.write(binaryData.data(), binaryData.size());
}
}
......
9d63c7fbd7bcd043e463a32dff0e93c7a40dcfa1
\ No newline at end of file
cf4368d97c92bbc3cb76d10bde464d387fe3b174
\ No newline at end of file
66abc7eeb1567431586708fb0e203782ddcb097c
\ No newline at end of file
de400ad21e57f7568fc2124158f5c3ca26338fde
\ 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