Skip to content

Commit 16f2de2

Browse files
committed
Progress workflow for decomp.dev
1 parent fcf8aee commit 16f2de2

4 files changed

Lines changed: 252 additions & 6 deletions

File tree

.github/scripts/gen_report.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import json
4+
from collections import defaultdict
5+
from common.util import utils
6+
from common.util.utils import FunctionStatus
7+
from report_pb2 import Report, Measures
8+
9+
def compute_measures(version: str | None = None) -> Measures:
10+
counts = defaultdict(int)
11+
sizes = defaultdict(int)
12+
13+
total_code = 0
14+
total_functions = 0
15+
16+
for func in utils.get_functions(version=version):
17+
counts[func.status] += 1
18+
sizes[func.status] += func.size
19+
total_code += func.size
20+
total_functions += 1
21+
22+
matched_code = sizes[FunctionStatus.Matching]
23+
matched_functions = counts[FunctionStatus.Matching]
24+
25+
m = Measures()
26+
m.total_code = total_code
27+
m.matched_code = matched_code
28+
m.matched_code_percent = (matched_code / total_code * 100) if total_code else 0.0
29+
30+
m.total_functions = total_functions
31+
m.matched_functions = matched_functions
32+
m.matched_functions_percent = (matched_functions / total_functions * 100) if total_functions else 0.0
33+
34+
m.total_data = 0
35+
m.matched_data = 0
36+
m.matched_data_percent = 0.0
37+
m.complete_data = 0
38+
m.complete_data_percent = 0.0
39+
40+
m.total_units = 0
41+
m.complete_units = 0
42+
43+
return m
44+
45+
def build_report(version: str | None = None) -> Report:
46+
report = Report()
47+
report.version = 1
48+
report.measures.CopyFrom(compute_measures(version))
49+
return report
50+
51+
def main():
52+
parser = argparse.ArgumentParser()
53+
parser.add_argument("--version", help="CSV version to read")
54+
parser.add_argument("--output", "-o", help="Output JSON file")
55+
args = parser.parse_args()
56+
57+
report = build_report(args.version)
58+
59+
from google.protobuf.json_format import MessageToJson
60+
json_str = MessageToJson(report, indent=2)
61+
62+
if args.output:
63+
with open(args.output, "w") as f:
64+
f.write(json_str)
65+
else:
66+
print(json_str)
67+
68+
if __name__ == "__main__":
69+
main()

.github/scripts/report.proto

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// From https://github.com/encounter/objdiff/blob/main/objdiff-core/protos/report.proto
2+
3+
syntax = "proto3";
4+
5+
package objdiff.report;
6+
7+
// Project progress report
8+
message Report {
9+
// Overall progress info
10+
Measures measures = 1;
11+
// Units within this report
12+
repeated ReportUnit units = 2;
13+
// Report version
14+
uint32 version = 3;
15+
// Progress categories
16+
repeated ReportCategory categories = 4;
17+
}
18+
19+
// Progress info for a report or unit
20+
message Measures {
21+
// Overall match percent, including partially matched functions and data
22+
float fuzzy_match_percent = 1;
23+
// Total size of code in bytes
24+
uint64 total_code = 2;
25+
// Fully matched code size in bytes
26+
uint64 matched_code = 3;
27+
// Fully matched code percent
28+
float matched_code_percent = 4;
29+
// Total size of data in bytes
30+
uint64 total_data = 5;
31+
// Fully matched data size in bytes
32+
uint64 matched_data = 6;
33+
// Fully matched data percent
34+
float matched_data_percent = 7;
35+
// Total number of functions
36+
uint32 total_functions = 8;
37+
// Fully matched functions
38+
uint32 matched_functions = 9;
39+
// Fully matched functions percent
40+
float matched_functions_percent = 10;
41+
// Completed (or "linked") code size in bytes
42+
uint64 complete_code = 11;
43+
// Completed (or "linked") code percent
44+
float complete_code_percent = 12;
45+
// Completed (or "linked") data size in bytes
46+
uint64 complete_data = 13;
47+
// Completed (or "linked") data percent
48+
float complete_data_percent = 14;
49+
// Total number of units
50+
uint32 total_units = 15;
51+
// Completed (or "linked") units
52+
uint32 complete_units = 16;
53+
}
54+
55+
message ReportCategory {
56+
// The ID of the category
57+
string id = 1;
58+
// The name of the category
59+
string name = 2;
60+
// Progress info for this category
61+
Measures measures = 3;
62+
}
63+
64+
// A unit of the report (usually a translation unit)
65+
message ReportUnit {
66+
// The name of the unit
67+
string name = 1;
68+
// Progress info for this unit
69+
Measures measures = 2;
70+
// Sections within this unit
71+
repeated ReportItem sections = 3;
72+
// Functions within this unit
73+
repeated ReportItem functions = 4;
74+
// Extra metadata for this unit
75+
optional ReportUnitMetadata metadata = 5;
76+
}
77+
78+
// Extra metadata for a unit
79+
message ReportUnitMetadata {
80+
// Whether this unit is marked as complete (or "linked")
81+
optional bool complete = 1;
82+
// The name of the module this unit belongs to
83+
optional string module_name = 2;
84+
// The ID of the module this unit belongs to
85+
optional uint32 module_id = 3;
86+
// The path to the source file of this unit
87+
optional string source_path = 4;
88+
// Progress categories for this unit
89+
repeated string progress_categories = 5;
90+
// Whether this unit is automatically generated (not user-provided)
91+
optional bool auto_generated = 6;
92+
}
93+
94+
// A section or function within a unit
95+
message ReportItem {
96+
// The name of the item
97+
string name = 1;
98+
// The size of the item in bytes
99+
uint64 size = 2;
100+
// The overall match percent for this item
101+
float fuzzy_match_percent = 3;
102+
// Extra metadata for this item
103+
optional ReportItemMetadata metadata = 4;
104+
// Address of the item (section-relative offset)
105+
optional uint64 address = 5;
106+
}
107+
108+
// Extra metadata for an item
109+
message ReportItemMetadata {
110+
// The demangled name of the function
111+
optional string demangled_name = 1;
112+
// The virtual address of the function or section
113+
optional uint64 virtual_address = 2;
114+
}

.github/scripts/report_pb2.py

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/update-progress.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,35 @@ on:
77

88
jobs:
99
update-progress:
10-
if: github.repository == 'GRAnimated/MinecraftLCE'
1110
runs-on: ubuntu-latest
12-
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
version: [1.12.1920.0]
15+
1316
steps:
1417
- name: Checkout code
15-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1619
with:
1720
submodules: true
1821

1922
- name: Set up Python
2023
uses: actions/setup-python@v4
2124
with:
22-
python-version: '3.x'
25+
python-version: '3.11'
2326

2427
- name: Install dependencies
25-
run: pip install capstone colorama cxxfilt pyelftools ansiwrap watchdog python-Levenshtein toml gitpython
26-
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install protobuf capstone colorama cxxfilt pyelftools ansiwrap watchdog python-Levenshtein toml gitpython
31+
2732
- name: Generate progress CSV
2833
run: python tools/common/progress.py -c > progress.csv
2934

35+
- name: Generate report
36+
run: |
37+
PYTHONPATH="${PYTHONPATH}:${{ github.workspace }}/tools" python .github/scripts/gen_report.py -o report.json
38+
3039
- name: Checkout progress repository
3140
uses: actions/checkout@v3
3241
with:
@@ -37,6 +46,12 @@ jobs:
3746
- name: Copy CSV to progress repository
3847
run: cp progress.csv MinecraftLCE-docs/
3948

49+
- name: Upload report
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: ${{ matrix.version }}_report
53+
path: report.json
54+
4055
- name: Update repository description
4156
run: |
4257
IFS=',' read -r version timestamp git_hash num_total code_size_total matching_count matching_code_size equivalent_count equivalent_code_size non_matching_count non_matching_code_size < progress.csv

0 commit comments

Comments
 (0)