def write_spconfig(package): # Set-up the environment spack.build_environment.setup_package(package) cmd = [str(which('cmake'))] + package.std_cmake_args + package.cmake_args() env = dict() paths = os.environ['PATH'].split(':') paths = [item for item in paths if 'spack/env' not in item] env['PATH'] = ':'.join(paths) env['SPACK_TRANSITIVE_INCLUDE_PATH'] = spack_transitive_include_path() env['CMAKE_PREFIX_PATH'] = os.environ['CMAKE_PREFIX_PATH'] env['CC'] = os.environ['SPACK_CC'] env['CXX'] = os.environ['SPACK_CXX'] env['FC'] = os.environ['SPACK_FC'] setup_fname = 'spconfig.py' with open(setup_fname, 'w') as fout: fout.write( r"""#!%s # import sys import os import subprocess def cmdlist(str): return list(x.strip().replace("'",'') for x in str.split('\n') if x) env = dict(os.environ) """ % sys.executable) env_vars = sorted(list(env.keys())) for name in env_vars: val = env[name] if string.find(name, 'PATH') < 0: fout.write('env[%s] = %s\n' % (repr(name), repr(val))) else: if name == 'SPACK_TRANSITIVE_INCLUDE_PATH': sep = ';' else: sep = ':' fout.write( 'env[%s] = "%s".join(cmdlist("""\n' % (repr(name), sep)) for part in string.split(val, sep): fout.write(' %s\n' % part) fout.write('"""))\n') fout.write('\ncmd = cmdlist("""\n') fout.write('%s\n' % cmd[0]) for arg in cmd[1:]: fout.write(' %s\n' % arg) fout.write('""") + sys.argv[1:]\n') fout.write('\nproc = subprocess.Popen(cmd, env=env)\nproc.wait()\n') set_executable(setup_fname)