Source

envcc / envcc.py

Full commit
#!/usr/bin/env python
import re, os, sys
import subprocess

def getpath(program):
    proc = subprocess.Popen(["which", program], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    output,err = proc.communicate()
    if proc.returncode == 0:
        return os.path.dirname(output.strip())
    return None
def usage():
    print 'envcc <program> +|-<program>'
    print ''

if len(sys.argv) <= 1:
    usage()
    sys.exit(255)

preg = re.compile('(\+|\-)?([a-z]+)')

paths = {}
for arg in sys.argv[1:]:
    m = preg.match(arg)
    try:
        if m:
            p = m.group(2)
            if m.group(1) == '-' and p in paths:
                del paths[p]
            elif m.group(1) == '+':
                paths[p] = getpath(p)
            else:
                paths = {p: getpath(p)}
    except OSError:
        print 'Error occured'
print os.pathsep.join(paths.values())