File: tag.py

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (132 lines) | stat: -rw-r--r-- 3,521 bytes parent folder | download | duplicates (5)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python3

# Copyright (C) 2003. Pedro Ferreira
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or copy at
# https://www.bfgroup.xyz/b2/LICENSE.txt)

import BoostBuild

import re
from functools import reduce

###############################################################################
#
# test_folder_with_dot_in_name()
# ------------------------------
#
###############################################################################

def test_folder_with_dot_in_name(t):
    """
      Regression test: the 'tag' feature did not work in directories that had a
    dot in their name.

    """
    t.write("version-1.32.0/jamroot.jam", """\
project test : requirements <tag>@$(__name__).tag ;

rule tag ( name : type ? : property-set )
{
   # Do nothing, just make sure the rule is invoked OK.
   ECHO The tag rule has been invoked. ;
}
exe a : a.cpp ;
""")
    t.write("version-1.32.0/a.cpp", "int main() {}\n")

    t.run_build_system(subdir="version-1.32.0")
    t.expect_addition("version-1.32.0/bin/$toolset/debug*/a.exe")
    t.expect_output_lines("The tag rule has been invoked.")


###############################################################################
#
# test_tag_property()
# -------------------
#
###############################################################################

def test_tag_property(t):
    """Basic tag property test."""

    t.write("jamroot.jam", """\
import virtual-target ;

rule tag ( name : type ? : property-set )
{
    local tags ;
    switch [ $(property-set).get <variant> ]
    {
        case debug   : tags += d ;
        case release : tags += r ;
    }
    switch [ $(property-set).get <link> ]
    {
        case shared : tags += s ;
        case static : tags += t ;
    }
    switch $(type)
    {
        case SHARED_LIB : tags += _dll ;
        case STATIC_LIB : tags += _lib ;
        case EXE        : tags += _exe ;
    }
    if $(tags)
    {
        return [ virtual-target.add-prefix-and-suffix $(name)_$(tags:J="")
            : $(type) : $(property-set) ] ;
    }
}

# Test both fully-qualified and local name of the rule
exe a : a.cpp : <tag>@$(__name__).tag ;
lib b : a.cpp : <tag>@tag ;
stage c : a ;
""")

    t.write("a.cpp", """\
int main() {}
""")

    file_list = {
        "bin/$toolset/debug*/a_ds_exe.exe",
        "bin/$toolset/debug*/b_ds_dll.dll",
        "c/a_ds_exe.exe",
        "bin/$toolset/release*/a_rs_exe.exe",
        "bin/$toolset/release*/b_rs_dll.dll",
        "c/a_rs_exe.exe",
        "bin/$toolset/debug*/a_dt_exe.exe",
        "bin/$toolset/debug*/b_dt_lib.lib",
        "c/a_dt_exe.exe",
        "bin/$toolset/release*/a_rt_exe.exe",
        "bin/$toolset/release*/b_rt_lib.lib",
        "c/a_rt_exe.exe",
    }
    if t.is_pdb_expected():
        file_list |= {re.sub(r'(_\w*d\w*)\.(exe|dll)$', r'\1.pdb', file)
                      for file in file_list}
    file_list = list(reduce(lambda x, y: x+y, map(BoostBuild.List, file_list)))

    variants = ["debug", "release", "link=static,shared", "debug-symbols=on"]

    t.run_build_system(variants)
    t.expect_addition(file_list)

    t.run_build_system(variants + ["clean"])
    t.expect_removal(file_list)


###############################################################################
#
# main()
# ------
#
###############################################################################

t = BoostBuild.Tester(use_test_config=False)

test_tag_property(t)
test_folder_with_dot_in_name(t)

t.cleanup()