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 optparse 19import os 20import sys 21import json 22sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 23from utils import makedirs 24 25 26def get_args(args): 27 parser = optparse.OptionParser() 28 if hasattr(parser, 'add_option'): 29 func = parser.add_option 30 else: 31 func = parser.add_argument 32 func('--depfile', help='Path to depfile (refer to `gn help depfile`)') 33 parser.add_option('--output_dir', help='output directory') 34 parser.add_option('--source_dir', help='source directory') 35 parser.add_option('--target', help='name of target') 36 parser.add_option('--target_label') 37 parser.add_option('--test_type') 38 parser.add_option('--module_list_file', help='file name of module list') 39 parser.add_option('--sources_file_search_root_dir', \ 40 help='root dir to search xx.sources files') 41 parser.add_option('--sources', \ 42 help='case sources path defined in test template') 43 options, _ = parser.parse_args(args) 44 return options, parser 45 46 47def main(args): 48 options, _ = get_args(args) 49 print("test module_list_file = {}".\ 50 format(os.path.dirname(options.module_list_file))) 51 if not os.path.exists(os.path.dirname(options.module_list_file)): 52 makedirs(os.path.dirname(options.module_list_file)) 53 with open(options.module_list_file, 'w') 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 with open(os.path.join(fold, sources_file_name), 'a') \ 72 as source_defined_file: 73 list_sources = arg_sources.split(",") 74 for source in list_sources: 75 content = "{}/{}\n".format( 76 os.path.dirname(options.source_dir), source) 77 source_defined_file.write(content) 78 79 80if __name__ == '__main__': 81 sys.exit(main(sys.argv[1:])) 82