1#!/usr/bin/env python3
2#
3# Copyright (C) 2021-2022 Intel Corporation.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8import sys, os
9import lxml.etree
10from defusedxml.lxml import parse, fromstring
11import argparse
12sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library'))
13import acrn_config_utilities
14from importlib import import_module
15
16def main(args):
17    # Initialize configuration libraries for backward compatibility
18    acrn_config_utilities.BOARD_INFO_FILE = args.board
19    acrn_config_utilities.SCENARIO_INFO_FILE = args.scenario
20    acrn_config_utilities.get_vm_num(args.scenario)
21    acrn_config_utilities.get_load_order()
22
23    scripts_path = os.path.dirname(os.path.realpath(__file__))
24    current = os.path.basename(__file__)
25
26    board_etree = parse(args.board)
27    scenario_etree = parse(args.scenario)
28    allocation_etree = lxml.etree.ElementTree(element=fromstring("<acrn-config></acrn-config>"))
29    for script in sorted([f for f in os.listdir(scripts_path) if f.endswith(".py") and f != current]):
30        module_name = os.path.splitext(script)[0]
31        module = import_module(f"{module_name}")
32        module.fn(board_etree, scenario_etree, allocation_etree)
33    allocation_etree.write(args.output, pretty_print=True)
34
35if __name__ == '__main__':
36    parser = argparse.ArgumentParser()
37    parser.add_argument("--board", help="the XML file summarizing characteristics of the target board")
38    parser.add_argument("--scenario", help="the XML file specifying the scenario to be set up")
39    parser.add_argument("--output", help="location of the output XML")
40    args = parser.parse_args()
41
42    main(args)
43