• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2014-2018 Intel Corporation.   All Rights Reserved.
2#
3# Permission is hereby granted, free of charge, to any person obtaining a
4# copy of this software and associated documentation files (the "Software"),
5# to deal in the Software without restriction, including without limitation
6# the rights to use, copy, modify, merge, publish, distribute, sublicense,
7# and/or sell copies of the Software, and to permit persons to whom the
8# Software is furnished to do so, subject to the following conditions:
9#
10# The above copyright notice and this permission notice (including the next
11# paragraph) shall be included in all copies or substantial portions of the
12# Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20# IN THE SOFTWARE.
21
22# Python source
23import os
24import sys
25import knob_defs
26from gen_common import *
27
28def main(args=sys.argv[1:]):
29
30    # parse args
31    parser = ArgumentParser()
32    parser.add_argument("--output", "-o", help="Path to output file", required=True)
33    parser.add_argument("--gen_h", "-gen_h", help="Generate gen_knobs.h", action="store_true", default=False)
34    parser.add_argument("--gen_cpp", "-gen_cpp", help="Generate gen_knobs.cpp", action="store_true", required=False)
35
36    args = parser.parse_args()
37
38    cur_dir = os.path.dirname(os.path.abspath(__file__))
39    template_cpp = os.path.join(cur_dir, 'templates', 'gen_knobs.cpp')
40    template_h = os.path.join(cur_dir, 'templates', 'gen_knobs.h')
41
42    output_filename = os.path.basename(args.output)
43    output_dir = MakeTmpDir('_codegen')
44
45    output_file = os.path.join(output_dir, output_filename)
46
47    rval = 0
48
49    try:
50        if args.gen_h:
51            MakoTemplateWriter.to_file(
52                template_h,
53                output_file,
54                cmdline=sys.argv,
55                filename='gen_knobs',
56                knobs=knob_defs.KNOBS)
57
58        if args.gen_cpp:
59            MakoTemplateWriter.to_file(
60                template_cpp,
61                output_file,
62                cmdline=sys.argv,
63                filename='gen_knobs',
64                knobs=knob_defs.KNOBS,
65                includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'])
66
67        rval = CopyFileIfDifferent(output_file, args.output)
68
69    except:
70        rval = 1
71
72    finally:
73        # ignore errors from delete of tmp directory
74        DeleteDirTree(output_dir)
75
76    return 0
77
78if __name__ == '__main__':
79    sys.exit(main())
80
81