[Scons-users] Scanner for .c and .h added to SourceFileScanner is not invoked

William Blevins wblevins001 at gmail.com
Fri Jul 24 11:08:38 EDT 2015


Nacho,

So I will answer your question at some point, but after skimming your
initial information I believe it is more important to answer a question you
didn't ask.  Firstly, shouldn't need to create your own cscanner; it
already exists.

Really what you want to do here is create an emitter for your "code
generator" which outputs the excel file, and then have a builder/emitter
for the excel file which emits the embedded list of targets.  This will
allow the default cscanner to correctly find your generated headers! Please
see https://bitbucket.org/scons/scons/wiki/DynamicSourceGenerator

To answer your actual question, add_scanner appends to the end of the list
of scanners; thus, the default cpp scanner will always get called since it
already provides a match for the ".c" scanner key.  If I am not mistaken,
you can env.Prepend( SCANNERS = [ yourscanner ] ) instead.

I highly recommend reviewing the dynamic scanner wiki page because this is
a better solution to your problem.  Let us know if you have other questions
:)

V/R,
William

On Fri, Jul 24, 2015 at 8:37 AM, Nacho Piqueras <natxo.piq at gmail.com> wrote:

> Hello,
> first of all, thanks for all the effort put in the development of this
> great tool, including the administrators of this mail list.
>
> I work on some system that generates header files using a legacy tool
> (by parsing xls files). The name of the header files generated cannot
> be known without opening and parsing the excel file, but they match a
> pattern that can be extracted from the excel file name.
>
> To be able to detect dependencies for .c files that include the
> headers generated by invocations to this tool I wrote my own Scanner
> and added it to SourceFileScanner.
>
> The Scanner function just gets the include directive in every source,
> searches for a expected pattern that indicates that the include file
> is autogenerated and returns the (list of) xls files that this c file
> depends on.
>
> (For the sake of completness: the legacy tool also generates a text
> file -which is the real TARGET-. The Scanner function does not return
> the xls file name, but its TARGET name. This way I ensure that after a
> xls is modified, the legacy tool is executed first, and then the C
> files that depend on it are recompiled)
>
> So far, so good. This way works as expected when the include
> directives are located in the c file.
>
> The problem is that if the include <autogenerated_random.h> is located
> in a header file that a c files includes, Scons is unable to detect
> that the c file still depends on the autogenerated tool. Seems that
> the scanner is not launched on Object
>
> So, to recap:
>
> def hdr_scanner(node, env, path):
>     dependencies = list()
>     scanned_file = node.get_text_contents()
>     for include_file_name in scanned_file: # regular expression here
>         #from_include_file_name_to_excel_file_name
>         dependencies.append(File(match_path))  # here I get something
> like EXCEL_FILE_NAME.gen.out
>     return dependencies
>
> hdr_generator = Builder(action='$LEGACY_TOOL $SOURCE  > $TARGET',
>                         suffix='.gen.out',
>                         src_suffix='.xls')
> env.Append(BUILDERS={'HDR_GEN': hdr_generator})
>
> scanner = Scanner(function=hdr_scanner, skeys=['.c', '.h'])
>
> # I am not sure about the syntax here!
> SourceFileScanner.add_scanner('.c', scanner)
> SourceFileScanner.add_scanner('.h', scanner)
>
> # in some other part of the project
> env.HDR_GEN('EXCEL_FILE_NAME')  # works good: calls to the
> autogenerated tool every time the excel file is modified
>
> # in some other part of the project
> env.Object('file_that_depends_on_autogenerated_header.c')   # is not
> recompiled if the include directive is no directly located in the c
> file
>
> I know that in the scanner I could try to open included files and
> repeat the search for the pattern. But obviously, I don't like the
> idea.
>
> How could I get the SourceFileScanner to take into account the header
> files?
>
> Thanks a lot,
> _______________________________________________
> 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/20150724/773d177a/attachment.html>


More information about the Scons-users mailing list