Experiment in setting up a C++ build pipeline.
Table of Contents
Run the app with
bazel run //main:cpp-sample
or, for the alternate strategy (same result):
bazel run //main:cpp-sample-alt
This code demonstrates the application of the dependency inversion principle. Naively, one would simply make the main programm dependent on the concrete implementation of the transformation strategy. Here, we simply let the main programm own the interface, making it independent of the implementation and therefore the strategy exchangable.
Dependencies of
//main:main
bazel query 'filter("^//", kind("source file", deps(//main:main)))' //main:fizzbuzz.h //main:main.cc
Then, to put everything together, cpp-sample.cc
or
cpp-sample-alt.cc
pull in the concrete implementaion making a
runnable application:
Dependencies of
//main:cpp-sample
bazel query 'filter("^//", kind("source file", deps(//main:cpp-sample)))' //lib:fizzbuzz.cc //main:fizzbuzz.h //main:main.cc
Dependencies of
//main:cpp-sample-alt
bazel query 'filter("^//", kind("source file", deps(//main:cpp-sample-alt)))' //lib_alt:fizzbuzz.cc //main:fizzbuzz.h //main:main.cc
The tests work the same way:
Dependencies of
//test:fizzbuzz-test
bazel query 'filter("^//", kind("source file", deps(//test:fizzbuzz-test)))' //lib:fizzbuzz.cc //main:fizzbuzz.h //test:fizzbuzz-test.cc
Dependencies of
//test:fizzbuzz-test-alt
bazel query 'filter("^//", kind("source file", deps(//test:fizzbuzz-test-alt)))' //lib_alt:fizzbuzz.cc //main:fizzbuzz.h //test:fizzbuzz-test.cc