2 # Copyright (c) 2019. Vinci Consulting Corp. All Rights Reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
21 from multiprocessing import Pool
24 subprocess.check_output("git rev-parse --show-toplevel", shell=True)
30 output_path = pathlib.Path(
31 "%s/build-root/install-vpp-native/vpp/share/vpp/api/" % BASE_DIR
33 output_path_debug = pathlib.Path(
34 "%s/build-root/install-vpp_debug-native/vpp/share/vpp/api/" % BASE_DIR
46 def api_search_globs(src_dir):
48 for g in output_dir_map:
49 globs.extend(list(src_dir.glob("%s/**/*.api" % g)))
53 def api_files(src_dir):
54 print("Searching '%s' for .api files." % src_dir.as_posix())
55 return [x for x in api_search_globs(src_dir)]
58 def get_n_parallel(n_parallel):
60 n_parallel = os.environ.get("MAKE_PARALLEL_JOBS", os.cpu_count())
62 n_parallel = int(n_parallel)
65 return n_parallel or os.cpu_count()
69 cliparser = argparse.ArgumentParser(description="VPP API JSON definition generator")
70 cliparser.add_argument("--srcdir", action="store", default="%s/src" % BASE_DIR),
71 cliparser.add_argument("--output", action="store", help="directory to store files"),
72 cliparser.add_argument(
73 "--parallel", type=int, default=0, help="Number of parallel processes"
75 cliparser.add_argument(
79 help="'True' if -debug target",
82 args = cliparser.parse_args()
84 src_dir = pathlib.Path(args.srcdir)
85 output_target = output_path_debug if args.debug_target else output_path
88 output_dir = pathlib.Path(args.output)
90 output_dir = pathlib.Path(output_target)
92 for d in output_dir_map.values():
93 output_dir.joinpath(d).mkdir(exist_ok=True, parents=True)
95 for f in output_dir.glob("**/*.api.json"):
98 with Pool(get_n_parallel(args.parallel)) as p:
100 vppapigen.run_kw_vppapigen,
103 "output": "%s/%s/%s.json"
107 f.as_posix().split("/")[
108 src_dir_depth + BASE_DIR.count("/") - 1
113 "input_file": f.as_posix(),
114 "includedir": [src_dir.as_posix()],
115 "output_module": "JSON",
117 for f in api_files(src_dir)
121 print("json files written to: %s/." % output_dir)
124 if __name__ == "__main__":