extedended main SConscript to support building executables of C++ cod…#375
extedended main SConscript to support building executables of C++ cod…#375iagaponenko merged 5 commits intomasterfrom
Conversation
…e, added a demo application which tests if versions of the Gpoogle Protobuf headers and libraries match
andy-slac
left a comment
There was a problem hiding this comment.
This is not what I expected 😑 Let me think about how to do it right, I'll probably make another commit on your branch tomorrow.
core/modules/tests/SConscript
Outdated
| standardModule(env, exclude=exclude, unit_tests="") | ||
|
|
||
| Return('module_build_targets') | ||
| s |
There was a problem hiding this comment.
Oops! I'll fix this.
core/modules/tests/SConscript
Outdated
|
|
||
| standardModule(env, exclude=exclude, unit_tests="") | ||
|
|
||
| Return('module_build_targets') |
There was a problem hiding this comment.
We don't use Return, everything is passed via env
There was a problem hiding this comment.
I thought that a module's SConscript is a function which returns a value of a locally defined (within the called module) variable which is inspected by the main SConscript. That (returned) list is used on each iteration of the main SConscript's look over modules. Are you suggesting I should inject that variable into the global 'env'?
core/modules/tests/SConscript
Outdated
| "protobuf", | ||
| "log", | ||
| "log4cxx"]) | ||
| exclude.append(f) |
There was a problem hiding this comment.
We should try to make this generic and move to standardModule()
There was a problem hiding this comment.
Hence, the idea is to add an optional parameter to "standardModule" to allow passing a list of module's binary products (along with their dependencies), someting like:
standardModule(binaries=[
{"tests_app.cc": ["qserv_common","util","log4cxx"]},
{"tests_somethingelse.cc":[...]),,,],
core/modules/tests/SConscript
Outdated
| # SConscript. Also add the source file into a list of sources to be excluded | ||
| # from the shared library product. | ||
|
|
||
| env.Append(LIBPATH=['$build_dir'] + env['LIBPATH']) |
There was a problem hiding this comment.
That changes global environment which you don't want to do.
There was a problem hiding this comment.
Should I then pass this as a parameter to the Program target when doing?
env.Program(...LIBPATH=['$build_dir'] + env['LIBPATH']...)
There was a problem hiding this comment.
Okay, I've deleted a line of code which modified LIBPATH in the global environment and passed it to each env.Program() invocation as a parameter. And this works.
…late code into function standardModule. This should simplify module-level SConscript file, and it will also make them more robust
|
@andy-slac okay, I've made an improved version of the build system as per your suggestion. NOw it should be trivial to add C++ binaries from the module's SConscriot files - just a dictionary of C++ file names (keys) and list of the corresponding libraries for dependencies It's also more robust compared with the prior version. Have a look at SConscript file of module "tests" as an example. Could you have a look at it please? Thanks! |
andy-slac
left a comment
There was a problem hiding this comment.
Looks mostly OK, see comments below.
core/modules/SConscript
Outdated
| then use this parameter to pass list (or space-separated | ||
| string) of application names. Can be empty string or list to | ||
| not run any unit tests. | ||
| @param bin_cc_targets: a dictionary defining whgich binary products (not |
There was a problem hiding this comment.
whgich -> which
Not shure targets has a meaning here. The key in dict is a name of the source, not target?
There was a problem hiding this comment.
I'll come up with a better name
core/modules/SConscript
Outdated
| # library or unit tests | ||
| exclude_cc_files = [] | ||
| if exclude is not None: | ||
| exclude_cc_files = exclude |
There was a problem hiding this comment.
exclude_cc_files += exclude, otherwise you are potentially modifying exclude too
There was a problem hiding this comment.
Agreed. My Python is rusty :-)
core/modules/SConscript
Outdated
| if exclude is not None: | ||
| exclude_cc_files = exclude | ||
| if bin_cc_targets is not None: | ||
| for f in bin_cc_targets: exclude_cc_files.append(f) |
There was a problem hiding this comment.
exclude_cc_files += bin_cc_targets.keys()?
core/modules/SConscript
Outdated
| string) of application names. Can be empty string or list to | ||
| not run any unit tests. | ||
| @param bin_cc_targets: a dictionary defining whgich binary products (not | ||
| the unit tests should be built out of C/C++ files. Each key |
There was a problem hiding this comment.
Opening parenthesis on previous line is not closed, I guess it should go after "tests".
core/modules/SConscript
Outdated
| # inject binary targets built of the optionally provided C/C++ files | ||
| if bin_cc_targets is not None: | ||
| for f,dependencies in bin_cc_targets.items(): | ||
| source = os.path.basename(str(f)) |
There was a problem hiding this comment.
Why do you need basename for source?
There was a problem hiding this comment.
Agreed. No need. I will eliminate it.
core/modules/SConscript
Outdated
| target=target, | ||
| source=[source], | ||
| LIBS=dependencies, | ||
| LIBPATH=['$build_dir'] + env['LIBPATH']) |
There was a problem hiding this comment.
Looks a bit complicated, I'd think this should work:
for f, dependencies in bin_cc_targets.items():
p = env.Program(f, LIBS=dependencies, LIBPATH=['$build_dir'] + env['LIBPATH'])
There was a problem hiding this comment.
I will give it a try, and if it works then I'll make mods to the code.
core/modules/tests/SConscript
Outdated
| bin_cc_targets = {} | ||
| path = "." | ||
| for f in env.Glob(os.path.join(path, "tests_*.cc"), source=True, strings=True): | ||
| bin_cc_targets[f] = ["qserv_common","util","protobuf","log","log4cxx"] |
There was a problem hiding this comment.
Don't overdo it. Normally all "test*.cc" files are (unit) tests and we don't want their binaries installed so don't try to make all test_*.cc into true binaries. I'd probably give it different name, not starting with "test".
I believe you can also write:
bin_cc_targets[f] = "qserv_common util protobuf log log4cxx"
There was a problem hiding this comment.
Perhaps we should come up with some naming convention for the binaries. Something like: qserv--.cc. For instance my only app module tests should be renamed from "tests_protobuf_version.cc" into "qserv-tests-protobuf.cc". And I agree about avoiding using "test*" in apps names". I just wanted to see if my implementation of standardModule would work. And thanks for the advice to replace a list of dependencies with a string. I'll give it a try.
|
@andy-slac thank you for reviewing the code and making good suggestions! I've just committed a few more modification to the code as per your suggestions. |
e, added a demo application which tests if versions of the Gpoogle Protobuf headers and libraries match