Experiment in setting up a C++ build pipeline.
Table of Contents
Run the app with
bazel run //main:cpp-sampleor, for the alternate strategy (same result):
bazel run //main:cpp-sample-altThis 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:mainbazel 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-samplebazel query 'filter("^//", kind("source file", deps(//main:cpp-sample)))'
//lib:fizzbuzz.cc
//main:fizzbuzz.h
//main:main.cc
Dependencies of
//main:cpp-sample-altbazel 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-testbazel query 'filter("^//", kind("source file", deps(//test:fizzbuzz-test)))'
//lib:fizzbuzz.cc
//main:fizzbuzz.h
//test:fizzbuzz-test.cc
Dependencies of
//test:fizzbuzz-test-altbazel query 'filter("^//", kind("source file", deps(//test:fizzbuzz-test-alt)))'
//lib_alt:fizzbuzz.cc
//main:fizzbuzz.h
//test:fizzbuzz-test.cc