]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/buckifier/buckify_rocksdb.py
1 from __future__
import absolute_import
2 from __future__
import division
3 from __future__
import print_function
4 from __future__
import unicode_literals
5 from targets_builder
import TARGETSBuilder
6 from optparse
import OptionParser
12 from util
import ColorString
15 # tests to export as libraries for inclusion in other projects
16 _EXPORTED_TEST_LIBS
= ["env_basic_test"]
18 # Parse src.mk files as a Dictionary of
19 # VAR_NAME => list of files
20 def parse_src_mk(repo_path
):
21 src_mk
= repo_path
+ "/src.mk"
23 for line
in open(src_mk
):
25 if len(line
) == 0 or line
[0] == '#':
28 current_src
= line
.split('=')[0].strip()
29 src_files
[current_src
] = []
31 src_path
= line
.split('.cc')[0].strip() + '.cc'
32 src_files
[current_src
].append(src_path
)
36 # get all .cc / .c files
37 def get_cc_files(repo_path
):
39 for root
, dirnames
, filenames
in os
.walk(repo_path
):
40 root
= root
[(len(repo_path
) + 1):]
44 for filename
in fnmatch
.filter(filenames
, '*.cc'):
45 cc_files
.append(os
.path
.join(root
, filename
))
46 for filename
in fnmatch
.filter(filenames
, '*.c'):
47 cc_files
.append(os
.path
.join(root
, filename
))
51 # Get tests from Makefile
52 def get_tests(repo_path
):
53 Makefile
= repo_path
+ "/Makefile"
55 # Dictionary TEST_NAME => IS_PARALLEL
59 for line
in open(Makefile
):
61 if line
.startswith("TESTS ="):
64 if line
.endswith("\\"):
65 # remove the trailing \
70 # we consumed all the tests
73 found_parallel_tests
= False
74 for line
in open(Makefile
):
76 if line
.startswith("PARALLEL_TEST ="):
77 found_parallel_tests
= True
78 elif found_parallel_tests
:
79 if line
.endswith("\\"):
80 # remove the trailing \
85 # we consumed all the parallel tests
91 # Prepare TARGETS file for buck
92 def generate_targets(repo_path
):
93 print(ColorString
.info("Generating TARGETS"))
95 src_mk
= parse_src_mk(repo_path
)
97 cc_files
= get_cc_files(repo_path
)
98 # get tests from Makefile
99 tests
= get_tests(repo_path
)
101 if src_mk
is None or cc_files
is None or tests
is None:
104 TARGETS
= TARGETSBuilder("%s/TARGETS" % repo_path
)
108 src_mk
["LIB_SOURCES"] +
109 src_mk
["TOOL_LIB_SOURCES"])
113 src_mk
.get("MOCK_LIB_SOURCES", []) +
114 src_mk
.get("TEST_LIB_SOURCES", []) +
115 src_mk
.get("EXP_LIB_SOURCES", []),
120 src_mk
.get("BENCH_LIB_SOURCES", []) +
121 ["util/testutil.cc"],
124 # test for every test we found in the Makefile
126 match_src
= [src
for src
in cc_files
if ("/%s.c" % test
) in src
]
127 if len(match_src
) == 0:
128 print(ColorString
.warning("Cannot find .cc file for %s" % test
))
130 elif len(match_src
) > 1:
131 print(ColorString
.warning("Found more than one .cc for %s" % test
))
135 assert(len(match_src
) == 1)
136 is_parallel
= tests
[test
]
137 TARGETS
.register_test(test
, match_src
[0], is_parallel
)
139 if test
in _EXPORTED_TEST_LIBS
:
140 test_library
= "%s_lib" % test
141 TARGETS
.add_library(test_library
, match_src
, [":rocksdb_test_lib"])
142 TARGETS
.flush_tests()
144 print(ColorString
.info("Generated TARGETS Summary:"))
145 print(ColorString
.info("- %d libs" % TARGETS
.total_lib
))
146 print(ColorString
.info("- %d binarys" % TARGETS
.total_bin
))
147 print(ColorString
.info("- %d tests" % TARGETS
.total_test
))
151 def get_rocksdb_path():
152 # rocksdb = {script_dir}/..
153 script_dir
= os
.path
.dirname(sys
.argv
[0])
154 script_dir
= os
.path
.abspath(script_dir
)
155 rocksdb_path
= os
.path
.abspath(
156 os
.path
.join(script_dir
, "../"))
160 def exit_with_error(msg
):
161 print(ColorString
.error(msg
))
166 # Generate TARGETS file for buck
167 ok
= generate_targets(get_rocksdb_path())
169 exit_with_error("Failed to generate TARGETS files")
171 if __name__
== "__main__":