File: preprocessed_file_size_stats.py

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (42 lines) | stat: -rwxr-xr-x 1,183 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3

import clang.cindex
import click
import json
import os
import os.path
import sys


@click.command()
@click.option('--remove_prefix', type=str, default='')
@click.argument('build_dir', type=click.Path(exists=True))
def main(build_dir, remove_prefix):
    libclang = os.environ.get('LIBCLANG')
    if libclang is not None:
        clang.cindex.Config.set_library_file(libclang)
    db = clang.cindex.CompilationDatabase.fromDirectory(build_dir)
    files = dict()
    total = 0
    for command in db.getAllCompileCommands():
        try:
            size = os.stat(os.path.join(command.directory, get_output_path(command.arguments))).st_size
            files[command.filename.removeprefix(remove_prefix)] = size
            total += size
        except Exception as e:
            print(f'Failed to process command for {command.filename}: {e}', file=sys.stderr)
            pass
    files['total'] = total
    json.dump(files, sys.stdout)


def get_output_path(arguments):
    return_next = False
    for v in arguments:
        if return_next:
            return v
        elif v == '-o':
            return_next = True

if __name__ == '__main__':
    main()