• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2import subprocess
3import re
4from collections import defaultdict
5
6def run_ninja_command():
7    try:
8        # Execute the ninja command
9        cmd = '../../prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -t deps > ninja_deps.txt'
10        subprocess.run(cmd, shell=True, check=True)
11        print("Successfully generated ninja_deps.txt")
12    except subprocess.CalledProcessError as e:
13        print(f"Error running ninja command: {e}")
14        exit(1)
15
16def analyze_deps_file():
17    pattern = re.compile(r'.*\.h$')  # Match .h files
18    keywords = ['arkui/ace_engine', 'arkui/framework/core']
19    count_dict = defaultdict(int)
20
21    try:
22        with open('ninja_deps.txt', 'r') as f:
23            for line in f:
24                line = line.strip()
25                if pattern.search(line):
26                    if any(keyword in line for keyword in keywords):
27                        count_dict[line] += 1
28    except FileNotFoundError:
29        print("Error: ninja_deps.txt not found")
30        exit(1)
31
32    return count_dict
33
34def write_results(count_dict, output_file='arkui_hfile_counts.txt'):
35    with open(output_file, 'w') as f:
36        for filename, count in sorted(count_dict.items(), key=lambda x: x[1], reverse=True):
37            f.write(f"{filename}: {count}\n")
38    print(f"Results written to {output_file}")
39
40def main():
41    # Step 1: Run the ninja command
42    run_ninja_command()
43
44    # Step 2: Analyze the generated file
45    counts = analyze_deps_file()
46
47    # Step 3: Write results to output file
48    write_results(counts)
49
50    # Print summary
51    print(f"Found {len(counts)} matching .h files")
52
53if __name__ == "__main__":
54    main()