diff --git a/Makefile b/Makefile index ae970a6..842fdf1 100644 --- a/Makefile +++ b/Makefile @@ -15,3 +15,17 @@ oclint: bazel build --config=oclint //src/... find bazel-bin/src/**/oclint-analysis/** -name 'analyzed*.txt' -exec cat {} + find bazel-bin/src/**/oclint-analysis/** -name 'metadata.json' -exec cat {} + + +patched: + bazel build //src/apps:math --define=sin=true + # calculate sin + bazel-bin/src/apps/math 1 + + bazel build //src/apps:math + # calculate cos + bazel-bin/src/apps/math 1 + + bazel clean + bazel build //src/apps:math --define=sin=true + # calculate sin + bazel-bin/src/apps/math 1 diff --git a/patches/BUILD.bazel b/patches/BUILD.bazel new file mode 100644 index 0000000..a3f4ff1 --- /dev/null +++ b/patches/BUILD.bazel @@ -0,0 +1 @@ +exports_files(["math.cc.sin.patch"]) diff --git a/patches/math.cc.sin.patch b/patches/math.cc.sin.patch new file mode 100644 index 0000000..9268b73 --- /dev/null +++ b/patches/math.cc.sin.patch @@ -0,0 +1,14 @@ +diff --git a/src/apps/math.cc b/src/apps/math.cc +index 41283af..f3823ff 100644 +--- a/src/apps/math.cc ++++ b/src/apps/math.cc +@@ -5,7 +5,7 @@ + + int main(int argc, char *argv[]) { + double value = std::stod(argv[1]); +- double result = gcem::cos(value); +- std::cout << "The cos of " << value << " is: " << result << std::endl; ++ double result = gcem::sin(value); ++ std::cout << "The sin of " << value << " is: " << result << std::endl; + return 0; + } diff --git a/src/apps/BUILD.bazel b/src/apps/BUILD.bazel index a22f377..829c2b4 100644 --- a/src/apps/BUILD.bazel +++ b/src/apps/BUILD.bazel @@ -18,9 +18,28 @@ sh_binary( srcs = ["release_metadata.sh"], ) +config_setting( + name = "sin", + values = {"define": "sin=true"}, +) + +genrule( + name = "math_maybe_patched", + srcs = [ + "math.cc", + "//patches:math.cc.sin.patch", + ], + outs = ["math_maybe_patched.cc"], + cmd = select({ + ":sin": "cp $(location math.cc) $@ && patch $@ < $(location //patches:math.cc.sin.patch)", + "//conditions:default": "cp $(location math.cc) $@", + }), + tools = [], +) + cc_binary( name = "math", - srcs = ["math.cc"], + srcs = [":math_maybe_patched"], deps = [ "@gcem", ],