From 9dbce74a3fe44397c2623cf9480611c4ee409fca Mon Sep 17 00:00:00 2001 From: Zhongming Qu Date: Sun, 10 Dec 2017 18:03:56 -0800 Subject: [PATCH 1/7] Add Bazel BUILD. --- BUILD | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 BUILD diff --git a/BUILD b/BUILD new file mode 100644 index 0000000000..9cd75df456 --- /dev/null +++ b/BUILD @@ -0,0 +1,17 @@ +licenses(['notice']) + +cc_library( + name = 'benchmark', + srcs = glob(['src/*.cc']), + hdrs = glob(['include/**/*.h', 'src/*.h']), + includes = [ + 'include', '.' + ], + copts = [ + '-DHAVE_POSIX_REGEX' + ], + linkstatic = 1, + visibility = [ + '//visibility:public', + ], +) From 39ffb950775db644a04c9bdacee47fdb8cc8d8fc Mon Sep 17 00:00:00 2001 From: Zhongming Qu Date: Thu, 14 Dec 2017 13:39:37 -0800 Subject: [PATCH 2/7] Fully Bazelise the build and tests. --- .gitignore | 3 +- BUILD | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++--- WORKSPACE | 69 +++++++++++++++++++++++++ 3 files changed, 210 insertions(+), 7 deletions(-) create mode 100644 WORKSPACE diff --git a/.gitignore b/.gitignore index bfc6b57b45..c87b71ecd8 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ rules.ninja build/ _build/ -# in-source dependancies /googletest/ +# Bazel directories. +bazel-* diff --git a/BUILD b/BUILD index 9cd75df456..f5da197c81 100644 --- a/BUILD +++ b/BUILD @@ -1,17 +1,150 @@ licenses(['notice']) +package(default_visibility=['//visibility:public']) + +benchmark_copts = [ + # Choose the regex backend by defining one of the macros below: + # HAVE_GNU_POSIX_REGEX + # HAVE_POSIX_REGEX + # HAVE_STD_REGEX + '-DHAVE_POSIX_REGEX', + '-UNDEBUG', + '-Wall', + '-Wextra', + '-Wfloat-equal', + '-Wshadow', + '-Wstrict-aliasing', + '-Wzero-as-null-pointer-constant', + '-fstrict-aliasing', + '-pedantic', + '-pedantic-errors', + '-std=c++11', +] + +gtest_dep = '@com_github_google_googletest//:gtest' cc_library( name = 'benchmark', - srcs = glob(['src/*.cc']), - hdrs = glob(['include/**/*.h', 'src/*.h']), + srcs = [ + 'src/arraysize.h', + 'src/benchmark.cc', + 'src/benchmark_api_internal.h', + 'src/benchmark_register.cc', + 'src/check.h', + 'src/colorprint.cc', + 'src/colorprint.h', + 'src/commandlineflags.cc', + 'src/commandlineflags.h', + 'src/complexity.cc', + 'src/complexity.h', + 'src/console_reporter.cc', + 'src/counter.cc', + 'src/counter.h', + 'src/csv_reporter.cc', + 'src/cycleclock.h', + 'src/internal_macros.h', + 'src/json_reporter.cc', + 'src/log.h', + 'src/mutex.h', + 'src/re.h', + 'src/reporter.cc', + 'src/sleep.cc', + 'src/sleep.h', + 'src/statistics.cc', + 'src/statistics.h', + 'src/string_util.cc', + 'src/string_util.h', + 'src/sysinfo.cc', + 'src/timers.cc', + 'src/timers.h', + ], + hdrs = [ + 'include/benchmark/benchmark.h', + ], includes = [ - 'include', '.' + 'include', + ], + copts = benchmark_copts, + linkopts = [ + '-lm', + ], +) + +[cc_test( + name = f, + srcs = [ + 'test/%s.cc' % f, + ], + copts = benchmark_copts, + deps = [ + ':benchmark', + gtest_dep, + ], + testonly = 1, +) for f in [ + 'basic_test', + 'benchmark_test', + 'diagnostics_test', + 'donotoptimize_test', + 'filter_test', + 'fixture_test', + 'map_test', + 'multiple_ranges_test', + 'options_test', + 'register_benchmark_test', + 'skip_with_error_test', + 'templated_fixture_test', + ] +] + +[cc_test( + name = f, + srcs = [ + 'test/%s.cc' % f, + ], + copts = benchmark_copts, + deps = [ + ':output_test_helper', + gtest_dep, + ], + testonly = 1, +) for f in [ + 'complexity_test', + 'reporter_output_test', + 'user_counters_tabular_test', + 'user_counters_test', + ] +] + +cc_test( + name = 'cxx03_test', + srcs = [ + 'test/cxx03_test.cc', ], copts = [ - '-DHAVE_POSIX_REGEX' + '-std=c++03', ], - linkstatic = 1, + deps = [ + ':benchmark', + gtest_dep, + ], + testonly = 1, +) + +cc_library( + name = 'output_test_helper', visibility = [ - '//visibility:public', + '//visibility:__pkg__', + ], + srcs = [ + 'test/output_test_helper.cc', + ], + hdrs = [ + 'test/output_test.h', + ], + strip_include_prefix = 'test', + copts = benchmark_copts, + deps = [ + ':benchmark', ], + testonly = 1, ) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000000..2f86e4b346 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,69 @@ +new_git_repository( + name = 'com_github_google_googletest', + remote = 'https://github.com/google/googletest.git', + tag = 'release-1.8.0', + build_file_content = ''' +# This content is copied from +# https://github.com/google/googletest/blob/master/BUILD.bazel +# But because the filename is not BUILD, the git_repository() rule will +# complain. +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +config_setting( + name = "win", + values = {"cpu": "x64_windows_msvc"}, +) + +# Google Test including Google Mock +cc_library( + name = "gtest", + srcs = glob( + include = [ + "googletest/src/*.cc", + "googletest/src/*.h", + "googletest/include/gtest/**/*.h", + "googlemock/src/*.cc", + "googlemock/include/gmock/**/*.h", + ], + exclude = [ + "googletest/src/gtest-all.cc", + "googletest/src/gtest_main.cc", + "googlemock/src/gmock-all.cc", + "googlemock/src/gmock_main.cc", + ], + ), + hdrs =glob([ + "googletest/include/gtest/*.h", + "googlemock/include/gmock/*.h", + ]), + copts = select( + { + ":win": [], + "//conditions:default": ["-pthread"], + }, + ), + includes = [ + "googlemock", + "googlemock/include", + "googletest", + "googletest/include", + ], + linkopts = select({ + ":win": [], + "//conditions:default": [ + "-pthread", + ], + }), +) + +cc_library( + name = "gtest_main", + srcs = [ + "googlemock/src/gmock_main.cc", + ], + deps = ["//:gtest"], +) +''', +) From a1f5d4362f6359b13822c443de4152a2ce2805dd Mon Sep 17 00:00:00 2001 From: Zhongming Qu Date: Mon, 18 Dec 2017 19:49:42 -0800 Subject: [PATCH 3/7] Remove unused gtest dependencies. --- BUILD | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/BUILD b/BUILD index f5da197c81..1d0963f4c0 100644 --- a/BUILD +++ b/BUILD @@ -1,7 +1,7 @@ licenses(['notice']) package(default_visibility=['//visibility:public']) -benchmark_copts = [ +BENCHMARK_COPTS = [ # Choose the regex backend by defining one of the macros below: # HAVE_GNU_POSIX_REGEX # HAVE_POSIX_REGEX @@ -20,7 +20,8 @@ benchmark_copts = [ '-std=c++11', ] -gtest_dep = '@com_github_google_googletest//:gtest' + +GTEST_DEP = '@com_github_google_googletest//:gtest' cc_library( name = 'benchmark', @@ -63,9 +64,10 @@ cc_library( includes = [ 'include', ], - copts = benchmark_copts, + copts = BENCHMARK_COPTS, linkopts = [ '-lm', + '-pthread', ], ) @@ -74,10 +76,9 @@ cc_library( srcs = [ 'test/%s.cc' % f, ], - copts = benchmark_copts, + copts = BENCHMARK_COPTS, deps = [ ':benchmark', - gtest_dep, ], testonly = 1, ) for f in [ @@ -101,10 +102,10 @@ cc_library( srcs = [ 'test/%s.cc' % f, ], - copts = benchmark_copts, + copts = BENCHMARK_COPTS, deps = [ ':output_test_helper', - gtest_dep, + GTEST_DEP, ], testonly = 1, ) for f in [ @@ -125,7 +126,6 @@ cc_test( ], deps = [ ':benchmark', - gtest_dep, ], testonly = 1, ) @@ -142,7 +142,7 @@ cc_library( 'test/output_test.h', ], strip_include_prefix = 'test', - copts = benchmark_copts, + copts = BENCHMARK_COPTS, deps = [ ':benchmark', ], From 1fce7a8357c51d7fb6fb527418bec42540e40b8b Mon Sep 17 00:00:00 2001 From: Zhongming Qu Date: Mon, 18 Dec 2017 20:02:34 -0800 Subject: [PATCH 4/7] Rename BUILD to BUILD.bazel to work around case-insentivity. The rationale for making this change is docmented here: https://github.com/google/benchmark/pull/501 Briefly speaking, some test bots on TravisCI do not have case sensitive filesystems. So the build will fail to create the `build directory`. It does not look like Travis is going to resolve this problem on their side anytime soon, yet. So I am making this change to pass the test. --- BUILD => BUILD.bazel | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename BUILD => BUILD.bazel (100%) diff --git a/BUILD b/BUILD.bazel similarity index 100% rename from BUILD rename to BUILD.bazel From ba133ba81945c26c9ecb9889b87c0408943fee8c Mon Sep 17 00:00:00 2001 From: Zhongming Qu Date: Mon, 18 Dec 2017 20:11:47 -0800 Subject: [PATCH 5/7] Add Bazel tests to Travis --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 58be73f06c..39d18d82b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -155,11 +155,18 @@ install: brew update; brew install gcc@7; fi + - if [ "${TRAVIS_OS_NAME}" == "linux" ]; then + wget https://github.com/bazelbuild/bazel/releases/download/0.8.1/bazel-0.8.1-installer-linux-x86_64.sh --output-document bazel-installer.sh && sudo bash bazel-installer.sh; + fi + - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then + brew install bazel@0.8.1; + fi script: - cmake -DCMAKE_C_COMPILER=${C_COMPILER} -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_FLAGS="${EXTRA_FLAGS}" -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON -DBENCHMARK_BUILD_32_BITS=${BUILD_32_BITS} .. - make - ctest -C ${BUILD_TYPE} --output-on-failure + - bazel test //... --test_output=errors after_success: - if [ "${BUILD_TYPE}" == "Coverage" -a "${TRAVIS_OS_NAME}" == "linux" ]; then From 4fa07d233d6d36bd6391e876514b98f3320919c4 Mon Sep 17 00:00:00 2001 From: Zhongming Qu Date: Mon, 18 Dec 2017 21:19:09 -0800 Subject: [PATCH 6/7] Fix the WORKSPACE file. --- WORKSPACE | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 2f86e4b346..47b7729eb6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,10 +3,10 @@ new_git_repository( remote = 'https://github.com/google/googletest.git', tag = 'release-1.8.0', build_file_content = ''' -# This content is copied from +# This content is modified from # https://github.com/google/googletest/blob/master/BUILD.bazel -# But because the filename is not BUILD, the git_repository() rule will -# complain. +# But we cannot just use that file as-is due to this issue: +# https://github.com/google/googletest/pull/1212 package(default_visibility = ["//visibility:public"]) licenses(["notice"]) @@ -63,7 +63,7 @@ cc_library( srcs = [ "googlemock/src/gmock_main.cc", ], - deps = ["//:gtest"], + deps = [":gtest"], ) ''', ) From acf6319d5f2d5c5becb985001333ec7709c07014 Mon Sep 17 00:00:00 2001 From: Zhongming Qu Date: Mon, 18 Dec 2017 21:42:45 -0800 Subject: [PATCH 7/7] Work around an issue in the googletest repo. By using a different fork, for now, with the understanding that we should switch to the google official googletest repo as soon as the issue below is resolved: https://github.com/google/googletest/pull/1212 --- .travis.yml | 2 +- WORKSPACE | 72 ++++------------------------------------------------- 2 files changed, 6 insertions(+), 68 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39d18d82b0..829998c247 100644 --- a/.travis.yml +++ b/.travis.yml @@ -159,7 +159,7 @@ install: wget https://github.com/bazelbuild/bazel/releases/download/0.8.1/bazel-0.8.1-installer-linux-x86_64.sh --output-document bazel-installer.sh && sudo bash bazel-installer.sh; fi - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then - brew install bazel@0.8.1; + brew install bazel; fi script: diff --git a/WORKSPACE b/WORKSPACE index 47b7729eb6..8eb0bc79b2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,69 +1,7 @@ -new_git_repository( +git_repository( name = 'com_github_google_googletest', - remote = 'https://github.com/google/googletest.git', - tag = 'release-1.8.0', - build_file_content = ''' -# This content is modified from -# https://github.com/google/googletest/blob/master/BUILD.bazel -# But we cannot just use that file as-is due to this issue: -# https://github.com/google/googletest/pull/1212 -package(default_visibility = ["//visibility:public"]) - -licenses(["notice"]) - -config_setting( - name = "win", - values = {"cpu": "x64_windows_msvc"}, -) - -# Google Test including Google Mock -cc_library( - name = "gtest", - srcs = glob( - include = [ - "googletest/src/*.cc", - "googletest/src/*.h", - "googletest/include/gtest/**/*.h", - "googlemock/src/*.cc", - "googlemock/include/gmock/**/*.h", - ], - exclude = [ - "googletest/src/gtest-all.cc", - "googletest/src/gtest_main.cc", - "googlemock/src/gmock-all.cc", - "googlemock/src/gmock_main.cc", - ], - ), - hdrs =glob([ - "googletest/include/gtest/*.h", - "googlemock/include/gmock/*.h", - ]), - copts = select( - { - ":win": [], - "//conditions:default": ["-pthread"], - }, - ), - includes = [ - "googlemock", - "googlemock/include", - "googletest", - "googletest/include", - ], - linkopts = select({ - ":win": [], - "//conditions:default": [ - "-pthread", - ], - }), -) - -cc_library( - name = "gtest_main", - srcs = [ - "googlemock/src/gmock_main.cc", - ], - deps = [":gtest"], -) -''', + # TODO: Use googletest/googltest.git once the following PR is committed: + # https://github.com/google/googletest/pull/1212 + remote = 'https://github.com/qzmfranklin/googletest.git', + commit = 'a7bd3725f08fe38374544bbf8f03699fc0d32a0b' )