1e9297d28Sopenharmony_ci#!/usr/bin/env python
2e9297d28Sopenharmony_ci# -*- coding: utf-8 -*-
3e9297d28Sopenharmony_ci
4e9297d28Sopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd.
5e9297d28Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
6e9297d28Sopenharmony_ci# you may not use this file except in compliance with the License.
7e9297d28Sopenharmony_ci# You may obtain a copy of the License at
8e9297d28Sopenharmony_ci#
9e9297d28Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
10e9297d28Sopenharmony_ci#
11e9297d28Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
12e9297d28Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
13e9297d28Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14e9297d28Sopenharmony_ci# See the License for the specific language governing permissions and
15e9297d28Sopenharmony_ci# limitations under the License.
16e9297d28Sopenharmony_ci
17e9297d28Sopenharmony_ciimport os
18e9297d28Sopenharmony_ciimport sys
19e9297d28Sopenharmony_ciimport shutil
20e9297d28Sopenharmony_ciimport errno
21e9297d28Sopenharmony_ci
22e9297d28Sopenharmony_ci
23e9297d28Sopenharmony_cidef main():
24e9297d28Sopenharmony_ci    if (len(sys.argv) != 3):
25e9297d28Sopenharmony_ci        sys.stderr.write("MUST have 1 parameter for the source path and 1 parameter for the destination")
26e9297d28Sopenharmony_ci        sys.stderr.write(os.linesep)
27e9297d28Sopenharmony_ci        exit(errno.EINVAL)
28e9297d28Sopenharmony_ci
29e9297d28Sopenharmony_ci    source_dir = os.path.realpath(sys.argv[1])
30e9297d28Sopenharmony_ci    if (not os.path.isdir(source_dir)):
31e9297d28Sopenharmony_ci        sys.stderr.write("Source path MUST be a directory")
32e9297d28Sopenharmony_ci        sys.stderr.write(os.linesep)
33e9297d28Sopenharmony_ci        exit(errno.EINVAL)
34e9297d28Sopenharmony_ci
35e9297d28Sopenharmony_ci    dest_dir = os.path.realpath(sys.argv[2])
36e9297d28Sopenharmony_ci    if (not os.path.isdir(dest_dir)):
37e9297d28Sopenharmony_ci        sys.stderr.write("Destination path MUST be a directory")
38e9297d28Sopenharmony_ci        sys.stderr.write(os.linesep)
39e9297d28Sopenharmony_ci        exit(errno.EINVAL)
40e9297d28Sopenharmony_ci
41e9297d28Sopenharmony_ci    for item in os.listdir(source_dir):
42e9297d28Sopenharmony_ci        if item in ["ohos", "preview"]:
43e9297d28Sopenharmony_ci            continue
44e9297d28Sopenharmony_ci
45e9297d28Sopenharmony_ci        if not os.path.isdir(os.path.join(source_dir, item)):
46e9297d28Sopenharmony_ci            continue
47e9297d28Sopenharmony_ci
48e9297d28Sopenharmony_ci        file_path = os.path.join(source_dir, item, "build", "platform.gni")
49e9297d28Sopenharmony_ci        if not os.path.isfile(file_path):
50e9297d28Sopenharmony_ci            continue
51e9297d28Sopenharmony_ci
52e9297d28Sopenharmony_ci        dest_dir_build_folder = os.path.join(dest_dir, item, "build")
53e9297d28Sopenharmony_ci        if not os.path.exists(dest_dir_build_folder):
54e9297d28Sopenharmony_ci            shutil.copytree(os.path.join(source_dir, item, "build"), dest_dir_build_folder, dirs_exist_ok=True)
55e9297d28Sopenharmony_ci
56e9297d28Sopenharmony_ciif __name__ == "__main__":
57e9297d28Sopenharmony_ci    main()
58