Skip to content

Commit 7746648

Browse files
authored
[Auto-Sync] LLVM 18 update (#2296)
Refactor auto-sync updater This refactors the auto-sync updater scripts, adds multiple tests and some other smaller things: - Converts the updater in a proper Python package. - Renaming was done to fit this new package structure. - Format code with usort and black and enforce it with the CI. - Add license information to auto-sync scripts. - Update tree-sitter-cpp to v20.0.5 - Fix py-tree-sitter version to `< 0.22.0` due to tree-sitter/tree-sitter-cpp#250 - Allow file/dir creation of non existing paths. - Add CI tests for Patch, inc gen, translation and diff persistence testing. - Implement editing of diffs with an editor. - Fix: Add Namespace id also to anonymous enumeration members.
1 parent 24d99a9 commit 7746648

File tree

104 files changed

+2395
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2395
-549
lines changed

.github/workflows/auto-sync.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Auto-Sync
2+
on:
3+
push:
4+
paths:
5+
- "suite/auto-sync/**"
6+
pull_request:
7+
8+
jobs:
9+
check:
10+
runs-on: ubuntu-latest
11+
defaults:
12+
run:
13+
working-directory: suite/auto-sync/
14+
steps:
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.11'
19+
20+
- name: Check out repository
21+
uses: actions/checkout@v4
22+
with:
23+
submodules: true
24+
25+
- name: Install auto-sync package
26+
run: |
27+
pip install .
28+
29+
- name: Check formatting
30+
run: |
31+
python3.11 -m black --check src/autosync
32+
33+
- name: Build llvm-tblgen
34+
run: |
35+
git clone https://github.com/capstone-engine/llvm-capstone.git vendor/llvm_root
36+
cd vendor/llvm_root
37+
mkdir build
38+
cd build
39+
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm
40+
cmake --build . --target llvm-tblgen --config Debug
41+
cd ../../../
42+
43+
- name: Test generation of inc files
44+
run: |
45+
./src/autosync/ASUpdater.py -d -a AArch64 -s IncGen
46+
./src/autosync/ASUpdater.py -d -a Alpha -s IncGen
47+
./src/autosync/ASUpdater.py -d -a ARM -s IncGen
48+
./src/autosync/ASUpdater.py -d -a PPC -s IncGen
49+
50+
- name: CppTranslator - Patch tests
51+
run: |
52+
python -m unittest src/autosync/cpptranslator/Tests/test_patches.py
53+
54+
- name: CppTranslator - Differ tests
55+
run: |
56+
python -m unittest src/autosync/cpptranslator/Tests/test_differ.py
57+
58+
- name: CppTranslator - Test translation
59+
run: |
60+
./src/autosync/ASUpdater.py --ci -d -a AArch64 -s Translate
61+
./src/autosync/ASUpdater.py --ci -d -a ARM -s Translate
62+
./src/autosync/ASUpdater.py --ci -d -a PPC -s Translate
63+
64+
- name: Test Header patcher
65+
run: |
66+
python -m unittest src/autosync/Tests/test_header_patcher.py

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,6 @@ android-ndk-*
143143

144144
# python virtual env
145145
.venv/
146+
147+
# Auto-sync files
148+
suite/auto-sync/src/autosync.egg-info

.reuse/dep5

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: CapstoneEngine
3+
Source: https://github.com/capstone-engine/capstone
4+
5+
Files: src/autosync/cpptranslator/Tests/test_config.json
6+
Copyright: 2022 Rot127 <[email protected]>
7+
License: BSD-3
8+
9+
Files: src/autosync/cpptranslator/arch_config.json
10+
Copyright: 2022 Rot127 <[email protected]>
11+
License: BSD-3
12+
13+
Files: src/autosync/cpptranslator/saved_patches.json
14+
Copyright: 2022 Rot127 <[email protected]>
15+
License: BSD-3
16+
17+
Files: src/autosync/path_vars.json
18+
Copyright: 2022 Rot127 <[email protected]>
19+
License: BSD-3
20+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% for copyright_line in copyright_lines %}
2+
{{ copyright_line }}
3+
{% endfor %}
4+
{% for contributor_line in contributor_lines %}
5+
SPDX-FileContributor: {{ contributor_line }}
6+
{% endfor %}
7+
{% for expression in spdx_expressions %}
8+
SPDX-License-Identifier: {{ expression }}
9+
{% endfor %}
File renamed without changes.

LICENSES/LICENSE_BSD_3_CLAUSE.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright (c) <year> <owner>.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
5+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
7+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8+
9+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10+
11+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File renamed without changes.

bindings/python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def copy_sources():
9696
src.extend(glob.glob(os.path.join(BUILD_DIR, "*.mk")))
9797

9898
src.extend(glob.glob(os.path.join(BUILD_DIR, "Makefile")))
99-
src.extend(glob.glob(os.path.join(BUILD_DIR, "LICENSE*")))
99+
src.extend(glob.glob(os.path.join(BUILD_DIR, "LICENSES/*")))
100100
src.extend(glob.glob(os.path.join(BUILD_DIR, "README")))
101101
src.extend(glob.glob(os.path.join(BUILD_DIR, "*.TXT")))
102102
src.extend(glob.glob(os.path.join(BUILD_DIR, "RELEASE_NOTES")))

dev_requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

suite/auto-sync/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
build/
22
vendor/llvm_root
33
*/.idea
4-
Updater/config.json
4+
src/auto-sync/config.json
5+
src/autosync/cpptranslator/Tests/Differ/test_saved_patches.json
6+
src/autosync.egg-info
57

suite/auto-sync/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
<!--
2+
Copyright © 2022 Rot127 <[email protected]>
3+
Copyright © 2024 2022 Rot127 <[email protected]>
4+
SPDX-License-Identifier: BSD-3
5+
-->
6+
17
# Architecture updater
28

39
This is Capstones updater for some architectures.
410
Unfortunately not all architectures are supported yet.
511

612
## Install dependencies
713

8-
Install clang-format
9-
10-
```
11-
sudo apt install clang-format-18
12-
```
13-
1414
Setup Python environment and Tree-sitter
1515

1616
```
@@ -20,28 +20,28 @@ sudo apt install python3-venv
2020
# Setup virtual environment in Capstone root dir
2121
python3 -m venv ./.venv
2222
source ./.venv/bin/activate
23-
pip3 install -r dev_requirements.txt
2423
```
2524

2625
Clone C++ grammar
2726

2827
```
2928
cd suite/auto-sync/
3029
git submodule update --init --recursive ./vendor/
30+
pip install -e .
3131
```
3232

3333
## Update
3434

3535
Check if your architecture is supported.
3636

3737
```
38-
./Updater/ASUpdater.py -h
38+
./src/autosync/ASUpdater.py -h
3939
```
4040

4141
Clone Capstones LLVM fork and build `llvm-tblgen`
4242

4343
```
44-
git clone https://github.com/capstone-engine/llvm-capstone
44+
git clone https://github.com/capstone-engine/llvm-capstone vendor/llvm_root/
4545
cd llvm-capstone
4646
git checkout auto-sync
4747
mkdir build
@@ -55,7 +55,7 @@ cd ../../
5555
Run the updater
5656

5757
```
58-
./Updater/ASUpdater.py -a <ARCH>
58+
./src/autosync/ASUpdater.py -a <ARCH>
5959
```
6060

6161
## Post-processing steps

suite/auto-sync/Updater/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

suite/auto-sync/Updater/PathVarHandler.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

suite/auto-sync/Updater/README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

suite/auto-sync/Updater/path_vars.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

suite/auto-sync/Updater/requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

suite/auto-sync/format_py.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/bash
2+
3+
python3.11 -m usort format src/autosync
4+
python3.11 -m black src/autosync

suite/auto-sync/pyproject.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright © 2022 Rot127 <[email protected]>
2+
# Copyright © 2024 2022 Rot127 <[email protected]>
3+
# SPDX-License-Identifier: BSD-3
4+
5+
[project]
6+
name = "autosync"
7+
version = "0.1.0"
8+
dependencies = [
9+
"termcolor >= 2.3.0",
10+
"tree_sitter < 0.22.0",
11+
"black >= 24.3.0",
12+
"usort >= 1.0.8",
13+
"setuptools >= 69.2.0",
14+
"ninja >= 1.11.1.1",
15+
"cmake >= 3.28.3",
16+
"reuse >= 3.0.1",
17+
"clang-format >= 18.1.1",
18+
]
19+
requires-python = ">= 3.11"
20+
21+
[tool.setuptools]
22+
packages = ["autosync", "autosync.cpptranslator", "autosync.cpptranslator.patches"]
23+
package-dir = {"" = "src"}

0 commit comments

Comments
 (0)