1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2024 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
17import os
18import sys
19import shutil
20import errno
21
22
23def main():
24    if (len(sys.argv) != 3):
25        sys.stderr.write("MUST have 1 parameter for the source path and 1 parameter for the destination")
26        sys.stderr.write(os.linesep)
27        exit(errno.EINVAL)
28
29    source_dir = os.path.realpath(sys.argv[1])
30    if (not os.path.isdir(source_dir)):
31        sys.stderr.write("Source path MUST be a directory")
32        sys.stderr.write(os.linesep)
33        exit(errno.EINVAL)
34
35    dest_dir = os.path.realpath(sys.argv[2])
36    if (not os.path.isdir(dest_dir)):
37        sys.stderr.write("Destination path MUST be a directory")
38        sys.stderr.write(os.linesep)
39        exit(errno.EINVAL)
40
41    for item in os.listdir(source_dir):
42        if item in ["ohos", "preview"]:
43            continue
44
45        if not os.path.isdir(os.path.join(source_dir, item)):
46            continue
47
48        file_path = os.path.join(source_dir, item, "build", "platform.gni")
49        if not os.path.isfile(file_path):
50            continue
51
52        dest_dir_build_folder = os.path.join(dest_dir, item, "build")
53        if not os.path.exists(dest_dir_build_folder):
54            shutil.copytree(os.path.join(source_dir, item, "build"), dest_dir_build_folder, dirs_exist_ok=True)
55
56if __name__ == "__main__":
57    main()
58