1#!/usr/bin/env python3
2#
3# Copyright (C) 2019 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import argparse
19import os
20import sys
21
22from abitool import get_abi_tool
23
24def dump_abi(abitool, linux_tree, out_file, whitelist):
25    tool = get_abi_tool(abitool)
26    tool.dump_kernel_abi(linux_tree, out_file, whitelist)
27
28def main():
29    """ Build the linux kernel, freshly cloning if needed"""
30    parser = argparse.ArgumentParser()
31    parser.add_argument('--linux-tree',
32                        help='Path to kernel tree containing '
33                             'vmlinux and modules',
34                        required=True)
35    parser.add_argument('--abi-tool', default='libabigail',
36                        help='abi tool to be used to monitor abi')
37    parser.add_argument('--out-file', default=None,
38                        help='where to write the abi dump to')
39    parser.add_argument('--kmi-whitelist', default=None,
40                        help='KMI whitelist to filter for')
41
42    args = parser.parse_args()
43
44    dump_abi(args.abi_tool,
45             args.linux_tree,
46             args.out_file or os.path.join(args.linux_tree, "abi.xml"),
47             args.kmi_whitelist)
48
49if __name__ == "__main__":
50    sys.exit(main())
51