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 {
|
||||
|
||||
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
|
||||
// size_t. Pre-C++20 there the behavior for unsigned-to-signed conversion
|
||||
// (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.
|
||||
TINT_ASSERT(Utils, ext.length() <=
|
||||
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()));
|
||||
if (file != -1) {
|
||||
close(file);
|
||||
|
|
Loading…
Reference in New Issue