2019-04-18 17:51:19 +00:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
2022-09-21 00:47:52 +00:00
|
|
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
|
|
|
2019-10-23 20:51:03 +00:00
|
|
|
try:
|
2022-09-21 00:47:52 +00:00
|
|
|
from builtins import object, str
|
2019-10-23 20:51:03 +00:00
|
|
|
except ImportError:
|
2022-09-21 00:47:52 +00:00
|
|
|
from __builtin__ import object, str
|
2022-02-18 18:59:57 +00:00
|
|
|
import pprint
|
2017-04-04 23:09:31 +00:00
|
|
|
|
2022-09-21 00:47:52 +00:00
|
|
|
import targets_cfg
|
|
|
|
|
|
|
|
|
2017-11-15 22:13:39 +00:00
|
|
|
def pretty_list(lst, indent=8):
|
2017-04-04 23:09:31 +00:00
|
|
|
if lst is None or len(lst) == 0:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
if len(lst) == 1:
|
2022-09-21 00:47:52 +00:00
|
|
|
return '"%s"' % lst[0]
|
Change BUCK template files (#4624)
Summary:
Slightly changes the format of generated BUCK files for Facebook consumption. Generated targets end up looking like this:
```
cpp_library(
name = "rocksdb_tools_lib",
srcs = [
"tools/db_bench_tool.cc",
"tools/trace_analyzer_tool.cc",
"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,
deps = [":rocksdb_lib"],
external_deps = rocksdb_external_deps,
)
```
Instead of
```
cpp_library(
name = "rocksdb_tools_lib",
srcs = [
"tools/db_bench_tool.cc",
"tools/trace_analyzer_tool.cc",
"util/testutil.cc",
],
headers = AutoHeaders.RECURSIVE_GLOB,
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,
)
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4624
Reviewed By: riversand963
Differential Revision: D12906711
Pulled By: philipjameson
fbshipit-source-id: 32ab64a3390cdcf2c4043ff77517ac1ad58a5e2b
2018-11-02 21:20:20 +00:00
|
|
|
|
2022-09-21 00:47:52 +00:00
|
|
|
separator = '",\n%s"' % (" " * indent)
|
2017-11-15 22:13:39 +00:00
|
|
|
res = separator.join(sorted(lst))
|
2022-09-21 00:47:52 +00:00
|
|
|
res = "\n" + (" " * indent) + '"' + res + '",\n' + (" " * (indent - 4))
|
2017-04-04 23:09:31 +00:00
|
|
|
return res
|
|
|
|
|
|
|
|
|
2023-08-25 23:22:09 +00:00
|
|
|
class TARGETSBuilder:
|
2021-01-28 00:19:43 +00:00
|
|
|
def __init__(self, path, extra_argv):
|
2017-04-04 23:09:31 +00:00
|
|
|
self.path = path
|
2021-01-28 00:19:43 +00:00
|
|
|
header = targets_cfg.rocksdb_target_header_template.format(
|
2022-09-21 00:47:52 +00:00
|
|
|
extra_argv=extra_argv
|
|
|
|
)
|
|
|
|
with open(path, "wb") as targets_file:
|
|
|
|
targets_file.write(header.encode("utf-8"))
|
2017-04-04 23:09:31 +00:00
|
|
|
self.total_lib = 0
|
|
|
|
self.total_bin = 0
|
|
|
|
self.total_test = 0
|
2017-11-15 22:13:39 +00:00
|
|
|
self.tests_cfg = ""
|
2017-04-04 23:09:31 +00:00
|
|
|
|
2022-09-21 00:47:52 +00:00
|
|
|
def add_library(
|
|
|
|
self,
|
|
|
|
name,
|
|
|
|
srcs,
|
|
|
|
deps=None,
|
|
|
|
headers=None,
|
|
|
|
extra_external_deps="",
|
|
|
|
link_whole=False,
|
|
|
|
external_dependencies=None,
|
|
|
|
extra_test_libs=False,
|
|
|
|
):
|
2022-02-18 18:59:57 +00:00
|
|
|
if headers is not None:
|
2020-05-20 18:35:28 +00:00
|
|
|
headers = "[" + pretty_list(headers) + "]"
|
2022-09-21 00:47:52 +00:00
|
|
|
with open(self.path, "ab") as targets_file:
|
|
|
|
targets_file.write(
|
|
|
|
targets_cfg.library_template.format(
|
|
|
|
name=name,
|
|
|
|
srcs=pretty_list(srcs),
|
|
|
|
headers=headers,
|
|
|
|
deps=pretty_list(deps),
|
|
|
|
extra_external_deps=extra_external_deps,
|
|
|
|
link_whole=link_whole,
|
|
|
|
external_dependencies=pretty_list(external_dependencies),
|
|
|
|
extra_test_libs=extra_test_libs,
|
|
|
|
).encode("utf-8")
|
|
|
|
)
|
2017-04-04 23:09:31 +00:00
|
|
|
self.total_lib = self.total_lib + 1
|
|
|
|
|
2022-09-21 00:47:52 +00:00
|
|
|
def add_rocksdb_library(self, name, srcs, headers=None, external_dependencies=None):
|
2022-02-18 18:59:57 +00:00
|
|
|
if headers is not None:
|
2020-05-20 18:35:28 +00:00
|
|
|
headers = "[" + pretty_list(headers) + "]"
|
2022-09-21 00:47:52 +00:00
|
|
|
with open(self.path, "ab") as targets_file:
|
|
|
|
targets_file.write(
|
|
|
|
targets_cfg.rocksdb_library_template.format(
|
|
|
|
name=name,
|
|
|
|
srcs=pretty_list(srcs),
|
|
|
|
headers=headers,
|
|
|
|
external_dependencies=pretty_list(external_dependencies),
|
|
|
|
).encode("utf-8")
|
2022-02-18 18:59:57 +00:00
|
|
|
)
|
2020-05-17 04:46:21 +00:00
|
|
|
self.total_lib = self.total_lib + 1
|
|
|
|
|
2022-09-21 00:47:52 +00:00
|
|
|
def add_binary(
|
|
|
|
self,
|
|
|
|
name,
|
|
|
|
srcs,
|
|
|
|
deps=None,
|
|
|
|
extra_preprocessor_flags=None,
|
|
|
|
extra_bench_libs=False,
|
|
|
|
):
|
|
|
|
with open(self.path, "ab") as targets_file:
|
|
|
|
targets_file.write(
|
|
|
|
targets_cfg.binary_template.format(
|
|
|
|
name=name,
|
|
|
|
srcs=pretty_list(srcs),
|
|
|
|
deps=pretty_list(deps),
|
|
|
|
extra_preprocessor_flags=pretty_list(extra_preprocessor_flags),
|
|
|
|
extra_bench_libs=extra_bench_libs,
|
|
|
|
).encode("utf-8")
|
|
|
|
)
|
2017-04-04 23:09:31 +00:00
|
|
|
self.total_bin = self.total_bin + 1
|
|
|
|
|
2020-07-03 03:27:31 +00:00
|
|
|
def add_c_test(self):
|
2022-09-21 00:47:52 +00:00
|
|
|
with open(self.path, "ab") as targets_file:
|
|
|
|
targets_file.write(
|
|
|
|
b"""
|
2022-02-18 18:59:57 +00:00
|
|
|
add_c_test_wrapper()
|
2022-09-21 00:47:52 +00:00
|
|
|
"""
|
|
|
|
)
|
2020-07-03 03:27:31 +00:00
|
|
|
|
2022-02-18 18:59:57 +00:00
|
|
|
def add_test_header(self):
|
2022-09-21 00:47:52 +00:00
|
|
|
with open(self.path, "ab") as targets_file:
|
|
|
|
targets_file.write(
|
|
|
|
b"""
|
2022-02-18 18:59:57 +00:00
|
|
|
# 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.
|
2022-09-21 00:47:52 +00:00
|
|
|
"""
|
|
|
|
)
|
2020-07-03 03:27:31 +00:00
|
|
|
|
2022-09-21 00:47:52 +00:00
|
|
|
def add_fancy_bench_config(
|
|
|
|
self,
|
|
|
|
name,
|
|
|
|
bench_config,
|
|
|
|
slow,
|
|
|
|
expected_runtime,
|
|
|
|
sl_iterations,
|
|
|
|
regression_threshold,
|
|
|
|
):
|
|
|
|
with open(self.path, "ab") as targets_file:
|
|
|
|
targets_file.write(
|
|
|
|
targets_cfg.fancy_bench_template.format(
|
2022-02-18 18:59:57 +00:00
|
|
|
name=name,
|
|
|
|
bench_config=pprint.pformat(bench_config),
|
|
|
|
slow=slow,
|
|
|
|
expected_runtime=expected_runtime,
|
2022-03-01 23:09:45 +00:00
|
|
|
sl_iterations=sl_iterations,
|
2022-09-21 00:47:52 +00:00
|
|
|
regression_threshold=regression_threshold,
|
|
|
|
).encode("utf-8")
|
|
|
|
)
|
2017-04-04 23:09:31 +00:00
|
|
|
|
2022-09-21 00:47:52 +00:00
|
|
|
def register_test(self, test_name, src, deps, extra_compiler_flags):
|
|
|
|
with open(self.path, "ab") as targets_file:
|
|
|
|
targets_file.write(
|
|
|
|
targets_cfg.unittests_template.format(
|
|
|
|
test_name=test_name,
|
|
|
|
test_cc=str(src),
|
|
|
|
deps=deps,
|
|
|
|
extra_compiler_flags=extra_compiler_flags,
|
|
|
|
).encode("utf-8")
|
|
|
|
)
|
2017-04-04 23:09:31 +00:00
|
|
|
self.total_test = self.total_test + 1
|