Re: Generated headers in variant build
Ian Scons <[email protected]> Mon, 27 Nov 2023 10:32:14 +0000
| Newsgroups | gmane.comp.programming.tools.scons.user |
|---|---|
| Message-ID | <CAMER1UY2f_M=XdRcUQsK+_Edg4jZw6q8TPHHa9FEBM7M5oGx5Q@mail.gmail.com> |
Thanks Mats. Sorry that it was a long post but I wanted to make sure all of the relevant information was included. > although it gets trickier if you generate two > outputs from protoc, as it seems you're doing - a .h and a .cc Yes, that is correct. This is pretty fundamental to what is needed for gRPC/protobuf. I guess this means that the suffix suggestion might not be appropriate for my case? > 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. OK, that sounds like a good suggestion. I will take a look at that. > By the way, there's a protoc builder in the scons-contrib repository I will look at that as well. Thank you, I. On Sun, 26 Nov 2023 at 15:15, Mats Wichmann <[email protected]> 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 > [email protected] > https://pairlist4.pair.net/mailman/listinfo/scons-users > _______________________________________________ Scons-users mailing list [email protected] https://pairlist4.pair.net/mailman/listinfo/scons-users