]> git.bitcoin.ninja Git - ldk-java/commitdiff
Move version information out of git into new files
authorMatt Corallo <git@bluematt.me>
Sun, 26 Sep 2021 04:53:04 +0000 (04:53 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 27 Sep 2021 00:44:18 +0000 (00:44 +0000)
.github/workflows/build.yml
genbindings.py
genbindings.sh
java_strings.py
pom.xml
typescript_strings.py

index c15aeb79d5c01d3569c1c2412e86c74fcc921b7f..d4c0485d67fde3b33103d58d6c6b0340b22aab3c 100644 (file)
@@ -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: |
index cc63c11aa3b8b276b140e09816c9804dcdb8d457..3733d540bc06f95e65e2221a9b458e83be29a862 100755 (executable)
@@ -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('<git_version_ldk_garbagecollected>', 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('<git_version_ldk_garbagecollected>', 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('<git_version_ldk_garbagecollected>', 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('<git_version_ldk_garbagecollected>', local_git_version))
 with open(f"{sys.argv[3]}/structs/UtilMethods{consts.file_ext}", "a") as util:
     util.write(consts.util_fn_sfx)
index 7bf369f5a4df3da54304d90f9515063275d2bb85..4cb6502b4235b18bd6a53c5c3fe7bcd53e4b3803 100755 (executable)
@@ -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
index 357c32eaaaf20083cb4ba4cdcc9e09d35db1f6b2..b93677aa87e0a900c63d4b3ecbe1ac7f5ddf8cd4 100644 (file)
@@ -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 "<git_version_ldk_garbagecollected>";
-       }
        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 "<git_version_ldk_garbagecollected>";
+       }
+}"""
 
         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, "<git_version_ldk_garbagecollected>", strlen("<git_version_ldk_garbagecollected>"));
-}
 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, "<git_version_ldk_garbagecollected>", strlen("<git_version_ldk_garbagecollected>"));
+}"""
 
         self.hu_struct_file_prefix = """package org.ldk.structs;
 
diff --git a/pom.xml b/pom.xml
index 833b75e9cea72473ce876539874786dc66c27c51..5f5342d340503377b403fffaf8bab358635ac035 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
 
     <groupId>org.lightningdevkit</groupId>
     <artifactId>ldk-java</artifactId>
-    <version>0.0.101.0</version>
+    <version>Set in genbindings.sh automagically</version>
 
     <name>LDK Java Bindings and Binaries</name>
     <description>LDK Java Bindings and Release Binaries</description>
index f3a7f29adcd6fa5879a23e532aacbece19e65dbd..f823e6cb7274ecfe81907d7ecc85fdd604dfb273 100644 (file)
@@ -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<void> {
             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