Avoid race on mkdir

Should fix https://github.com/KhronosGroup/SPIRV-Tools/issues/340
This commit is contained in:
David Neto 2016-08-12 14:19:17 -04:00
parent 097ff25ea7
commit 033b7d00f0
3 changed files with 22 additions and 5 deletions

View File

@ -9,6 +9,7 @@ v2016.3-dev 2016-08-11
- Add optimization pass: Eliminate dead constants.
- Fixes issues:
#288: Check def-use dominance rules for OpPhi (variable,parent) operands
#340: Avoid race on mkdir during build
v2016.2 2016-08-05
- Validator is incomplete

View File

@ -3,6 +3,7 @@
from __future__ import print_function
import errno
import functools
import json
import os.path
@ -24,8 +25,11 @@ def make_path_to_file(f):
dir = os.path.dirname(os.path.abspath(f))
try:
os.makedirs(dir)
except:
pass
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(dir):
pass
else:
raise
def populate_capability_bit_mapping_dict(cap_dict):

View File

@ -32,12 +32,26 @@
from __future__ import print_function
import datetime
import errno
import os.path
import re
import subprocess
import sys
def mkdir_p(directory):
"""Make the directory, and all its ancestors as required. Any of the
directories are allowed to already exist."""
try:
os.makedirs(directory)
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(directory):
pass
else:
raise
def command_output(cmd, directory):
"""Runs a command in a directory and returns its standard output stream.
@ -99,9 +113,7 @@ def main():
sys.exit(1)
output_file = sys.argv[2]
output_dir = os.path.dirname(output_file)
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
mkdir_p(os.path.dirname(output_file))
software_version = deduce_software_version(sys.argv[1])
new_content = '"{}", "SPIRV-Tools {} {}"\n'.format(