[Scons-users] Generated headers in variant build

Bill Deegan bill at baddogconsulting.com
Sun Nov 26 13:27:31 EST 2023


Ian,

Do you know how your variant dirs are specified? Are you using
VariantDir(), or specifying variant_dir when calling SConscript()?
Which version of SCons and Python are you using?

-Bill

On Sun, Nov 26, 2023 at 7:15 AM Mats Wichmann <mats at wichmann.us> wrote:

> On 11/26/23 06:12, Ian Scons wrote:
>
> That's a lot of detail - thanks, though it will take a while to pick
> through it.
>
> > Here, "client.cpp" has a #include of "protos/client.grpc.pb.h", which is
> > a generated header.
>
> ...
>
> > In order to implement the code generation, I have defined a new builder
> > in the SConstruct:
> >
> >      def protoc_emitter(tgt, src, env):
> >          gen_tgt = []
> >          for t in tgt:
> >              ... # append names of generated *.h, *.cc based on t.path
> >          return gen_tgt, src
> >
> >      env["BUILDERS"]["GrpcProtoc"] = Builder(
> >          action=[...], # this is fine, and runs protoc to generate the
> > files as expected
> >          emitter=protoc_emitter,
> >      )
>
> The first reaction is that the plumbing may work more easily if the
> builder is defined to "know" the source and target file suffixes it is
> responsible for.  That would mean adding the suffix and src_suffix
> kwargs to the builder call. I might use suffix=".grpc.pb.h" and
> "src_suffix=.proto"  (although it gets trickier if you generate two
> outputs from protoc, as it seems you're doing - a .h and a .cc).
>
>  > Even if I do (i), sometimes the build fails because client.grpc.pb.h
> cannot be found. It can be seen that the file does exist on the filesystem
>
> One issue in dealing with generated files is that SCons relocates the
> things it needs to based on the directory of the SConscript, but when
> indirect execution is involved, like an emitter, it doesn't always
> figure out it needs to - and you end up with the human saying "but the
> file is there" and SCons saying "I don't see anything *where I'm
> looking*".  In your emitter, you might try generating the added targets
> as File nodes, rather than as strings, and see if that helps - nodes
> have path information in them so they don't get lost track of.
>
>
> By the way, there's a protoc builder in the scons-contrib repository,
> you might look at what it does differently/same as yours (my memory is
> it was fairly convoluted)
>
> https://github.com/scons/scons-contrib
>
> https://github.com/SCons/scons-contrib/tree/master/sconscontrib/SCons/Tool/Protoc
>
>
> _______________________________________________
> 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/20231126/8c3558d0/attachment-0001.htm>


More information about the Scons-users mailing list