media/webrtc/trunk/build/ios/clean_env.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/python
michael@0 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 3 # Use of this source code is governed by a BSD-style license that can be
michael@0 4 # found in the LICENSE file.
michael@0 5
michael@0 6 import os
michael@0 7 import sys
michael@0 8
michael@0 9 def Main(argv):
michael@0 10 """This is like 'env -i', but it uses a whitelist of env variables to allow
michael@0 11 through to the command being run. It attempts to strip off Xcode-added
michael@0 12 values from PATH.
michael@0 13 """
michael@0 14 # Note: An attempt was made to do something like: env -i bash -lc '[command]'
michael@0 15 # but that fails to set the things set by login (USER, etc.), so instead
michael@0 16 # the only approach that seems to work is to have a whitelist.
michael@0 17 env_key_whitelist = (
michael@0 18 'HOME',
michael@0 19 'LOGNAME',
michael@0 20 # 'PATH' added below (but filtered).
michael@0 21 'PWD',
michael@0 22 'SHELL',
michael@0 23 'TEMP',
michael@0 24 'TMPDIR',
michael@0 25 'USER'
michael@0 26 )
michael@0 27
michael@0 28 # Need something to run.
michael@0 29 # TODO(lliabraa): Make this output a usage string and exit (here and below).
michael@0 30 assert(len(argv) > 0)
michael@0 31
michael@0 32 add_to_path = [];
michael@0 33 first_entry = argv[0];
michael@0 34 if first_entry.startswith('ADD_TO_PATH='):
michael@0 35 argv = argv[1:];
michael@0 36 add_to_path = first_entry.replace('ADD_TO_PATH=', '', 1).split(':')
michael@0 37
michael@0 38 # Still need something to run.
michael@0 39 assert(len(argv) > 0)
michael@0 40
michael@0 41 clean_env = {}
michael@0 42
michael@0 43 # Pull over the whitelisted keys.
michael@0 44 for key in env_key_whitelist:
michael@0 45 val = os.environ.get(key, None)
michael@0 46 if not val is None:
michael@0 47 clean_env[key] = val
michael@0 48
michael@0 49 # Collect the developer dir as set via Xcode, defaulting it.
michael@0 50 dev_prefix = os.environ.get('DEVELOPER_DIR', '/Developer/')
michael@0 51 if dev_prefix[-1:] != '/':
michael@0 52 dev_prefix += '/'
michael@0 53
michael@0 54 # Now pull in PATH, but remove anything Xcode might have added.
michael@0 55 initial_path = os.environ.get('PATH', '')
michael@0 56 filtered_chunks = \
michael@0 57 [x for x in initial_path.split(':') if not x.startswith(dev_prefix)]
michael@0 58 if filtered_chunks:
michael@0 59 clean_env['PATH'] = ':'.join(add_to_path + filtered_chunks)
michael@0 60
michael@0 61 # Add any KEY=VALUE args before the command to the cleaned environment.
michael@0 62 args = argv[:]
michael@0 63 while '=' in args[0]:
michael@0 64 (key, val) = args[0].split('=', 1)
michael@0 65 clean_env[key] = val
michael@0 66 args = args[1:]
michael@0 67
michael@0 68 # Still need something to run.
michael@0 69 assert(len(args) > 0)
michael@0 70
michael@0 71 # Off it goes...
michael@0 72 os.execvpe(args[0], args, clean_env)
michael@0 73 # Should never get here, so return a distinctive, non-zero status code.
michael@0 74 return 66
michael@0 75
michael@0 76 if __name__ == '__main__':
michael@0 77 sys.exit(Main(sys.argv[1:]))

mercurial