Skip to content

Commit

Permalink
[Auto-Sync] LLVM 18 update (#2296)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Rot127 authored Apr 22, 2024
1 parent 24d99a9 commit 7746648
Show file tree
Hide file tree
Showing 104 changed files with 2,395 additions and 549 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/auto-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Auto-Sync
on:
push:
paths:
- "suite/auto-sync/**"
pull_request:

jobs:
check:
runs-on: ubuntu-latest
defaults:
run:
working-directory: suite/auto-sync/
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Check out repository
uses: actions/checkout@v4
with:
submodules: true

- name: Install auto-sync package
run: |
pip install .
- name: Check formatting
run: |
python3.11 -m black --check src/autosync
- name: Build llvm-tblgen
run: |
git clone https://github.com/capstone-engine/llvm-capstone.git vendor/llvm_root
cd vendor/llvm_root
mkdir build
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm
cmake --build . --target llvm-tblgen --config Debug
cd ../../../
- name: Test generation of inc files
run: |
./src/autosync/ASUpdater.py -d -a AArch64 -s IncGen
./src/autosync/ASUpdater.py -d -a Alpha -s IncGen
./src/autosync/ASUpdater.py -d -a ARM -s IncGen
./src/autosync/ASUpdater.py -d -a PPC -s IncGen
- name: CppTranslator - Patch tests
run: |
python -m unittest src/autosync/cpptranslator/Tests/test_patches.py
- name: CppTranslator - Differ tests
run: |
python -m unittest src/autosync/cpptranslator/Tests/test_differ.py
- name: CppTranslator - Test translation
run: |
./src/autosync/ASUpdater.py --ci -d -a AArch64 -s Translate
./src/autosync/ASUpdater.py --ci -d -a ARM -s Translate
./src/autosync/ASUpdater.py --ci -d -a PPC -s Translate
- name: Test Header patcher
run: |
python -m unittest src/autosync/Tests/test_header_patcher.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@ android-ndk-*

# python virtual env
.venv/

# Auto-sync files
suite/auto-sync/src/autosync.egg-info
20 changes: 20 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: CapstoneEngine
Source: https://github.com/capstone-engine/capstone

Files: src/autosync/cpptranslator/Tests/test_config.json
Copyright: 2022 Rot127 <[email protected]>
License: BSD-3

Files: src/autosync/cpptranslator/arch_config.json
Copyright: 2022 Rot127 <[email protected]>
License: BSD-3

Files: src/autosync/cpptranslator/saved_patches.json
Copyright: 2022 Rot127 <[email protected]>
License: BSD-3

Files: src/autosync/path_vars.json
Copyright: 2022 Rot127 <[email protected]>
License: BSD-3

9 changes: 9 additions & 0 deletions .reuse/templates/license-template.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% for copyright_line in copyright_lines %}
{{ copyright_line }}
{% endfor %}
{% for contributor_line in contributor_lines %}
SPDX-FileContributor: {{ contributor_line }}
{% endfor %}
{% for expression in spdx_expressions %}
SPDX-License-Identifier: {{ expression }}
{% endfor %}
File renamed without changes.
11 changes: 11 additions & 0 deletions LICENSES/LICENSE_BSD_3_CLAUSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) <year> <owner>.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

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.

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.

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.
2 changes: 1 addition & 1 deletion bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def copy_sources():
src.extend(glob.glob(os.path.join(BUILD_DIR, "*.mk")))

src.extend(glob.glob(os.path.join(BUILD_DIR, "Makefile")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "LICENSE*")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "LICENSES/*")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "README")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "*.TXT")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "RELEASE_NOTES")))
Expand Down
4 changes: 0 additions & 4 deletions dev_requirements.txt

This file was deleted.

4 changes: 3 additions & 1 deletion suite/auto-sync/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
build/
vendor/llvm_root
*/.idea
Updater/config.json
src/auto-sync/config.json
src/autosync/cpptranslator/Tests/Differ/test_saved_patches.json
src/autosync.egg-info

20 changes: 10 additions & 10 deletions suite/auto-sync/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!--
Copyright © 2022 Rot127 <[email protected]>
Copyright © 2024 2022 Rot127 <[email protected]>
SPDX-License-Identifier: BSD-3
-->

# Architecture updater

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

## Install dependencies

Install clang-format

```
sudo apt install clang-format-18
```

Setup Python environment and Tree-sitter

```
Expand All @@ -20,28 +20,28 @@ sudo apt install python3-venv
# Setup virtual environment in Capstone root dir
python3 -m venv ./.venv
source ./.venv/bin/activate
pip3 install -r dev_requirements.txt
```

Clone C++ grammar

```
cd suite/auto-sync/
git submodule update --init --recursive ./vendor/
pip install -e .
```

## Update

Check if your architecture is supported.

```
./Updater/ASUpdater.py -h
./src/autosync/ASUpdater.py -h
```

Clone Capstones LLVM fork and build `llvm-tblgen`

```
git clone https://github.com/capstone-engine/llvm-capstone
git clone https://github.com/capstone-engine/llvm-capstone vendor/llvm_root/
cd llvm-capstone
git checkout auto-sync
mkdir build
Expand All @@ -55,7 +55,7 @@ cd ../../
Run the updater

```
./Updater/ASUpdater.py -a <ARCH>
./src/autosync/ASUpdater.py -a <ARCH>
```

## Post-processing steps
Expand Down
2 changes: 0 additions & 2 deletions suite/auto-sync/Updater/.gitignore

This file was deleted.

67 changes: 0 additions & 67 deletions suite/auto-sync/Updater/PathVarHandler.py

This file was deleted.

7 changes: 0 additions & 7 deletions suite/auto-sync/Updater/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions suite/auto-sync/Updater/path_vars.json

This file was deleted.

2 changes: 0 additions & 2 deletions suite/auto-sync/Updater/requirements.txt

This file was deleted.

4 changes: 4 additions & 0 deletions suite/auto-sync/format_py.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/bash

python3.11 -m usort format src/autosync
python3.11 -m black src/autosync
23 changes: 23 additions & 0 deletions suite/auto-sync/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright © 2022 Rot127 <[email protected]>
# Copyright © 2024 2022 Rot127 <[email protected]>
# SPDX-License-Identifier: BSD-3

[project]
name = "autosync"
version = "0.1.0"
dependencies = [
"termcolor >= 2.3.0",
"tree_sitter < 0.22.0",
"black >= 24.3.0",
"usort >= 1.0.8",
"setuptools >= 69.2.0",
"ninja >= 1.11.1.1",
"cmake >= 3.28.3",
"reuse >= 3.0.1",
"clang-format >= 18.1.1",
]
requires-python = ">= 3.11"

[tool.setuptools]
packages = ["autosync", "autosync.cpptranslator", "autosync.cpptranslator.patches"]
package-dir = {"" = "src"}
Loading

0 comments on commit 7746648

Please sign in to comment.