• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2021 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import argparse
17import sys
18import os
19import zipfile
20
21sys.path.append(
22    os.path.dirname(os.path.dirname(os.path.dirname(
23        os.path.abspath(__file__)))))
24from scripts.util import build_utils  # noqa: E402
25
26
27def main():
28    parser = argparse.ArgumentParser()
29    build_utils.add_depfile_option(parser)
30
31    parser.add_argument('--sdk-notice-file', required=True)
32    parser.add_argument('--sdk-archive-dir', default=None)
33    parser.add_argument('--output', required=True)
34    parser.add_argument('--skip-pattern', required=True)
35
36    options = parser.parse_args()
37
38    sdk_archives = []
39    for root, _, files in os.walk(options.sdk_archive_dir):
40        sdk_archives.extend(
41            [os.path.join(root, f) for f in files if f.endswith('.zip')])
42    for archive in sdk_archives:
43        if options.skip_pattern in archive:
44            continue
45        with zipfile.ZipFile(archive, 'a') as zip_file, open(
46            options.sdk_notice_file) as notice:
47            if not zip_file.namelist():
48                continue
49            dirname = zip_file.namelist()[0].split('/')[0]
50            arcname = os.path.join(dirname,
51                                   os.path.basename(options.sdk_notice_file))
52            if arcname in zip_file.namelist():
53                print("Warning: {} is already in {}".format(arcname, archive))
54                continue
55            zip_info = zipfile.ZipInfo(filename=arcname,
56                                       date_time=build_utils.HERMETIC_TIMESTAMP)
57            zip_file.writestr(zip_info,
58                              notice.read(),
59                              compress_type=zipfile.ZIP_STORED)
60    build_utils.touch(options.output)
61
62    build_utils.write_depfile(options.depfile,
63                             options.output,
64                             sdk_archives,
65                             add_pydeps=False)
66
67
68if __name__ == '__main__':
69    sys.exit(main())
70