Reputation: 173
I am trying to understand how "cmock"/"unity" works under the hood. Both of this are using ruby rake build tool. Is there an easy way to show/log all shell commands and its option that were invoked by rake during build? I would expect to see among other bunch of (or similar):
gcc a.c -o a.o -Wall -g -I"some/path"
gcc b.c -o b.o -Wall -g -I"some/path"
edit:
Some background to the question: I do not understand (yet) how rake and cmock works. So i thought: It would be great help if I can log how other programs (mainly compiler) were invoked by rake while building provided example. This way I can see process step by step without learning too much about reke/cmock just yet. (I have tried -t option but it does not show shell commands).
Upvotes: 1
Views: 273
Reputation: 3205
There are two basic issues here.
Rake doesn't really let you easily configure your compilers, and doesn't really easily let you see the "magic" it's doing behind the scenes.
I was in the same position, and found answers to both those questions. You probably only care about the visibility issue, but I think others will want the next step ("now that I see what it's doing, how do I change it?") so I'll add them both.
First is much easier. Rake does a bunch of build commands, and you can see them by adding "--trace", for example:
rake --trace compile
In many cases, though, you may find that rake has been asked to build a Makefile and use 'make' or 'gmake' or some other variant, you'll end up seeing in the trace output:
/bin/gmake install target_prefix=
And that gmake is running some Makefile, probably in some path like "tmp/x86_64-linux/libxml_ruby/3.2.2" or whatever matches your system, library and version you're working on.
That Makefile is generated by rake extensiontask, and usually it just uses 'gcc' and 'g++' with no path at all, which is a nightmare if you have multiple gcc installs and want to specify it.
If your rake task does call something like gmake or make, then you can see what commands that is calling by first setting the environment variable:
bash/sh: export MAKE='gmake V=1'
tcsh/csh: setenv MAKE 'gmake V=1'
But more importantly, if you want to specify the actual path to the compiler, things get messy. If you look in the same (tmp/..) directory that has the Makefile you will see that it (if it was built by rake extensiontask) will have a hidden file called ".rake-compiler-siteconf.rb" (this is on Unix, I'm not completely sure what the windows paths would be).
Inside of that file you can add some patches, I actually updated my rake compiler library by adding lines to 'lib/rake/extensiontask.rb' after the lines around:
siteconf.puts "require 'mkmf'"
(and then rebuild rake-compiler) but that will change the CC/CXX settings for any rake that uses that gem's extensiontask.
The other option is to add it directly to the ".rake-compiler-siteconf.rb" for the library you are trying to compile and trying to do your rake build/compile again.
The lines would look like:
RbConfig::MAKEFILE_CONFIG['CC'] = '/my/path/to/gcc'
RbConfig::MAKEFILE_CONFIG['CXX'] = '/my/path/to/c++/or/gcc/or/g++/or/whatever'
RbConfig::MAKEFILE_CONFIG['LDSHAREDXX'] = '/my/path/to/gcc/or/ld'
$DLDFLAGS.qsub!('-Wl,--example-of-removing-flags-from-default-ld-flags')
Upvotes: 0