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

Nacho Piqueras natxo.piq at gmail.com
Fri Jul 24 08:37:03 EDT 2015


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,


More information about the Scons-users mailing list