mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-14 11:21:40 +00:00
utils: Put temporary files in the tmp directory
Instead of the CWD. Can improve performance of the test-runner, as emitting a lot of short-lived files in the source tree can waist a lot of cycles triggering IDE file monitoring logic. Change-Id: I25de15af02ab816fff5d8a079fda901883793478 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60342 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com> Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
d388bc9b36
commit
ec4a1df77b
@ -25,6 +25,11 @@ namespace utils {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::string TmpFilePath(std::string ext) {
|
std::string TmpFilePath(std::string ext) {
|
||||||
|
char const* dir = getenv("TMPDIR");
|
||||||
|
if (dir == nullptr) {
|
||||||
|
dir = "/tmp";
|
||||||
|
}
|
||||||
|
|
||||||
// mkstemps requires an `int` for the file extension name but STL represents
|
// mkstemps requires an `int` for the file extension name but STL represents
|
||||||
// size_t. Pre-C++20 there the behavior for unsigned-to-signed conversion
|
// size_t. Pre-C++20 there the behavior for unsigned-to-signed conversion
|
||||||
// (when the source value exceeds the representable range) is implementation
|
// (when the source value exceeds the representable range) is implementation
|
||||||
@ -32,7 +37,7 @@ std::string TmpFilePath(std::string ext) {
|
|||||||
// enforce this here at runtime.
|
// enforce this here at runtime.
|
||||||
TINT_ASSERT(Utils, ext.length() <=
|
TINT_ASSERT(Utils, ext.length() <=
|
||||||
static_cast<size_t>(std::numeric_limits<int>::max()));
|
static_cast<size_t>(std::numeric_limits<int>::max()));
|
||||||
std::string name = "tint_XXXXXX" + ext;
|
std::string name = std::string(dir) + "/tint_XXXXXX" + ext;
|
||||||
int file = mkstemps(&name[0], static_cast<int>(ext.length()));
|
int file = mkstemps(&name[0], static_cast<int>(ext.length()));
|
||||||
if (file != -1) {
|
if (file != -1) {
|
||||||
close(file);
|
close(file);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user