[Scons-users] Building generated code
Ale Strooisma
a.strooisma at student.utwente.nl
Thu Mar 10 07:26:35 EST 2016
Hi Bill & other readers,
I tried the following, where .build is my build directory as specified with
VariantDir:
gen = env.Program('gen', Glob('.build/gen/*.cpp') + common_source_files)
Ignore('.', gen)
but sadly this also causes 'scons -c' to ignore the target. The same
happens when I use Default to only build all other programs. I think this
is unavoidable with the way SCons works.
I also gave your single pass idea a try, but I did run into some trouble
trying that. I'll need to go into some more details:
Basically there are three steps:
1 - build common + generator code
2 - run code generator
3 - build generated code
Step 1 is triggered if the source code changes.
To trigger step 2, I made a file that is known to be generated depend on
the input files used to determine what must be generated and on the code
generator executable that is built in step 1, so new code is generated
whenever the source code or the input changes.
Step 3 is then triggered because its target depends on the source code that
is generated: if the generated code changes, it is rebuilt.
All generated code is placed into the directory gen, so I used the
following command to build the code, where .build is again my build
directory as specified with VariantDir:
gen = env.Program('gen', Glob('.build/gen/*.cpp') + common_source_files)
However, because Glob runs before the targets are built, it might not find
the right files as they are not generated yet. I also see no way of
specifying these files beforehand, because the generator determines which
files are generated in a rather complex way.
Because of this I don't think there is a way to do it in a single pass,
unless I change my generator to put everything into one file. If you know
of any other way to bypass this problem, I'd be glad to hear it.
Kind regards,
Ale
On 9 March 2016 at 17:23, Bill Deegan <bill at baddogconsulting.com> wrote:
> Ale,
>
>
>
> On Wed, Mar 9, 2016 at 3:48 AM, Ale Strooisma <
> a.strooisma at student.utwente.nl> wrote:
>
>> Hi Bill,
>>
>> Thanks for your response.
>>
>> To answer your questions: yes, I am running two passes (or more): first I
>> build the code generation framework. At some point the user runs it to
>> generate code, then builds the generated software.
>> The reason I am not doing this in one pass is that the code generation
>> step depends on user input - it is really a separate step, a user
>> interaction with the software, not part of the normal build process.
>>
>> A better solution than my if statement might be to set the Default
>> targets to all targets except gen. Downside is that whenever I add a target
>> I also need to add it to the defaults list, which is going to go wrong for
>> certain. Isn't there some kind of 'NoDefault' option or something similar?
>>
>
> Ignore() is somewhat equivalent, though you need to specify which target
> should ignore it's dependency.
>
> Perhaps it would make sense to have your user's input go to a file, and
> then that file run with your tools to generate code.
> Then code generation would only run when the file changes?
> Assuming that the code is always needed by your system?
>
>
>
>> Regarding your link: it is clear which files need to be built, so I don't
>> think it applies.
>>
> o.k.
>
> -Bill
>
>
>>
>> On 8 March 2016 at 23:28, Bill Deegan <bill at baddogconsulting.com> wrote:
>>
>>> Ale,
>>>
>>>
>>> On Tue, Mar 8, 2016 at 6:17 AM, Ale Strooisma <
>>> a.strooisma at student.utwente.nl> wrote:
>>>
>>>> Dear readers,
>>>>
>>>> my current project consists of two parts: a code generation framework
>>>> and a runtime framework that in part consists of code generated by the code
>>>> generation framework. Both also use some common parts. This architecture
>>>> causes some difficulties with building:
>>>>
>>>> 1. By default I want to build everything except the generated code -
>>>> because it might not be there. How would I do that? Currently I have put
>>>> the target in an if statement:
>>>>
>>>> if 'gen' in COMMAND_LINE_TARGETS:
>>>> env.Program('gen', Glob('.build/gen/*.cpp') + common_source_files)
>>>>
>>>> The problem with this is that the target is not put in the build tree
>>>> at all, instead of just not being executed. One consequence is that this
>>>> target is not picked up by 'scons -c' unless I specifically include the
>>>> target on the command line.
>>>>
>>>
>>>
>>> Why do this at all?
>>> Are you currently running two passes of your build?
>>> Why would the code not be there?
>>> Is there a situation where you don't want to generate the files?
>>>
>>> Would this apply ?
>>> https://bitbucket.org/scons/scons/wiki/DynamicSourceGenerator
>>>
>>>
>>>> 2. A related problem: when I run 'scons -c gen', all the common
>>>> sub-targets are cleaned as well, which makes perfect sense. Is there a way
>>>> to only clean the files specific to this target?
>>>>
>>>
>>> Not easily. You could declare all the other files NoClean() when gen is
>>> the target.
>>>
>>>
>>> -Bill
>>>
>>>
>>> _______________________________________________
>>> Scons-users mailing list
>>> Scons-users at scons.org
>>> https://pairlist4.pair.net/mailman/listinfo/scons-users
>>>
>>>
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> https://pairlist4.pair.net/mailman/listinfo/scons-users
>>
>>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20160310/30ccac21/attachment.html>
More information about the Scons-users
mailing list