Use the Node, Luke!
Items in the SCons build tree are represented as Nodes, not only plain file names. In the case of an output into your VariantDir, the node will remember the output path (such as build/file.o) as well as the original source input path (file.o) and for both of these, it also knows the absolute path. These properties are something you'll always want to see when debugging.
print n.abspath
print n.srcnode().abspath
See the section File and Directory Nodes for specific property documentation.
Use the Emitters, Leia!
SCons is a little obsessive and really likes to keep track of everything. It likes to know what files come in and what will fall out. With this information, it can make sure everything is properly rebuilt on any change and it can nicely clean your directory with the -c switch.
If you need to call some external command, it's a good idea to provide this information to SCons so that it knows what will happen. In my build, I need to generate header files for JNI classes using javah. The built-in tool doesn't really work for me because it needs Java compilation first so I ended up writing my own.
The file and class names in Java are tightly coupled, you can pretty much just do
file = clsname.replace('.', '/') + '.java'
to find the source file for a class. I'm using this fact to make my emitter. I take great care to have the correct .java files listed as the source for the Builder. Having only the directory just doesn't cut it, I have to Glob() in subdirs too. To have a good idea of what's happening, I first debug-print my source and target nodes in the emitter:
The emitted target node doesn't need to have an absolute path or contain the VariantDir name, that should be handled by SCons. Just imagine you are building in the same directory and return a relative path.
def emit_javah(target, source, env):
print 'emit source', [x.abspath for x in source]
print 'emit target orig', [x.abspath for x in target]
The emitted target node doesn't need to have an absolute path or contain the VariantDir name, that should be handled by SCons. Just imagine you are building in the same directory and return a relative path.
Really this article is truly one of the best in article history and am a collector of old "items" and sometimes read new items if i find them interesting which is one that I found quite fascinating and should be part of my collection. Very good work!
ReplyDeleteData Scientist Course in Gurgaon
I am hoping the same best effort from you in the future as well and in fact your creative writing skills has inspired me.
ReplyDeleteData Science Course near me
I would like to say that this blog really convinced me to do it and thanks for informative post and bookmarked to check out new things of your post…
ReplyDeleteData Science Institute in Noida
Just a shine from you here and have never expected anything less from you and have not disappointed me at all which i guess you will continue the quality work. Great post.
ReplyDeleteData Science Training in Gurgaon
Interesting post. which i wondered about this issue so thanks for posting and very good article which is a really very nice and useful article. Thank you
ReplyDeleteData Science Course in Noida
Very great post which I really enjoy reading this and it is not everyday that I have the possibility to see something like this. Thank You.
ReplyDeleteBest Online Data Science Courses
I read your excellent blog post. It's a great job. I enjoyed reading your post for the first time, thank you.
ReplyDeleteData Science Institutes in Bangalore
Informative Post. The information you have posted is very useful and sites you have referred was good. Thanks for sharing.
ReplyDeleteData Science Course with Placement