[Scons-users] Dependencies and Pseudo Builders

Bill Deegan bill at baddogconsulting.com
Mon Sep 7 11:05:34 EDT 2020


Greetings,

You've got a lot of things not correct.. ;)
But as a newbie.. to be expected.

What documents have you read?
Did you read the users guide?
(That's a good place to start)
Don't just start googling stuff and follow random stackoverflow pages..
you'll end up with a giant mess that probably doesn't work, probably isn't
correct even if it does work and zero understanding of how to do it
correctly.

See comments inline below.


On Sun, Sep 6, 2020 at 7:31 PM Michał Palczewski <
michal.palczewski at gmail.com> wrote:

> 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?
>

All the above is completely incorrect.
You want to create a builder here and not a psuedo builder.
You should (Almost) never use Execute.
You should (Almost) never have to explicitly create a File node.. Not sure
how you went down that path.
If there's some scons docs that lead you that way please let us know so we
can revise them.

See the user guide,  the man page, and also this wiki page
https://github.com/SCons/scons/wiki/ToolsForFools

Do you have to create many test running source files? (or just one, if just
one, then env.Command() will likely do the trick)



> 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
>

Another important point. DONT try to force order. The correct way to use
SCons (and really any build system), is to list dependencies. The tools
should connect the dots for you.

And if you have to use Depends() you're probably doing something wrong.

If you have a builder (which you should) which generates test_case_runner.c
from test_case_source, and you have
a Program() which has test_case_runner.c as a source. No need to do
anything else. SCons will figure that out.


> 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.
>

What do you want to do with the results?
Be explicit.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20200907/a723487e/attachment.html>


More information about the Scons-users mailing list