[Scons-users] Dependencies and Pseudo Builders

Michał Palczewski michal.palczewski at gmail.com
Sun Sep 6 19:30:31 EDT 2020


Hi Everybody!
At the very beginning, I would like to say Hello! to everybody, I'm a
newbie here :-D

But let's go to the point. Frankly speaking I need some help to write
correct and SConsy idiomatic SConstruct to generate, build, and run unit
tests. The entire flow is as follows:

1) Generate Unity 'test_runner' code - I use provided Unity test runner
generator, it's Ruby script
2) Build Program, where the code generated in point 1 is one of the input
source files
3) Run the Program that has been build in point 2
4) Get the results and start Python script to analyze the results.

Generally, I think I know (or not....) how to perform each action, but I
cannot ling all of them together to force the correct order of those steps.

Let's describe my ideas:

Point 1)
To do Point1 I've made a PseudoBuilder (basing on:
https://scons.org/doc/production/HTML/scons-user/ch20.html)

    def generate_runner(env, test, test_runner):
        os.makedirs(os.path.dirname(test_runner), exist_ok=True)
        env.Execute(f"ruby {env['UNITY_DIR']}/auto/generate_test_runner.rb
{test} {test_runner}")
        return SCons.Node.FS.FS().File(test_runner)
...
env.AddMethod(generate_runner, "GenerateRunner")

Is it Execute correct here?

Point 2)
To do Point2 I've used build-in Builder combined by dependency with my own
one:

runner = env.GenerateRunner('test_case_source", "test_case_runner.c")
program = env.Program(name="test_case_name", souces=['test_case_source.c',
'test_case_runner.c']

env.Depends(program, runner)

And until this Point everything seems to be working correctly.
In fact, all files from Point 1 are generated in single run but it always
happens before Point 2,

.e.g.:
ruby
ruby
ruby
gcc
gcc
gcc

when I would expect (doubtfully?):
ruby
gcc
ruby
gcc
ruby
gcc

but I stop thinking about that because it generally works

Point 3)
There a problem appears, I've written following pseudo builder:

    def run_test(env, path):
        try:
            process_output = subprocess.run([path], check=True,
stdout=subprocess.PIPE, universal_newlines=True).stdout
        except subprocess.CalledProcessError as e:
            process_output = e.output

        return process_output

As you can see there is no created any files, all results of the call is
stored in memory. So I just need to return that results.
But if I add it to env:
test_result = env.RunTest(path)
env.Depend(test_result, program)
then that builder is called too early (before source code is built) and I
have no idea how to make a correct dependency between Program from Point2
and it's run in Point3. I suppose that builder should return something from
SCons env but I have no idea what it should be.


Could you please help me to do it correctly?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20200907/ac6a1ac4/attachment.html>


More information about the Scons-users mailing list