def environment_modifications_for_spec(spec, view=None):
    """List of environment (shell) modifications to be processed for spec.

    This list is specific to the location of the spec or its projection in
    the view."""
    spec = spec.copy()
    if view and not spec.external:
        spec.prefix = prefix.Prefix(view.view().get_projection_for_spec(spec))

    # generic environment modifications determined by inspecting the spec
    # prefix
    env = environment.inspect_path(
        spec.prefix,
        prefix_inspections(spec.platform),
        exclude=environment.is_system_path
    )

    # Let the extendee/dependency modify their extensions/dependents
    # before asking for package-specific modifications
    env.extend(
        build_env.modifications_from_dependencies(
            spec, context='run'
        )
    )

    # Package specific modifications
    build_env.set_module_variables_for_package(spec.package)
    spec.package.setup_run_environment(env)

    return env
def test_inspect_path(tmpdir):
    inspections = {
        'bin': ['PATH'],
        'man': ['MANPATH'],
        'share/man': ['MANPATH'],
        'share/aclocal': ['ACLOCAL_PATH'],
        'lib': ['LIBRARY_PATH', 'LD_LIBRARY_PATH'],
        'lib64': ['LIBRARY_PATH', 'LD_LIBRARY_PATH'],
        'include': ['CPATH'],
        'lib/pkgconfig': ['PKG_CONFIG_PATH'],
        'lib64/pkgconfig': ['PKG_CONFIG_PATH'],
        'share/pkgconfig': ['PKG_CONFIG_PATH'],
        '': ['CMAKE_PREFIX_PATH']
    }

    tmpdir.mkdir('bin')
    tmpdir.mkdir('lib')
    tmpdir.mkdir('include')

    env = environment.inspect_path(str(tmpdir), inspections)
    names = [item.name for item in env]
    assert 'PATH' in names
    assert 'LIBRARY_PATH' in names
    assert 'LD_LIBRARY_PATH' in names
    assert 'CPATH' in names
def test_exclude_paths_from_inspection():
    inspections = {
        'lib': ['LIBRARY_PATH', 'LD_LIBRARY_PATH'],
        'lib64': ['LIBRARY_PATH', 'LD_LIBRARY_PATH'],
        'include': ['CPATH']
    }

    env = environment.inspect_path('/usr', inspections, exclude=is_system_path)

    assert len(env) == 0
Esempio n. 4
0
def environment_modifications_for_spec(spec,
                                       view=None,
                                       set_package_py_globals=True):
    """List of environment (shell) modifications to be processed for spec.

    This list is specific to the location of the spec or its projection in
    the view.

    Args:
        spec (spack.spec.Spec): spec for which to list the environment modifications
        view: view associated with the spec passed as first argument
        set_package_py_globals (bool): whether or not to set the global variables in the
            package.py files (this may be problematic when using buildcaches that have
            been built on a different but compatible OS)
    """
    spec = spec.copy()
    if view and not spec.external:
        spec.prefix = prefix.Prefix(view.get_projection_for_spec(spec))

    # generic environment modifications determined by inspecting the spec
    # prefix
    env = environment.inspect_path(spec.prefix,
                                   prefix_inspections(spec.platform),
                                   exclude=environment.is_system_path)

    # Let the extendee/dependency modify their extensions/dependents
    # before asking for package-specific modifications
    env.extend(
        spack.build_environment.modifications_from_dependencies(
            spec, context='run',
            set_package_py_globals=set_package_py_globals))

    if set_package_py_globals:
        spack.build_environment.set_module_variables_for_package(spec.package)

    spec.package.setup_run_environment(env)

    return env