xref: /aosp_15_r20/external/deqp/scripts/src_util/check_file_size_limit.py (revision 35238bce31c2a825756842865a792f8cf7f89930)
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright 2015 The Android Open Source Project
8# Copyright 2023 The Khronos Group Inc.
9#
10# Licensed under the Apache License, Version 2.0 (the "License");
11# you may not use this file except in compliance with the License.
12# You may obtain a copy of the License at
13#
14#      http://www.apache.org/licenses/LICENSE-2.0
15#
16# Unless required by applicable law or agreed to in writing, software
17# distributed under the License is distributed on an "AS IS" BASIS,
18# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19# See the License for the specific language governing permissions and
20# limitations under the License.
21#
22#-------------------------------------------------------------------------
23
24import os
25import sys
26from argparse import ArgumentParser
27from common import getChangedFiles, getAllProjectFiles
28
29def checkFileSizeLimit (file, limitBytes):
30    fileSize = os.path.getsize(file)
31    if fileSize <= limitBytes:
32        return True
33    else:
34        print(f"File size {fileSize} bytes exceeds the limit of {limitBytes} bytes for {file}")
35        return False
36
37def checkFilesSizeLimit (files, limitBytes):
38    error = False
39    for file in files:
40        if not checkFileSizeLimit(file, limitBytes):
41            error = True
42
43    return not error
44
45if __name__ == "__main__":
46    parser = ArgumentParser()
47    parser.add_argument("-l", "--limit", required=True, type=int, help="Maximum file size allowed in MB")
48    args = parser.parse_args()
49
50    files = getAllProjectFiles()
51    error = not checkFilesSizeLimit(files, args.limit * 1024 * 1024)
52
53    if error:
54        print("One or more checks failed")
55        sys.exit(1)
56
57    print("All checks passed")
58