From a16457625243e22b08cd1c87ce01153e4f554d77 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Tue, 17 Sep 2024 13:21:57 -0700 Subject: [PATCH] Remove last user of AutoHeaders.RECURSIVE_GLOB Summary: I came across this code while buckifying parts of folly and fizz in open source. This is pretty hacky code and cleaning it up doesn't seem that hard, so I did it. Reviewed By: zertosh, pdillinger Differential Revision: D62781766 fbshipit-source-id: 43714bce992c53149d1e619063d803297362fb5d --- TARGETS | 14 +++++++------- buckifier/buckify_rocksdb.py | 4 ++-- buckifier/targets_builder.py | 29 ++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/TARGETS b/TARGETS index 4b79a73e42..f09e5fffd1 100644 --- a/TARGETS +++ b/TARGETS @@ -362,9 +362,9 @@ cpp_library_wrapper(name="rocksdb_lib", srcs=[ "//folly/experimental/coro:coroutine", "//folly/experimental/coro:task", "//folly/synchronization:distributed_mutex", - ], headers=None, link_whole=False, extra_test_libs=False) + ], headers=glob(["**/*.h"]), link_whole=False, extra_test_libs=False) -cpp_library_wrapper(name="rocksdb_whole_archive_lib", srcs=[], deps=[":rocksdb_lib"], headers=None, link_whole=True, extra_test_libs=False) +cpp_library_wrapper(name="rocksdb_whole_archive_lib", srcs=[], deps=[":rocksdb_lib"], headers=[], link_whole=True, extra_test_libs=False) cpp_library_wrapper(name="rocksdb_test_lib", srcs=[ "db/db_test_util.cc", @@ -378,7 +378,7 @@ cpp_library_wrapper(name="rocksdb_test_lib", srcs=[ "tools/trace_analyzer_tool.cc", "utilities/agg_merge/test_agg_merge.cc", "utilities/cassandra/test_utils.cc", - ], deps=[":rocksdb_lib"], headers=None, link_whole=False, extra_test_libs=True) + ], deps=[":rocksdb_lib"], headers=[], link_whole=False, extra_test_libs=True) cpp_library_wrapper(name="rocksdb_tools_lib", srcs=[ "test_util/testutil.cc", @@ -386,9 +386,9 @@ cpp_library_wrapper(name="rocksdb_tools_lib", srcs=[ "tools/db_bench_tool.cc", "tools/simulated_hybrid_file_system.cc", "tools/trace_analyzer_tool.cc", - ], deps=[":rocksdb_lib"], headers=None, link_whole=False, extra_test_libs=False) + ], deps=[":rocksdb_lib"], headers=[], link_whole=False, extra_test_libs=False) -cpp_library_wrapper(name="rocksdb_cache_bench_tools_lib", srcs=["cache/cache_bench_tool.cc"], deps=[":rocksdb_lib"], headers=None, link_whole=False, extra_test_libs=False) +cpp_library_wrapper(name="rocksdb_cache_bench_tools_lib", srcs=["cache/cache_bench_tool.cc"], deps=[":rocksdb_lib"], headers=[], link_whole=False, extra_test_libs=False) rocks_cpp_library_wrapper(name="rocksdb_stress_lib", srcs=[ "db_stress_tool/batched_ops_stress.cc", @@ -410,7 +410,7 @@ rocks_cpp_library_wrapper(name="rocksdb_stress_lib", srcs=[ "test_util/testutil.cc", "tools/block_cache_analyzer/block_cache_trace_analyzer.cc", "tools/trace_analyzer_tool.cc", - ], headers=None) + ], headers=[]) cpp_binary_wrapper(name="ldb", srcs=["tools/ldb.cc"], deps=[":rocksdb_tools_lib"], extra_preprocessor_flags=[], extra_bench_libs=False) @@ -5026,7 +5026,7 @@ cpp_unittest_wrapper(name="dynamic_bloom_test", extra_compiler_flags=[]) -cpp_library_wrapper(name="env_basic_test_lib", srcs=["env/env_basic_test.cc"], deps=[":rocksdb_test_lib"], headers=None, link_whole=False, extra_test_libs=True) +cpp_library_wrapper(name="env_basic_test_lib", srcs=["env/env_basic_test.cc"], deps=[":rocksdb_test_lib"], headers=[], link_whole=False, extra_test_libs=True) cpp_unittest_wrapper(name="env_basic_test", srcs=["env/env_basic_test.cc"], diff --git a/buckifier/buckify_rocksdb.py b/buckifier/buckify_rocksdb.py index 815e55d7bf..0ce29a695e 100755 --- a/buckifier/buckify_rocksdb.py +++ b/buckifier/buckify_rocksdb.py @@ -11,7 +11,7 @@ import json import os import sys -from targets_builder import TARGETSBuilder +from targets_builder import TARGETSBuilder, LiteralValue from util import ColorString @@ -150,6 +150,7 @@ def generate_targets(repo_path, deps_map): "//folly/experimental/coro:task", "//folly/synchronization:distributed_mutex", ], + headers=LiteralValue("glob([\"**/*.h\"])") ) # rocksdb_whole_archive_lib TARGETS.add_library( @@ -158,7 +159,6 @@ def generate_targets(repo_path, deps_map): deps=[ ":rocksdb_lib", ], - headers=None, extra_external_deps="", link_whole=True, ) diff --git a/buckifier/targets_builder.py b/buckifier/targets_builder.py index f5d727469b..f6e35593d4 100644 --- a/buckifier/targets_builder.py +++ b/buckifier/targets_builder.py @@ -9,17 +9,28 @@ import pprint import targets_cfg +class LiteralValue: + def __init__(self, value): + self.value = value + + def __str__(self): + return str(self.value) + +def smart_quote_value(val): + if isinstance(val, LiteralValue): + return str(val) + return '"%s"' % val def pretty_list(lst, indent=8): if lst is None or len(lst) == 0: return "" if len(lst) == 1: - return '"%s"' % lst[0] + return smart_quote_value(lst[0]) - separator = '",\n%s"' % (" " * indent) - res = separator.join(sorted(lst)) - res = "\n" + (" " * indent) + '"' + res + '",\n' + (" " * (indent - 4)) + separator = ',\n%s' % (" " * indent) + res = separator.join(sorted(map(smart_quote_value, lst))) + res = "\n" + (" " * indent) + res + ',\n' + (" " * (indent - 4)) return res @@ -48,7 +59,12 @@ class TARGETSBuilder: extra_test_libs=False, ): if headers is not None: - headers = "[" + pretty_list(headers) + "]" + if isinstance(headers, LiteralValue): + headers = str(headers) + else: + headers = "[" + pretty_list(headers) + "]" + else: + headers = "[]" with open(self.path, "ab") as targets_file: targets_file.write( targets_cfg.library_template.format( @@ -65,8 +81,7 @@ class TARGETSBuilder: self.total_lib = self.total_lib + 1 def add_rocksdb_library(self, name, srcs, headers=None, external_dependencies=None): - if headers is not None: - headers = "[" + pretty_list(headers) + "]" + headers = "[" + pretty_list(headers) + "]" with open(self.path, "ab") as targets_file: targets_file.write( targets_cfg.rocksdb_library_template.format(