Пример #1
0
def test_fetch(mock_archive, secure, _fetch_method, checksum_type, config,
               mutable_mock_repo):
    """Fetch an archive and make sure we can checksum it."""
    mock_archive.url
    mock_archive.path

    algo = crypto.hash_fun_for_algo(checksum_type)()
    with open(mock_archive.archive_file, 'rb') as f:
        algo.update(f.read())
    checksum = algo.hexdigest()

    # Get a spec and tweak the test package with new chcecksum params
    spec = Spec('url-test')
    spec.concretize()

    pkg = spack.repo.get('url-test')
    pkg.url = mock_archive.url
    pkg.versions[ver('test')] = {checksum_type: checksum, 'url': pkg.url}
    pkg.spec = spec

    # Enter the stage directory and check some properties
    with pkg.stage:
        with spack.config.override('config:verify_ssl', secure):
            with spack.config.override('config:url_fetch_method',
                                       _fetch_method):
                pkg.do_stage()
        with working_dir(pkg.stage.source_path):
            assert os.path.exists('configure')
            assert is_exe('configure')

            with open('configure') as f:
                contents = f.read()
            assert contents.startswith('#!/bin/sh')
            assert 'echo Building...' in contents
Пример #2
0
def check_sbang_installation():
    sbang_path = sbang.sbang_install_path()
    sbang_bin_dir = os.path.dirname(sbang_path)
    assert sbang_path.startswith(spack.store.store.unpadded_root)

    assert os.path.exists(sbang_path)
    assert fs.is_exe(sbang_path)

    status = os.stat(sbang_path)
    assert (status.st_mode & 0o777) == 0o755

    status = os.stat(sbang_bin_dir)
    assert (status.st_mode & 0o777) == 0o755
Пример #3
0
 def cmake_args(self):
     spec = self.spec
     args = [
         "-DWITH_CPU_BACKEND:Bool=TRUE",
         # TODO: no ROCm stuff available in spack yet
         "-DWITH_ROCM_BACKEND:Bool=FALSE",
         "-DWITH_CUDA_BACKEND:Bool={0}".format("TRUE" if "+cuda" in
                                               spec else "FALSE"),
         # prevent hipSYCL's cmake to look for other LLVM installations
         # if the specified one isn't compatible
         "-DDISABLE_LLVM_VERSION_CHECK:Bool=TRUE",
     ]
     # LLVM directory containing all installed CMake files
     # (e.g.: configs consumed by client projects)
     llvm_cmake_dirs = filesystem.find(spec["llvm"].prefix,
                                       "LLVMExports.cmake")
     if len(llvm_cmake_dirs) != 1:
         raise InstallError("concretized llvm dependency must provide "
                            "a unique directory containing CMake client "
                            "files, found: {0}".format(llvm_cmake_dirs))
     args.append("-DLLVM_DIR:String={0}".format(
         path.dirname(llvm_cmake_dirs[0])))
     # clang internal headers directory
     llvm_clang_include_dirs = filesystem.find(
         spec["llvm"].prefix, "__clang_cuda_runtime_wrapper.h")
     if len(llvm_clang_include_dirs) != 1:
         raise InstallError(
             "concretized llvm dependency must provide a "
             "unique directory containing clang internal "
             "headers, found: {0}".format(llvm_clang_include_dirs))
     args.append("-DCLANG_INCLUDE_PATH:String={0}".format(
         path.dirname(llvm_clang_include_dirs[0])))
     # target clang++ executable
     llvm_clang_bin = path.join(spec["llvm"].prefix.bin, "clang++")
     if not filesystem.is_exe(llvm_clang_bin):
         raise InstallError("concretized llvm dependency must provide a "
                            "valid clang++ executable, found invalid: "
                            "{0}".format(llvm_clang_bin))
     args.append(
         "-DCLANG_EXECUTABLE_PATH:String={0}".format(llvm_clang_bin))
     # explicit CUDA toolkit
     if "+cuda" in spec:
         args.append("-DCUDA_TOOLKIT_ROOT_DIR:String={0}".format(
             spec["cuda"].prefix))
     return args
Пример #4
0
def check_sbang_installation(group=False):
    sbang_path = sbang.sbang_install_path()
    sbang_bin_dir = os.path.dirname(sbang_path)
    assert sbang_path.startswith(spack.store.store.unpadded_root)

    assert os.path.exists(sbang_path)
    assert fs.is_exe(sbang_path)

    status = os.stat(sbang_bin_dir)
    mode = (status.st_mode & 0o777)
    if group:
        assert mode == 0o775, 'Unexpected {0}'.format(oct(mode))
    else:
        assert mode == 0o755, 'Unexpected {0}'.format(oct(mode))

    status = os.stat(sbang_path)
    mode = (status.st_mode & 0o777)
    if group:
        assert mode == 0o775, 'Unexpected {0}'.format(oct(mode))
    else:
        assert mode == 0o755, 'Unexpected {0}'.format(oct(mode))
Пример #5
0
def test_fetch(
        mock_archive,
        secure,
        checksum_type,
        config,
        mutable_mock_packages
):
    """Fetch an archive and make sure we can checksum it."""
    mock_archive.url
    mock_archive.path

    algo = crypto.hash_fun_for_algo(checksum_type)()
    with open(mock_archive.archive_file, 'rb') as f:
        algo.update(f.read())
    checksum = algo.hexdigest()

    # Get a spec and tweak the test package with new chcecksum params
    spec = Spec('url-test')
    spec.concretize()

    pkg = spack.repo.get('url-test')
    pkg.url = mock_archive.url
    pkg.versions[ver('test')] = {checksum_type: checksum, 'url': pkg.url}
    pkg.spec = spec

    # Enter the stage directory and check some properties
    with pkg.stage:
        with spack.config.override('config:verify_ssl', secure):
            pkg.do_stage()

        with working_dir(pkg.stage.source_path):
            assert os.path.exists('configure')
            assert is_exe('configure')

            with open('configure') as f:
                contents = f.read()
            assert contents.startswith('#!/bin/sh')
            assert 'echo Building...' in contents
Пример #6
0
def test_fetch(mock_archive, secure, checksum_type, config,
               refresh_builtin_mock):
    """Fetch an archive and make sure we can checksum it."""
    mock_archive.url
    mock_archive.path

    algo = crypto.hashes[checksum_type]()
    with open(mock_archive.archive_file, 'rb') as f:
        algo.update(f.read())
    checksum = algo.hexdigest()

    # Get a spec and tweak the test package with new chcecksum params
    spec = Spec('url-test')
    spec.concretize()

    pkg = spack.repo.get('url-test', new=True)
    pkg.url = mock_archive.url
    pkg.versions[ver('test')] = {checksum_type: checksum, 'url': pkg.url}
    pkg.spec = spec

    # Enter the stage directory and check some properties
    with pkg.stage:
        try:
            spack.insecure = secure
            pkg.do_stage()
        finally:
            spack.insecure = False

        with working_dir(pkg.stage.source_path):
            assert os.path.exists('configure')
            assert is_exe('configure')

            with open('configure') as f:
                contents = f.read()
            assert contents.startswith('#!/bin/sh')
            assert 'echo Building...' in contents
Пример #7
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)