Exemplo n.º 1
0
def test_subst_returns_unmodified():
    bs = BS(some="value")
    fixture = "this string needs no subst"
    result = subst(bs, fixture, for_command=True)
    assert result == fixture.split()

    result = subst(bs, "this string needs no subst")
    assert result == fixture
Exemplo n.º 2
0
def test_subst_callable_cannot_mutate_build_state():
    def mutator(bs):
        bs["MUTATED"] = True

    bs = BS(MUTATOR=mutator)
    try:
        subst(bs, "$MUTATOR")
        assert False, "MUTATOR mutated the build state!"
    except TypeError:
        pass
Exemplo n.º 3
0
def test_subst_self_referential():
    bs = BS(CC="gcc",
            CCFLAGS=["-gsplit-dwarf", "-Werror", "-Wall"],
            LINKFLAGS="$CCFLAGS")

    result = subst(bs, "$CC $CCFLAGS $LINKFLAGS", for_command=True)
    assert result == [
        "gcc",
        "-gsplit-dwarf",
        "-Werror",
        "-Wall",
        "-gsplit-dwarf",
        "-Werror",
        "-Wall",
    ]
Exemplo n.º 4
0
def test_subst_generate_real_command():
    bs = BS(
        CC="gcc",
        CCFLAGS=["-gsplit-dwarf", "-Werror", "-Wall"],
    )

    s = "$CC -o $target $CCFLAGS $LINKFLAGS $sources"
    result = subst(bs, s, targets=["foo"], sources=["foo.c"], for_command=True)
    assert result == [
        "gcc",
        "-o",
        "foo",
        "-gsplit-dwarf",
        "-Werror",
        "-Wall",
        "foo.c",
    ]
Exemplo n.º 5
0
def test_subst_callable():
    def include_paths(bs):
        include_flags = [
            "-I{}".format(subst(bs, path, for_command=False))
            for path in bs.get("CPATH", [])
        ]
        return include_flags

    def recursive_callable(bs):
        return "$RECURSED"

    bs = BS(
        CC_COMMAND=
        "$CC $_INCLUDES $CCFLAGS -o $target $sources $recursive_callable",
        _INCLUDES=include_paths,
        recursive_callable=recursive_callable,
        RECURSED=True,
        BUILD_DIR="build",
        CPATH=["$BUILD_DIR", "/usr/local/include"],
        CC="gcc",
    )

    result = subst(bs,
                   "$CC_COMMAND",
                   for_command=True,
                   targets=["foo"],
                   sources=["foo.c"])
    assert result == [
        "gcc",
        "-Ibuild",
        "-I/usr/local/include",
        "-o",
        "foo",
        "foo.c",
        "True",
    ]
Exemplo n.º 6
0
 def subst(self, s):
     return subst(self, s, for_command=False)
Exemplo n.º 7
0
 def subst_command(self, s, targets=None, sources=None):
     return subst(self, s, for_command=True, targets=targets, sources=sources)
Exemplo n.º 8
0
 def include_paths(bs):
     include_flags = [
         "-I{}".format(subst(bs, path, for_command=False))
         for path in bs.get("CPATH", [])
     ]
     return include_flags
Exemplo n.º 9
0
def test_subst_mixed_string_and_list_variables():
    bs = BS(CC="gcc", CCFLAGS=["-gsplit-dwarf", "-Werror", "-Wall"])

    result = subst(bs, "$CC $CCFLAGS", for_command=True)
    assert result == ["gcc", "-gsplit-dwarf", "-Werror", "-Wall"]
Exemplo n.º 10
0
def test_subst_only_string_variables():
    bs = BS(foo="FOO", bar="BAR", baz="BAZ")
    result = subst(bs, "$foo $baz $bar", for_command=True)
    assert result == ["FOO", "BAZ", "BAR"]