Add even more pre-commit hooks
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Testing passed
|
Commit Message
This adds pre-commit hooks to run gdbarch.py and
make-target-delegates.py. They should be triggered when the
appropriate input files are modified. This patch includes some minor
hacks to the scripts so that they will continue to work if run from
the root directory of the source tree.
---
.pre-commit-config.yaml | 14 ++++++++++++++
gdb/gdbarch.py | 14 +++++++++-----
gdb/make-target-delegates.py | 5 +++++
3 files changed, 28 insertions(+), 5 deletions(-)
@@ -22,3 +22,17 @@ repos:
- id: isort
types_or: [file]
files: 'gdb/.*\.py(\.in)?$'
+ - repo: local
+ hooks:
+ - id: make-target-delegates
+ name: make-target-delegates
+ language: python
+ entry: gdb/make-target-delegates.py
+ files: '^gdb/(make-target-delegates\.py|target\.h)$'
+ - repo: local
+ hooks:
+ - id: gdbarch
+ name: gdbarch
+ language: python
+ entry: gdb/gdbarch.py
+ files: '^gdb/gdbarch.*\.py$'
@@ -19,6 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os
import textwrap
# gdbarch_components is imported only for its side-effect of filling
@@ -33,11 +34,6 @@ def indentation(n_columns: int):
return "\t" * (n_columns // 8) + " " * (n_columns % 8)
-copyright = gdbcopyright.copyright(
- "gdbarch.py", "Dynamic architecture support for GDB, the GNU debugger."
-)
-
-
def info(c: Component):
"Filter function to only allow Info components."
return type(c) is Info
@@ -48,6 +44,14 @@ def not_info(c: Component):
return type(c) is not Info
+# Maybe we're being run from the pre-commit hook.
+if not os.path.exists("gdbarch.h") and os.path.exists("gdb/gdbarch.h"):
+ os.chdir("gdb")
+
+copyright = gdbcopyright.copyright(
+ "gdbarch.py", "Dynamic architecture support for GDB, the GNU debugger."
+)
+
with open("gdbarch-gen.h", "w") as f:
print(copyright, file=f)
print(file=f)
@@ -20,6 +20,7 @@
# Usage:
# make-target-delegates.py
+import os
import re
from typing import Dict, List, TextIO
@@ -341,6 +342,10 @@ def print_class(
delegators: List[str] = []
entries: Dict[str, Entry] = {}
+# Maybe we're being run from the pre-commit hook.
+if not os.path.exists("target.h") and os.path.exists("gdb/target.h"):
+ os.chdir("gdb")
+
for current_line in scan_target_h():
# See comments in scan_target_h. Here we strip away the leading
# and trailing whitespace.