summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/build_system_guess.py
blob: 97e357b8ebe1c696e5eb2c99b1aab96ea1ba2595 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import pytest

import spack.cmd.create
import spack.stage
import spack.util.executable
import spack.util.url as url_util


@pytest.fixture(
    scope="function",
    params=[
        ("configure", "autotools"),
        ("CMakeLists.txt", "cmake"),
        ("project.pro", "qmake"),
        ("pom.xml", "maven"),
        ("SConstruct", "scons"),
        ("waf", "waf"),
        ("argbah.rockspec", "lua"),
        ("setup.py", "python"),
        ("NAMESPACE", "r"),
        ("WORKSPACE", "bazel"),
        ("Makefile.PL", "perlmake"),
        ("Build.PL", "perlbuild"),
        ("foo.gemspec", "ruby"),
        ("Rakefile", "ruby"),
        ("setup.rb", "ruby"),
        ("GNUmakefile", "makefile"),
        ("makefile", "makefile"),
        ("Makefile", "makefile"),
        ("meson.build", "meson"),
        ("configure.py", "sip"),
        ("foobar", "generic"),
    ],
)
def url_and_build_system(request, tmpdir):
    """Sets up the resources to be pulled by the stage with
    the appropriate file name and returns their url along with
    the correct build-system guess
    """
    tar = spack.util.executable.which("tar")
    orig_dir = tmpdir.chdir()
    filename, system = request.param
    tmpdir.ensure("archive", filename)
    tar("czf", "archive.tar.gz", "archive")
    url = url_util.path_to_file_url(str(tmpdir.join("archive.tar.gz")))
    yield url, system
    orig_dir.chdir()


def test_build_systems(url_and_build_system):
    url, build_system = url_and_build_system
    with spack.stage.Stage(url) as stage:
        stage.fetch()
        guesser = spack.cmd.create.BuildSystemGuesser()
        guesser(stage, url)
        assert build_system == guesser.build_system