summaryrefslogtreecommitdiffstats
path: root/test/TaskMaster/bug_2811/fixture_dir/SConstruct
blob: 1f8c3643053799a410e12c289a30a0dce5f196e1 (plain)
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
# SPDX-License-Identifier: MIT
#
# Copyright The SCons Foundation

"""
This issue requires the following.
1. Generated source file which outputs 2 (or more) files
2. Action string gets scanned providing only compiler as part of implicit scan
3. Generated file gets built. Without the bugfix only the first target's .implicit list is cleared.
4. builder/executor/action gets tried again and implicits scanned. 2nd to Nth targets end up 
   with the compiler at the beginning of the implicit list and the rest of the scanned files added to that list.
5. That bimplicit gets saved into sconsign
6. Second run loads sconsign, now with generated file present a regular implicit scan occurs. This yields 2nd through
   Nth target's implicit lists changing when compared to SConsign's which have been loaded.
7. This forces rebuild of source file and this propagates to massive recompile
"""
import sys
import SCons.Tool


def _dwo_emitter(target, source, env):
    new_targets = []
    for t in target:
        base, ext = SCons.Util.splitext(str(t))
        if not any(ext == env[osuffix] for osuffix in ['OBJSUFFIX', 'SHOBJSUFFIX']):
            continue
        # TODO: Move 'dwo' into DWOSUFFIX so it can be customized? For
        # now, GCC doesn't let you control the output filename, so it
        # doesn't matter.
        dwotarget = (t.builder.target_factory or env.File)(base + ".dwo")
        new_targets.append(dwotarget)
    targets = target + new_targets
    return (targets, source)

build_string = '$MYCOPY $SOURCE $TARGET'
bld = Builder(action=build_string)

DefaultEnvironment(tools=[])
env = Environment(BUILDERS={'Foo': bld}, MYCOPY="%s mycopy.py"%sys.executable)
env['SHCCCOM'] = '$MYCOPY $SOURCE $TARGET && $MYCOPY $SOURCE ${TARGETS[1]}'
env['SHCCCOMSTR'] = env['SHCCCOM']
suffixes = ['.c']

for object_builder in SCons.Tool.createObjBuilders(env):
    emitterdict = object_builder.builder.emitter
    for suffix in emitterdict.keys():
        if not suffix in suffixes:
            continue
        base = emitterdict[suffix]
        emitterdict[suffix] = SCons.Builder.ListEmitter([
            base,
            _dwo_emitter,
        ])

vs = ['a']

for v in vs:
    env.Foo('%s.c' % v, v)
    env.SharedObject('%s.c'%v)

env.Foo('b','b.in')
# seems like processing is always alphabetical..


# code: language=python insertSpaces=4 tabSize=4