From: Matt Corallo Date: Sun, 26 Sep 2021 04:53:04 +0000 (+0000) Subject: Move version information out of git into new files X-Git-Tag: v0.0.101.1^2~7 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=7c6f77d2bd9bffc95dd79caa0397ec63921b2601;p=ldk-java Move version information out of git into new files --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c15aeb79..d4c0485d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,6 +86,7 @@ jobs: run: ./build-release-jar.sh - name: Check latest headers are in git run: | + git checkout pom.xml git diff --exit-code - name: Check latest library and jars are in bins repo run: | diff --git a/genbindings.py b/genbindings.py index cc63c11a..3733d540 100755 --- a/genbindings.py +++ b/genbindings.py @@ -424,7 +424,7 @@ java_c_types_none_allowed = False # C structs created by cbindgen are declared i with open(f"{sys.argv[3]}/structs/UtilMethods{consts.file_ext}", "a") as util: util.write(consts.util_fn_pfx) -with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: +with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", "w") as out_java: # Map a top-level function def map_fn(line, re_match, ret_arr_len, c_call_string, doc_comment): method_return_type = re_match.group(1) @@ -798,7 +798,9 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: write_c("\treturn tuple->" + e + ";\n") write_c("}\n") - out_java.write(consts.bindings_header.replace('', local_git_version)) + out_java.write(consts.bindings_header) + with open(f"{sys.argv[2]}/version{consts.file_ext}", "w") as out_java_version: + out_java_version.write(consts.bindings_version_file.replace('', local_git_version)) with open(f"{sys.argv[3]}/structs/CommonBase{consts.file_ext}", "w") as out_java_struct: out_java_struct.write(consts.common_base) @@ -1086,9 +1088,11 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDKCResult', 'Result')}{consts.file_ext}", "a") as out_java_struct: out_java_struct.write("}\n") -with open(sys.argv[4], "w") as out_c: - out_c.write(consts.c_file_pfx.replace('', local_git_version)) +with open(f"{sys.argv[4]}/bindings.c.body", "w") as out_c: + out_c.write(consts.c_file_pfx) out_c.write(consts.init_str()) out_c.write(c_file) +with open(f"{sys.argv[4]}/version.c", "w") as out_c: + out_c.write(consts.c_version_file.replace('', local_git_version)) with open(f"{sys.argv[3]}/structs/UtilMethods{consts.file_ext}", "a") as util: util.write(consts.util_fn_sfx) diff --git a/genbindings.sh b/genbindings.sh index 7bf369f5..4cb6502b 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -74,14 +74,14 @@ if [ "$3" = "leaks" ]; then DEBUG_ARG="true" fi if [ "$4" = "true" ]; then - ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/java/org/ldk src/main/jni/bindings.c.body $DEBUG_ARG android $4 + ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl src/main/java/org/ldk src/main/jni/ $DEBUG_ARG android $4 else - ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/java/org/ldk src/main/jni/bindings.c.body $DEBUG_ARG java $4 + ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl src/main/java/org/ldk src/main/jni/ $DEBUG_ARG java $4 fi echo "#define LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ LDKCVec_TransactionOutputsZ" > src/main/jni/bindings.c echo "#define CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free CVec_TransactionOutputsZ_free" >> src/main/jni/bindings.c cat src/main/jni/bindings.c.body >> src/main/jni/bindings.c -javac -h src/main/jni src/main/java/org/ldk/enums/*.java src/main/java/org/ldk/impl/bindings.java +javac -h src/main/jni src/main/java/org/ldk/enums/*.java src/main/java/org/ldk/impl/*.java rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.class IS_MAC=false @@ -162,7 +162,7 @@ fi echo "Creating TS bindings..." mkdir -p ts/{enums,structs} rm -f ts/{enums,structs}/*.ts -./genbindings.py "./lightning.h" ts/bindings.ts ts ts/bindings.c.body $DEBUG_ARG typescript +./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript echo "#define LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ LDKCVec_TransactionOutputsZ" > ts/bindings.c echo "#define CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free CVec_TransactionOutputsZ_free" >> ts/bindings.c cat ts/bindings.c.body >> ts/bindings.c diff --git a/java_strings.py b/java_strings.py index 357c32ea..b93677aa 100644 --- a/java_strings.py +++ b/java_strings.py @@ -24,6 +24,7 @@ class Consts: self.bindings_header = """package org.ldk.impl; import org.ldk.enums.*; +import org.ldk.impl.version; import java.io.File; import java.io.InputStream; import java.io.IOException; @@ -64,7 +65,7 @@ public class bindings { } init(java.lang.Enum.class, VecOrSliceDef.class); init_class_cache(); - if (!get_lib_version_string().equals(get_ldk_java_bindings_version())) + if (!get_lib_version_string().equals(version.get_ldk_java_bindings_version())) throw new IllegalArgumentException("Compiled LDK library and LDK class failes do not match"); // Fetching the LDK versions from C also checks that the header and binaries match get_ldk_c_bindings_version(); @@ -74,9 +75,6 @@ public class bindings { static native void init_class_cache(); static native String get_lib_version_string(); - public static String get_ldk_java_bindings_version() { - return ""; - } public static native String get_ldk_c_bindings_version(); public static native String get_ldk_version(); @@ -93,6 +91,13 @@ public class bindings { public static native long new_empty_slice_vec(); """ + self.bindings_version_file = """package org.ldk.impl; + +public class version { + public static String get_ldk_java_bindings_version() { + return ""; + } +}""" self.bindings_footer = "}\n" @@ -461,16 +466,17 @@ static inline LDKStr java_to_owned_str(JNIEnv *env, jstring str) { return res; } -JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1lib_1version_1string(JNIEnv *env, jclass _c) { - return str_ref_to_java(env, "", strlen("")); -} JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1ldk_1c_1bindings_1version(JNIEnv *env, jclass _c) { return str_ref_to_java(env, check_get_ldk_bindings_version(), strlen(check_get_ldk_bindings_version())); } JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1ldk_1version(JNIEnv *env, jclass _c) { return str_ref_to_java(env, check_get_ldk_version(), strlen(check_get_ldk_version())); } +#include "version.c" """ + self.c_version_file = """JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1lib_1version_1string(JNIEnv *env, jclass _c) { + return str_ref_to_java(env, "", strlen("")); +}""" self.hu_struct_file_prefix = """package org.ldk.structs; diff --git a/pom.xml b/pom.xml index 833b75e9..5f5342d3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.lightningdevkit ldk-java - 0.0.101.0 + Set in genbindings.sh automagically LDK Java Bindings and Binaries LDK Java Bindings and Release Binaries diff --git a/typescript_strings.py b/typescript_strings.py index f3a7f29a..f823e6cb 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -71,6 +71,8 @@ public static native long new_empty_slice_vec(); """ + self.bindings_version_file = "" + self.bindings_footer = """ export async function initializeWasm(allowDoubleInitialization: boolean = false): Promise { if(isWasmInitialized && !allowDoubleInitialization) { @@ -261,6 +263,8 @@ void __attribute__((visibility("default"))) TS_free(uint32_t ptr) { } """ + self.c_version_file = "" + self.hu_struct_file_prefix = f""" import CommonBase from './CommonBase'; import * as bindings from '../bindings' // TODO: figure out location