[Scons-users] how to use env.ParseDepends() to parse *.d files with different format style
Mats Wichmann
mats at wichmann.us
Sun Nov 10 14:57:38 EST 2024
On 11/9/24 23:36, 于 wrote:
> Hello guys,
>
> I want to use env.ParseDepends() add *.o dependencies. But different
> compilers can generate different style *.d.
> Add SCons version is 4.8.1.
> I generate *.d files, like makefile style (multiple rules). Such as below,
>
> D:/workspace/LCfg.o: D:/workspace/inc/Std_Types.h
>
> There is a string ': ' between *.o and *.d and there is a ':' after 'D'.
> The env.ParseDepends() separate *.o and *.d, so the first 'D' was
> detected as target file.
> And then, I modify the env.ParseDepends(), I add a space ' ' in target,
> depends= line.split(': ', 1)
> Then *.d file can be parsed successfully.
> But I think that is improper to modify source code.
>
> My question is that how could I parse different style *.d with a better
> method.
ParseDepends is written to a very specific implementation, so I think
you don't have a choice but to specialize it if you want to accommodate
a different format (including your case where the drive letter notation
will confuse the very simplistic splitting - as you've noted). SCons
allows you to add your own functions to the environment - you can add
your variant using AddMethod and call that, see:
https://scons.org/doc/production/HTML/scons-man.html#f-AddMethod
As far as I recall, ParseDepends is not otherwise wired in to SCons,
it's a standalone method for you to call, that then uses Depends() to
add in what it finds to the dependency tree. So it shouldn't cause any
problem to add where you worry about it getting called properly by other
routines (if that speculation makes sense).
Meanwhile, don't think anyone's asked for this on Windows over SCons'
many years, but it *might* be considered a bug that it doesn't work
there. If folks agree, we can fix it, but that won't help you in the
short term, since it would be in a future release.
Also, ParseDepends isn't really an optimal interface because of the
sequence in which things happen - you can read more about that problem
in the User Guide:
https://scons.org/doc/production/HTML/scons-user.html#id1330
More information about the Scons-users
mailing list