Experiment in setting up a C++ build pipeline.
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.
//main:main
bazel query 'filter("^//", kind("source file", deps(//main:main)))' //main:fizzbuzz.h //main:main.cc //main:main.h
Then, to put everything together, cpp-sample.cc
or
cpp-sample-alt.cc
pull in the concrete implementaion making a
runnable application:
//main:cpp-sample
bazel query 'filter("^//", kind("source file", deps(//main:cpp-sample)))' //lib:fizzbuzz.cc //lib:fizzbuzz.h //main:cpp-sample.cc //main:fizzbuzz.h //main:main.cc //main:main.h
//main:cpp-sample-alt
bazel query 'filter("^//", kind("source file", deps(//main:cpp-sample-alt)))' //lib:fizzbuzz-alt.cc //lib:fizzbuzz-alt.h //main:cpp-sample-alt.cc //main:fizzbuzz.h //main:main.cc //main:main.h
The test depends on both implementations, testing them via the shared interface:
//test:fizzbuzz-test
bazel query 'filter("^//", kind("source file", deps(//test:fizzbuzz-test)))' //lib:fizzbuzz-alt.cc //lib:fizzbuzz-alt.h //lib:fizzbuzz.cc //lib:fizzbuzz.h //main:fizzbuzz.h //test:fizzbuzz-test.cc
Copyright 2021 melsicon GmbH
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this material except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.