2019-04-18 19:51:19 +02:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
2017-04-05 01:09:31 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import unicode_literals
|
2019-10-23 22:51:03 +02:00
|
|
|
try:
|
|
|
|
from builtins import object
|
|
|
|
from builtins import str
|
|
|
|
except ImportError:
|
|
|
|
from __builtin__ import object
|
|
|
|
from __builtin__ import str
|
2017-04-05 01:09:31 +02:00
|
|
|
import targets_cfg
|
|
|
|
|
2017-11-15 23:13:39 +01:00
|
|
|
def pretty_list(lst, indent=8):
|
2017-04-05 01:09:31 +02:00
|
|
|
if lst is None or len(lst) == 0:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
if len(lst) == 1:
|
|
|
|
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 22:20:20 +01:00
|
|
|
|
2017-04-05 01:09:31 +02:00
|
|
|
separator = "\",\n%s\"" % (" " * indent)
|
2017-11-15 23:13:39 +01:00
|
|
|
res = separator.join(sorted(lst))
|
|
|
|
res = "\n" + (" " * indent) + "\"" + res + "\",\n" + (" " * (indent - 4))
|
2017-04-05 01:09:31 +02:00
|
|
|
return res
|
|
|
|
|
|
|
|
|
2019-10-23 22:51:03 +02:00
|
|
|
class TARGETSBuilder(object):
|
2020-06-05 21:14:42 +02:00
|
|
|
def __init__(self, path):
|
2017-04-05 01:09:31 +02:00
|
|
|
self.path = path
|
2020-09-23 21:54:29 +02:00
|
|
|
self.targets_file = open(path, 'wb')
|
2020-06-05 21:14:42 +02:00
|
|
|
header = targets_cfg.rocksdb_target_header_template
|
2020-09-23 21:54:29 +02:00
|
|
|
self.targets_file.write(header.encode("utf-8"))
|
2017-04-05 01:09:31 +02:00
|
|
|
self.total_lib = 0
|
|
|
|
self.total_bin = 0
|
|
|
|
self.total_test = 0
|
2017-11-15 23:13:39 +01:00
|
|
|
self.tests_cfg = ""
|
2017-04-05 01:09:31 +02:00
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
self.targets_file.close()
|
|
|
|
|
2020-06-05 21:14:42 +02:00
|
|
|
def add_library(self, name, srcs, deps=None, headers=None,
|
|
|
|
extra_external_deps=""):
|
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 22:20:20 +01:00
|
|
|
headers_attr_prefix = ""
|
2017-04-05 01:09:31 +02:00
|
|
|
if headers is None:
|
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 22:20:20 +01:00
|
|
|
headers_attr_prefix = "auto_"
|
2017-04-05 01:09:31 +02:00
|
|
|
headers = "AutoHeaders.RECURSIVE_GLOB"
|
2020-05-20 20:35:28 +02:00
|
|
|
else:
|
|
|
|
headers = "[" + pretty_list(headers) + "]"
|
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 22:20:20 +01:00
|
|
|
self.targets_file.write(targets_cfg.library_template.format(
|
|
|
|
name=name,
|
|
|
|
srcs=pretty_list(srcs),
|
|
|
|
headers_attr_prefix=headers_attr_prefix,
|
|
|
|
headers=headers,
|
2020-06-05 21:14:42 +02:00
|
|
|
deps=pretty_list(deps),
|
2020-09-23 21:54:29 +02:00
|
|
|
extra_external_deps=extra_external_deps).encode("utf-8"))
|
2017-04-05 01:09:31 +02:00
|
|
|
self.total_lib = self.total_lib + 1
|
|
|
|
|
2020-05-17 06:46:21 +02:00
|
|
|
def add_rocksdb_library(self, name, srcs, headers=None):
|
|
|
|
headers_attr_prefix = ""
|
|
|
|
if headers is None:
|
|
|
|
headers_attr_prefix = "auto_"
|
|
|
|
headers = "AutoHeaders.RECURSIVE_GLOB"
|
2020-05-20 20:35:28 +02:00
|
|
|
else:
|
|
|
|
headers = "[" + pretty_list(headers) + "]"
|
2020-05-17 06:46:21 +02:00
|
|
|
self.targets_file.write(targets_cfg.rocksdb_library_template.format(
|
|
|
|
name=name,
|
|
|
|
srcs=pretty_list(srcs),
|
|
|
|
headers_attr_prefix=headers_attr_prefix,
|
2020-09-23 21:54:29 +02:00
|
|
|
headers=headers).encode("utf-8"))
|
2020-05-17 06:46:21 +02:00
|
|
|
self.total_lib = self.total_lib + 1
|
|
|
|
|
2017-04-05 01:09:31 +02:00
|
|
|
def add_binary(self, name, srcs, deps=None):
|
2020-09-23 21:54:29 +02:00
|
|
|
self.targets_file.write(targets_cfg.binary_template.format(
|
|
|
|
name=name,
|
|
|
|
srcs=pretty_list(srcs),
|
|
|
|
deps=pretty_list(deps)).encode("utf-8"))
|
2017-04-05 01:09:31 +02:00
|
|
|
self.total_bin = self.total_bin + 1
|
|
|
|
|
2020-07-03 05:27:31 +02:00
|
|
|
def add_c_test(self):
|
2020-09-23 21:54:29 +02:00
|
|
|
self.targets_file.write(b"""
|
2020-07-07 20:24:02 +02:00
|
|
|
if not is_opt_mode:
|
|
|
|
cpp_binary(
|
|
|
|
name = "c_test_bin",
|
|
|
|
srcs = ["db/c_test.c"],
|
|
|
|
arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS,
|
|
|
|
os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
|
|
|
|
compiler_flags = ROCKSDB_COMPILER_FLAGS,
|
|
|
|
preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
|
|
|
|
deps = [":rocksdb_test_lib"],
|
|
|
|
)
|
2020-07-03 05:27:31 +02:00
|
|
|
|
2020-07-07 20:24:02 +02:00
|
|
|
if not is_opt_mode:
|
|
|
|
custom_unittest(
|
|
|
|
"c_test",
|
|
|
|
command = [
|
|
|
|
native.package_name() + "/buckifier/rocks_test_runner.sh",
|
|
|
|
"$(location :{})".format("c_test_bin"),
|
|
|
|
],
|
|
|
|
type = "simple",
|
|
|
|
)
|
2020-07-03 05:27:31 +02:00
|
|
|
""")
|
|
|
|
|
2019-08-02 19:40:32 +02:00
|
|
|
def register_test(self,
|
|
|
|
test_name,
|
|
|
|
src,
|
|
|
|
is_parallel,
|
|
|
|
extra_deps,
|
|
|
|
extra_compiler_flags):
|
2017-04-05 01:09:31 +02:00
|
|
|
exec_mode = "serial"
|
|
|
|
if is_parallel:
|
|
|
|
exec_mode = "parallel"
|
2017-11-15 23:13:39 +01:00
|
|
|
self.tests_cfg += targets_cfg.test_cfg_template % (
|
|
|
|
test_name,
|
|
|
|
str(src),
|
2019-08-02 19:40:32 +02:00
|
|
|
str(exec_mode),
|
|
|
|
extra_deps,
|
|
|
|
extra_compiler_flags)
|
2017-04-05 01:09:31 +02:00
|
|
|
|
|
|
|
self.total_test = self.total_test + 1
|
|
|
|
|
|
|
|
def flush_tests(self):
|
2020-09-23 21:54:29 +02:00
|
|
|
self.targets_file.write(targets_cfg.unittests_template.format(tests=self.tests_cfg).encode("utf-8"))
|
2017-11-15 23:13:39 +01:00
|
|
|
self.tests_cfg = ""
|