Home | History | Annotate | Download | only in mesa
      1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import os
      6 import os.path
      7 import subprocess
      8 import sys
      9 
     10 if len(sys.argv) < 3:
     11   print "Usage: %s OUTPUTFILE SCRIPTNAME ARGUMENTS" % sys.argv[0]
     12   print "Re-execs the python interpreter against SCRIPTNAME with ARGS,"
     13   print "redirecting output to OUTPUTFILE."
     14   sys.exit(1)
     15 
     16 abs_outputfile = os.path.abspath(sys.argv[1])
     17 abs_outputdir = os.path.dirname(abs_outputfile)
     18 
     19 if not os.path.isdir(abs_outputdir):
     20   os.makedirs(abs_outputdir)
     21 
     22 ret = 0
     23 
     24 with open(abs_outputfile, "w") as f:
     25   ret = subprocess.Popen([sys.executable] + sys.argv[2:], stdout=f).wait()
     26 
     27 if ret:
     28   os.remove(abs_outputfile)
     29   sys.exit(ret)
     30