mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-20 20:03:07 +02:00
Merge pull request #129 from signalapp/jrose/gen_java_decl-verify
Add a --verify option to gen_java_decl.py
This commit is contained in:
commit
e32862ef24
3
.github/workflows/build_and_test.yml
vendored
3
.github/workflows/build_and_test.yml
vendored
@ -154,6 +154,9 @@ jobs:
|
||||
- name: Install NDK tool
|
||||
run: cargo install cargo-ndk
|
||||
|
||||
- name: Verify that the JNI bindings are up to date
|
||||
run: rust/bridge/jni/bin/gen_java_decl.py --verify
|
||||
|
||||
- name: Build libsignal-client-java
|
||||
run: ./gradlew build
|
||||
working-directory: java
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (C) 2020 Signal Messenger, LLC.
|
||||
// Copyright (C) 2020-2021 Signal Messenger, LLC.
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
//
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (C) 2020 Signal Messenger, LLC.
|
||||
// Copyright (C) 2020-2021 Signal Messenger, LLC.
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
//
|
||||
|
||||
|
@ -1,15 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
#
|
||||
# Copyright (C) 2020 Signal Messenger, LLC.
|
||||
# Copyright (C) 2020-2021 Signal Messenger, LLC.
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
#
|
||||
|
||||
import difflib
|
||||
import os
|
||||
import subprocess
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
# If the command-line handling below gets any more complicated, this should be switched to argparse.
|
||||
def print_usage_and_exit():
|
||||
print('usage: %s [--verify]' % sys.argv[0], file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
mode = None
|
||||
if len(sys.argv) > 2:
|
||||
print_usage_and_exit()
|
||||
elif len(sys.argv) == 2:
|
||||
mode = sys.argv[1]
|
||||
if mode != '--verify':
|
||||
print_usage_and_exit()
|
||||
|
||||
our_abs_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
cbindgen = subprocess.Popen(['cbindgen'], cwd=os.path.join(our_abs_dir, '..'), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
@ -102,6 +118,17 @@ native_java = os.path.join(our_abs_dir, '../../../../java/java/src/main/java/org
|
||||
if not os.access(native_java, os.F_OK):
|
||||
raise Exception("Didn't find Native.java where it was expected")
|
||||
|
||||
fh = open(native_java, 'w')
|
||||
fh.write(contents)
|
||||
fh.close()
|
||||
if not mode:
|
||||
with open(native_java, 'w') as fh:
|
||||
fh.write(contents)
|
||||
elif mode == '--verify':
|
||||
with open(native_java) as fh:
|
||||
current_contents = fh.readlines()
|
||||
diff = difflib.unified_diff(current_contents, contents.splitlines(keepends=True))
|
||||
first_line = next(diff, None)
|
||||
if first_line:
|
||||
sys.stdout.write(first_line)
|
||||
sys.stdout.writelines(diff)
|
||||
sys.exit("error: Native.java not up to date; re-run %s!" % sys.argv[0])
|
||||
else:
|
||||
raise Exception("mode not properly validated")
|
||||
|
Loading…
Reference in New Issue
Block a user