diff --git a/TARGETS b/TARGETS index 469b8a3b6..7df9e3848 100644 --- a/TARGETS +++ b/TARGETS @@ -1,12 +1,9 @@ load("@fbcode_macros//build_defs:auto_headers.bzl", "AutoHeaders") +load(":defs.bzl", "test_binary") REPO_PATH = package_name() + "/" -BUCK_BINS = "buck-out/gen/" + REPO_PATH - -TEST_RUNNER = REPO_PATH + "buckifier/rocks_test_runner.sh" - -rocksdb_compiler_flags = [ +ROCKSDB_COMPILER_FLAGS = [ "-fno-builtin-memcmp", "-DROCKSDB_PLATFORM_POSIX", "-DROCKSDB_LIB_IO_POSIX", @@ -33,7 +30,7 @@ rocksdb_compiler_flags = [ "-Wnarrowing", ] -rocksdb_external_deps = [ +ROCKSDB_EXTERNAL_DEPS = [ ("bzip2", None, "bz2"), ("snappy", None, "snappy"), ("zlib", None, "z"), @@ -45,13 +42,13 @@ rocksdb_external_deps = [ ("googletest", None, "gtest"), ] -rocksdb_preprocessor_flags = [ +ROCKSDB_PREPROCESSOR_FLAGS = [ # Directories with files for #include "-I" + REPO_PATH + "include/", "-I" + REPO_PATH, ] -rocksdb_arch_preprocessor_flags = { +ROCKSDB_ARCH_PREPROCESSOR_FLAGS = { "x86_64": [ "-DHAVE_SSE42", "-DHAVE_PCLMUL", @@ -64,16 +61,15 @@ is_opt_mode = build_mode.startswith("opt") # -DNDEBUG is added by default in opt mode in fbcode. But adding it twice # doesn't harm and avoid forgetting to add it. -if is_opt_mode: - rocksdb_compiler_flags.append("-DNDEBUG") +ROCKSDB_COMPILER_FLAGS += (["-DNDEBUG"] if is_opt_mode else []) sanitizer = read_config("fbcode", "sanitizer") # Do not enable jemalloc if sanitizer presents. RocksDB will further detect # whether the binary is linked with jemalloc at runtime. -if sanitizer == "": - rocksdb_compiler_flags.append("-DROCKSDB_JEMALLOC") - rocksdb_external_deps.append(("jemalloc", None, "headers")) +ROCKSDB_COMPILER_FLAGS += (["-DROCKSDB_JEMALLOC"] if sanitizer == "" else []) + +ROCKSDB_EXTERNAL_DEPS += ([("jemalloc", None, "headers")] if sanitizer == "" else []) cpp_library( name = "rocksdb_lib", @@ -306,11 +302,11 @@ cpp_library( "utilities/write_batch_with_index/write_batch_with_index_internal.cc", ], auto_headers = AutoHeaders.RECURSIVE_GLOB, - arch_preprocessor_flags = rocksdb_arch_preprocessor_flags, - compiler_flags = rocksdb_compiler_flags, - preprocessor_flags = rocksdb_preprocessor_flags, + arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + compiler_flags = ROCKSDB_COMPILER_FLAGS, + preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, deps = [], - external_deps = rocksdb_external_deps, + external_deps = ROCKSDB_EXTERNAL_DEPS, ) cpp_library( @@ -328,11 +324,11 @@ cpp_library( "utilities/column_aware_encoding_util.cc", ], auto_headers = AutoHeaders.RECURSIVE_GLOB, - arch_preprocessor_flags = rocksdb_arch_preprocessor_flags, - compiler_flags = rocksdb_compiler_flags, - preprocessor_flags = rocksdb_preprocessor_flags, + arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + compiler_flags = ROCKSDB_COMPILER_FLAGS, + preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, deps = [":rocksdb_lib"], - external_deps = rocksdb_external_deps, + external_deps = ROCKSDB_EXTERNAL_DEPS, ) cpp_library( @@ -343,22 +339,22 @@ cpp_library( "util/testutil.cc", ], auto_headers = AutoHeaders.RECURSIVE_GLOB, - arch_preprocessor_flags = rocksdb_arch_preprocessor_flags, - compiler_flags = rocksdb_compiler_flags, - preprocessor_flags = rocksdb_preprocessor_flags, + arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + compiler_flags = ROCKSDB_COMPILER_FLAGS, + preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, deps = [":rocksdb_lib"], - external_deps = rocksdb_external_deps, + external_deps = ROCKSDB_EXTERNAL_DEPS, ) cpp_library( name = "env_basic_test_lib", srcs = ["env/env_basic_test.cc"], auto_headers = AutoHeaders.RECURSIVE_GLOB, - arch_preprocessor_flags = rocksdb_arch_preprocessor_flags, - compiler_flags = rocksdb_compiler_flags, - preprocessor_flags = rocksdb_preprocessor_flags, + arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + compiler_flags = ROCKSDB_COMPILER_FLAGS, + preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, deps = [":rocksdb_test_lib"], - external_deps = rocksdb_external_deps, + external_deps = ROCKSDB_EXTERNAL_DEPS, ) # [test_name, test_src, test_type] @@ -1103,26 +1099,16 @@ ROCKS_TESTS = [ # Generate a test rule for each entry in ROCKS_TESTS # Do not build the tests in opt mode, since SyncPoint and other test code # will not be included. -if not is_opt_mode: - for test_cfg in ROCKS_TESTS: - test_name = test_cfg[0] - test_cc = test_cfg[1] - ttype = "gtest" if test_cfg[2] == "parallel" else "simple" - test_bin = test_name + "_bin" - - cpp_binary( - name = test_bin, - srcs = [test_cc], - arch_preprocessor_flags = rocksdb_arch_preprocessor_flags, - compiler_flags = rocksdb_compiler_flags, - preprocessor_flags = rocksdb_preprocessor_flags, - deps = [":rocksdb_test_lib"], - external_deps = rocksdb_external_deps, - ) - - custom_unittest( - name = test_name, - command = [TEST_RUNNER, BUCK_BINS + test_bin], - type = ttype, - deps = [":" + test_bin], - ) +[ + test_binary( + parallelism = parallelism, + rocksdb_arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + rocksdb_compiler_flags = ROCKSDB_COMPILER_FLAGS, + rocksdb_external_deps = ROCKSDB_EXTERNAL_DEPS, + rocksdb_preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, + test_cc = test_cc, + test_name = test_name, + ) + for test_name, test_cc, parallelism in ROCKS_TESTS + if not is_opt_mode +] diff --git a/buckifier/targets_cfg.py b/buckifier/targets_cfg.py index 7a2198fa7..190081138 100644 --- a/buckifier/targets_cfg.py +++ b/buckifier/targets_cfg.py @@ -3,14 +3,11 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals rocksdb_target_header = """load("@fbcode_macros//build_defs:auto_headers.bzl", "AutoHeaders") +load(":defs.bzl", "test_binary") REPO_PATH = package_name() + "/" -BUCK_BINS = "buck-out/gen/" + REPO_PATH - -TEST_RUNNER = REPO_PATH + "buckifier/rocks_test_runner.sh" - -rocksdb_compiler_flags = [ +ROCKSDB_COMPILER_FLAGS = [ "-fno-builtin-memcmp", "-DROCKSDB_PLATFORM_POSIX", "-DROCKSDB_LIB_IO_POSIX", @@ -37,7 +34,7 @@ rocksdb_compiler_flags = [ "-Wnarrowing", ] -rocksdb_external_deps = [ +ROCKSDB_EXTERNAL_DEPS = [ ("bzip2", None, "bz2"), ("snappy", None, "snappy"), ("zlib", None, "z"), @@ -49,13 +46,13 @@ rocksdb_external_deps = [ ("googletest", None, "gtest"), ] -rocksdb_preprocessor_flags = [ +ROCKSDB_PREPROCESSOR_FLAGS = [ # Directories with files for #include "-I" + REPO_PATH + "include/", "-I" + REPO_PATH, ] -rocksdb_arch_preprocessor_flags = { +ROCKSDB_ARCH_PREPROCESSOR_FLAGS = { "x86_64": [ "-DHAVE_SSE42", "-DHAVE_PCLMUL", @@ -68,16 +65,15 @@ is_opt_mode = build_mode.startswith("opt") # -DNDEBUG is added by default in opt mode in fbcode. But adding it twice # doesn't harm and avoid forgetting to add it. -if is_opt_mode: - rocksdb_compiler_flags.append("-DNDEBUG") +ROCKSDB_COMPILER_FLAGS += (["-DNDEBUG"] if is_opt_mode else []) sanitizer = read_config("fbcode", "sanitizer") # Do not enable jemalloc if sanitizer presents. RocksDB will further detect # whether the binary is linked with jemalloc at runtime. -if sanitizer == "": - rocksdb_compiler_flags.append("-DROCKSDB_JEMALLOC") - rocksdb_external_deps.append(("jemalloc", None, "headers")) +ROCKSDB_COMPILER_FLAGS += (["-DROCKSDB_JEMALLOC"] if sanitizer == "" else []) + +ROCKSDB_EXTERNAL_DEPS += ([("jemalloc", None, "headers")] if sanitizer == "" else []) """ @@ -86,11 +82,11 @@ cpp_library( name = "{name}", srcs = [{srcs}], {headers_attr_prefix}headers = {headers}, - arch_preprocessor_flags = rocksdb_arch_preprocessor_flags, - compiler_flags = rocksdb_compiler_flags, - preprocessor_flags = rocksdb_preprocessor_flags, + arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + compiler_flags = ROCKSDB_COMPILER_FLAGS, + preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, deps = [{deps}], - external_deps = rocksdb_external_deps, + external_deps = ROCKSDB_EXTERNAL_DEPS, ) """ @@ -98,11 +94,11 @@ binary_template = """ cpp_binary( name = "%s", srcs = [%s], - arch_preprocessor_flags = rocksdb_arch_preprocessor_flags, - compiler_flags = rocksdb_compiler_flags, - preprocessor_flags = rocksdb_preprocessor_flags, + arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + compiler_flags = ROCKSDB_COMPILER_FLAGS, + preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, deps = [%s], - external_deps = rocksdb_external_deps, + external_deps = ROCKSDB_EXTERNAL_DEPS, ) """ @@ -121,27 +117,17 @@ ROCKS_TESTS = [ # Generate a test rule for each entry in ROCKS_TESTS # Do not build the tests in opt mode, since SyncPoint and other test code # will not be included. -if not is_opt_mode: - for test_cfg in ROCKS_TESTS: - test_name = test_cfg[0] - test_cc = test_cfg[1] - ttype = "gtest" if test_cfg[2] == "parallel" else "simple" - test_bin = test_name + "_bin" - - cpp_binary( - name = test_bin, - srcs = [test_cc], - arch_preprocessor_flags = rocksdb_arch_preprocessor_flags, - compiler_flags = rocksdb_compiler_flags, - preprocessor_flags = rocksdb_preprocessor_flags, - deps = [":rocksdb_test_lib"], - external_deps = rocksdb_external_deps, - ) - - custom_unittest( - name = test_name, - command = [TEST_RUNNER, BUCK_BINS + test_bin], - type = ttype, - deps = [":" + test_bin], - ) +[ + test_binary( + parallelism = parallelism, + rocksdb_arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + rocksdb_compiler_flags = ROCKSDB_COMPILER_FLAGS, + rocksdb_external_deps = ROCKSDB_EXTERNAL_DEPS, + rocksdb_preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, + test_cc = test_cc, + test_name = test_name, + ) + for test_name, test_cc, parallelism in ROCKS_TESTS + if not is_opt_mode +] """