• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_rootpath"]
22
23
24def is_source_code_rootpath(path):
25    check_name_list = ["build.sh", "base", "build"]
26    for item in check_name_list:
27        check_path = os.path.join(path, item)
28        if not os.path.exists(check_path):
29            return False
30    return True
31
32
33def get_source_code_rootpath(path):
34    source_code_rootpath = path
35    while True:
36        if source_code_rootpath == "":
37            break
38        if source_code_rootpath == "/" or source_code_rootpath.endswith(":\\"):
39            source_code_rootpath = ""
40            break
41        if is_source_code_rootpath(source_code_rootpath):
42            break
43        source_code_rootpath = os.path.dirname(source_code_rootpath)
44    return source_code_rootpath
45