xref: /test/testfwk/developer_test/src/core/common.py (revision 3f085823)
1#!/usr/bin/env python3
2# coding=utf-8
3
4#
5# Copyright (c) 2022 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20
21__all__ = ["get_source_code_root_path"]
22
23
24def is_source_code_root_path(path):
25    check_name_list = ["./build.sh",
26                       "build",
27                       "prebuilts"]
28    for item in check_name_list:
29        check_path = os.path.join(path, item)
30        if os.path.exists(check_path):
31            return True
32    return False
33
34
35def get_source_code_root_path(path):
36    code_root_path = path
37    while True:
38        if code_root_path == "":
39            break
40        if code_root_path == "/" or code_root_path.endswith(":\\"):
41            code_root_path = ""
42            break
43        if is_source_code_root_path(code_root_path):
44            break
45        code_root_path = os.path.dirname(code_root_path)
46    return code_root_path
47
48
49def is_open_source_product(product_name):
50    open_source_products = ["Hi3516DV300"]
51    return True
52