Example #1
0
def setup_package(pkg, dirty, context='build'):
    """Execute all environment setup routines."""
    env = EnvironmentModifications()

    if not dirty:
        clean_environment()

    # setup compilers and build tools for build contexts
    need_compiler = context == 'build' or (context == 'test'
                                           and pkg.test_requires_compiler)
    if need_compiler:
        set_compiler_environment_variables(pkg, env)
        set_build_environment_variables(pkg, env, dirty)

    # architecture specific setup
    pkg.architecture.platform.setup_platform_environment(pkg, env)

    if context == 'build':
        # recursive post-order dependency information
        env.extend(modifications_from_dependencies(pkg.spec, context=context))

        if (not dirty) and (not env.is_unset('CPATH')):
            tty.debug("A dependency has updated CPATH, this may lead pkg-"
                      "config to assume that the package is part of the system"
                      " includes and omit it when invoked with '--cflags'.")

        # setup package itself
        set_module_variables_for_package(pkg)
        pkg.setup_build_environment(env)
    elif context == 'test':
        import spack.user_environment as uenv  # avoid circular import
        env.extend(uenv.environment_modifications_for_spec(pkg.spec))
        env.extend(modifications_from_dependencies(pkg.spec, context=context))
        set_module_variables_for_package(pkg)
        env.prepend_path('PATH', '.')

    # Loading modules, in particular if they are meant to be used outside
    # of Spack, can change environment variables that are relevant to the
    # build of packages. To avoid a polluted environment, preserve the
    # value of a few, selected, environment variables
    # With the current ordering of environment modifications, this is strictly
    # unnecessary. Modules affecting these variables will be overwritten anyway
    with preserve_environment('CC', 'CXX', 'FC', 'F77'):
        # All module loads that otherwise would belong in previous
        # functions have to occur after the env object has its
        # modifications applied. Otherwise the environment modifications
        # could undo module changes, such as unsetting LD_LIBRARY_PATH
        # after a module changes it.
        if need_compiler:
            for mod in pkg.compiler.modules:
                # Fixes issue https://github.com/spack/spack/issues/3153
                if os.environ.get("CRAY_CPU_TARGET") == "mic-knl":
                    load_module("cce")
                load_module(mod)

        # kludge to handle cray libsci being automatically loaded by PrgEnv
        # modules on cray platform. Module unload does no damage when
        # unnecessary
        module('unload', 'cray-libsci')

        if pkg.architecture.target.module_name:
            load_module(pkg.architecture.target.module_name)

        load_external_modules(pkg)

    implicit_rpaths = pkg.compiler.implicit_rpaths()
    if implicit_rpaths:
        env.set('SPACK_COMPILER_IMPLICIT_RPATHS', ':'.join(implicit_rpaths))

    # Make sure nothing's strange about the Spack environment.
    validate(env, tty.warn)
    env.apply_modifications()
Example #2
0
 def add_default_view_to_shell(self, shell):
     env_mod = EnvironmentModifications()
     for var, paths in self._shell_vars():
         for path in paths:
             env_mod.prepend_path(var, path)
     return env_mod.shell_modifications(shell)