Пример #1
0
def load(parser, args):
    env = ev.active_environment()

    if args.list:
        results = spack.cmd.filter_loaded_specs(args.specs())
        if sys.stdout.isatty():
            spack.cmd.print_how_many_pkgs(results, "loaded")
        spack.cmd.display_specs(results)
        return

    specs = [spack.cmd.disambiguate_spec(spec, env, first=args.load_first)
             for spec in spack.cmd.parse_specs(args.constraint)]

    if not args.shell:
        specs_str = ' '.join(args.constraint) or "SPECS"
        spack.cmd.common.shell_init_instructions(
            "spack load",
            "    eval `spack load {sh_arg} %s`" % specs_str,
        )
        return 1

    with spack.store.db.read_transaction():
        if 'dependencies' in args.things_to_load:
            include_roots = 'package' in args.things_to_load
            specs = [dep for spec in specs
                     for dep in
                     spec.traverse(root=include_roots, order='post')]

        env_mod = spack.util.environment.EnvironmentModifications()
        for spec in specs:
            env_mod.extend(uenv.environment_modifications_for_spec(spec))
            env_mod.prepend_path(uenv.spack_loaded_hashes_var, spec.dag_hash())
        cmds = env_mod.shell_modifications(args.shell)

        sys.stdout.write(cmds)
Пример #2
0
Файл: load.py Проект: eic/spack
def load(parser, args):
    env = ev.get_env(args, 'load')
    specs = [
        spack.cmd.disambiguate_spec(spec, env, first=args.load_first)
        for spec in spack.cmd.parse_specs(args.specs)
    ]

    if not args.shell:
        specs_str = ' '.join(args.specs) or "SPECS"
        spack.cmd.common.shell_init_instructions(
            "spack load",
            "    eval `spack load {sh_arg}` %s" % specs_str,
        )
        return 1

    with spack.store.db.read_transaction():
        if 'dependencies' in args.things_to_load:
            include_roots = 'package' in args.things_to_load
            specs = [
                dep for spec in specs
                for dep in spec.traverse(root=include_roots, order='post')
            ]

        env_mod = spack.util.environment.EnvironmentModifications()
        for spec in specs:
            env_mod.extend(uenv.environment_modifications_for_spec(spec))
            env_mod.prepend_path(uenv.spack_loaded_hashes_var, spec.dag_hash())
        cmds = env_mod.shell_modifications(args.shell)

        sys.stdout.write(cmds)
Пример #3
0
def unload(parser, args):
    """Unload spack packages from the user environment."""
    if args.specs and args.all:
        raise spack.error.SpackError("Cannot specify specs on command line"
                                     " when unloading all specs with '--all'")

    hashes = os.environ.get(uenv.spack_loaded_hashes_var, '').split(':')
    if args.specs:
        specs = [
            spack.cmd.disambiguate_spec_from_hashes(spec, hashes)
            for spec in spack.cmd.parse_specs(args.specs)
        ]
    else:
        specs = spack.store.db.query(hashes=hashes)

    if not args.shell:
        specs_str = ' '.join(args.specs) or "SPECS"

        spack.cmd.common.shell_init_instructions(
            "spack unload",
            "    eval `spack unload {sh_arg}` %s" % specs_str,
        )
        return 1

    env_mod = spack.util.environment.EnvironmentModifications()
    for spec in specs:
        env_mod.extend(
            uenv.environment_modifications_for_spec(spec).reversed())
        env_mod.remove_path(uenv.spack_loaded_hashes_var, spec.dag_hash())
    cmds = env_mod.shell_modifications(args.shell)

    sys.stdout.write(cmds)
Пример #4
0
def load(parser, args):
    env = ev.get_env(args, 'load')
    specs = [
        spack.cmd.disambiguate_spec(spec, env)
        for spec in spack.cmd.parse_specs(args.specs)
    ]

    if not args.shell:
        msg = [
            "This command works best with Spack's shell support", ""
        ] + spack.cmd.common.shell_init_instructions + [
            'Or, if you want to use `spack load` without initializing',
            'shell support, you can run one of these:',
            '',
            '    eval `spack load --sh %s`   # for bash/sh' % args.specs,
            '    eval `spack load --csh %s`  # for csh/tcsh' % args.specs,
        ]
        tty.msg(*msg)
        return 1

    with spack.store.db.read_transaction():
        if 'dependencies' in args.things_to_load:
            include_roots = 'package' in args.things_to_load
            specs = [
                dep for spec in specs
                for dep in spec.traverse(root=include_roots, order='post')
            ]

        env_mod = spack.util.environment.EnvironmentModifications()
        for spec in specs:
            env_mod.extend(uenv.environment_modifications_for_spec(spec))
            env_mod.prepend_path(uenv.spack_loaded_hashes_var, spec.dag_hash())
        cmds = env_mod.shell_modifications(args.shell)

        sys.stdout.write(cmds)
Пример #5
0
 def install(self, spec, prefix):
     """ Create bash setup script in prefix."""
     # first, log spack version to build-out
     tty.msg('* **Spack:**', get_version())
     tty.msg('* **Python:**', platform.python_version())
     tty.msg(
         '* **Platform:**',
         architecture.Arch(architecture.platform(), 'frontend', 'frontend'))
     # get all dependency specs, including compiler
     with spack.store.db.read_transaction():
         specs = [dep for dep in spec.traverse(order='post')]
     # record all changes to the environment by packages in the stack
     env_mod = spack.util.environment.EnvironmentModifications()
     # first setup compiler, similar to build_environment.py in spack
     compiler = self.compiler
     if compiler.cc:
         env_mod.set('CC', compiler.cc)
     if compiler.cxx:
         env_mod.set('CXX', compiler.cxx)
     if compiler.f77:
         env_mod.set('F77', compiler.f77)
     if compiler.fc:
         env_mod.set('FC', compiler.fc)
     compiler.setup_custom_environment(self, env_mod)
     env_mod.prepend_path('PATH', os.path.dirname(compiler.cxx))
     # now setup all other packages
     for _spec in specs:
         env_mod.extend(uenv.environment_modifications_for_spec(_spec))
         env_mod.prepend_path(uenv.spack_loaded_hashes_var,
                              _spec.dag_hash())
     # transform to bash commands, and write to file
     cmds = k4_generate_setup_script(env_mod)
     with open(os.path.join(prefix, "setup.sh"), "w") as f:
         f.write(cmds)
         # optionally add a symlink (location configurable via environment variable
         # K4_LATEST_SETUP_PATH. Step will be skipped if it is empty)
         try:
             symlink_path = os.environ.get("K4_LATEST_SETUP_PATH", "")
             if symlink_path:
                 # make sure that the path exists, create if not
                 if not os.path.exists(os.path.dirname(symlink_path)):
                     os.makedirs(os.path.dirname(symlink_path))
                 # make sure that an existing file will be overwritten,
                 # even if it is a symlink (for which 'exists' is false!)
                 if os.path.exists(symlink_path) or os.path.islink(
                         symlink_path):
                     os.remove(symlink_path)
                 os.symlink(os.path.join(prefix, "setup.sh"), symlink_path)
         except:
             tty.warn("Could not create symlink")
Пример #6
0
 def install(self, spec, prefix):
     """ Create bash setup script in prefix."""
     # first, log spack version to build-out
     tty.msg('* **Spack:**', get_version())
     tty.msg('* **Python:**', platform.python_version())
     tty.msg(
         '* **Platform:**',
         architecture.Arch(architecture.platform(), 'frontend', 'frontend'))
     # get all dependency specs, including compiler
     with spack.store.db.read_transaction():
         specs = [dep for dep in spec.traverse(order='post')]
         try:
             gcc_spec = spack.cmd.disambiguate_spec(str(spec.compiler),
                                                    None,
                                                    first=True)
             gcc_specs = [dep for dep in gcc_spec.traverse(order='post')]
             specs = specs + gcc_specs
         except:
             tty.warn("No spec found for " + str(spec.compiler) +
                      ". Assuming it is a system compiler,"
                      "not adding it to the setup.")
     # record all changes to the environment by packages in the stack
     env_mod = spack.util.environment.EnvironmentModifications()
     for _spec in specs:
         env_mod.extend(uenv.environment_modifications_for_spec(_spec))
         env_mod.prepend_path(uenv.spack_loaded_hashes_var,
                              _spec.dag_hash())
     # transform to bash commands, and write to file
     cmds = k4_generate_setup_script(env_mod)
     with open(os.path.join(prefix, "setup.sh"), "w") as f:
         f.write(cmds)
         # optionally add a symlink (location configurable via environment variable
         # K4_LATEST_SETUP_PATH. Step will be skipped if it is empty)
         try:
             symlink_path = os.environ.get("K4_LATEST_SETUP_PATH", "")
             if symlink_path:
                 # make sure that the path exists, create if not
                 if not os.path.exists(os.path.dirname(symlink_path)):
                     os.makedirs(os.path.dirname(symlink_path))
                 # make sure that an existing file will be overwritten,
                 # even if it is a symlink (for which 'exists' is false!)
                 if os.path.exists(symlink_path) or os.path.islink(
                         symlink_path):
                     os.remove(symlink_path)
                 os.symlink(os.path.join(prefix, "setup.sh"), symlink_path)
         except:
             tty.warn("Could not create symlink")
Пример #7
0
    def install(self, spec, prefix):
      """ Create bash setup script in prefix."""

      # first, log spack version to build-out

      tty.msg('* **Spack:**', get_version())
      tty.msg('* **Python:**', platform.python_version())
      tty.msg('* **Platform:**', architecture.Arch(
          architecture.platform(), 'frontend', 'frontend'))


      specs = [spec]
      with spack.store.db.read_transaction():
               specs = [dep for _spec in specs
                        for dep in
                        _spec.traverse( order='post')]
               try: 
                   gcc_specs = [spack.cmd.disambiguate_spec(str(spec.compiler), None, first=True)]
                   gcc_specs = [dep for _spec in gcc_specs
                            for dep in
                            _spec.traverse( order='post')]
                   specs = specs + gcc_specs
               except:
                   tty.warn("No spec found for " + str(spec.compiler) + " Assuming it is a system compiler and not adding it to the setup.")
      env_mod = spack.util.environment.EnvironmentModifications()
      for _spec in specs:
          env_mod.extend(uenv.environment_modifications_for_spec(_spec))
          env_mod.prepend_path(uenv.spack_loaded_hashes_var, _spec.dag_hash())
      cmds = k4_generate_setup_script(env_mod)
      with open(os.path.join(prefix, "setup.sh"), "w") as f:
        f.write(cmds)
        try:
          symlink_path = os.environ.get("K4_LATEST_SETUP_PATH", "")
          if symlink_path:
              if not os.path.exists(os.path.dirname(symlink_path)):
                os.makedirs(os.path.dirname(symlink_path))
              if os.path.exists(symlink_path) or os.path.islink(symlink_path):
                os.remove(symlink_path)
              os.symlink(os.path.join(prefix, "setup.sh"), symlink_path)
        except:
          tty.warn("Could not create symlink")
Пример #8
0
def unload(parser, args):
    """Unload spack packages from the user environment."""
    if args.specs and args.all:
        raise spack.error.SpackError("Cannot specify specs on command line"
                                     " when unloading all specs with '--all'")

    hashes = os.environ.get(uenv.spack_loaded_hashes_var, '').split(':')
    if args.specs:
        specs = [
            spack.cmd.disambiguate_spec_from_hashes(spec, hashes)
            for spec in spack.cmd.parse_specs(args.specs)
        ]
    else:
        specs = spack.store.db.query(hashes=hashes)

    if not args.shell:
        msg = [
            "This command works best with Spack's shell support", ""
        ] + spack.cmd.common.shell_init_instructions + [
            'Or, if you want to use `spack unload` without initializing',
            'shell support, you can run one of these:',
            '',
            '    eval `spack unload --sh %s`   # for bash/sh' % args.specs,
            '    eval `spack unload --csh %s`  # for csh/tcsh' % args.specs,
        ]
        tty.msg(*msg)
        return 1

    env_mod = spack.util.environment.EnvironmentModifications()
    for spec in specs:
        env_mod.extend(
            uenv.environment_modifications_for_spec(spec).reversed())
        env_mod.remove_path(uenv.spack_loaded_hashes_var, spec.dag_hash())
    cmds = env_mod.shell_modifications(args.shell)

    sys.stdout.write(cmds)
Пример #9
0
def get_executable(exe, spec=None, install=False):
    """Find an executable named exe, either in PATH or in Spack

    Args:
        exe (str): needed executable name
        spec (Spec or str): spec to search for exe in (default exe)
        install (bool): install spec if not available

    When ``install`` is True, Spack will use the python used to run Spack as an
    external. The ``install`` option should only be used with packages that
    install quickly (when using external python) or are guaranteed by Spack
    organization to be in a binary mirror (clingo)."""
    # Search the system first
    runner = spack.util.executable.which(exe)
    if runner:
        return runner

    # Check whether it's already installed
    spec = spack.spec.Spec(spec or exe)
    installed_specs = spack.store.db.query(spec, installed=True)
    for ispec in installed_specs:
        # filter out directories of the same name as the executable
        exe_path = [exe_p for exe_p in fs.find(ispec.prefix, exe)
                    if fs.is_exe(exe_p)]
        if exe_path:
            ret = spack.util.executable.Executable(exe_path[0])
            envmod = EnvironmentModifications()
            for dep in ispec.traverse(root=True, order='post'):
                envmod.extend(uenv.environment_modifications_for_spec(dep))
            ret.add_default_envmod(envmod)
            return ret
        else:
            tty.warn('Exe %s not found in prefix %s' % (exe, ispec.prefix))

    def _raise_error(executable, exe_spec):
        error_msg = 'cannot find the executable "{0}"'.format(executable)
        if exe_spec:
            error_msg += ' from spec "{0}'.format(exe_spec)
        raise RuntimeError(error_msg)

    # If we're not allowed to install this for ourselves, we can't find it
    if not install:
        _raise_error(exe, spec)

    with spack_python_interpreter():
        # We will install for ourselves, using this python if needed
        # Concretize the spec
        spec.concretize()

    spec.package.do_install()
    # filter out directories of the same name as the executable
    exe_path = [exe_p for exe_p in fs.find(spec.prefix, exe)
                if fs.is_exe(exe_p)]
    if exe_path:
        ret = spack.util.executable.Executable(exe_path[0])
        envmod = EnvironmentModifications()
        for dep in spec.traverse(root=True, order='post'):
            envmod.extend(uenv.environment_modifications_for_spec(dep))
        ret.add_default_envmod(envmod)
        return ret

    _raise_error(exe, spec)
Пример #10
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()