• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (c) 2021 Huawei Device Co., Ltd.
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 stat
20import os
21import sys
22import json
23sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
24from utils import makedirs
25
26
27def get_args(args):
28    parser = argparse.ArgumentParser()
29    parser.add_argument('--depfile', help='Path to depfile (refer to `gn help depfile`)')
30    parser.add_argument('--output_dir', help='output directory')
31    parser.add_argument('--source_dir', help='source directory')
32    parser.add_argument('--target', help='name of target')
33    parser.add_argument('--target_label')
34    parser.add_argument('--test_type')
35    parser.add_argument('--module_list_file', help='file name of module list')
36    parser.add_argument('--sources_file_search_root_dir',
37                        help='root dir to search xx.sources files')
38    parser.add_argument('--sources',
39                        help='case sources path defined in test template')
40    options = parser.parse_args(args)
41    return options
42
43
44def main(args):
45    options = get_args(args)
46    print("test module_list_file = {}".\
47        format(os.path.dirname(options.module_list_file)))
48    if not os.path.exists(os.path.dirname(options.module_list_file)):
49        makedirs(os.path.dirname(options.module_list_file))
50
51    with os.fdopen(os.open(options.module_list_file,
52                           os.O_RDWR | os.O_CREAT, stat.S_IWUSR | stat.S_IRUSR),
53                   'w', encoding='utf-8') as module_list_file:
54        contents = json.dumps([{
55            'target': options.target,
56            'label': options.target_label,
57            'source_directory': options.source_dir,
58            'output_directory': options.output_dir,
59            'test_type': options.test_type
60        }])
61        module_list_file.write(contents)
62
63    # create xx.sources file
64    fold = os.path.join(options.sources_file_search_root_dir, \
65        options.source_dir[(options.source_dir.rfind("../") + len("../")):])
66    if not os.path.exists(fold):
67        makedirs(fold)
68    sources_file_name = fold[fold.rfind("/") + len("/"):] + ".sources"
69
70    arg_sources = options.sources[0: (len(options.sources) - len(","))]
71
72    with os.fdopen(os.open(os.path.join(fold, sources_file_name),
73                           os.O_RDWR | os.O_CREAT, stat.S_IWUSR | stat.S_IRUSR),
74                   'a', encoding='utf-8') as source_defined_file:
75        list_sources = arg_sources.split(",")
76        for source in list_sources:
77            content = "{}/{}\n".format(
78                os.path.dirname(options.source_dir), source)
79            source_defined_file.write(content)
80
81
82if __name__ == '__main__':
83    sys.exit(main(sys.argv[1:]))
84