~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to tools/response_file.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import tempfile, os, sys, shlex
 
2
 
 
3
# Routes the given cmdline param list in args into a new response file and returns the filename to it.
 
4
# The returned filename has a suffix '.rsp'.
 
5
def create_response_file(args, directory):
 
6
  (response_fd, response_filename) = tempfile.mkstemp(prefix='emscripten_', suffix='.rsp', dir=directory, text=True)
 
7
  response_fd = os.fdopen(response_fd, "w")
 
8
  #print >> sys.stderr, "Creating response file '%s'" % response_filename
 
9
  args = map(lambda p: p.replace(' ', '').replace('\\', '\\\\').replace('"', '\\"'), args)
 
10
  response_fd.write(' '.join(args))
 
11
  response_fd.close()
 
12
  return response_filename
 
13
 
 
14
# Reads a response file, and returns the list of cmdline params found in the file.
 
15
# The parameter response_filename may start with '@'.
 
16
def read_response_file(response_filename):
 
17
  if response_filename.startswith('@'):
 
18
    response_filename = response_filename[1:]
 
19
 
 
20
  #print >> sys.stderr, "Using response file '%s'" % response_filename
 
21
  if not os.path.exists(response_filename):
 
22
    raise Exception("Response file '%s' not found!" % response_filename)
 
23
 
 
24
  response_fd = open(response_filename, 'r')
 
25
  args = response_fd.read()
 
26
  response_fd.close()
 
27
  args = shlex.split(args)
 
28
  return args