1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (c) 2023 Huawei Device Co., Ltd.
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
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
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.
15
16import os
17import sys
18import argparse
19
20import check_deps_handler
21import check_external_deps
22import check_part_subsystem_name
23sys.path.append(
24    os.path.dirname(os.path.dirname(os.path.dirname(
25        os.path.abspath(__file__)))))
26from scripts.util.build_utils import write_depfile, add_depfile_option, touch  # noqa: E402
27
28
29def parse_args():
30    parser = argparse.ArgumentParser()
31    add_depfile_option(parser)
32    parser.add_argument("--skip-check-subsystem", required=False, action="store_true")
33    parser.add_argument('--part-name', required=True)
34    parser.add_argument('--subsystem-name', required=True)
35    parser.add_argument('--source-root-dir', required=True)
36    parser.add_argument('--target-path', required=True)
37    parser.add_argument('--deps', nargs='*', required=False)
38    parser.add_argument('--external-deps', nargs='*', required=False)
39    parser.add_argument('--output', required=True)
40    parser.add_argument('--compile-standard-allow-file', required=True)
41    args = parser.parse_args()
42
43    return args
44
45
46def main():
47    args = parse_args()
48
49    depfiles = []
50    if not args.skip_check_subsystem:
51        _depfile = check_part_subsystem_name.check(args)
52        depfiles.extend(_depfile)
53
54    if args.deps:
55        _depfile = check_deps_handler.check(args)
56        depfiles.extend(_depfile)
57
58    if args.external_deps:
59        _depfile = check_external_deps.check(args)
60        depfiles.extend(_depfile)
61
62    if depfiles:
63        depfiles = list(set(depfiles))
64        write_depfile(args.depfile, args.output, depfiles)
65
66    touch(args.output)
67
68    return 0
69
70
71if __name__ == '__main__':
72    sys.exit(main())
73